mof-statsdclient
Version:
middleware of floodesh, which provides a statsd client that allows you to send data to statsd server and automatically has some statistics sent that generally apply to all requests.
43 lines (36 loc) • 894 B
JavaScript
const lynx = require('lynx');
function StatsdClient(config) {
this.client = new lynx(config.host, config.port);
}
StatsdClient.prototype.count = function(name, value, sampleRate) {
let content = {};
content[name] = value + '|c';
if(sampleRate) {
this.client.send(content, sampleRate);
} else {
this.client.send(content);
}
}
StatsdClient.prototype.gauge = function(name, value, sampleRate) {
let content = {};
content[name] = value + '|g';
if(sampleRate) {
this.client.send(content, sampleRate);
} else {
this.client.send(content);
}
}
StatsdClient.prototype.timer = function(name, value, sampleRate) {
let content = {};
content[name] = value + '|ms';
if(sampleRate) {
this.client.send(content, sampleRate);
} else {
this.client.send(content);
}
}
StatsdClient.prototype.close = function() {
this.client.close();
}
module.exports = StatsdClient;