Skip to content

Instantly share code, notes, and snippets.

@deedubs
Created April 30, 2014 15:06
Show Gist options
  • Select an option

  • Save deedubs/9596f8349a27023df762 to your computer and use it in GitHub Desktop.

Select an option

Save deedubs/9596f8349a27023df762 to your computer and use it in GitHub Desktop.
Send response times to influxdb
var InfluxDB = require('influx');
module.exports.register = function (plugin, options, ready) {
var influx = new InfluxDB(options.host, options.port, options.username, options.password, options.database);
plugin.expose('client', influx);
plugin.ext('onRequest', function (req, next) {
req.plugins.stats = {startTime: process.hrtime()};
next();
});
plugin.ext('onPreResponse', function (req, next) {
var diff = process.hrtime(req.plugins.stats.startTime);
var responseTime = (diff[0] * 1e9 + diff[1]) / 1e6;
influx.writePoint('response_times', {path: req.path, value: responseTime, method: req.method, user: req.user && req.user._id}, function () {});
next();
});
ready();
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment