diff --git a/funnel.js b/funnel.js index 927fbc9..af72eed 100644 --- a/funnel.js +++ b/funnel.js @@ -17,12 +17,16 @@ var collect = function (sourcesdotdotdot) { var asMetricName = function (data, preserveDot) { var name = ['funnel']; - name.push(data.funnel); - name.push(fixMetricName(data.nodeName)); - if (data.serviceName) { - name.push(fixMetricName(data.serviceName)); + if (data.explicitMetricName) { + name.push(data.explicitMetricName); + } else { + name.push(data.funnel); + name.push(fixMetricName(data.nodeName)); + if (data.serviceName) { + name.push(fixMetricName(data.serviceName)); + } + name.push(fixMetricName(data.metricName, preserveDot)); } - name.push(fixMetricName(data.metricName, preserveDot)); return name.join('.'); }; diff --git a/plugin/mongo.js b/plugin/mongo.js index 3ed272d..07abb2a 100644 --- a/plugin/mongo.js +++ b/plugin/mongo.js @@ -66,18 +66,27 @@ module.exports = function (service) { if (typeof service.from == 'string') { service.from = [service.from]; } + var mongodb = require('mongodb'); + service.from.forEach(function (from) { mongodb.connect(from, function(err, conn) { for (var serviceName in service.services) { (function (thisService) { + var funnelerWrapper = function (data) { + if (thisService.metricName) { + data.explicitMetricName = thisService.metricName; + } + funneler(data); + }; + if (thisService === shared.COUNT || thisService.count) { - doCount(conn, from, funneler, serviceName, thisService); + doCount(conn, from, funnelerWrapper, serviceName, thisService); } else if (thisService.query) { - doQuery(conn, from, funneler, serviceName, thisService); + doQuery(conn, from, funnelerWrapper, serviceName, thisService); } else if (thisService.aggregate) { - doAggregate(conn, from, funneler, serviceName, thisService); + doAggregate(conn, from, funnelerWrapper, serviceName, thisService); } })(service.services[serviceName]); }