Skip to content

Instantly share code, notes, and snippets.

@astrotars
Created July 19, 2018 14:40
Show Gist options
  • Save astrotars/fd4a44124e55af9e611b39bb752103ab to your computer and use it in GitHub Desktop.
Save astrotars/fd4a44124e55af9e611b39bb752103ab to your computer and use it in GitHub Desktop.
import config from '../config';
import { StatsD } from 'node-statsd';
var statsDClient = null;
function getStatsDClient() {
if (!statsDClient) {
statsDClient = new StatsD({
host: config.statsd.host,
port: config.statsd.port,
prefix: config.statsd.prefix,
cacheDns: true,
});
}
return statsDClient;
}
async function timeIt(name, fn) {
let t0 = new Date();
let r = await fn();
getStatsDClient().timing(name, new Date() - t0);
return r;
}
exports.getStatsDClient = getStatsDClient;
exports.timeIt = timeIt;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment