forked from statsd/statsd
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adding http_socketio backend to statsd
- Loading branch information
Showing
4 changed files
with
56 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters