Created
April 30, 2014 15:06
-
-
Save deedubs/9596f8349a27023df762 to your computer and use it in GitHub Desktop.
Send response times to influxdb
This file contains hidden or 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
| 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