Skip to content

Commit

Permalink
Add metrics_received counter
Browse files Browse the repository at this point in the history
Similar to packets_received, but counts individual (good or bad) metrics lines
received
  • Loading branch information
Ben Burry committed Oct 13, 2014
1 parent 206bdf0 commit e3c237f
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 39 deletions.
8 changes: 7 additions & 1 deletion stats.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 104,9 @@ function flushMetrics() {
conf.deleteCounters = conf.deleteCounters || false;
for (var counter_key in metrics.counters) {
if (conf.deleteCounters) {
if ((counter_key.indexOf("packets_received") != -1) || (counter_key.indexOf("bad_lines_seen") != -1)) {
if ((counter_key.indexOf("packets_received") != -1) ||
(counter_key.indexOf("metrics_received") != -1) ||
(counter_key.indexOf("bad_lines_seen") != -1)) {
metrics.counters[counter_key] = 0;
} else {
delete(metrics.counters[counter_key]);
Expand Down Expand Up @@ -174,11 176,13 @@ config.configFile(process.argv[2], function (config) {
//setup the names for the stats stored in counters{}
bad_lines_seen = prefixStats ".bad_lines_seen";
packets_received = prefixStats ".packets_received";
metrics_received = prefixStats ".metrics_received";
timestamp_lag_namespace = prefixStats ".timestamp_lag";

//now set to zero so we can increment them
counters[bad_lines_seen] = 0;
counters[packets_received] = 0;
counters[metrics_received] = 0;

if (!serverLoaded) {

Expand All @@ -201,6 205,8 @@ config.configFile(process.argv[2], function (config) {
if (metrics[midx].length === 0) {
continue;
}

counters[metrics_received] ;
if (config.dumpMessages) {
l.log(metrics[midx].toString());
}
Expand Down
14 changes: 7 additions & 7 deletions test/graphite_delete_counters_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 157,7 @@ module.exports = {
return data;
});
test.ok(_.include(_.map(entries,function(x) { return _.keys(x)[0] }),'statsd.numStats'),'graphite output includes numStats');
test.equal(_.find(entries, function(x) { return _.keys(x)[0] == 'statsd.numStats' })['statsd.numStats'],2);
test.equal(_.find(entries, function(x) { return _.keys(x)[0] == 'statsd.numStats' })['statsd.numStats'],3);
test.done();
});
});
Expand All @@ -180,9 180,9 @@ module.exports = {
});
var numstat_test = function(post){
var mykey = 'statsd.numStats';
return _.include(_.keys(post),mykey) && (post[mykey] == 3);
return _.include(_.keys(post),mykey) && (post[mykey] == 4);
};
test.ok(_.any(hashes,numstat_test), 'statsd.numStats should be 3');
test.ok(_.any(hashes,numstat_test), 'statsd.numStats should be 4');

var bad_lines_seen_value_test = function(post){
var mykey = 'stats_counts.statsd.bad_lines_seen';
Expand Down Expand Up @@ -213,9 213,9 @@ module.exports = {
});
var numstat_test = function(post){
var mykey = 'statsd.numStats';
return _.include(_.keys(post),mykey) && (post[mykey] == 3);
return _.include(_.keys(post),mykey) && (post[mykey] == 4);
};
test.ok(_.any(hashes,numstat_test), 'statsd.numStats should be 3');
test.ok(_.any(hashes,numstat_test), 'statsd.numStats should be 4');

var testtimervalue_test = function(post){
var mykey = 'stats.timers.a_test_value.mean_90';
Expand Down Expand Up @@ -246,9 246,9 @@ module.exports = {
});
var numstat_test = function(post){
var mykey = 'statsd.numStats';
return _.include(_.keys(post),mykey) && (post[mykey] == 3);
return _.include(_.keys(post),mykey) && (post[mykey] == 4);
};
test.ok(_.any(hashes,numstat_test), 'statsd.numStats should be 3');
test.ok(_.any(hashes,numstat_test), 'statsd.numStats should be 4');

var testavgvalue_test = function(post){
var mykey = 'stats.a_test_value';
Expand Down
10 changes: 5 additions & 5 deletions test/graphite_legacy_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 149,7 @@ module.exports = {
return data;
});
test.ok(_.include(_.map(entries,function(x) { return _.keys(x)[0] }),'statsd.numStats'),'graphite output includes numStats');
test.equal(_.find(entries, function(x) { return _.keys(x)[0] == 'statsd.numStats' })['statsd.numStats'],2);
test.equal(_.find(entries, function(x) { return _.keys(x)[0] == 'statsd.numStats' })['statsd.numStats'],3);
test.done();
});
});
Expand All @@ -172,9 172,9 @@ module.exports = {
});
var numstat_test = function(post){
var mykey = 'statsd.numStats';
return _.include(_.keys(post),mykey) && (post[mykey] == 4);
return _.include(_.keys(post),mykey) && (post[mykey] == 5);
};
test.ok(_.any(hashes,numstat_test), 'statsd.numStats should be 4');
test.ok(_.any(hashes,numstat_test), 'statsd.numStats should be 5');

