Skip to content

Commit

Permalink
adding http_socketio backend to statsd
Browse files Browse the repository at this point in the history
  • Loading branch information
vireshas committed Mar 25, 2013
1 parent fda91d4 commit 954cb31
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 2 deletions.
38 changes: 38 additions & 0 deletions backends/http.js
@@ -0,0 +1,38 @@
/** This backend pushes the metrics to browser.
* Uses socket.io and the stats are pushed to browser every 10s.
*/

var util = require('util')
var app = require('express')();
var server = require('http').createServer(app);
var socketIO = require('socket.io').listen(server);

server.listen(8000);

app.get('/', function(req, res) {
res.sendfile(__dirname + '/index.html');
});

function HttpBackend(startUpTime, config, emitter){
console.log("configuring httpbackend");
var self = this;
this.lastFlush = startUpTime;
this.lastException = startUpTime;
this.config = config.http || {};
}

push_stats = function(timestamp, metrics){
socketIO.sockets.emit("counters", metrics);
}

HttpBackend.prototype.status = function(write) {
['lastFlush', 'lastException'].forEach(function(key) {
write(null, 'console', key, this[key]);
}, this);
};

exports.init = function(startupTime, config, events) {
var instance = new HttpBackend(startupTime, config, events);
events.on("flush", push_stats);
return true;
};
14 changes: 14 additions & 0 deletions backends/index.html
@@ -0,0 +1,14 @@
<html>
<head>
<script src="/socket.io/socket.io.js"></script>
<script type="text/javascript">
var socket = io.connect('http://localhost:8000');
socket.on("counters", function(metrics){
console.log(metrics);
});
console.log("hello");
</script>
</head>
<body>
</body>
</html>
2 changes: 1 addition & 1 deletion exampleConfig.js
Expand Up @@ -94,5 +94,5 @@ Optional Variables:
graphitePort: 2003
, graphiteHost: "localhost"
, port: 8125
, backends: [ "./backends/graphite"]
, backends: [ "./backends/graphite", "./backends/console", "./backends/http" ]
}
4 changes: 3 additions & 1 deletion package.json
Expand Up @@ -18,7 +18,9 @@
"devDependencies": {
"nodeunit": "0.7.x",
"underscore": "1.4.x",
"temp": "0.4.x"
"temp": "0.4.x",
"express": "3.0.0",
"socket.io": "0.9.x"
},
"optionalDependencies": {
"node-syslog":"1.1.7",
Expand Down

0 comments on commit 954cb31

Please sign in to comment.