npm.io
0.0.1 • Published 8 years ago

@playster/statsd-http-plugin

Licence
ISC
Version
0.0.1
Deps
3
Size
9 kB
Vulns
1
Weekly
0

Statsd Http Plugin

A statsd plugin to help monitor https calls

Every events sent using the api of this plugin will be queued and sent every second

Installation

$ npm i -S @playster/statsd-http-plugin

or with yarn

$ yarn add @playster/statsd-http-plugin

Usage

// Commonjs
const StatsdHttpPlugin = require('@playster/statsd-http-plugin').default

// ES6 module way
import StatsdHttpPlugin from '@playster/statsd-http-plugin'

const statsd = new StatsdHttpPlugin({
  accumulatorPrefix: 'someprefix', // most likely the http service slug
  host: 'graphite.test.com', // hosts where the stats are sent
  prefix: 'someprefix', // statsd prefix for graphite
  debug: false,
  cacheDns: true,
  interval: 1000
})

API

success method

Sends a success event

example:
statsd.success()
error method

Sends a error event

example:
statsd.error()
timeout method

Sends a timeout event

example:
statsd.timeout()
timing method

Sends the latency to statsd

example:
const startTime = Date.now()
const response = await fetch('http://test.com/')
const endTime = Date.now()

statsd.timing(endTime - startTime)