var testtimervalue_test = function(post){
var mykey = 'stats.timers.a_test_value.mean_90';
Expand Down Expand Up @@ -205,9 205,9 @@ module.exports = {
});
var numstat_test = function(post){
var mykey = 'statsd.numStats';
return _.include(_.keys(post),mykey) && (post[mykey] == 4);
return _.include(_.keys(post),mykey) && (post[mykey] == 5);
};
test.ok(_.any(hashes,numstat_test), 'statsd.numStats should be 4');
test.ok(_.any(hashes,numstat_test), 'statsd.numStats should be 5');

var testavgvalue_test = function(post){
var mykey = 'stats.a_test_value';
Expand Down
10 changes: 5 additions & 5 deletions test/graphite_legacy_tests_statsprefix.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 150,7 @@ module.exports = {
return data;
});
test.ok(_.include(_.map(entries,function(x) { return _.keys(x)[0] }),'statsprefix.numStats'),'graphite output includes numStats');
test.equal(_.find(entries, function(x) { return _.keys(x)[0] == 'statsprefix.numStats' })['statsprefix.numStats'],2);
test.equal(_.find(entries, function(x) { return _.keys(x)[0] == 'statsprefix.numStats' })['statsprefix.numStats'],3);
test.done();
});
});
Expand All @@ -173,9 173,9 @@ module.exports = {
});
var numstat_test = function(post){
var mykey = 'statsprefix.numStats';
return _.include(_.keys(post),mykey) && (post[mykey] == 4);
return _.include(_.keys(post),mykey) && (post[mykey] == 5);
};
test.ok(_.any(hashes,numstat_test), 'statsprefix.numStats should be 4');
test.ok(_.any(hashes,numstat_test), 'statsprefix.numStats should be 5');

var testtimervalue_test = function(post){
var mykey = 'stats.timers.a_test_value.mean_90';
Expand Down Expand Up @@ -206,9 206,9 @@ module.exports = {
});
var numstat_test = function(post){
var mykey = 'statsprefix.numStats';
return _.include(_.keys(post),mykey) && (post[mykey] == 4);
return _.include(_.keys(post),mykey) && (post[mykey] == 5);
};
test.ok(_.any(hashes,numstat_test), 'statsprefix.numStats should be 4');
test.ok(_.any(hashes,numstat_test), 'statsprefix.numStats should be 5');

var testavgvalue_test = function(post){
var mykey = 'stats.a_test_value';
Expand Down
14 changes: 7 additions & 7 deletions test/graphite_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 151,7 @@ module.exports = {
return data;
});
test.ok(_.include(_.map(entries,function(x) { return _.keys(x)[0] }),'stats.statsd.numStats'),'graphite output includes numStats');
test.equal(_.find(entries, function(x) { return _.keys(x)[0] == 'stats.statsd.numStats' })['stats.statsd.numStats'],2);
test.equal(_.find(entries, function(x) { return _.keys(x)[0] == 'stats.statsd.numStats' })['stats.statsd.numStats'],3);
test.done();
});
});
Expand All @@ -174,9 174,9 @@ module.exports = {
});
var numstat_test = function(post){
var mykey = 'stats.statsd.numStats';
return _.include(_.keys(post),mykey) && (post[mykey] == 3);
return _.include(_.keys(post),mykey) && (post[mykey] == 4);
};
test.ok(_.any(hashes,numstat_test), 'statsd.numStats should be 3');
test.ok(_.any(hashes,numstat_test), 'statsd.numStats should be 4');

var bad_lines_seen_value_test = function(post){
var mykey = 'stats.counters.statsd.bad_lines_seen.count';
Expand Down Expand Up @@ -207,9 207,9 @@ module.exports = {
});
var numstat_test = function(post){
var mykey = 'stats.statsd.numStats';
return _.include(_.keys(post),mykey) && (post[mykey] == 4);
return _.include(_.keys(post),mykey) && (post[mykey] == 5);
};
test.ok(_.any(hashes,numstat_test), 'stats.statsd.numStats should be 4');
test.ok(_.any(hashes,numstat_test), 'stats.statsd.numStats should be 5');

var testtimervalue_test = function(post){
var mykey = 'stats.timers.a_test_value.mean_90';
Expand Down Expand Up @@ -278,9 278,9 @@ module.exports = {
});
var numstat_test = function(post){
var mykey = 'stats.statsd.numStats';
return _.include(_.keys(post),mykey) && (post[mykey] == 4);
return _.include(_.keys(post),mykey) && (post[mykey] == 5);
};
test.ok(_.any(hashes,numstat_test), 'statsd.numStats should be 4');
test.ok(_.any(hashes,numstat_test), 'statsd.numStats should be 5');

