Skip to content

Commit

Permalink
update pr/232 to be merge-able
Browse files Browse the repository at this point in the history
  • Loading branch information
draco2003 committed Mar 14, 2013
2 parents 270a96a + f21e6d0 commit 7aa543b
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 5 deletions.
9 changes: 9 additions & 0 deletions docs/metric_types.md
Expand Up @@ -38,6 +38,9 @@ generate the following list of stats for each threshold:
Where `$KEY` is the stats key you specify when sending to statsd, and `$PCT` is
the percentile threshold.

If the count at flush is 0 then you can opt to send no metric at all for this timer,
by setting `config.deleteTimers`.

Use the `config.histogram` setting to instruct statsd to maintain histograms
over time. Specify which metrics to match and a corresponding list of
ordered non-inclusive upper limits of bins (class intervals).
Expand Down Expand Up @@ -72,6 +75,9 @@ StatsD now also supports gauges, arbitrary values, which can be recorded.

gaugor:333|g

If the gauge is not updated at the next flush, it will send the previous value. You can opt to send
no metric at all for this gauge, by setting `config.deleteGauge`

Adding a sign to the gauge value will change the value, rather than setting it.

gaugor:-10|g
Expand All @@ -92,6 +98,9 @@ using a Set to store all occuring events.

uniques:765|s

If the count at flush is 0 then you can opt to send no metric at all for this set, by
setting `config.deleteSets`.

Multi-Metric Packets
--------------------
StatsD supports receiving multiple metrics in a single packet by separating them
Expand Down
6 changes: 6 additions & 0 deletions exampleConfig.js
Expand Up @@ -34,6 +34,12 @@ Optional Variables:
interval: how often to log frequent keys [ms, default: 0]
percent: percentage of frequent keys to log [%, default: 100]
log: location of log file for frequent keys [default: STDOUT]
deleteIdleStats: don't send values to graphite for inactive counters, sets, gauges, or timeers
as opposed to sending 0. For gauges, this unsets the gauge (instead of sending
the previous value). Can be indivdually overriden. [default: false]
deleteGauges : don't send values to graphite for inactive gauges, as opposed to sending the previous value [default: false]
deleteTimers: don't send values to graphite for inactive timers, as opposed to sending 0 [default: false]
deleteSets: don't send values to graphite for inactive sets, as opposed to sending 0 [default: false]
deleteCounters: don't send values to graphite for inactive counters, as opposed to sending 0 [default: false]
prefixStats: prefix to use for the statsd statistics data for this running instance of statsd [default: statsd]
applies to both legacy and new namespacing
Expand Down
38 changes: 34 additions & 4 deletions stats.js
Expand Up @@ -59,6 +59,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;
for (var counter_key in metrics.counters) {
Expand All @@ -74,14 +85,33 @@ function flushMetrics() {
}

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

// Clear the sets
conf.deleteSets = conf.deleteSets || false;
for (var set_key in metrics.sets) {
metrics.sets[set_key] = new set.Set();
if (conf.deleteSets) {
delete(metrics.sets[set_key]);
} else {
metrics.sets[set_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 (var gauge_key in metrics.gauges) {
delete(metrics.gauges[gauge_key]);
}
}
});

Expand Down Expand Up @@ -121,7 +151,7 @@ config.configFile(process.argv[2], function (config, oldConfig) {
// key counting
var keyFlushInterval = Number((config.keyFlush && config.keyFlush.interval) || 0);

var udp_version = config.address_ipv6 ? 'udp6' : 'udp4'
var udp_version = config.address_ipv6 ? 'udp6' : 'udp4';
server = dgram.createSocket(udp_version, function (msg, rinfo) {
backendEvents.emit('packet', msg, rinfo);
counters[packets_received]++;
Expand Down
9 changes: 8 additions & 1 deletion test/graphite_delete_counters_tests.js
@@ -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 7aa543b

Please sign in to comment.