Skip to content

Commit

Permalink
Merge branch 'p/deleteidlestats'
Browse files Browse the repository at this point in the history
  • Loading branch information
david raistrick committed Jan 4, 2013
2 parents 7179511 + 1a755c4 commit f560634
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 3 deletions.
33 changes: 31 additions & 2 deletions stats.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,17 @@ function flushMetrics() {

// After all listeners, reset the stats
backendEvents.once('flush', function clear_metrics(ts, metrics) {
// TODO: a lot of this should be moved up into an init/constructor so we don't have to do it every
// single flushInterval....
// allows us to flag all of these on with a single config but still override them individually
conf.deleteIdleStats = conf.deleteIdleStats !== undefined ? conf.deleteIdleStats : false;
if (conf.deleteIdleStats) {
conf.deleteCounters = conf.deleteCounters !== undefined ? conf.deleteCounters : true;
conf.deleteTimers = conf.deleteTimers !== undefined ? conf.deleteTimers : true;
conf.deleteSets = conf.deleteSets !== undefined ? conf.deleteSets : true;
conf.deleteGauges = conf.deleteGauges !== undefined ? conf.deleteGauges : true;
}

// Clear the counters
conf.deleteCounters = conf.deleteCounters || false;

Expand Down Expand Up @@ -87,13 +98,31 @@ function flushMetrics() {
}

// Clear the timers
conf.deleteTimers = conf.deleteTimers || false;
for (key in metrics.timers) {
metrics.timers[key] = [];
if (conf.deleteTimers) {
delete(metrics.timers[key]);
} else {
metrics.timers[key] = [];
}
}

// Clear the sets
conf.deleteSets = conf.deleteSets || false;
for (key in metrics.sets) {
metrics.sets[key] = new set.Set();
if (conf.deleteSets) {
delete(metrics.sets[key]);
} else {
metrics.sets[key] = new set.Set();
}
}

// normally gauges are not reset. so if we don't delete them, continue to persist previous value
conf.deleteGauges = conf.deleteGauges || false;
if (conf.deleteGauges) {
for (key in metrics.gauges) {
delete(metrics.gauges[key]);
}
}
});

Expand Down
9 changes: 8 additions & 1 deletion test/graphite_delete_counters_tests.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
// this unit test, for deleteCounters and other stats related to deleteIdleStats
// should probably be reviewed for sanity - I'm not sure it really tests appropriately
// for example, it should test that data is written the first time
// then test that the counter/etc is actually removed when it doesn't get data..
// - keen99


var fs = require('fs'),
net = require('net'),
temp = require('temp'),
Expand Down Expand Up @@ -79,7 +86,7 @@ module.exports = {
, port: 8125\n\
, dumpMessages: false \n\
, debug: false\n\
, deleteCounters: true\n\
, deleteIdleStats: true\n\
, graphitePort: " + this.testport + "\n\
, graphiteHost: \"127.0.0.1\"}";

Expand Down

0 comments on commit f560634

Please sign in to comment.