Monitoring Tool in the Cloud in (less than) 2 minutes…


This article will show how to deploy a simple monitoring application in the Cloud in a couple of minutes using statusdashboard and Heroku.

I already introduced StatusDashboard several months ago with a small websocket client I wrote allowing to connect to the web application and streaming monitoring data directly in the terminal. The monitoring data is produced by the server which is periodically trying to call a set of defined services (HTTP, HTTPs, FTP, TCP, UDP, …).

In the last version, you can now embed StatusDashboard in any node application with a really simple to use API. This is especially nice to customize it for your needs, for example, getting settings from a configuration file, from a remote service or whatever:


{
"title": "Platform Status Sample",
"hostname": "0.0.0.0",
"port": 8080,
"client": {
"transports": []
},
"services": [
{
"name": "BLOG",
"label": "BLOG",
"check": "http",
"host": "chamerling.org",
"port": 80,
"path": "/"
},
],
"plugins" : {
"console" : {
"enable": false
},
"irc" : {
"enable": false,
"server": "irc.freenode.net",
"nick": "mystatusdashboardsample",
"options": {
"debug": false,
"channels": ["#mystatusdashboardsample"]
}
},
"heartbeat": {
"enable": true,
"period": 20000
}
},
"serviceInterval": 20000,
"serviceDelay": 500
}

view raw

config.json

hosted with ❤ by GitHub


var fs = require('fs')
, util = require('util')
, server = require('statusdashboard/server')
var input = fs.readFileSync('./config.json', 'utf-8');
var settings = JSON.parse(input);
// update for Heroku
settings.port = process.env.PORT || settings.port;
process.on('exit', function () {
util.log('Bye bye Statusdashboard.');
});
process.on('uncaughtException', function(err) {
util.log(err.stack.replace(/^ /gm, ' '));
});
var dashboard = new server.dashboard(settings, function() {
console.log('Server is started with settings', settings);
});

view raw

server.js

hosted with ❤ by GitHub

Let’s deploy it on Heroku…


git clone http://github.com/chamerling/statusdashboard-server.git
cd statusdashboard-server
heroku login
# …
heroku create
# Will create all the required stuff on heroku (git repository) and add a remote in your git repository. Takes 5 seconds.
git push heroku master
# Some hooks will detect the nodejs app, launch npm… Takes 30 seconds.
heroku open

view raw

heroku.sh

hosted with ❤ by GitHub

There is one problem with the current approach: When running such an application on Heroku with the default Heroku Plan, it will ends when nobody browse it. This will stop the monitoring loop which is not really useful for a monitoring app… In order to avoid such behavior, I added a heartbeat mechanism last night which is configured from the application settings. It also needs to define some environment variable with the heroku client. Let’s assume that your application is running on http://YOURAPP.herokuapp.com, you have to define this variable like:


heroku config:add HEARTBEAT_URL=http://YOURAPP.herokuapp.com

view raw

heroku.sh

hosted with ❤ by GitHub

It will restart your application (if not, restart it manually), will start to ping itself and keep the application alive.

The code of this article is available at https://github.com/chamerling/statusdashboard-server. You get fork/clone/whatever and start monitoring your services in the next minutes…

And the proof that it works in less than 2 minutes (with a poor Internet connection, and taking time to browse source code…)

 

Kids are sick? Take coffee and code


I had some time since several nights (thanks kids to be sick…) to start watching how to implement a REST API using node.js (my new friend).

I plan to create an OW2 API this year; but before I started to wrap some existing services as proof of concept. The first feature focuses on how to get projects data from the gitorious instance we run at OW2. There is no clear API for gitorious but after some googling and source code search, it looks that there is a read-only XML API. Since I am targeting node.js, let’s translate this API into a JSON one: xml2js will do the job.

This results in a first library (gitoriou.js) which just call the gitorious instance and translates the XML data into JSON without any other data mapping. The following gist is showing how to get information from a project:


