Comparing version 0.6.5 to 0.6.6
@@ -28,2 +28,9 @@ // Default configurations. | ||
// Monitors configured here are started directly upon loading. | ||
// This is an array of objects, each passed as the first parameter | ||
// to a new Monitor instance. | ||
autoStart: [ | ||
// {name: 'ProbeName', probeClass: 'ProbeClass', initParams:{specialized:'initParams'}} | ||
], | ||
// Configure the built-in console log output | ||
@@ -30,0 +37,0 @@ consoleLogListener: { |
@@ -5,2 +5,6 @@ // Configurations for running tests | ||
autoStart: [ | ||
{probeName: 'ProcessTest', probeClass: 'Process', initParams:{pollInterval: 2345}} | ||
], | ||
// Squelch log output so error tests aren't chatty | ||
@@ -7,0 +11,0 @@ consoleLogListener: { |
@@ -1,2 +0,2 @@ | ||
// grunt.js (c) 2010-2013 Loren West and other contributors | ||
// grunt.js (c) 2010-2014 Loren West and other contributors | ||
// May be freely distributed under the MIT license. | ||
@@ -3,0 +3,0 @@ // For all details and documentation: |
@@ -0,1 +1,9 @@ | ||
0.6.6 / 2014-02-21 | ||
=================== | ||
* Named monitor instances | ||
* Auto-start monitors | ||
* Added tests for server start/stop | ||
* Made the example a little less confusing | ||
0.6.5 / 2014-01-06 | ||
@@ -2,0 +10,0 @@ =================== |
@@ -366,2 +366,3 @@ // Connection.js (c) 2010-2014 Loren West and other contributors | ||
var onConnect = function(error, probe) { | ||
if (error) { | ||
@@ -368,0 +369,0 @@ log.error(t.logId + 'probeConnect', error, logCtxt); |
@@ -12,2 +12,3 @@ // Monitor.js (c) 2010-2014 Loren West and other contributors | ||
log = null, stat = null, | ||
autoStartedMonitors = [], | ||
Cron = commonJS ? require('cron') : null; | ||
@@ -110,2 +111,3 @@ | ||
name: '', | ||
probeName: '', | ||
probeClass: '', | ||
@@ -682,2 +684,3 @@ initParams: {}, | ||
// configs from the config package. Otherwise just use the defaults. | ||
// See config/default.js for more information on these configurations. | ||
var defaultConfig = { | ||
@@ -690,3 +693,4 @@ appName: 'unknown', | ||
pattern: "{trace,warn,error,fatal}.*" | ||
} | ||
}, | ||
autoStart: [] | ||
}; | ||
@@ -713,2 +717,18 @@ if (commonJS) { | ||
// Auto-start monitors after loading | ||
var autoStart = Monitor.Config.Monitor.autoStart; | ||
if (autoStart && autoStart.length) { | ||
setTimeout(function(){ | ||
autoStart.forEach(function(params) { | ||
var autoStarted = new Monitor(params); | ||
autoStarted.connect(function(error) { | ||
if (error) { | ||
log.error('autoStart', 'Error auto-starting probe', params, error); | ||
} | ||
}); | ||
autoStartedMonitors.push(autoStarted); | ||
}); | ||
},0); | ||
} | ||
}(this)); |
@@ -244,2 +244,3 @@ // Router.js (c) 2010-2014 Loren West and other contributors | ||
probeJSON = null, | ||
probeName = monitorJSON.probeName, | ||
probeClass = monitorJSON.probeClass, | ||
@@ -250,4 +251,4 @@ startTime = Date.now(), | ||
// Class name must be set | ||
if (!probeClass) { | ||
var errStr = 'probeClass must be set'; | ||
if (!probeClass && !probeName) { | ||
var errStr = 'monitor name or probeClass must be set'; | ||
log.error('connectMonitor', errStr); | ||
@@ -341,2 +342,4 @@ return callback(errStr); | ||
* @param probeJSON {Object} - An object containing: | ||
* @param probeJSON.probeName {String} - The client-defined probe name | ||
* -or- | ||
* @param probeJSON.probeClass {String} - The probe class name (required) | ||
@@ -347,3 +350,10 @@ * @param probeJSON.initParams {Object} - Probe initialization parameters (if any) | ||
buildProbeKey: function(probeJSON) { | ||
var probeKey = probeJSON.probeClass, initParams = probeJSON.initParams; | ||
var probeKey = probeJSON.probeClass, | ||
initParams = probeJSON.initParams; | ||
// Allow probes to be externally identified by name | ||
if (probeJSON.probeName) { | ||
return probeJSON.probeName; | ||
} | ||
if (initParams) { | ||
@@ -381,3 +391,6 @@ _.keys(initParams).sort().forEach(function(key){ | ||
determineConnection: function(monitorJSON, makeNewConnections, callback) { | ||
var t = this, connection = null, probeClass = monitorJSON.probeClass, | ||
var t = this, | ||
connection = null, | ||
probeName = monitorJSON.probeName, | ||
probeClass = monitorJSON.probeClass, | ||
errStr = '', | ||
@@ -429,3 +442,3 @@ hostName = monitorJSON.hostName, | ||
connection.on('error', onError); | ||
return connection.connect(callback); | ||
return connection.connect(); | ||
} | ||
@@ -445,3 +458,3 @@ | ||
// Connect internally if the probe is available | ||
if (Probe.classes[probeClass] != null) { | ||
if (t.runningProbesByKey[probeName] || Probe.classes[probeClass] != null) { | ||
return callback(null, null); | ||
@@ -448,0 +461,0 @@ } |
@@ -1,2 +0,2 @@ | ||
// monitor.js (c) 2010-2013 Loren West and other contributors | ||
// monitor.js (c) 2010-2014 Loren West and other contributors | ||
// May be freely distributed under the MIT license. | ||
@@ -3,0 +3,0 @@ // For further details and documentation: |
{ | ||
"name": "monitor", | ||
"description": "Runtime monitoring for node.js applications", | ||
"version": "0.6.5", | ||
"version": "0.6.6", | ||
"main": "./lib/index.js", | ||
@@ -12,2 +12,3 @@ "author": { | ||
"homepage": "http://lorenwest.github.com/node-monitor/", | ||
"keywords": ["monitor", "node-monitor", "remote control", "realtime", "probe", "JMX"], | ||
"repository": { | ||
@@ -14,0 +15,0 @@ "type": "git", |
@@ -9,4 +9,8 @@ Monitor your Node.js application | ||
Node-monitor is an npm module that lets you monitor your running Node.js app servers. | ||
Node-monitor is a library for remote monitoring and control of your Node.js app servers. | ||
Like JMX in the Java world, node-monitor comes with a handful of general monitors, and allows you to create custom monitors for your application. | ||
These monitors can be scripted using JavaScript, or placed onto a dashboard. | ||
Project Guidelines | ||
@@ -18,3 +22,3 @@ ------------------ | ||
* *Lightweight* - Inactive until used, small footprint during use | ||
* *Flexible* - For custom application monitoring | ||
* *Flexible* - Easy to write custom monitors for your app | ||
* *Stable* - Well tested foundation for module developers | ||
@@ -26,3 +30,3 @@ | ||
Install monitor in your package.json, or run the following from your app server directory | ||
Run the following from your app server directory | ||
@@ -33,3 +37,3 @@ $ npm install monitor | ||
var Monitor = require('monitor').start(); | ||
require('monitor').start(); | ||
@@ -45,2 +49,3 @@ Monitoring your app with a REPL console | ||
> var Monitor = require('monitor'); | ||
undefined | ||
@@ -121,3 +126,3 @@ Now connect a monitor to a probe on your app server. There are a handful of built-in probes, and you can build custom probes for your application or npm module. | ||
The monitor-dashboard project lets you visualize your monitors in a dashboard. | ||
The [monitor-dashboard](https://github.com/lorenwest/monitor-dashboard) application lets you visualize your monitors in a dashboard. | ||
@@ -124,0 +129,0 @@ $ npm install monitor-dashboard |
@@ -12,2 +12,6 @@ // MonitorTest.js (c) 2010-2014 Loren West and other contributors | ||
// This should be run before other tests to set up configurations | ||
process.env.NODE_ENV='test'; | ||
var config = require('config'); | ||
// Dependencies | ||
@@ -21,2 +25,3 @@ var Monitor = require('../lib/index'), | ||
name: 'Test monitor', | ||
probeName: 'NoName', | ||
probeClass: 'NoClass', | ||
@@ -119,2 +124,123 @@ initParams: {a:1}, | ||
/** | ||
* ## Tests for starting up the monitor server | ||
* @method Server | ||
*/ | ||
module.exports['Server'] = { | ||
/** | ||
* Tests that the server starts when requested | ||
* | ||
* @method Server-Start | ||
*/ | ||
Start: function(test) { | ||
Monitor.start(function(error) { | ||
test.equal(error, null, 'No errors on server start'); | ||
var processMonitor = new Monitor({probeClass:'Process', hostName:'localhost'}); | ||
processMonitor.connect(function(error) { | ||
test.equal(error, null, 'No errors on connect'); | ||
var probeId = processMonitor.get('probeId'); | ||
test.ok(probeId, "The probeId is set"); | ||
test.ok(probeId && probeId.length === 36, "The probeId is a uuid"); | ||
test.done(); | ||
}); | ||
}); | ||
}, | ||
/** | ||
* Tests that the server stops when requested | ||
* | ||
* @method Server-Stop | ||
*/ | ||
Stop: function(test) { | ||
Monitor.stop(function(error) { | ||
test.equal(error, null, 'No errors on server stop'); | ||
test.done(); | ||
}); | ||
}, | ||
/** | ||
* Tests that the server can restart after being stopped | ||
* | ||
* @method Server-Restart | ||
*/ | ||
Restart: function(test) { | ||
Monitor.start(function(error) { | ||
test.equal(error, null, 'No errors on server restart'); | ||
Monitor.stop(function(error) { | ||
test.equal(error, null, 'No errors on server re-stop'); | ||
test.done(); | ||
}); | ||
}); | ||
} | ||
}; | ||
/** | ||
* ## Tests for auto-start and named monitors | ||
* @method AutoStart | ||
*/ | ||
module.exports['AutoStart'] = { | ||
/** | ||
* Tests that an auto-start monitor is started on load | ||
* | ||
* @method AutoStart-Starts | ||
*/ | ||
Starts: function(test) { | ||
var runningProbesByKey = Monitor.getRouter().runningProbesByKey; | ||
var autoStartedProbe = null; | ||
for (var key in runningProbesByKey) { | ||
var probeInstance = runningProbesByKey[key]; | ||
// 2345 is the signature polling interval for the test probe | ||
if (probeInstance.get('pollInterval') === 2345) { | ||
autoStartedProbe = probeInstance; | ||
} | ||
} | ||
test.ok(autoStartedProbe, 'The auto started test probe is running'); | ||
test.done(); | ||
}, | ||
/** | ||
* Tests that a local probe can be connected to by name. | ||
* | ||
* @method AutoStart-ConnectLocalByName | ||
*/ | ||
ConnectLocalByName: function(test) { | ||
var testMonitor = new Monitor({probeName:'ProcessTest'}); | ||
testMonitor.connect(function(error) { | ||
if (error) { | ||
console.error('ConnectLocalByName', error); | ||
} | ||
test.equal(error, null, 'No errors on monitor connect'); | ||
test.equal(testMonitor.get('pollInterval'), 2345, 'The named monitor got the correct probe instance'); | ||
test.done(); | ||
}); | ||
}, | ||
/** | ||
* Tests that a remote probe can be connected to by name. | ||
* | ||
* @method AutoStart-ConnectRemoteByName | ||
*/ | ||
ConnectRemoteByName: function(test) { | ||
Monitor.start(function(error) { | ||
test.equal(error, null, 'No errors on server restart'); | ||
var testMonitor = new Monitor({probeName:'ProcessTest', hostName:'localhost'}); | ||
testMonitor.connect(function(error) { | ||
if (error) { | ||
console.error('ConnectRemoteByName', error); | ||
} | ||
test.equal(error, null, 'No errors on monitor connect'); | ||
test.equal(testMonitor.get('pollInterval'), 2345, 'The named monitor got the correct probe instance'); | ||
Monitor.stop(function(error) { | ||
test.equal(error, null, 'No errors on server re-stop'); | ||
test.done(); | ||
}); | ||
}); | ||
}); | ||
} | ||
}; | ||
/** | ||
* ## Tests for the toJSON methods | ||
@@ -121,0 +247,0 @@ * @method JSON |
@@ -5,3 +5,3 @@ { | ||
"version": "0.0.0", | ||
"year": "2013", | ||
"year": "2014", | ||
"url": "http://lorenwest.github.com/node-monitor", | ||
@@ -8,0 +8,0 @@ "logo": "", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
906161
20316
149
37