Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed illegal character problem #11

Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
'use strict';
let defaultInterval = 10;
let oneSecInMs = 1000;
let keyCountAppendName = 'keyCounter';
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');
@@ -44,13 +45,14 @@ 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;
}

statsdClient.gauge(`${prefix}${stat.key}${suffix}`, stat.count);
statsdClient.gauge(`${prefix}${cleanKey}${suffix}`, stat.count);
});

}, (statsConfig.interval || defaultInterval) * oneSecInMs);
6 changes: 6 additions & 0 deletions lib/utils.js
Original file line number Diff line number Diff line change
@@ -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);
};
7 changes: 7 additions & 0 deletions tests/utils.js
Original file line number Diff line number Diff line change
@@ -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');
});
});
});