Skip to content

Instantly share code, notes, and snippets.

@jderrett
Created September 2, 2014 17:42
Show Gist options
  • Save jderrett/b2f7216c4df44c029540 to your computer and use it in GitHub Desktop.
Save jderrett/b2f7216c4df44c029540 to your computer and use it in GitHub Desktop.
var express = require('express')
var app = express();
var librato = require('librato-node')
var sleep = require('sleep')
librato.configure({
email: 'me@example.com',
token: 'abc1234',
source: 'my.server.1'
})
//app.use(librato.middleware())
app.use(librato.middleware({
requestCountKey: 'node.request.count',
responseTimeKey: 'node.response.time'
}))
librato.start()
process.once('exit', function() {
return librato.stop();
});
app.set('port', (process.env.PORT || 5000))
app.use(express.static(__dirname + '/public'))
app.get('/', function(request, response) {
response.send('Hello World!')
})
app.get('/instrument', function(request, response) {
// Increment a counter
librato.increment('node.counter.test')
response.send('this is a count...')
})
app.get('/timing', function(request, response) {
// Time an action
var startTime = new Date
sleep.sleep(1) // do work
var latency = new Date - startTime
librato.timing('node.timing.test', latency)
response.send('this is a timer...')
})
app.listen(app.get('port'), function() {
console.log("Node app is running at localhost:" + app.get('port'))
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment