Search code examples
javascriptnode.jsstatsd

Node.js with StatsD


I'm using etsy/statsd using the node.js.

I have created a config file too.

I'm starting statsD using: node node_modules/statsd/bin/statsd statsDConfig.js

To check I used: echo "foo:1|c" | nc -u -w0 127.0.0.1 8125

There is not much documentation how I could use it programatically. I want to utilize statsd to get the API calls count to the facebook made through a script.

I have done following steps:

  1. Installed statsD using "npm i statsd".
  2. I have changed the backend to console.

I have bit knowledge about counters, sets, guages, etc. But when I require it in node.js code using :

Var statsd = require('statsd');

var start = Date.now();
retun AuthSerrver.auth(req.headers)
.then(function() {})
.finally(function() {
var latency = Date.now() -start;
statsd.histogram('auth.latency_ms', latency);
});

It gives me error like: "Error: Cannot find module 'statsd'" Whereas I can find the it in node_modules.

Any help on how to get it working would be appreciated. Any example would be a cherry on the cake.

Thanks.


Solution

  • Here's what you can do.

    There is nothing wrong with the statsD installation.

    Basically your syntax for using it is wrong.

    I will share a slideshow that will guide you through the actual use of statsD.

    You should check the StatsD docs.

    Hope this helps you.