@shopify/statsd
An opinionated StatsD client for Shopify Node.js servers and other StatsD utilities.
Installation
yarn add @shopify/statsd
Usage
Client
Create a StatsD client with the following:
import {StatsDClient} from '@shopify/statsd';
const statsdClient = new StatsDClient({
host: 'some-statsd-host.com',
port: '8125',
prefix: 'AppName',
globalTags: {hello: 'world'},
});
distribution
Tracks the statistical distribution of a set of values across your infrastructure.
statsdClient.distribution(
'navigationComplete',
100,
['navigation', 'complete', 'performance'],
);
timing
Represents the timing stat
statsdClient.timing(
'request_duration',
100,
[],
);
gauge
Represents the gauge stat
statsdClient.gauge(
'my_gauge',
123.45,
[],
);
increment
Increments a stat by 1.
statsdClient.increment(
'myCounter',
['navigation', 'complete', 'performance'],
);
close
Close statsd client.
This will ensure all stats are sent and stop statsd from doing anything more.
statsdClient.close();
childClient
Create a child client and add more context to the client.
The globalTags will be merged.
The prefix and suffix will be concatenate using the .
separator.
statsdClient.childClient({
prefix: 'MyPrefix',
suffix: 'MySuffix',
globalTags: {foo: 'bar'},
});
In this example the prefix will be AppName.NewPrefix
, the suffix will be MySuffix
and the globalTags will be {hello: 'world', foo: 'bar'}
.