Yodlr Metrics Library
The goal of this library is to provide a consistent API for sending metrics from our NodeJS services.
This library exposes a constructor which provides the following metric API calls:
- count
- increment
- decrement
- timing
- timer
- gauge
- set
Using this library
Construction
Staticaly define host/port and prefixes
var opts = prefix: 'services.myapp' //optional statsd: prefix: 'account-uuid' // optional host: '10.1.1.5' port: 8125 { // if not defined, will emit 'error' instead console; }
Pull host/port and prefix from etcd.
If the values change, yodlr-metrics will dynamically reconfigure how it sends data. You don't need to modify you code at all.
If insufficient data is provided in etcd, yodlr-metrics will emit an error which you should capture and probably log.
var opts = etcdHost: '172.17.42.1' // default, optional etcdPort: 4001 // default, optional prefix: 'services.myapp' // optional statsd: prefix_etcd: '/services/statsd/prefix' // optional hostEtcd: '/services/statsd/host' portEtcd: '/services/statsd/port'
Once you've decided on your configuration, you can construct a metrics object like this:
var YodlrMetrics = ; var opts = prefix: 'services.myapp' statsd: prefix: 'account-uuid' host: '10.1.1.5' port: 8125 var metric = opts;metric
Count
Increases or decreased a counter by the provider number.
metric; // increments counter by 5
Increment
Increases a counter by 1
metric; // increments counter by 1
Decrement
Decreases a counter by 1
metric; // increments counter by 1
Timing
Sends a timing metric in ms
metric; // sends timing metric of 50ms
Timer
Variation on the timing metric which provides a timing object with a Stop() function
var timer = metric;;
Gauge
Sets a currently configured gauge to this new value
metric; // sets gauge to 500
Set
Used to count unique occurrences of events between flushes, using a Set to store all occurring events.
If a method is called multiple times with the same value in the same sample period, that value will only be counted once.
metric;metric;metric; //