Permalink
Browse files

Statusdashboard 0.4.0

- Remove journey and paperboy
- Use Express - close #25
- Node.js 0.6.x - close #26
- Heroku compliant
- Clean settings
- change js CDN
  • Loading branch information...
1 parent d27a59e commit 90878c94c68dcf5a48207437aa823ddfd8b6de11 @obazoud obazoud committed Sep 29, 2012
Showing with 87 additions and 150 deletions.
  1. +1 −0 Procfile
  2. +1 −2 README.md
  3. +9 −7 api.js
  4. +9 −9 package.json
  5. +10 −9 plugins/history/history_plugin.js
  6. +3 −3 plugins/history/public/toolbar-popin.html
  7. +4 −4 public/index.html
  8. +48 −65 server.js
  9. +2 −51 settings.js
View
@@ -0,0 +1 @@
+web: node server.js
View
@@ -48,7 +48,7 @@ settings['xxx'] = {
};
</pre>
-* export APP_ENV=xxx
+* export APP_ENV=demo
* node server.js
You can override settings with an external settings for private information like passwords, ..
@@ -148,4 +148,3 @@ In the news
* IT Wars: [StatusDashboard monitoring avec Node.js](http://www.it-wars.com/article265/statusdashboard-monitoring-avec-node-js)
* William Durand blog: [Services Status Dashboard](http://williamdurand.fr/2012/01/16/services-status-dashboard/)
-
View
16 api.js
@@ -1,3 +1,4 @@
+var util = require('util');
var http = require('http');
var https = require('https');
var net = require('net');
@@ -338,28 +339,29 @@ setInterval(updatingServices, settings.serviceInterval);
updatingServices();
module.exports.services = function(req, res) {
- res.send(200, {}, JSON.stringify(status));
+ res.send(JSON.stringify(status), 200);
};
module.exports.servicesElement = function(req, res, value) {
- res.send(200, {}, JSON.stringify(_.first(_.select(status.services, function(data){ return data.name == value; }))));
+ res.send(JSON.stringify(_.first(_.select(status.services, function(data){ return data.name == value; }))), 200);
};
module.exports.summarize = function(req, res) {
- res.send(200, {}, { up: status.summarize.up, critical: status.summarize.critical, down: status.summarize.down, unknown: status.summarize.unknown });
+ res.send({ up: status.summarize.up, critical: status.summarize.critical, down: status.summarize.down, unknown: status.summarize.unknown }, 200);
};
exports.getServicesElement = function(value) {
return status.services[value];
};
module.exports.configClient = function(req, res) {
- res.send(200, {}, JSON.stringify(settings.client));
+ console.log(util.inspect(settings.client));
+ res.send(JSON.stringify(settings.client), 200);
}
module.exports.pluginsClient = function(req, res) {
var plugins = _.map(_.select(_.map(settings.plugins, function(num, key) { return { name:key, enable: num.enable, client: num.client } }), function(data) { return (data.enable == true && data.client == true); }), function(num, key) { return { name:num.name } });
- res.send(200, {}, JSON.stringify(plugins));
+ res.send(JSON.stringify(plugins), 200);
}
module.exports.getStatus = function() {
@@ -390,10 +392,10 @@ module.exports.uptime = function(req, res) {
var now = new Date().valueOf();
var uptime = now - startupTime;
var human = humanized_time_span.humanized_time_span(startupTime, now, date_formats);
- res.send(200, {}, { startupTime: startupTime, now: now, uptime: uptime, human: human});
+ res.send({ startupTime: startupTime, now: now, uptime: uptime, human: human}, 200);
}
module.exports.info = function(req, res) {
- res.send(200, {}, info);
+ res.send(info, 200);
}
View
@@ -1,6 +1,6 @@
{
"name": "statusdashboard",
- "version": "0.3.0",
+ "version": "0.4.0",
"description": "A services status dashboard",
"author": "Olivier Bazoud <olivier.bazoud@gmail.com>",
"homepage": "http://github.com/obazoud/statusdashboard.git",
@@ -25,18 +25,18 @@
},
"main": "server.js",
"engines": {
- "node": "0.4.x"
+ "node": "0.6.x",
+ "npm": "1.0.x"
},
"dependencies": {
- "socket.io": "0.9.2",
- "paperboy": "0.0.3",
- "journey": "0.4.0-pre-3",
- "underscore": "1.3.1",
- "irc": "0.3.3",
+ "socket.io": "0.9.10",
+ "express": "2.5.11",
+ "underscore": "1.4.0",
+ "irc": "0.3.4",
"twitter": "0.1.18",
- "redis": "0.7.1",
+ "redis": "0.8.1",
"hiredis": "0.1.14",
"pkginfo": "0.2.3",
- "nodemailer": "0.1.22"
+ "nodemailer": "0.3.28"
}
}
@@ -14,9 +14,9 @@ exports.create = function(api, settings) {
});
// new route should be: /api/[pluginName]/whatever
- api.emit("routeContribution", { method: 'GET', path: /^\/api\/history\/service\/([a-z\-]+)$/, binding: module.exports.serviceHistory });
- api.emit("routeContribution", { method: 'GET', path: /^\/api\/history\/all\/([a-z\-]+)$/, binding: module.exports.serviceAllHistory });
- api.emit("routeContribution", { method: 'GET', path: /^\/api\/history\/all$/, binding: module.exports.allHistory });
+ api.emit("routeContribution", { path: /^\/api\/history\/service\/([a-z\-]+)$/, binding: module.exports.serviceHistory });
+ api.emit("routeContribution", { path: /^\/api\/history\/all\/([a-z\-]+)$/, binding: module.exports.serviceAllHistory });
+ api.emit("routeContribution", { path: /^\/api\/history\/all$/, binding: module.exports.allHistory });
// serve static file: /api/[pluginName]/public
api.emit("staticContribution", 'history');
@@ -50,19 +50,20 @@ exports.create = function(api, settings) {
module.exports.serviceHistory = function(req, res, value) {
client.lrange(mysettings.plugins.history.namespace + ":" + value, 0, 100, function(err, data) {
if (!err) {
- res.send(200, {}, JSON.stringify(data));
+ res.send(JSON.stringify(data), 200);
} else {
- res.send(500, {}, err);
+ res.send(err, 500);
}
});
};
module.exports.serviceAllHistory = function(req, res, value) {
+ console.log("rrr");
client.lrange(mysettings.plugins.history.namespace + ":" + value, 0, -1, function(err, data) {
if (!err) {
- res.send(200, {}, JSON.stringify(data));
+ res.send(JSON.stringify(data), 200);
} else {
- res.send(500, {}, err);
+ res.send(err, 500);
}
});
};
@@ -80,9 +81,9 @@ module.exports.allHistory = function(req, res) {
replies.forEach(function (reply, index) {
data[mysettings.services[index].name] = JSON.parse("[" + reply.toString() + "]");
});
- res.send(200, {}, JSON.stringify(data));
+ res.send(JSON.stringify(data), 200);
} else {
- res.send(500, {}, err);
+ res.send(err, 500);
}
});
};
@@ -4,7 +4,7 @@
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>History chart</title>
- <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.js"></script>
+ <script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
var options = {
@@ -95,8 +95,8 @@
</head>
<body>
- <script type="text/javascript" src="http://highcharts.com/js/testing-stock.js"></script>
- <script type="text/javascript" src="http://highcharts.com/js/modules/exporting.js"></script>
+ <script type="text/javascript" src="http://code.highcharts.com/stock/highstock.js"></script>
+ <script type="text/javascript" src="http://code.highcharts.com/stock/modules/exporting.js"></script>
<div id="container" style="height: 500px"></div>
</body>
</html>
View
@@ -4,9 +4,9 @@
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>Services Status Dashboard</title>
- <script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.6.1.min.js"></script>
- <script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jquery.templates/beta1/jquery.tmpl.min.js"></script>
- <script type="text/javascript" src="http://ajax.cdnjs.com/ajax/libs/underscore.js/1.1.6/underscore-min.js"></script>
+ <script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
+ <script type="text/javascript" src="http://ajax.microsoft.com/ajax/jquery.templates/beta1/jquery.tmpl.min.js"></script>
+ <script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/underscore.js/1.3.3/underscore-min.js"></script>
<script type="text/javascript" src="/socket.io/socket.io.js"></script>
<script type="text/javascript" src="/js/jquery.gritter.min.js"></script>
<script type="text/javascript" src="/js/jquery.fancybox-1.3.4.pack.js"></script>
@@ -23,7 +23,7 @@
data: "",
dataType: "json",
success: function(data) {
- // alert(data.transports);
+ // console.log(data.transports);
var socket = io.connect(null, {transports: data.transports});
$(window).bind('beforeunload', function() {
View
113 server.js
@@ -1,8 +1,5 @@
+var path = require('path');
var util = require('util');
-var http = require('http');
-var journey = require('journey');
-var router = new(journey.Router)();
-var paperboy = require('paperboy');
var url = require('url');
var _ = require('underscore')._;
@@ -18,62 +15,61 @@ String.prototype.startsWith = function(str) {
return (this.indexOf(str) === 0);
}
-// settings
+// Directories
+var rootPath = process.cwd();
+var staticPath = path.join(rootPath, 'public');
+
+// Settings
var settings = require('./settings').create();
var api = require('./api');
-// router
-router.get(/^\/api\/services$/).bind(api.services);
-router.get(/^\/api\/services\/([a-z\-]+)$/).bind(api.servicesElement);
-router.get(/^\/api\/summarize$/).bind(api.summarize);
-router.get(/^\/api\/config\/client$/).bind(api.configClient);
-router.get(/^\/api\/plugins\/client$/).bind(api.pluginsClient);
-router.get(/^\/api\/uptime$/).bind(api.uptime);
-router.get(/^\/api\/info$/).bind(api.info);
-// static
-var docRoot = __dirname + '/public';
-var pluginsDocRoot = [];
+// Server
+var express = require('express')
+var app = express.createServer();
+app.configure(function () {
+ util.log("Express server static directory: " + staticPath);
+ app.use(express.static(staticPath));
+ app.use(express.favicon(path.join(staticPath, 'favicon.ico')));
+ app.use(express.logger());
+ app.use(express.bodyParser());
+ app.use(express.methodOverride());
+});
+var port = process.env.PORT || settings.port;
+app.listen(port, settings.hostname);
+util.log('Server running at http://' + settings.hostname + ':' + port);
-// server
-var server = http.createServer(function(req, res) {
- var body = '';
- req.on('data', function(chunk) {
- body += chunk;
- });
- req.on('end', function() {
- router.handle(req, body, function (route) {
- if (route.status === 404) {
- paperboy.deliver(docRoot, req, res).otherwise(function(err) {
- var pathname = url.parse(req.url).pathname;
- var pluginDocRootSelect = _.select(pluginsDocRoot, function(data) { return pathname.toString().startsWith(data.prefix); });
- if (pluginDocRootSelect && pluginDocRootSelect[0]) {
- var pluginDocRoot = pluginDocRootSelect[0];
- req.url = pathname.toString().replace(pluginDocRoot.prefix, "");
- paperboy.deliver(pluginDocRoot.docRoot, req, res).otherwise(function(err) {
- res.writeHead(404);
- res.end('File not found.');
- });
- } else {
- res.writeHead(route.status, route.headers);
- res.end(route.body);
- }
- });
- } else {
- res.writeHead(route.status, route.headers);
- res.end(route.body);
- }
- });
- });
+// Routes
+app.get(/^\/api\/services$/, api.services);
+app.get(/^\/api\/services\/([a-z\-]+)$/, api.servicesElement);
+app.get(/^\/api\/summarize$/, api.summarize);
+app.get(/^\/api\/config\/client$/, api.configClient);
+app.get(/^\/api\/plugins\/client$/, api.pluginsClient);
+app.get(/^\/api\/uptime$/, api.uptime);
+app.get(/^\/api\/info$/, api.info);
+
+app.get('/healthCheck', function(req, res) {
+ res.send('ok', 200);
});
-server.listen(settings.port, settings.hostname);
-var count = 0;
-var io = require('socket.io').listen(server);
+api.on("routeContribution", function(route) {
+ app.get(route.path, route.binding);
+ util.log("Add route contribution: " + route.path);
+});
+
+api.on("staticContribution", function(plugin) {
+ var docRoot = __dirname + '/plugins/' + plugin + '/public';
+ app.use("/api/" + plugin, express.static(docRoot));
+ util.log("Add static contribution: " + plugin + ", " + docRoot);
+});
+var count = 0;
+var io = require('socket.io').listen(app);
// https://github.com/LearnBoost/Socket.IO/wiki/Configuring-Socket.IO
-io.enable('browser client minification');
-io.enable('browser client etag');
-io.set('log level', 1);
+io.configure(function () {
+ io.enable('browser client minification');
+ io.enable('browser client etag');
+ io.set('log level', 1);
+});
io.sockets.on('connection', function(socket) {
count++;
@@ -93,17 +89,4 @@ api.on("refresh", function(status) {
io.sockets.emit('status', status);
});
-api.on("routeContribution", function(route) {
- router.route(route.method, route.path).bind(route.binding);
-});
-
-api.on("staticContribution", function(plugin) {
- util.log("Add static contribution: " + plugin);
- var docRoot = __dirname + '/plugins/' + plugin + '/public';
- pluginsDocRoot.push( { prefix: "/api/" + plugin, docRoot: docRoot });
- util.log("Add static contribution: " + util.inspect(pluginsDocRoot));
-});
-
util.log('Server started.');
-util.log('Server running at http://' + settings.hostname + ':' + settings.port);
-
Oops, something went wrong.

0 comments on commit 90878c9

Please sign in to comment.