8 |
--------------------------------------------------------------------------------
/doc/assets/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Redirector
5 |
6 |
7 |
8 | Click here to redirect
9 |
10 |
11 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | Repo Moved
2 | ==========
3 |
4 | This repository has moved to the [Node Monitor](https://github.com/lorenwest/node-monitor) project.
5 |
6 | Monitor-Min is kept here for commit histories.
7 |
8 | [](https://travis-ci.org/lorenwest/monitor-min)
9 |
--------------------------------------------------------------------------------
/config/external.js:
--------------------------------------------------------------------------------
1 | // Configuration overrides when NODE_ENV=external
2 |
3 | // This configuration allows incoming connections from remote systems.
4 | // It should be used only after assuring the network firewall prevents
5 | // untrusted connections on the service port range (usually 42000+).
6 | module.exports = {
7 | MonitorMin: {
8 | allowExternalConnections: true
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/yuidoc.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "monitor-min",
3 | "description": "Monitor Min",
4 | "version": "0.0.0",
5 | "year": "2013",
6 | "url": "http://lorenwest.github.com/monitor-min",
7 | "logo": "",
8 | "themedir": "./config/doc",
9 | "options": {
10 | "external": {
11 | },
12 | "linkNatives": "true",
13 | "attributesEmit": "true",
14 | "paths": [
15 | "./lib",
16 | "./test"
17 | ],
18 | "outdir": "./doc"
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/doc/assets/js/yui-prettify.js:
--------------------------------------------------------------------------------
1 | YUI().use('node', function(Y) {
2 | var code = Y.all('.prettyprint.linenums');
3 | if (code.size()) {
4 | code.each(function(c) {
5 | var lis = c.all('ol li'),
6 | l = 1;
7 | lis.each(function(n) {
8 | n.prepend('');
9 | l++;
10 | });
11 | });
12 | var h = location.hash;
13 | location.hash = '';
14 | h = h.replace('LINE_', 'LINENUM_');
15 | location.hash = h;
16 | }
17 | });
18 |
--------------------------------------------------------------------------------
/doc/assets/vendor/prettify/prettify-min.css:
--------------------------------------------------------------------------------
1 | .str{color:#080}.kwd{color:#008}.com{color:#800}.typ{color:#606}.lit{color:#066}.pun{color:#660}.pln{color:#000}.tag{color:#008}.atn{color:#606}.atv{color:#080}.dec{color:#606}ol.linenums{margin-top:0;margin-bottom:0}li.L0,li.L1,li.L2,li.L3,li.L5,li.L6,li.L7,li.L8{list-style:none}li.L1,li.L3,li.L5,li.L7,li.L9{background:#eee}@media print{.str{color:#060}.kwd{color:#006;font-weight:bold}.com{color:#600;font-style:italic}.typ{color:#404;font-weight:bold}.lit{color:#044}.pun{color:#440}.pln{color:#000}.tag{color:#006;font-weight:bold}.atn{color:#404}.atv{color:#060}}
--------------------------------------------------------------------------------
/config/doc/README:
--------------------------------------------------------------------------------
1 | These override from the default yuidoc templates installed globally:
2 |
3 | /usr/local/lib/node_modules/yuidocjs/themes/default
4 |
5 | In order to load locally vs. requiring a network connection (required for developing on the train):
6 |
7 | * Download yui-min.js into assets/js/yui-min.js
8 | * Remove the reference to http://yui.yahooapis.com/
9 | * Download all combo* .js files that it grabs from yahoo -> into assets/js/combo-min.js
10 | * Download all combo* .css files -> into assets/css/combo-min.css
11 | * Download sprite.png -> into assets/css/sprite.png
12 | * Change all sprite.png references from url(http...sprite.png) to url(sprite.png) in combo-min.css
13 | * Edit the main.handlebars to include assets/js/combo-min.js and assets/css/combo-min.css
14 |
15 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Copyright (c) 2010-2013 Loren West and other contributors
2 |
3 | Permission is hereby granted, free of charge, to any person
4 | obtaining a copy of this software and associated documentation
5 | files (the "Software"), to deal in the Software without
6 | restriction, including without limitation the rights to use,
7 | copy, modify, merge, publish, distribute, sublicense, and/or sell
8 | copies of the Software, and to permit persons to whom the
9 | Software is furnished to do so, subject to the following
10 | conditions:
11 |
12 | The above copyright notice and this permission notice shall be
13 | included in all copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
17 | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
19 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22 | OTHER DEALINGS IN THE SOFTWARE.
23 |
--------------------------------------------------------------------------------
/config/doc/partials/index.handlebars:
--------------------------------------------------------------------------------
1 |
18 | Classes in this module represent baseline monitor functionality. They can
19 | be loaded and run in a node.js container as well as within a browser.
20 |
128 |
--------------------------------------------------------------------------------
/lib/probes/ProcessProbe.js:
--------------------------------------------------------------------------------
1 | // ProcessProbe.js (c) 2010-2013 Loren West and other contributors
2 | // May be freely distributed under the MIT license.
3 | // For further details and documentation:
4 | // http://lorenwest.github.com/monitor-min
5 | (function(root){
6 |
7 | // Module loading - this runs server-side only
8 | var util = require('util'), OS = require('os'),
9 | Monitor = root.Monitor || require('../Monitor'), _ = Monitor._,
10 | logger = Monitor.getLogger('ProcessProbe'),
11 | PollingProbe = Monitor.PollingProbe;
12 |
13 | /**
14 | * Probe for attaining process and O/S information
15 | *
16 | * @class ProcessProbe
17 | * @extends PollingProbe
18 | * @constructor
19 | * @param [initParams] {Object} Probe initialization parameters (from PollingProbe)
20 | * @param [initParams.pollInterval] {Integer} Polling interval in milliseconds. Default: null
21 | * @param [initParams.cronPattern] {String} Crontab syle polling pattern. Default once per second: "* * * * * *"
22 | * @param model {Object} Monitor data model elements
23 | * @param model.platform {String} O/S Platform
24 | * @param model.version {String} Node.js compiled-in version
25 | * @param model.installPrefix {String} Node.js installation directory
26 | * @param model.title {String} The current process title (as reported in ps)
27 | * @param model.execPath {String} The path to the current node.js executable
28 | * @param model.argv {Array(String)} Arguments passed on the command line to this process
29 | * @param model.env {Object} Current environment (inherited)
30 | * @param model.cwd {String} Current working directory
31 | * @param model.uptime {Integer} Number of seconds the process has been up (if available)
32 | * @param model.versions {String} Versions of V8 and dependent libraries (if available)
33 | * @param model.arch {String} Processor architecture (if available)
34 | * @param model.gid {Integer} Process group ID
35 | * @param model.uid {Integer} Process user ID
36 | * @param model.pid {Integer} Unique process ID
37 | * @param model.umask {Integer} The process file mode creation mask
38 | * @param model.memoryUsage {Object} An object describing memory usage of the node.js process
39 | * @param model.memoryUsage.rss {Integer} As defined by process.memoryUsage
40 | * @param model.memoryUsage.vsize {Integer} As defined by process.memoryUsage
41 | * @param model.memoryUsage.heapTotal {Integer} As defined by process.memoryUsage
42 | * @param model.memoryUsage.heapUsed {Integer} As defined by process.memoryUsage
43 | * @param model.os {Object} An object containing O/S information
44 | * @param model.os.hostname {String} Name of the host operating system
45 | * @param model.os.type {String} Operating system type
46 | * @param model.os.release {String} O/S Release version
47 | * @param model.os.uptime {String} O/S Uptime in seconds
48 | * @param model.os.loadavg {Array(Number)} An array containing the 1, 5, and 15 minute load averages
49 | * @param model.os.freemem {Integer} Free O/S memory (in bytes)
50 | * @param model.os.totalmem {Integer} Total O/S memory capacity (in bytes)
51 | * @param model.os.cpus {Array(Object)} An array of objects containing information about each CPU/core installed
52 | */
53 | var ProcessProbe = Monitor.ProcessProbe = PollingProbe.extend({
54 |
55 | // These are required for Probes
56 | probeClass: 'Process',
57 |
58 | /* not required
59 | initialize: function(){
60 | var t = this;
61 | PollingProbe.prototype.initialize.apply(t, arguments);
62 | ...
63 | },
64 | release: function() {
65 | var t = this;
66 | PollingProbe.prototype.release.apply(t, arguments);
67 | ... // release any resources held
68 | })
69 | */
70 |
71 | /**
72 | * Poll the probe for changes
73 | *
74 | * This method is called by the parent PollingProbe on the interval specified by the client Monitor.
75 | *
76 | * It polls for process information, and updates the data model with any changes.
77 | *
78 | * @method poll
79 | */
80 | poll: function() {
81 | var t = this,
82 | attrs = _.extend({
83 | platform: process.platform,
84 | version: process.version,
85 | installPrefix: process.installPrefix,
86 | title: process.title,
87 | execPath: process.execPath,
88 | argv: process.argv,
89 | env: process.env,
90 | cwd: process.cwd(),
91 | gid: process.getgid ? process.getgid() : 0,
92 | uid: process.getuid ? process.getuid() : 0,
93 | pid: process.pid,
94 | umask: process.umask(),
95 | hostname: OS.hostname(),
96 | type: OS.type(),
97 | release: OS.release(),
98 | osUptime: OS.uptime(),
99 | loadavg: OS.loadavg(),
100 | freemem: OS.freemem(),
101 | totalmem: OS.totalmem(),
102 | cpus: OS.cpus()
103 | }, process.memoryUsage());
104 | if (process.uptime) {attrs.uptime = process.uptime();}
105 | if (process.versions) {attrs.versions = process.versions;}
106 | if (process.arch) {attrs.arch = process.arch;}
107 | t.set(attrs);
108 | }
109 | });
110 |
111 | }(this));
112 |
--------------------------------------------------------------------------------
/lib/probes/InspectProbe.js:
--------------------------------------------------------------------------------
1 | // InspectProbe.js (c) 2010-2013 Loren West and other contributors
2 | // May be freely distributed under the MIT license.
3 | // For further details and documentation:
4 | // http://lorenwest.github.com/monitor-min
5 |
6 | /* This class is evil. You probably shouldn't use it. Or drink. Or drink while using it. */
7 | /*jslint evil: true */
8 |
9 | (function(root){
10 |
11 | // Module loading - this runs server-side only
12 | var Monitor = root.Monitor || require('../Monitor'),
13 | _ = Monitor._,
14 | Backbone = Monitor.Backbone,
15 | PollingProbe = Monitor.PollingProbe;
16 |
17 | // Constants
18 | var DEFAULT_DEPTH = 2;
19 |
20 | /**
21 | * Inspect and manipulate variables on the monitored server.
22 | *
23 | * This class monitors the variable specified by the key.
24 | *
25 | * The key is evaluated to determine the variable to monitor, so it may
26 | * be a complex key starting at global scope. If the key isn't
27 | * specified, it monitors all variables in the global scope.
28 | *
29 | * If the key points to an object of type Backbone.Model, this probe
30 | * will update the value in real time, triggered on the *change* event.
31 | * Otherwise it will update the value as it notices changes, while polling
32 | * on the specified polling interval (default: 1 second).
33 | *
34 | * @class InspectProbe
35 | * @extends PollingProbe
36 | * @constructor
37 | * @param [initParams] - Initialization parameters
38 | * @param [initParams.key=null] {String} A global variable name or expression
39 | * @param [initParams.depth=2] {Integer} If the key points to an object, this
40 | * is the depth to traverse the object for changes. Default=2, or 1 if
41 | * key='window'.
42 | * @param [initParams.pollInterval] {Integer} (from PollingProbe) Polling interval in milliseconds. Default: null
43 | * @param [initParams.cronPattern] {String} (from PollingProbe) Crontab syle polling pattern. Default once per second: "* * * * * *"
44 | * @param model - Monitor data model elements
45 | * @param model.value - The value of the element being inspected
46 | * @param model.isModel - Is the value a Backbone.Model?
47 | */
48 | var InspectProbe = Monitor.InspectProbe = PollingProbe.extend({
49 |
50 | // These are required for Probes
51 | probeClass: 'Inspect',
52 |
53 | initialize: function(initParams){
54 | var t = this;
55 |
56 | // Get the global object if the key isn't specified
57 | t.key = initParams.key;
58 | if (typeof initParams.key === 'undefined') {
59 | t.key = typeof window === 'undefined' ? 'global' : 'window';
60 | }
61 |
62 | // Get a good depth default. Default unless key = window.
63 | if (typeof initParams.depth === 'undefined') {
64 | if (!initParams.key && t.key === 'window') {
65 | t.depth = 1;
66 | } else {
67 | t.depth = DEFAULT_DEPTH;
68 | }
69 | } else {
70 | t.depth = initParams.depth;
71 | }
72 |
73 | // Evaluate the expression to see if it's a Backbone.Model
74 | // This will throw an exception if the key is a bad expression
75 | t.value = t._evaluate(t.key);
76 | t.isModel = t.value instanceof Backbone.Model;
77 |
78 | // Set the initial values
79 | t.set({
80 | value: Monitor.deepCopy(t.value, t.depth),
81 | isModel: t.isModel
82 | });
83 |
84 | // Watch for backbone model changes, or initialize the polling probe
85 | if (t.isModel) {
86 | t.value.on('change', t.poll, t);
87 | } else {
88 | PollingProbe.prototype.initialize.apply(t, arguments);
89 | }
90 | },
91 |
92 | // Stop watching for change events or polling
93 | release: function() {
94 | var t = this;
95 | if (t.isModel) {
96 | t.value.off('change', t.poll, t);
97 | } else {
98 | PollingProbe.prototype.release.apply(t, arguments);
99 | }
100 | },
101 |
102 | /**
103 | * Evaluate an expression, returning the depth-limited results
104 | *
105 | * @method eval_control
106 | * @param expression {String} Expression to evaluate
107 | * @param [depth=2] {Integer} Depth of the object to return
108 | * @return value {Mixed} Returns the depth-limited value
109 | */
110 | eval_control: function(expression, depth){
111 | var t = this;
112 |
113 | // Determine a default depth
114 | depth = typeof depth === 'undefined' ? DEFAULT_DEPTH : depth;
115 |
116 | // Get the raw value
117 | var value = t._evaluate(expression);
118 |
119 | // Return the depth limited results
120 | return Monitor.deepCopy(value, depth);
121 | },
122 |
123 | /**
124 | * Evaluate an expression, returning the raw results
125 | *
126 | * @protected
127 | * @method _evaluate
128 | * @param expression {String} Expression to evaluate
129 | * @return value {Mixed} Returns the expression value
130 | */
131 | _evaluate: function(expression){
132 | var t = this,
133 | value = null;
134 |
135 | // Evaluate the expression
136 | try {
137 | value = eval(expression);
138 | } catch (e) {
139 | throw new Error('Unable to evaluate: ' + expression);
140 | }
141 |
142 | // Return the value
143 | return value;
144 | },
145 |
146 | /**
147 | * Poll for changes in the evaluation
148 | *
149 | * @method poll
150 | */
151 | poll: function() {
152 | var t = this,
153 | newValue = t.eval_control(t.key, t.depth);
154 |
155 | // Set the new value if it has changed from the current value
156 | if (!_.isEqual(newValue, t.get('value'))) {
157 | t.set({value: newValue});
158 | }
159 | }
160 | });
161 |
162 | }(this));
163 |
--------------------------------------------------------------------------------
/doc/assets/vendor/prettify/CHANGES.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Change Log
5 |
6 |
7 | README
8 |
9 |
Known Issues
10 |
11 |
Perl formatting is really crappy. Partly because the author is lazy and
12 | partly because Perl is
13 | hard to parse.
14 |
On some browsers, <code> elements with newlines in the text
15 | which use CSS to specify white-space:pre will have the newlines
16 | improperly stripped if the element is not attached to the document at the time
17 | the stripping is done. Also, on IE 6, all newlines will be stripped from
18 | <code> elements because of the way IE6 produces
19 | innerHTML. Workaround: use <pre> for code with
20 | newlines.
21 |
22 |
23 |
Change Log
24 |
29 March 2007
25 |
26 |
Added tests for PHP support
27 | to address
28 | issue 3.
30 |
Fixed
31 | bug: prettyPrintOne was not halting. This was not
33 | reachable through the normal entry point.
34 |
Fixed
35 | bug: recursing into a script block or PHP tag that was not properly
37 | closed would not silently drop the content.
38 | (test)
39 |
Fixed bug: / in regex [charsets] should not end regex
62 |
63 |
5 Jul 2008
64 |
65 |
Defined language extensions for Lisp and Lua
66 |
67 |
14 Jul 2008
68 |
69 |
Language handlers for F#, OCAML, SQL
70 |
Support for nocode spans to allow embedding of line
71 | numbers and code annotations which should not be styled or otherwise
72 | affect the tokenization of prettified code.
73 | See the issue 22
74 | testcase.
75 |
76 |
6 Jan 2009
77 |
78 |
Language handlers for Visual Basic, Haskell, CSS, and WikiText
79 |
Added .mxml extension to the markup style handler for
80 | Flex MXML files. See
81 | issue 37.
84 |
Added .m extension to the C style handler so that Objective
85 | C source files properly highlight. See
86 | issue 58.
89 |
Changed HTML lexer to use the same embedded source mechanism as the
90 | wiki language handler, and changed to use the registered
91 | CSS handler for STYLE element content.
92 |
93 |
21 May 2009
94 |
95 |
Rewrote to improve performance on large files.
96 | See benchmarks.
97 |
Fixed bugs with highlighting of Haskell line comments, Lisp
98 | number literals, Lua strings, C preprocessor directives,
99 | newlines in Wiki code on Windows, and newlines in IE6.
100 |
101 |
14 August 2009
102 |
103 |
Fixed prettifying of <code> blocks with embedded newlines.
104 |
105 |
3 October 2009
106 |
107 |
Fixed prettifying of XML/HTML tags that contain uppercase letters.
108 |
A variety of markup formatting fixes courtesy smain and thezbyg.
122 |
Fixed copy and paste in IE[678].
123 |
Changed output to use   instead of
124 | so that the output works when embedded in XML.
125 | Bug
126 | 108.
128 |
129 |
130 |
131 |
--------------------------------------------------------------------------------
/lib/probes/SyncProbe.js:
--------------------------------------------------------------------------------
1 | // SyncProbe.js (c) 2010-2013 Loren West and other contributors
2 | // May be freely distributed under the MIT license.
3 | // For further details and documentation:
4 | // http://lorenwest.github.com/node-monitor
5 | (function(root){
6 |
7 | // Module loading - this runs server-side only
8 | var Monitor = root.Monitor || require('../Monitor'),
9 | _ = Monitor._, Probe = Monitor.Probe;
10 |
11 | /**
12 | * Probe for exposing backbone data models from server-side persistence
13 | *
14 | * This probe is used by the client-side Sync class
15 | * to connect a local backbone model with server-side storage.
16 | *
17 | * It delegates to a specialized SyncProbe defined by the server for the
18 | * specific data class. For example, the server may determine that one class
19 | * type uses FileSyncProbe, and another class uses a different persistence
20 | * mechanism.
21 | *
22 | * For security purposes, the server must configure specific SyncProbes for
23 | * classes, or a default sync probe before this will operate.
24 | *
25 | * @class SyncProbe
26 | * @extends Probe
27 | * @constructor
28 | * @param className {String} Name of the class to synchronize with
29 | * @param [modelId] {String} Id of the data model for live synchronization
30 | * If not set, a non-live probe is set up for control access only.
31 | * @param [model] {Object} If this is a liveSync probe, this contains
32 | * the attributes of the current model object.
33 | */
34 | var SyncProbe = Monitor.SyncProbe = Probe.extend({
35 |
36 | probeClass: 'Sync',
37 | defaults: {
38 | className: null,
39 | modelId: null,
40 | model: null
41 | },
42 |
43 | initialize: function(attributes, options){
44 | var t = this;
45 | Probe.prototype.initialize.apply(t, arguments);
46 |
47 | // Determine the probe name based on the class, and coerce this
48 | // object into one of those by copying all prototype methods.
49 | var className = t.get('className'),
50 | config = SyncProbe.Config,
51 | probeClassName = config.classMap[className] || config.defaultProbe,
52 | probeClass = SyncProbe[probeClassName];
53 | _.each(_.functions(probeClass.prototype), function(methodName) {
54 | t[methodName] = probeClass.prototype[methodName];
55 | });
56 | t.probeClass = probeClass.prototype.probeClass;
57 |
58 | // Forward class initialization to the coerced initialize method
59 | return t.initialize.apply(t, arguments);
60 | },
61 |
62 | release: function() {
63 | var t = this;
64 | Probe.prototype.release.apply(t, arguments);
65 | },
66 |
67 | /**
68 | * Create and save a new instance of the class into storage
69 | *
70 | * This probe control requests a new instance of a data model to be
71 | * persisted onto storage. It is invoked when a data model that has
72 | * the Sync probe attached calls ```save()``` on a new object.
73 | *
74 | * @method create_control
75 | * @param model {Object} Full data model to save. This must contain
76 | * the id element.
77 | * @param callback {Function(error, result)} Callback when complete
78 | * @param callback.error {Mixed} Set if an error occurs during creation.
79 | * @param callback.result {Object} An object containing any differing
80 | * parameters from the model sent in. Normally a blank object.
81 | */
82 | create_control: function(args, callback) {
83 | callback({msg: 'not implemented'});
84 | },
85 |
86 | /**
87 | * Read an instance from storage
88 | *
89 | * This probe control reads the instance with the specified id
90 | * from storage, and returns it in the callback.
91 | *
92 | * @method read_control
93 | * @param id {String} ID of the object to read
94 | * @param callback {Function(error, result)} Callback when complete
95 | * @param callback.error {Mixed} Set if an error occurs during read.
96 | * if error.code === 'NOTFOUND' then the requested object wasn't found.
97 | * if error.code === 'PARSE' then the document was poorly formatted JSON.
98 | * @param callback.result {Object} The full object.
99 | */
100 | read_control: function(args, callback) {
101 | callback({msg: 'not implemented'});
102 | },
103 |
104 | /**
105 | * Update a data model in storage
106 | *
107 | * This acts like a REST PUT, meaning it can create a new object, or
108 | * update an existing object.
109 | *
110 | * Backbone has only a save() method. If the client sets the ID
111 | * of the object before save(), Backbone thinks the object exists and
112 | * will call update vs. create.
113 | *
114 | * @method update_control
115 | * @param model {Object} Full data model to save. This must contain
116 | * the id element.
117 | * @param callback {Function(error, result)} Callback when complete
118 | * @param callback.error {Mixed} Set if an error occurs during save.
119 | * @param callback.result {Object} An object containing any differing
120 | * parameters from the model sent in. Normally a blank object.
121 | */
122 | update_control: function(args, callback) {
123 | callback({msg: 'not implemented'});
124 | },
125 |
126 | /**
127 | * Delete an instance from storage
128 | *
129 | * This probe control deletes the instance with the specified id
130 | * from storage.
131 | *
132 | * @method delete_control
133 | * @param id {String} ID of the object to read
134 | * @param callback {Function(error)} Callback when complete
135 | * @param callback.error {Mixed} Set if an error occurs during read.
136 | */
137 | delete_control: function(args, callback) {
138 | callback({msg: 'not implemented'});
139 | }
140 |
141 | });
142 |
143 | /**
144 | * Static Configurations
145 | *
146 | * These can be set onto the Monitor.SyncProbe class after it's loaded.
147 | *
148 | * The SyncProbe will *not* work until the defaultProbe is defined.
149 | *
150 | * Example:
151 | *
152 | * var syncConfig = Monitor.SyncProbe.Config;
153 | * syncConfig.defaultProbe = 'FileSyncProbe';
154 | * syncConfig.classMap = {
155 | * Book: 'MongoDbSync',
156 | * Author: 'MongoDbSync'
157 | * }
158 | *
159 | * @static
160 | * @property Config
161 | * @type <Object>
162 | *
163 | *
defaultProbe (String) Name of the sync probe to use if the class isn't listed in the classMap
164 | *
classMap (Object) Map of className to sync probe name to use instead of the default for that class
149 | Classes in this module represent baseline monitor functionality. They can
150 | be loaded and run in a node.js container as well as within a browser.
151 |
' +
163 | 'No results found. Maybe you\'ll have better luck with a ' +
164 | 'different query?' +
165 | '
'
166 | );
167 | }
168 |
169 |
170 | focusManager.refresh();
171 | }
172 |
173 | function onTabSelectionChange(e) {
174 | var tab = e.newVal,
175 | name = tab.get('label').toLowerCase();
176 |
177 | tabs.selected = {
178 | index: tab.get('index'),
179 | name : name,
180 | tab : tab
181 | };
182 |
183 | switch (name) {
184 | case 'classes': // fallthru
185 | case 'modules':
186 | filter.setAttrs({
187 | minQueryLength: 0,
188 | queryType : name
189 | });
190 |
191 | search.set('minQueryLength', -1);
192 |
193 | // Only send a request if this isn't the initially-selected tab.
194 | if (e.prevVal) {
195 | filter.sendRequest(filter.get('value'));
196 | }
197 | break;
198 |
199 | case 'everything':
200 | filter.set('minQueryLength', -1);
201 | search.set('minQueryLength', 1);
202 |
203 | if (search.get('value')) {
204 | search.sendRequest(search.get('value'));
205 | } else {
206 | inputNode.focus();
207 | }
208 | break;
209 |
210 | default:
211 | // WTF? We shouldn't be here!
212 | filter.set('minQueryLength', -1);
213 | search.set('minQueryLength', -1);
214 | }
215 |
216 | if (focusManager) {
217 | setTimeout(function () {
218 | focusManager.refresh();
219 | }, 1);
220 | }
221 | }
222 |
223 | function onTabSwitchKey(e) {
224 | var currentTabIndex = tabs.selected.index;
225 |
226 | if (!(e.ctrlKey || e.metaKey)) {
227 | return;
228 | }
229 |
230 | e.preventDefault();
231 |
232 | switch (e.keyCode) {
233 | case 37: // left arrow
234 | if (currentTabIndex > 0) {
235 | tabview.selectChild(currentTabIndex - 1);
236 | inputNode.focus();
237 | }
238 | break;
239 |
240 | case 39: // right arrow
241 | if (currentTabIndex < (Y.Object.size(tabs) - 2)) {
242 | tabview.selectChild(currentTabIndex + 1);
243 | inputNode.focus();
244 | }
245 | break;
246 | }
247 | }
248 |
249 | }, '3.4.0', {requires: [
250 | 'api-filter', 'api-search', 'event-key', 'node-focusmanager', 'tabview'
251 | ]});
252 |
--------------------------------------------------------------------------------
/lib/Probe.js:
--------------------------------------------------------------------------------
1 | // Probe.js (c) 2010-2013 Loren West and other contributors
2 | // May be freely distributed under the MIT license.
3 | // For further details and documentation:
4 | // http://lorenwest.github.com/monitor-min
5 | (function(root){
6 |
7 | // Module loading
8 | var Monitor = root.Monitor || require('./Monitor'),
9 | log = Monitor.getLogger('Probe'),
10 | stat = Monitor.getStatLogger('Probe'),
11 | Cron = Monitor.Cron, _ = Monitor._, Backbone = Monitor.Backbone;
12 |
13 | /**
14 | * A software device used to expose real time data to monitors
15 | *
16 | * This is the base class from which all probe implementations extend.
17 | *
18 | * In order to send probe data to monitors, probe implementations simply set
19 | * their model data using ```set()```. Those changes are detected and propagated
20 | * to all monitors of this probe, firing their change events.
21 | *
22 | * In order to allow remote probe control, probes need only provide a method
23 | * called ```{name}_control()```. See the ```ping_control()``` method as an example,
24 | * and the ```Probe.onControl()``` method for more information.
25 | *
26 | * @class Probe
27 | * @extends Backbone.Model
28 | * @constructor
29 | * @param model - Initial data model. Can be a JS object or another Model.
30 | * @param model.id {String} The probe id.
31 | * Assigned by the Router on probe instantiation.
32 | */
33 | var Probe = Monitor.Probe = Backbone.Model.extend({
34 |
35 | defaults: {
36 | id: null
37 | },
38 |
39 | /**
40 | * Initialize the probe
41 | *
42 | * This is called on the probe during construction. It contains
43 | * the probe initialization attributes and an option to make probe
44 | * construction asynchronous.
45 | *
46 | * Probe implementations can defer the initial response to the monitor until
47 | * the initial state is loaded. This allows the callback on
48 | * ```Monitor.connect()```
49 | * to have the complete initial state of the probe when called.
50 | *
51 | * If the initial probe state cannot be determined in ```initialize```, it should
52 | * set the ```options.asyncInit``` option to ```true```, and call the
53 | * ```options.callback(error)``` once the initial state is determined.
54 | *
55 | * // Asynchronous initialization
56 | * options.asyncInit = true;
57 | * var callback = options.callback
58 | *
59 | * If ```asyncInit``` is set to true, the ```callback``` must be called once
60 | * the initial state of the probe is known (or in an error condition).
61 | *
62 | * // Set the initial state, and call the callback
63 | * this.set(...);
64 | * callback(null);
65 | *
66 | * See the ```initialize```
67 | * method of the FileProbe probe for an example. It defers
68 | * returning the probe to the monitor until the initial file contents are loaded.
69 | *
70 | * @method initialize
71 | * @param attributes {Object} Initial probe attributes sent in from the Monitor
72 | * @param options {Object} Initialization options
73 | * @param options.asyncInit {boolean} Set this to TRUE if the initial probe
74 | * state can't be known immediately.
75 | * @param options.callback {function(error)} The callback to call
76 | * if asyncInit is set to true. If an error is passed, the probe
77 | * will not be used.
78 | */
79 | initialize: function(attributes, options) {
80 | var t = this;
81 | log.info('init', t.toJSON(), options);
82 | },
83 |
84 | /**
85 | * Release any resources consumed by this probe.
86 | *
87 | * This can be implemented by derived classes that need to be informed when
88 | * they are to be shut down.
89 | *
90 | * Probes that listen to events should use this method to remove their
91 | * event listeners.
92 | *
93 | * @method release
94 | */
95 | release: function(){
96 | var t = this;
97 | log.info('release', t.toJSON());
98 | },
99 |
100 | /**
101 | * Dispatch a control message to the appropriate control function.
102 | *
103 | * This is called when the
104 | * ```control()```
105 | * method of a monitor is called.
106 | * The name determines the method name called on the probe.
107 | *
108 | * The probe must implement a method with the name ```{name}_control()```,
109 | * and that method must accept two parameters - an input params and a callback.
110 | * The callback must be called, passing an optional error and response object.
111 | *
112 | * For example, if the probe supports a control with the name ```go```, then
113 | * all it needs to do is implement the ```go_control()``` method with the
114 | * proper signature. See ```ping_control()``` for an example.
115 | *
116 | * @method onControl
117 | * @param name {String} Name of the control message.
118 | * @param [params] {Any} Input parameters specific to the control message.
119 | * @param [callback] {Function(error, response)} Called to send the message (or error) response.
120 | *
121 | *
error (Any) An object describing an error (null if no errors)
122 | *
response (Any) Response parameters specific to the control message.
123 | *
Include the script and stylesheets in your document
26 | (you will need to make sure the css and js file are on your server, and
27 | adjust the paths in the script and link tag)
28 |
Add onload="prettyPrint()" to your
32 | document's body tag.
33 |
Modify the stylesheet to get the coloring you prefer
34 |
35 |
36 |
Usage
37 |
Put code snippets in
38 | <pre class="prettyprint">...</pre>
39 | or <code class="prettyprint">...</code>
40 | and it will automatically be pretty printed.
41 |
42 |
43 |
44 |
The original
45 |
Prettier
46 |
47 |
class Voila {
49 | public:
50 | // Voila
51 | static const string VOILA = "Voila";
52 |
53 | // will not interfere with embedded tags.
54 | }
55 |
56 |
class Voila {
57 | public:
58 | // Voila
59 | static const string VOILA = "Voila";
60 |
61 | // will not interfere with embedded tags.
62 | }
63 |
64 |
65 |
FAQ
66 |
Which languages does it work for?
67 |
The comments in prettify.js are authoritative but the lexer
68 | should work on a number of languages including C and friends,
69 | Java, Python, Bash, SQL, HTML, XML, CSS, Javascript, and Makefiles.
70 | It works passably on Ruby, PHP, VB, and Awk and a decent subset of Perl
71 | and Ruby, but, because of commenting conventions, doesn't work on
72 | Smalltalk, or CAML-like languages.
73 |
74 |
LISPy languages are supported via an extension:
75 | lang-lisp.js.
If you'd like to add an extension for your favorite language, please
96 | look at src/lang-lisp.js and file an
97 | issue including your language extension, and a testcase.
99 |
100 |
How do I specify which language my code is in?
101 |
You don't need to specify the language since prettyprint()
102 | will guess. You can specify a language by specifying the language extension
103 | along with the prettyprint class like so:
104 |
<pre class="prettyprint lang-html">
106 | The lang-* class specifies the language file extensions.
107 | File extensions supported by default include
108 | "bsh", "c", "cc", "cpp", "cs", "csh", "cyc", "cv", "htm", "html",
109 | "java", "js", "m", "mxml", "perl", "pl", "pm", "py", "rb", "sh",
110 | "xhtml", "xml", "xsl".
111 | </pre>
112 |
113 |
It doesn't work on <obfuscated code sample>?
114 |
Yes. Prettifying obfuscated code is like putting lipstick on a pig
115 | — i.e. outside the scope of this tool.
116 |
117 |
Which browsers does it work with?
118 |
It's been tested with IE 6, Firefox 1.5 & 2, and Safari 2.0.4.
119 | Look at the test page to see if it
120 | works in your browser.
Why doesn't Prettyprinting of strings work on WordPress?
126 |
Apparently wordpress does "smart quoting" which changes close quotes.
127 | This causes end quotes to not match up with open quotes.
128 |
This breaks prettifying as well as copying and pasting of code samples.
129 | See
130 | WordPress's help center for info on how to stop smart quoting of code
132 | snippets.
133 |
134 |
How do I put line numbers in my code?
135 |
You can use the linenums class to turn on line
136 | numbering. If your code doesn't start at line number 1, you can
137 | add a colon and a line number to the end of that class as in
138 | linenums:52.
139 |
140 |
// This is line 4.
153 | foo();
154 | bar();
155 | baz();
156 | boo();
157 | far();
158 | faz();
159 |
160 |
161 |
How do I prevent a portion of markup from being marked as code?
162 |
You can use the nocode class to identify a span of markup
163 | that is not code.
164 |
<pre class=prettyprint>
165 | int x = foo(); /* This is a comment <span class="nocode">This is not code</span>
166 | Continuation of comment */
167 | int y = bar();
168 | </pre>
169 | produces
170 |
171 | int x = foo(); /* This is a comment This is not code
172 | Continuation of comment */
173 | int y = bar();
174 |
175 |
176 |
For a more complete example see the issue22
177 | testcase.
178 |
179 |
I get an error message "a is not a function" or "opt_whenDone is not a function"
180 |
If you are calling prettyPrint via an event handler, wrap it in a function.
181 | Instead of doing
182 |