var testavgvalue_test = function(post){
var mykey = 'stats.counters.a_test_value.rate';
Expand Down
14 changes: 7 additions & 7 deletions test/graphite_tests_statsprefix.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 151,7 @@ module.exports = {
return data;
});
test.ok(_.include(_.map(entries,function(x) { return _.keys(x)[0] }),'stats.statsprefix.numStats'),'graphite output includes numStats');
test.equal(_.find(entries, function(x) { return _.keys(x)[0] == 'stats.statsprefix.numStats' })['stats.statsprefix.numStats'],2);
test.equal(_.find(entries, function(x) { return _.keys(x)[0] == 'stats.statsprefix.numStats' })['stats.statsprefix.numStats'],3);
test.done();
});
});
Expand All @@ -174,9 174,9 @@ module.exports = {
});
var numstat_test = function(post){
var mykey = 'stats.statsprefix.numStats';
return _.include(_.keys(post),mykey) && (post[mykey] == 3);
return _.include(_.keys(post),mykey) && (post[mykey] == 4);
};
test.ok(_.any(hashes,numstat_test), 'statsprefix.numStats should be 3');
test.ok(_.any(hashes,numstat_test), 'statsprefix.numStats should be 4');

var bad_lines_seen_value_test = function(post){
var mykey = 'stats.counters.statsprefix.bad_lines_seen.count';
Expand Down Expand Up @@ -207,9 207,9 @@ module.exports = {
});
var numstat_test = function(post){
var mykey = 'stats.statsprefix.numStats';
return _.include(_.keys(post),mykey) && (post[mykey] == 4);
return _.include(_.keys(post),mykey) && (post[mykey] == 5);
};
test.ok(_.any(hashes,numstat_test), 'stats.statsprefix.numStats should be 4');
test.ok(_.any(hashes,numstat_test), 'stats.statsprefix.numStats should be 5');

var testtimervalue_test = function(post){
var mykey = 'stats.timers.a_test_value.mean_90';
Expand Down Expand Up @@ -240,9 240,9 @@ module.exports = {
});
var numstat_test = function(post){
var mykey = 'stats.statsprefix.numStats';
return _.include(_.keys(post),mykey) && (post[mykey] == 4);
return _.include(_.keys(post),mykey) && (post[mykey] == 5);
};
test.ok(_.any(hashes,numstat_test), 'statsprefix.numStats should be 4');
test.ok(_.any(hashes,numstat_test), 'statsprefix.numStats should be 5');

var testavgvalue_test = function(post){
var mykey = 'stats.counters.a_test_value.rate';
Expand Down
14 changes: 7 additions & 7 deletions test/graphite_tests_statssuffix.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 153,7 @@ module.exports = {
});
test.ok(_.include(_.map(entries,function(x) { return _.keys(x)[0] }),'stats.statsd.numStats.statssuffix'),'graphite output includes numStats');

test.equal(_.find(entries, function(x) { return _.keys(x)[0] == 'stats.statsd.numStats.statssuffix' })['stats.statsd.numStats.statssuffix'],2);
test.equal(_.find(entries, function(x) { return _.keys(x)[0] == 'stats.statsd.numStats.statssuffix' })['stats.statsd.numStats.statssuffix'],3);
test.done();
});
});
Expand All @@ -176,9 176,9 @@ module.exports = {
});
var numstat_test = function(post){
var mykey = 'stats.statsd.numStats.statssuffix';
return _.include(_.keys(post),mykey) && (post[mykey] == 3);
return _.include(_.keys(post),mykey) && (post[mykey] == 4);
};
test.ok(_.any(hashes,numstat_test), 'numStats.statssuffix should be 3');
test.ok(_.any(hashes,numstat_test), 'numStats.statssuffix should be 4');

var bad_lines_seen_value_test = function(post){
var mykey = 'stats.counters.statsd.bad_lines_seen.count.statssuffix';
Expand Down Expand Up @@ -209,9 209,9 @@ module.exports = {
});
var numstat_test = function(post){
var mykey = 'stats.statsd.numStats.statssuffix';
return _.include(_.keys(post),mykey) && (post[mykey] == 4);
return _.include(_.keys(post),mykey) && (post[mykey] == 5);
};
test.ok(_.any(hashes,numstat_test), 'stats.statsd.numStats.statssuffix should be 4');
test.ok(_.any(hashes,numstat_test), 'stats.statsd.numStats.statssuffix should be 5');

var testtimervalue_test = function(post){
var mykey = 'stats.timers.a_test_value.mean_90.statssuffix';
Expand Down Expand Up @@ -242,9 242,9 @@ module.exports = {
});
var numstat_test = function(post){
var mykey = 'stats.statsd.numStats.statssuffix';
return _.include(_.keys(post),mykey) && (post[mykey] == 4);
return _.include(_.keys(post),mykey) && (post[mykey] == 5);
};
test.ok(_.any(hashes,numstat_test), 'numStats.statssuffix should be 4');
test.ok(_.any(hashes,numstat_test), 'numStats.statssuffix should be 5');

var testavgvalue_test = function(post){
var mykey = 'stats.counters.a_test_value.rate.statssuffix';
Expand Down

0 comments on commit e3c237f

Please sign in to comment.