/
lib_Monitor.js.html
854 lines (756 loc) · 29.5 KB
/
lib_Monitor.js.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>lib/Monitor.js - monitor</title>
<link rel="stylesheet" href="../assets/css/cssgrids-min.css">
<link rel="stylesheet" href="../assets/vendor/prettify/prettify-min.css">
<link rel="stylesheet" href="../assets/css/main.css" id="site_styles">
<link rel="stylesheet" href="../assets/css/combo-min.css" id="site_styles">
<script src="../assets/js/yui-min.js"></script>
<script src="../assets/js/combo-min.js"></script>
</head>
<body class="yui3-skin-sam">
<div id="doc">
<div id="hd" class="yui3-g header">
<div class="yui3-u-3-4">
<h1><a href="../index.html">Node Monitor</a> <span class="version">v0.6.5</span></h1>
</div>
</div>
<div id="bd" class="yui3-g">
<div class="yui3-u-1-4">
<div id="docs-sidebar" class="sidebar apidocs">
<div id="api-list">
<h2 class="off-left">APIs</h2>
<div id="api-tabview" class="tabview">
<ul class="tabs">
<li><a href="#api-classes">Classes</a></li>
<li><a href="#api-modules">Modules</a></li>
</ul>
<div id="api-tabview-filter">
<input type="search" id="api-filter" placeholder="Type to filter APIs">
</div>
<div id="api-tabview-panel">
<ul id="api-classes" class="apis classes">
<li><a href="../classes/Connection.html">Connection</a></li>
<li><a href="../classes/FileProbe.html">FileProbe</a></li>
<li><a href="../classes/FileSyncProbe.html">FileSyncProbe</a></li>
<li><a href="../classes/InspectProbe.html">InspectProbe</a></li>
<li><a href="../classes/Log.html">Log</a></li>
<li><a href="../classes/LogProbe.html">LogProbe</a></li>
<li><a href="../classes/Monitor.html">Monitor</a></li>
<li><a href="../classes/PollingProbe.html">PollingProbe</a></li>
<li><a href="../classes/Probe.html">Probe</a></li>
<li><a href="../classes/ProcessProbe.html">ProcessProbe</a></li>
<li><a href="../classes/ReplProbe.html">ReplProbe</a></li>
<li><a href="../classes/Router.html">Router</a></li>
<li><a href="../classes/Server.html">Server</a></li>
<li><a href="../classes/Stat.html">Stat</a></li>
<li><a href="../classes/StatProbe.html">StatProbe</a></li>
<li><a href="../classes/StreamProbe.html">StreamProbe</a></li>
<li><a href="../classes/Sync.html">Sync</a></li>
<li><a href="../classes/SyncProbe.html">SyncProbe</a></li>
</ul>
<ul id="api-modules" class="apis modules">
<li><a href="../modules/Monitor.html">Monitor</a></li>
<li><a href="../modules/Probes.html">Probes</a></li>
</ul>
</div>
</div>
</div>
</div>
</div>
<div class="yui3-u-3-4">
<div id="api-options">
Show:
<label for="api-show-inherited">
<input type="checkbox" id="api-show-inherited" checked>
Inherited
</label>
<label for="api-show-protected">
<input type="checkbox" id="api-show-protected">
Protected
</label>
<label for="api-show-private">
<input type="checkbox" id="api-show-private">
Private
</label>
</div>
<div class="apidocs">
<div id="docs-main">
<div class="content">
<h1 class="file-heading">File: lib/Monitor.js</h1>
<div class="file">
<pre class="code prettyprint linenums">
// Monitor.js (c) 2010-2014 Loren West and other contributors
// May be freely distributed under the MIT license.
// For further details and documentation:
// http://lorenwest.github.com/node-monitor
(function(root){
// Module loading
var commonJS = (typeof exports !== 'undefined'),
Backbone = commonJS ? require('backbone') : root.Backbone,
_ = commonJS ? require('underscore')._ : root._,
log = null, stat = null,
Cron = commonJS ? require('cron') : null;
// Constants
var DEFAULT_DEEP_COPY_DEPTH = 4;
/**
* Monitor a remote probe
*
* Monitor objects are the local interface to a remote <a href="Probe.html">Probe</a>.
* The probe may be running in this process or on a remote server.
*
* In a disconnected state, the monitor object contains information about
* the type, attributes, and location of the probe it will monitor.
*
* In a connected state, the monitor object contains the data attributes of
* the probe it is monitoring, and emits change events as the probe changes
* state.
*
* Many monitors may be attached to a single probe. When the probe data model
* changes, changes are broadcast to the connected monitors.
*
* Probes can be remotely controlled using the control() method.
* The control() method acts an RPC in that it accepts input arguments and
* returns results to the monitor initiating the request.
*
* Example:
*
* // Connecting a monitor to a probe
* var processMonitor = new Monitor({
* probeClass: 'Process'
* });
* processMonitor.connect();
*
* // Monitoring the probe
* processMonitor.on('change', function(){
* console.log('Changes:', processMonitor.getChangedAttributes());
* });
*
* // Remote control
* processMonitor.control('ping', function(error, response) {
* console.log('Ping response: ', response);
* });
*
* Monitoring a probe on a remote server requires the ```hostName``` parameter
* to be set.
*
* // Connecting to a remote monitor
* var processMonitor = new Monitor({
* probeClass: 'Process',
* hostName: 'remote-server1'
* });
* processMonitor.connect();
*
* Additional parameters can be set to identify a specific server if many
* servers are running on the specified ```hostName```.
*
* @class Monitor
* @extends Backbone.Model
* @constructor
* @param model - Initial data model. Can be a JS object or another Model.
* @param [model.id] {String} The monitor object id. Set externally.
* @param model.probeClass {String} Class name of the probe this is (or will be) monitoring.
* @param [model.initParams] {Object} Initialization parameters passed to the probe during instantiation.
* @param [model.hostName] {String} Hostname the probe is (or will) run on.
* If not set, the Router will connect with the first host capable of running this probe.
* @param [model.appName] {String} Application name the probe is (or will) run within.
* If not set, the Router will disregard the appName of the process it is connecting with.
* @param [model.appInstance] {String} Application instance ID the probe is (or will) run within.
* If not set, the Router will disregard the appInstance of the process it is connecting with.
* Application instances can (should) set the $NODE_APP_INSTANCE environment
* variable prior to running to uniquely identify their unique instance within a
* server or network. If this variable is not set prior to running the
* app, node-monitor will assign a unique ID among other running apps on the host.
* @param model.probeId {String} ID of the probe this is monitoring (once connected). READONLY
* @param model.PROBE_PARAMS... {(defined by the probe)} ... all other <strong>```model```</strong> parameters are READONLY parameters of the connected probe
*/
/**
* Receive real time notifications from the probe
*
* When the probe data model changes, all changed attributes are forwarded
* to monitors, triggering this event.
*
* All probe attributes are available in the monitor, and the
* getChangedAttributes() method returns the list of attributes changed
* since the last change event.
*
* myMonitor.on('change', function(){
* console.log('Changes:', myMonitor.getChangedAttributes());
* });
*
* @event change
*/
var Monitor = Backbone.Model.extend({
defaults: {
id: '',
name: '',
probeClass: '',
initParams: {},
hostName: '',
appName: '',
appInstance: ''
},
initialize: function(params, options) {
log.info('init', params);
},
/**
* Connect the monitor to the remote probe
*
* Upon connection, the monitor data model is a proxy of the current state
* of the probe.
*
* @method connect
* @param callback {Function(error)} Called when the probe is connected (or error)
*/
/**
* The monitor has successfully connected with the probe
* @event connect
*/
connect: function(callback) {
var t = this, startTime = Date.now();
Monitor.getRouter().connectMonitor(t, function(error) {
// Give the caller first crack at knowing we're connected,
// followed by anyone registered for the connect event.
if (callback) {callback(error);}
// Initial data setting into the model was done silently
// in order for the connect event to fire before the first
// change event. Fire the connect / change in the proper order.
if (!error) {
// An unfortunate side effect is any change listeners registered during
// connect will get triggered with the same values as during connect.
// To get around this, add change listeners from connect on nextTick.
t.trigger('connect', t);
t.trigger('change', t);
log.info('connected', {initParams: t.get('initParams'), probeId: t.get('probeId')});
stat.time('connect', Date.now() - startTime);
}
});
},
/**
* Get the connection to the remote probe
*
* This method returns the Connection object that represents the remote
* server used for communicating with the connected probe.
*
* If the probe is running internally or the monitor isn't currently
* connected, this will return null.
*
* @method getConnection
* @return connection {Connection} The connection object
*/
getConnection: function() {
var t = this;
return (t.probe && t.probe.connection ? t.probe.connection : null);
},
/**
* Is the monitor currently connected?
*
* @method isConnected
* @return {boolean} True if the monitor is currently connected
*/
isConnected: function() {
var t = this;
return (t.probe != null);
},
/**
* Disconnect from the remote probe
*
* This should be called when the monitor is no longer needed.
* It releases resources associated with monitoring the probe.
*
* If this was the last object monitoring the probe, the probe will be
* stopped, releasing resources associated with running the probe.
*
* @method disconnect
* @param callback {Function(error)} Called when disconnected (or error)
*/
/**
* The monitor has disconnected from the probe
* @event disconnect
* @param reason {String} Reason specified for the disconnect
* <ul>Known Reasons:
* <li>manual_disconnect - A manual call to disconnect() was made.</li>
* <li>connect_failed - Underlying transport connection problem.</li>
* <li>remote_disconnect - Underlying transport disconnected.</li>
* </ul>
*/
disconnect: function(callback) {
var t = this,
reason = 'manual_disconnect',
startTime = Date.now(),
probeId = t.get('probeId');
Monitor.getRouter().disconnectMonitor(t, reason, function(error, reason) {
if (callback) {callback(error);}
if (error) {
log.error('disconnect', {error: error});
}
else {
t.trigger('disconnect', reason);
log.info('disconnected', {reason: reason, probeId: probeId});
stat.time('disconnect', Date.now() - startTime);
}
});
},
/**
* Send a control message to the probe.
*
* Monitors can use this method to send a message and receive a response
* from a connected probe.
*
* The probe must implement the specified control method. All probes are
* derived from the base <a href="Probe.html">Probe</a> class, which offers
* a ping control.
*
* To send a ping message to a probe and log the results:
*
* var myMonitor.control('ping', console.log);
*
* @method control
* @param name {String} Name of the control message.
* @param [params] {Object} Named input parameters specific to the control message.
* @param [callback] {Function(error, response)} Function to call upon return.
* <ul>
* <li>error (Any) - An object describing an error (null if no errors)</li>
* <li>response (Any) - Response parameters specific to the control message.</li>
* </ul>
*/
control: function(name, params, callback) {
var t = this,
probe = t.probe,
logId = 'control.' + t.get('probeClass') + '.' + name,
startTime = Date.now();
// Switch callback if sent in 2nd arg
if (typeof params === 'function') {
callback = params;
params = null;
}
log.info(logId, params);
var whenDone = function(error, args) {
if (error) {
log.error(logId, error);
}
else {
log.info('return.' + logId, args);
stat.time(logId, Date.now() - startTime);
}
if (callback) {
callback.apply(t, arguments);
}
};
if (!probe) {
return whenDone('Probe not connected');
}
// Send the message internally or to the probe connection
if (probe.connection) {
probe.connection.emit('probe:control', {probeId: t.get('probeId'), name: name, params:params}, whenDone);
} else {
probe.onControl(name, params, whenDone);
}
},
/**
* Produce an object without monitor attributes
*
* A Monitor object contains a union of the connection attributes required for
* a Monitor, and the additional attributes defined by the probe it's monitoring.
*
* This method produces an object containing only the probe portion of
* those attributes.
*
* The id attribute of the returned JSON is set to the probeId from
* the monitor.
*
* @method toProbeJSON
* @param [options] {Object} Options to pass onto the model toJSON
* @return {Object} The probe attributes
*/
toProbeJSON: function(options) {
var t = this,
json = {id: t.get('probeId')};
// Transfer all non-monitor attrs
_.each(t.toJSON(options), function(value, key) {
if (!(key in t.defaults)) {
json[key] = value;
}
});
return json;
},
/**
* Produce an object with the monitor only attributes.
*
* A Monitor object contains a union of the connection attributes required for
* a Monitor, and the additional attributes defined by the probe it's monitoring.
*
* This method produces an object containing only the monitor portion of
* those attributes.
*
* @method toMonitorJSON
* @param [options] {Object} Options to pass onto the model toJSON
* @return {Object} The monitor attributes
*/
toMonitorJSON: function(options) {
var t = this,
json = {};
// Transfer all monitor attrs
_.each(t.toJSON(options), function(value, key) {
if (key in t.defaults) {
json[key] = value;
}
});
return json;
},
/**
* Produce a server string representation of the hostName:appName:appInstance
*
* Depending on the presence of the appName and appInstance, this will produce
* one of the following:
*
* hostName
* hostName:appName
* hostName:appName:appInstance
*
* @method toServerString
* @return {String} A string representation of the monitor server
*/
toServerString: function() {
return Monitor.toServerString(this.toMonitorJSON());
}
});
/////////////////////////
// Static helper methods
/////////////////////////
/**
* Generate a unique UUID-v4 style string
*
* This is a cross-platform UUID implementation used to uniquely identify
* model instances. It is a random number based UUID, and as such can't be
* guaranteed unique.
*
* @static
* @protected
* @method generateUniqueId
* @return {String} A globally unique ID
*/
Monitor.generateUniqueId = function() {
// Generate a 4 digit random hex string
stat.increment('generateUniqueId');
function rhs4() {return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1);}
return (rhs4()+rhs4()+"-"+rhs4()+"-"+rhs4()+"-"+rhs4()+"-"+rhs4()+rhs4()+rhs4());
};
/**
* Generate a unique ID for a collection
*
* This generates an ID to be used for new elements of the collection,
* assuring they don't clash with other elements in the collection.
*
* @method Monitor.generateUniqueCollectionId
* @param collection {Backbone.Collection} The collection to generate an ID for
* @param [prefix] {String} An optional prefix for the id
* @return id {String} A unique ID with the specified prefix
*/
Monitor.generateUniqueCollectionId = function(collection, prefix) {
var id = '';
prefix = prefix || '';
// First time - get the largest idSequence in the collection
if (!collection.idSequence) {
collection.idSequence = 0;
collection.forEach(function(item){
var id = item.get('id') || '',
sequence = +id.substr(prefix.length);
if (collection.idSequence <= sequence) {
collection.idSequence = sequence + 1;
}
});
}
return prefix + collection.idSequence++;
};
/**
* Get the default router (an application singleton)
*
* This instantiates a Router on first call.
*
* @static
* @protected
* @method getRouter
* @return {Router} The default router.
*/
Monitor.getRouter = function() {
// Instantiate a router if no default
if (!Monitor.defaultRouter) {
Monitor.defaultRouter = new Monitor.Router();
// If there's a global socket.io server available,
// then we're running on the browser. Set the default
// gateway to the global io socket.
if (root.io) {
Monitor.defaultRouter.setGateway({
socket:root.io.connect()
});
}
}
// Return the router
return Monitor.defaultRouter;
};
/**
* Start a monitor server in this process
*
* This is a shortand for the following:
*
* var Monitor = require('monitor');
* var server = new Monitor.Server();
* server.start();
*
* It can be chained like this:
*
* var Monitor = require('monitor').start(),
* log = Monitor.getLogger('my-app');
*
* For more fine-tuned starting, see the <a href="Server.html">Server</a> api.
*
* @static
* @method start
* @param options {Object} - Server.start() options. OPTIONAL
* @param options.port {Integer} - Port to attempt listening on if server isn't specified. Default: 42000
* @param callback {Function(error)} - Called when the server is accepting connections.
* @return monitor {Monitor} - Returns the static Monitor class (for chaining)
*/
Monitor.start = function(options, callback) {
log.info('start', options);
// Get a default monitor
if (!Monitor.defaultServer) {
Monitor.defaultServer = new Monitor.Server();
Monitor.defaultServer.start(options, callback);
} else {
callback();
}
return Monitor;
};
/**
* Stop a started monitor server in this process
*
* @static
* @method stop
* @param callback {Function(error)} - Called when the server is accepting connections.
*/
Monitor.stop = function(callback) {
log.info('stop');
if (Monitor.defaultServer) {
Monitor.defaultServer.stop(callback);
delete Monitor.defaultServer;
} else {
callback();
}
};
/**
* Produce a server string representation of the hostName:appName:appInstance
*
* Depending on the presence of the appName and appInstance, this will produce
* one of the following:
*
* hostName
* hostName:appName
* hostName:appName:appInstance
*
* @method toServerString
* @param monitorJSON [Object] JSON object containing the following
* @param hostName {String} The host to monitor
* @param [appName] {String} The app name running on the host
* @param [appInstance] {String} The application instance ID running on the host
* @return {String} A string representation of the monitor server
*/
Monitor.toServerString = function(monitorJSON) {
var str = monitorJSON.hostName;
if (monitorJSON.appName) {
str += ':' + monitorJSON.appName;
if (monitorJSON.appInstance) {
str += ':' + monitorJSON.appInstance;
}
}
return str;
};
/**
* Produce a depth-limited copy of the specified object
*
* Functions are copied for visual inspection purposes - the fact that
* they are a function, and any prototype members. This is so a JSON.stringify
* of the result will show the functions (normally JSON.stringify doesn't output
* functions).
*
* This method is mostly for debugging - for producing a human-readable stream
* representation of the object. It is an exact copy, except for elements of
* type function.
*
* @method deepCopy
* @param value {Mixed} Object or value to copy
* @param [depth=4] {Integer} Maximum depth to return. If the depth exceeds
* this value, the string "[Object]" is returned as the value.
* @return {Mixed} A depth-limited copy of the value
*/
Monitor.deepCopy = function(value, depth) {
// Defaults
depth = typeof(depth) === 'undefined' ? DEFAULT_DEEP_COPY_DEPTH : depth;
// Simple value - return the raw value
if (typeof value !== 'object' && typeof value !== 'function') {
return value;
}
// Build a string representation of the type
var strType = '[Object]';
if (typeof value === 'function') {
strType = '[Function]';
} else if (Array.isArray(value)) {
strType = '[Array]';
}
// Limit reached
if (depth <= 0) {
return strType;
}
// Create a new object to copy into.
// Proactively add constructor so it's at the top of a function
var copy = Array.isArray(value) ? [] : {};
// Copy all elements (by reference)
for (var prop in value) {
if (!value.hasOwnProperty || value.hasOwnProperty(prop)) {
var elem = value[prop];
if (typeof elem === 'object' || typeof elem === 'function') {
copy[prop] = Monitor.deepCopy(elem, depth - 1);
}
else {
copy[prop] = elem;
}
}
}
// Special string formatting for functions
if (typeof value === 'function') {
if (_.isEmpty(copy)) {
// No sub-elements. Identify it as a function.
copy = strType;
} else {
// Sub-elements exist. Identify it as a function by placing
// a constructor at the top of the object
copy = _.extend({constructor: strType},copy);
}
}
// Return the copy
return copy;
};
/**
* Produce a recursion-safe JSON string.
*
* This method recurses the specified object to a maximum specified depth
* (default 4).
*
* It also indents sub-objects for debugging output. The indent level can be
* specified, or set to 0 for no indentation.
*
* This is mostly useful in debugging when the standard JSON.stringify
* returns an error.
*
* @method stringify
* @param value {Mixed} Object or value to turn into a JSON string
* @param [depth=4] {Integer} Maximum depth to return. If the depth exceeds
* this value, the string "[Object]" is returned as the value.
* @param [indent=2] {Integer} Indent the specified number of spaces (0=no indent)
* @return {String} A JSON stringified value
*/
Monitor.stringify = function(value, depth, indent) {
// Defaults
indent = typeof(indent) === 'undefined' ? 2 : indent;
// Return a stringified depth-limited deep copy
return JSON.stringify(Monitor.deepCopy(value, depth), null, indent);
};
/**
* Expose the stat logger class
*
* @protected
* @method setStatLoggerClass
* @param statLoggerClass {Function} Stat logger class to expose
*/
Monitor.setStatLoggerClass = function(StatLoggerClass) {
// Build the getStatLogger function
Monitor.getStatLogger = function(module) {
return new StatLoggerClass(module);
};
// Get the logger for the Monitor module
stat = Monitor.getStatLogger('Monitor');
};
/**
* Expose the logger class
*
* @protected
* @method setLoggerClass
* @param loggerClass {Function} Logger class to expose
*/
Monitor.setLoggerClass = function(LoggerClass) {
// Build the getLogger function
Monitor.getLogger = function(module) {
return new LoggerClass(module);
};
// Get the logger for the Monitor module
log = Monitor.getLogger('Monitor');
};
/**
* Constructor for a list of Monitor objects
*
* var myList = new Monitor.List(initialElements);
*
* @static
* @method List
* @param [items] {Array} Initial list items. These can be raw JS objects or Monitor data model objects.
* @return {Backbone.Collection} Collection of Monitor data model objects
*/
Monitor.List = Backbone.Collection.extend({model: Monitor});
// Monitor configurations. If running in a commonJS environment, load the
// configs from the config package. Otherwise just use the defaults.
var defaultConfig = {
appName: 'unknown',
serviceBasePort: 42000,
portsToScan: 20,
allowExternalConnections: false,
consoleLogListener: {
pattern: "{trace,warn,error,fatal}.*"
}
};
if (commonJS) {
Monitor.Config = require('config');
Monitor.Config.setModuleDefaults('Monitor', defaultConfig);
} else {
Monitor.Config = {Monitor: defaultConfig};
}
// Expose external dependencies
Monitor._ = _;
Monitor.Backbone = Backbone;
Monitor.Cron = Cron;
Monitor.commonJS = commonJS;
// Export for both commonJS and the browser
if (commonJS) {
module.exports = Monitor;
} else {
root.Monitor = Monitor;
}
}(this));
</pre>
</div>
</div>
</div>
</div>
</div>
</div>
<div id="ft">
<div class="footer-left">
Copyright © 2010-2014 <a href="https://github.com/lorenwest/node-monitor">Loren West, and other contributors</a>. All rights reserved.
</div>
<div class="footer-right">
Docs generated using <a href="https://github.com/yui/yuidoc">YUIDoc JS</a>
</div>
</div>
</div>
<script src="../assets/vendor/prettify/prettify-min.js"></script>
<script>prettyPrint();</script>
<script src="../assets/js/yui-prettify.js"></script>
<script src="../assets/../api.js"></script>
<script src="../assets/js/api-filter.js"></script>
<script src="../assets/js/api-list.js"></script>
<script src="../assets/js/api-search.js"></script>
<script src="../assets/js/apidocs.js"></script>
</body>
</html>