mof-statsd

2.0.0 • Public • Published

mof-statsd

mof-statsd which is a wrapper of statsd-client is a middleware of floodesh

Install

npm install mof-statsd

Usage

const Worker = require("floodesh/worker")
const request = require('mof-request')
const statsd = require('mof-statsd')
 
const options = {
    host:"host of statsd daemon",
    port:8125,
    debug: fase
};
 
worker.use(statsd(options));// make sure statsd middlerware is before middleware which have to use statsd
worker.use(request());

The mof-request default sends a counting metric while requesting, and also a counting metric if error. Once a response comes back, it sends a timing metric wich represents a network latency.

Customise

Below is an example for sending a metric in your middleware:

//example.js
module.exports = (ctx, next)=>{
    //send a counter metric
    ctx.scounter("example");
 
    //a `timing` metric
    //first we set a beginning time
    ctx.ts = new Date();
 
    //...
 
    // then we send the diff, statsd automatically compute the diff between the moment calling the fucntion and the beginning time
    ctx.stiming("processtime");
}

Package Sidebar

Install

npm i mof-statsd

Weekly Downloads

2

Version

2.0.0

License

ISC

Last publish

Collaborators

  • mike442144