ericholiveira / studio

A nodejs framework to create decoupled and scalable applications
MIT License
488 stars 61 forks source link

statsd example #55

Closed sean-hill closed 8 years ago

sean-hill commented 8 years ago

I'd love to see an example of how to use the timer plugin with statsd, thanks :)

ericholiveira commented 8 years ago

Its insanely easy... basically copy and pasted from a project of mine...

var StatsD = require('node-statsd'),
    options = require('../conf').get('statsd'),
    os = require('os');

options.prefix = `${os.hostname().replace(/\./g,'_')}.${options.prefix}`;

var statsD =  new StatsD(options);

Studio.use(Studio.plugin.timer(function(res){
    var id = res.receiver.replace(/\//g,'.');
    if(res.err){
        id += '.error';
    }
    statsD.timing('services.'+id,res.time);
}));

I use it only for timing purposes... and studio timer already calculate and gives it for you.

Closing for now... reach me if needs to reopen

sean-hill commented 8 years ago

Thanks @ericholiveira. You're awesome. I guess the hard part is actually setting up statsd 😬

ericholiveira commented 8 years ago

oh yes... sometimes configuring statsd might be a pain in the ass