node-telegraf-statsd
Abbr: tstatsd means t(telegraf)statsd Generate telegraf statsd's inputs in NodeJs
- According to https://github.com/influxdata/telegraf/tree/master/plugins/inputs/statsd
- Etsy Statsd: https://github.com/etsy/statsd/blob/master/docs/metric_types.md
- Inspired by https://github.com/dscape/lynx
- Node UDP/DataGram Doc: https://nodejs.org/dist/latest-v4.x/docs/api/dgram.html
Usage
Install
npm install tstatsd --save
Example
const Tstatsd = require('tstatsd');
let tstatsd = new Tstatsd('10.211.55.18');
tstatsd.timing('tstatsd.test.timing', 10);
Api
Kind: global class
new Tstatsd(host, port)
| Param | Type | Description |
|---|---|---|
| host | String |
主机IP |
| port | Integer |
服务端口 |
tstatsd.gauge(key, value, operator)
gauge
Kind: instance method of Tstatsd
| Param | Type | Description |
|---|---|---|
| key | String |
|
| value | Integer |
|
| operator | Enum |
操作符,可选 ['+', '-'] |
tstatsd.counter(key, step, sample)
counter
Kind: instance method of Tstatsd
| Param | Type | Description |
|---|---|---|
| key | String |
|
| step | Integer |
步进 |
| sample | Float |
采样率,最后增量为 step/sample |
tstatsd.set(key, value)
set
Kind: instance method of Tstatsd
| Param | Type | Description |
|---|---|---|
| key | String |
|
| value | String |
遇到不同值才会加一 |
tstatsd.timing(key, value, unit, sample)
Kind: instance method of Tstatsd
| Param | Type | Description |
|---|---|---|
| key | String |
|
| value | Integer |
消耗时长 |
| unit | Enum |
计时单位, ms/h |
| sample | Float |
采样率,最后 counter=1/sample |
tstatsd.send(str)
原生发送方法
Kind: instance method of Tstatsd
| Param | Type | Description |
|---|---|---|
| str | String |
statsd 定义的字符串 |