Skip to content

Instantly share code, notes, and snippets.

@hawx
Created May 31, 2014 13:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hawx/7c0d1cdc87bd5f1ba5fc to your computer and use it in GitHub Desktop.
Save hawx/7c0d1cdc87bd5f1ba5fc to your computer and use it in GitHub Desktop.
var redis = require('redis').createClient();
var app = require('express')();
var total = 0, count = 0;
redis.on('message', function(channel, message) {
if (channel == "requests") {
var obj = JSON.parse(message);
total += obj.duration;
count += 1;
}
});
app.get('/', function(req, res){
if (count == 0) {
res.send("No requests recorded");
} else {
res.send('Average: ' + Math.round(total / count / 1e3) + 'µs');
}
});
process.on('SIGINT', function() {
redis.end();
process.exit();
});
redis.subscribe('requests');
console.log('started app.js on :4567');
app.listen(4567);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment