request-stats
Get stats on your Node.js HTTP server requests.
Emits an stats
event for each request with a single object as its
first argument, containing the following properties:
ok
: true
if the connection was closed correctly and false
otherwisetime
: The milliseconds it took to serve the requestreq
:
bytes
: Number of bytes sent by the clientheaders
: The headers sent by the clientmethod
: The HTTP method used by the clientpath
: The path part of the request URL
res
:
bytes
: Number of bytes sent back to the clientheaders
: The headers sent back to the clientstatus
: The HTTP status code returned to the client
Installation
npm install request-stats
Usage
var requestStats = require('request-stats');
http.createServer(function (req, res) {
requestStats(req, res).on('stats', function (stats) {
console.log(stats);
});
});
Or you can just parse it the http.Server
object to a completely
decoupled experience:
var server = http.createServer(function (req, res) {
});
requestStats(server).on('stats', function (stats) {
console.log(stats);
});
Can also be used as Connect/Express middleware:
app.use(requestStats.middleware());
requestStats().on('stats', function (stats) {
console.log(stats);
});
Acknowledgement
Thanks to mafintosh for coming up with
the initial concept and pointing me in the right direction.
License
MIT