Image for Watchmen, a simple node.js service monitor.
5.7K
http-head and http-contains are available. Read more about ping services and how to create one below.Check the web interface in action.




Make sure bower is installed globally:
$ npm install -g bower
Get redis from redis.io and install it.
git clone [email protected]:iloire/WatchMen.git
cd WatchMen
$ npm install
Make sure you have redis-server in your PATH. Then you can run watchmen services:
$ redis-server redis.conf
$ node run-monitor-server.js
$ node run-web-server.js
Install pm2:
$ npm install -g pm2
Configure env variables:
$ export WATCHMEN_WEB_PORT=8080
Run servers:
$ pm2 start run-monitor-server.js
$ pm2 start run-web-server.js
Server list:
$ pm2 list

Config is set through env variables.
Have a look at the /config folder for more details, but the general parameters are:
export WATCHMEN_BASE_URL='http://watchmen.letsnode.com'
export WATCHMEN_WEB_PORT='8080'
export WATCHMEN_ADMINS='[email protected]'
export WATCHMEN_GOOGLE_ANALYTICS_ID='your-GA-ID'
Watchmen uses Google Auth through passportjs for authentication. If your google email is present in WATCHMEN_ADMINS env variable, you will be able to manage services.
Make sure you set the right hostname so the OAuth dance can be negociated correctly:
export WATCHMEN_BASE_URL='http://watchmen.letsnode.com/'
You will also need to set the Google client ID and secret using env variables accordingly. (Login into https://console.developers.google.com/ to create them first)
export WATCHMEN_GOOGLE_CLIENT_ID='<your key>'
export WATCHMEN_GOOGLE_CLIENT_SECRET='<your secret>'
https://www.npmjs.com/package/watchmen-ping-http-head
https://www.npmjs.com/package/watchmen-ping-http-contains
Ping services are npm modules with the 'watchmen-ping' prefix.
For example, if you want to create a smtp ping service:
var request = require('request');
function PingService(){}
exports = module.exports = PingService;
PingService.prototype.ping = function(service, callback){
var startTime = +new Date();
request.get({ method: 'HEAD', uri: service.url }, function(error, response, body){
callback(error, body, response, +new Date() - startTime);
});
};
PingService.prototype.getDefaultOptions = function(){
return {}; // there is not need for UI confi options for this ping service
}
npm install watchmen-ping-smtp

### Monitor plugins
https://github.com/iloire/watchmen-plugin-aws-ses
export WATCHMEN_AWS_FROM='your@email'
export WATCHMEN_AWS_REGION='your AWS region'
export WATCHMEN_AWS_KEY='your AWS Key'
export WATCHMEN_AWS_SECRET='your AWS secret'
https://github.com/iloire/watchmen-plugin-console
A watchmen instance will be injected through your plugin constructor. Then you can subscribe to the desired events. Best is to show it through an example.
This what the console plugin looks like:
var colors = require('colors');
var moment = require('moment');
var eventHandlers = {
/**
* On a new outage
* @param service
* @param outage
*/
onNewOutage: function (service, outage) {
var errorMsg = service.name + ' down!'.red + '. Error: ' + JSON.stringify(outage.error).red;
console.log(errorMsg);
},
/**
* Failed ping on an existing outage
* @param service
* @param outage
*/
onCurrentOutage: function (service, outage) {
var errorMsg = service.name + ' is still down!'.red + '. Error: ' + JSON.stringify(outage.error).red;
console.log(errorMsg);
},
/**
* Warning alert
* @param service
* @param data.elapsedTime ms
*/
onLatencyWarning: function (service, data) {
var msg = service.name + ' latency warning'.yellow + '. Took: ' + (data.elapsedTime + ' ms.').yellow;
console.log(msg);
},
/**
* Service is back online
* @param service
* @param lastOutage
*/
onServiceBack: function (service, lastOutage) {
var duration = moment.duration(+new Date() - lastOutage.timestamp, 'seconds');
console.log(service.name.white + ' is back'.green + '. Down for '.gray + duration.humanize().white);
},
/**
* Service is responding correctly
* @param service
* @param data
*/
onServiceOk: function (service, data) {
var serviceOkMsg = service.name + ' responded ' + 'OK!'.green;
var responseTimeMsg = data.elapsedTime + ' ms.';
console.log(serviceOkMsg, responseTimeMsg.gray);
}
};
function ConsolePlugin(watchmen) {
watchmen.on('new-outage', eventHandlers.onNewOutage);
watchmen.on('current-outage', eventHandlers.onCurrentOutage);
watchmen.on('latency-warning', eventHandlers.onLatencyWarning);
watchmen.on('service-back', eventHandlers.onServiceBack);
watchmen.on('service-ok', eventHandlers.onServiceOk);
}
exports = module.exports = ConsolePlugin;
service - set with service id's
service:latestOutages - latest outages for all services
service:<serviceId> - hashMap with service details
service:<serviceId>:outages:current - current outage for a service (if any)
service:<serviceId>:outages - sorted set with outages info
service:<serviceId>:latency - sorted set with latency info
export WATCHMEN_REDIS_PORT_PRODUCTION=1216
export WATCHMEN_REDIS_DB_PRODUCTION=1
export WATCHMEN_REDIS_PORT_DEVELOPMENT=1216
export WATCHMEN_REDIS_DB_DEVELOPMENT=2
cd scripts
sh populate-dummy-data-120days.sh # will populate data for a 120 day period
or
sh populate-dummy-data-30days.sh
etc..
To run with docker, make sure you have docker-compose installed: https://docs.docker.com/compose/install/
Also, have a docker host running. A good way is using docker-machine with a local VM: https://docs.docker.com/machine/get-started/
To build and run Watchmen, run the following:
docker-compose build
docker-compose up
After this Watchmen webserver will be running and exposed in the port 3000 of the docker host.
To configure, please look docker-compose.yml and docker-compose.env.
$ npm test
$ npm run coverage
Then check the coverage reports:
$ open coverage/lcov-report/lib/index.html

watchmen uses debug
set DEBUG=*
You can contribute by:
3.0.0
2.5.0
2.4.0
2.3.0
2.2.0
2.1.0
2.0.0
1.1.1
1.1.0
1.0.alpha1 Major changes and improvements
redis storage is used by default but you can create your own : couchdb, mongodb, text file, etc (see lib/storage).http and smtp (smtp is just checking tcp connection right now). You can create your own or improve the existent ones easily.events.EventEmitter, so you can instanciate it and subscribe to the events of your choice (service_error, service_back, etc) to implement your custom logic (see server.js).0.9
0.8
0.7
0.6
0.5
0.4
0.3
0.2
0.1
(see package.json and bower.json for a complete list of libraries and dependencies)
Copyright (c) 2012 - 2015 Iván Loire
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Content type
Image
Digest
sha256:5decac67b…
Size
306.2 MB
Last updated
over 10 years ago
docker pull labianchin/watchmen