3 var env = require('gitter-web-env');
5 var logger = env.logger;
7 function parse(incoming) {
10 // Old way: just post an array
11 if (Array.isArray(incoming)) {
12 return { stats: incoming };
15 // New way: post a hash
16 if (incoming.stats && Array.isArray(incoming.stats)) {
21 function handleStats(incomingStats) {
22 var processed = parse(incomingStats);
23 if (!processed) return;
26 if (processed.features && Array.isArray(processed.features)) {
27 tags = processed.features.map(function(feature) {
28 return 'feature_' + feature + ':1';
32 processed.stats.forEach(function(s) {
37 if (!stat || typeof stat !== 'string' || !stat.match(/^[\w\-\.]{2,80}$/)) {
42 var statsName = 'client.' + stat;
45 if (typeof value !== 'number') return; /* Ignore */
46 stats.gaugeHF(statsName, value, 0.1, tags);
52 if (typeof time !== 'number') return; /* Ignore */
53 stats.responseTime(statsName, time, tags);
59 stats.eventHF(statsName, count || 1, 0.1, tags);
65 module.exports = function(req, res) {
71 logger.error('Problem dealing with stats: ' + e, { exception: e });