From f3225ae219e68ca269911b77b82bd04fa8f65ec7 Mon Sep 17 00:00:00 2001 From: Sebastian Pop Date: Mon, 17 Jul 2017 10:42:56 +0100 Subject: [PATCH 1/4] Fixed illegal character problem --- index.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 1072000..eb182e8 100644 --- a/index.js +++ b/index.js @@ -1,6 +1,10 @@ 'use strict'; let defaultInterval = 10; let oneSecInMs = 1000; +let keyCountAppendName = 'keyCounter'; +let statsdIllegalCharacter = ':'; +let defaultWordSeparatorCharacter = '-'; + const path = require('path'); const util = require('util'); const infoParser = require('./lib/info-parser'); @@ -46,7 +50,9 @@ redisClients.forEach((c) => { return; } - statsdClient.gauge(`${c.prefix}.${stat.key}.${c.suffix}`, stat.count); + var cleanKey = stat.key.replace(statsdIllegalCharacter, defaultWordSeparatorCharacter); + + statsdClient.gauge(`${prefix}${cleanKey}${suffix}`, stat.count); }); }, (statsConfig.interval || defaultInterval) * oneSecInMs); From c28701a7b6d2032a88a1b143d1c91b9f94b506de Mon Sep 17 00:00:00 2001 From: Sebastian Pop Date: Mon, 17 Jul 2017 11:03:03 +0100 Subject: [PATCH 2/4] Added test, changed version and fixed PR comments --- index.js | 13 +++++-------- lib/utils.js | 6 ++++++ tests/utils.js | 7 +++++++ 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/index.js b/index.js index c83c3b9..fd45dab 100644 --- a/index.js +++ b/index.js @@ -1,16 +1,14 @@ 'use strict'; -let defaultInterval = 10; -let oneSecInMs = 1000; -let keyCountAppendName = 'keyCounter'; -let statsdIllegalCharacter = ':'; -let defaultWordSeparatorCharacter = '-'; +const defaultInterval = 10; +const oneSecInMs = 1000; +const keyCountAppendName = 'keyCounter'; const path = require('path'); const util = require('util'); const infoParser = require('./lib/info-parser'); const redisClientFactory = require('./lib/redis-client-factory'); const libUtils = require('./lib/utils'); -let keyCounter = require('./lib/redis-key-counter'); +const keyCounter = require('./lib/redis-key-counter'); var configDir = path.resolve(process.argv[2] || './'); const StatsD = require('statsd-client'); @@ -47,13 +45,12 @@ redisClients.forEach((c) => { keyCounter.count(c, (err, stat) => { var prefix = libUtils.getPrefix(c, keyCountAppendName); var suffix = libUtils.getSuffix(c, keyCountAppendName); + let cleanKey = libUtils.cleanKey(stat.key); if (err) { util.log(`[${c.host}] ${err}`); return; } - - var cleanKey = stat.key.replace(statsdIllegalCharacter, defaultWordSeparatorCharacter); statsdClient.gauge(`${prefix}${cleanKey}${suffix}`, stat.count); }); diff --git a/lib/utils.js b/lib/utils.js index 600ffd8..d80823a 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -1,4 +1,6 @@ 'use strict'; +const statsdIllegalCharacter = ':'; +const defaultWordSeparatorCharacter = '-'; module.exports.getSuffix = (c, nodeName) => { var suffix = ''; @@ -25,3 +27,7 @@ module.exports.getPrefix = (c, nodeName) => { return pre; }; + +module.exports.cleanKey = (keyName) => { + return keyName.replace(statsdIllegalCharacter, defaultWordSeparatorCharacter); +}; diff --git a/tests/utils.js b/tests/utils.js index 70d6aac..d56c8b8 100644 --- a/tests/utils.js +++ b/tests/utils.js @@ -49,4 +49,11 @@ describe('utils', () => { result.should.equal(',host=foo,node=bar'); }); }); + + describe('cleanKey', () => { + it('should replace occurances of ":" with "-" in the given key', () => { + var result = utils.cleanKey('test:key'); + result.should.equal('test-key'); + }); + }); }); From 79a1609792288631eaa5f30ade6fe0e3e24fd51c Mon Sep 17 00:00:00 2001 From: Sebastian Pop Date: Mon, 17 Jul 2017 11:41:59 +0100 Subject: [PATCH 3/4] Removed tabs --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index fd45dab..33f45d3 100644 --- a/index.js +++ b/index.js @@ -51,7 +51,7 @@ redisClients.forEach((c) => { util.log(`[${c.host}] ${err}`); return; } - + statsdClient.gauge(`${prefix}${cleanKey}${suffix}`, stat.count); }); From 2d01911fac9593642842cb78460ddc9f97cbf367 Mon Sep 17 00:00:00 2001 From: Sebastian Pop Date: Mon, 17 Jul 2017 11:43:41 +0100 Subject: [PATCH 4/4] Saved package json version update --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 7b36043..96c9262 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "redis-statsd-reporter", - "version": "1.5.1", + "version": "1.5.2", "description": "Pull info from redis and publish to statsd", "main": "index.js", "scripts": {