chpr-metrics
v1.5.0
Published
Chauffeur Privé's statsd configuration
Downloads
17
Readme
This utility library implements our standard statsd configuration
Requirements
Minimum Node.js version: 4
## Installation
npm install --save chpr-metrics
Configuration
This simple configuration allows you to send metrics to a single statds server
- METRICS_HOST
- METRICS_PORT
- METRICS_PREFIX (prepended to all metrics name)
- METRICS_SUFFIX (appended to all metrics name)
- METRICS_CACHE_DNS (set to "true" to activate caching, any other values disables dns caching)
Advanced configuration
If you need to send metrics to several destinations, you can use the METRICS_DESTINATIONS variable, which allows you to specify a list of destinations as a JSON array:
Complete example:
[{
"METRICS_HOST": "host1.yourstats.com",
"METRICS_PORT": "1234",
"METRICS_PREFIX": "prefix1.",
"METRICS_SUFFIX": ".suffix1"
}, {
"METRICS_HOST": "your-other-host.com",
"METRICS_PORT": "44444",
"METRICS_PREFIX": "anotherPrefix.",
"METRICS_SUFFIX": ".anotherSuffix"
}]
If you use this in combination with the individual configuration variables listed in the previous sections, it will send metrics to all directions.
Use
'use strict';
const metrics = require('chpr-metrics');
// Timing: sends a timing command with the specified milliseconds
metrics.timing('response_time', 42);
// Increment: Increments a stat by a value (default is 1)
metrics.increment('my_counter');
The exported object is the configured statds client: see https://github.com/sivy/node-statsd