Skip to content

Commit

Permalink
feat(statsd): add logging to statsd
Browse files Browse the repository at this point in the history
  • Loading branch information
geekus committed Apr 27, 2017
1 parent 1c2e4e8 commit 5c52a6d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
13 changes: 13 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
'use strict';

const universalAnalytics = require('universal-analytics');
const StatsD = require('node-statsd');

const statsd = new StatsD({
host: process.env.STATSD_HOST || 'localhost',
port: process.env.STATSD_PORT || 8125,
prefix: process.env.STATSD_PREFIX || 'turbasen.',
});

module.exports = () => (req, res, next) => {
try {
Expand All @@ -11,6 +18,12 @@ module.exports = () => (req, res, next) => {
throw new Error(err);
}
});

statsd.increment('http.request.count');

if (req.user.type === 'token') {
statsd.increment(`http.request.count.${req.user.app}`.toLowerCase());
}
} catch (err) {
console.error(err); // eslint-disable-line no-console
} finally {
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
"node": ">=4.0.0"
},
"dependencies": {
"node-statsd": "^0.1.1",
"universal-analytics": "^0.4.9"
}
}

0 comments on commit 5c52a6d

Please sign in to comment.