Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

adding http_socketio backend to statsd

  • Loading branch information...
commit 954cb31bedfc977c23b2e4cc6fb9f578977c43d5 1 parent fda91d4
@vireshas authored
View
38 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;
+};
View
14 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>
View
2  exampleConfig.js
@@ -94,5 +94,5 @@ Optional Variables:
graphitePort: 2003
, graphiteHost: "localhost"
, port: 8125
-, backends: [ "./backends/graphite"]
+, backends: [ "./backends/graphite", "./backends/console", "./backends/http" ]
}
View
4 package.json
@@ -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",
Please sign in to comment.
Something went wrong with that request. Please try again.