Created
July 19, 2018 14:40
-
-
Save astrotars/fd4a44124e55af9e611b39bb752103ab to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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