/**
* Use the OW2.org gitorious instance for samples.
*
* Copyright(c) 2013 Christophe Hamerling <christophe.hamerling@gmail.com>
* MIT Licensed
*/
var Gitorious = require('../index').Gitorious
, _ = require('underscore');
var client = new Gitorious({url:'http://gitorious.ow2.org&#39;});
console.log('# Getting OW2 Shelbie information : ')
client.getProject('ow2-shelbie', function(err, result) {
if (err) {
console.log('Error:', err);
return;
}
// console.log(JSON.stringify(result, null, 4));
console.log('## Title:', result.project.title);
console.log('### Repositories');
_.each(result.project.repositories.mainlines.repository, function(item) {
console.log(' – ', item.clone_url);
})
});

view raw

gitorious.js

hosted with ❤ by GitHub

I talked about having a REST API, let’s use express.js for that and let’s run it on Heroku (this platform rules, just took 2 minutes to create, deploy and run the service and it is up at http://ow2apisample.herokuapp.com/).


/**
* OW2 API Sample
*
* Copyright(c) 2013 Christophe Hamerling <christophe.hamerling@gmail.com>
* MIT Licensed
*/
var express = require('express')
, http = require('http')
, path = require('path')
, app = express();
var Gitorious = require('gitoriou.js').Gitorious;
var config = {
url : 'http://gitorious.ow2.org&#39;,
port : 3000
}
var client = new Gitorious(config);
app.configure(function() {
app.set('port', process.env.PORT || config.port);
app.use(express.logger('dev'));
app.use(express.bodyParser());
app.use(express.static(path.join(__dirname, '../public')));
});
app.configure('development', function() {
app.use(express.errorHandler({ dumpExceptions: true, showStack: true }));
});
app.configure('production', function() {
app.use(express.errorHandler());
});
app.get('/projects', function(req, res) {
client.getProjects(function(err, result) {
if (err) {
res.json(500, err);
} else {
res.json(200, result);
}
});
});
app.get('/project/:name', function(req, res) {
client.getProject(req.param('name'), function(err, result) {
if (err) {
res.json(500, err);
} else {
res.json(200, result);
}
});
});
var server = http.createServer(app);
server.listen(app.get('port'), function () {
console.log('OW2 Server is started and listening on', app.get('port'));
});

view raw

server.js

hosted with ❤ by GitHub

To get information (as JSON) about the Jasmine project, just HTTP GET http://ow2apisample.herokuapp.com/project/ow2-jasmine

If you master any scripting language, you will be able to get all the repositories URLs from the JSON response, if not you can use the ow2git project to clone them all. Assuming node.js and npm are available on your system (you already have java, ruby and every other stuff installed, why not adding node?), you can install the binary:

npm install -g ow2git

and then clone all the repositories from any gitorious project

ow2git –clone ow2-jasmine

Will clone all the ow2-jasmine repositories into your current folder.

I am really impressed by node.js runtime, tools and community. Even if all of this is just a proof of concept, not really well designed, you can have something running quickly without many effort. Time to get something real. Soon…

2012


OK I am late for the ‘traditional’ past-year summary. So let’s do it short with 4 pictures…

OW2

OW2

I gave several talks at OW2Con 2012 and had fun like every year. I am also proud to be the new OW2 technology council chairman. There is just one thing to say: There are nice things to come this year!

OS X

OS X

I launched several OS X apps, just for fun and to get feedback from new communities. Check them out on the Apps menu. The end of the year has been busy but some updates are almost ready to be published, especially for my favorite app : QuickHub.

Linagora

Linagora, Open Source, Geek life

The big change of the year: Work. PetalsLink has been acquired by Linagora. Some good challenges and nice Open source stuff to develop in this new company. I am also always looking for new challenges and new languages to learn. I started the year with some ObjectiveC/Cocoa stuff as described above, then move to Ruby and finally finished the year with javascript and node.js development which is completely fun and easy to handle for a Java developer like me.

This is the most important thing of the year, no!?

Family

The most important thing of the year. Loris now have a sister: Mila.

Node.js client for Status Dashboard


Status Dashboard is an awesome node.js monitoring application developed by @obazoud. I recently sent some pull requests to Olivier to improve the IRC plugin and then I though that even if I am always connected to IRC, jabber or whatever, I also have a Terminal opened most of the time. So the question was: How can I get my services status pushed to my laptop in realtime?
Socket.IO is the candidate: It does not provide only server and browser modules, there is also the socket.io-client module which can be used in your node runtime, on the client side in exactly the same way you use Socket.IO in your HTML pages. Since Socket.IO is already used in Status Dashboard to push status to the browser, we have the right solution.

I created a simple node.js client application called statusdashboard-client which connect to a status dashboard instance using Socket.IO. Once data is pushed by the server to the client, it is displayed with some basic code colors on the terminal:

It is totally fun to see what we can do without any node.js expertise. I just start looking at it but I already have many ideas, especially for platform monitoring.