Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add support for gauge deltas.

* Add tests for gauges and new gauge deltas.
* Add support for +/- prefix for gauge values to support modifying
  gauge values in-place.
  • Loading branch information...
commit 3eecd18d3c68828e3754882d0d6ab8b34be0ab31 1 parent 4ea57cf
James Socol authored committed
Showing with 75 additions and 1 deletion.
  1. +5 −1 stats.js
  2. +70 −0 test/graphite_tests.js
View
6 stats.js
@@ -191,7 +191,11 @@ config.configFile(process.argv[2], function (config, oldConfig) {
timers[key].push(Number(fields[0] || 0));
timer_counters[key] += (1 / sampleRate);
} else if (fields[1].trim() == "g") {
- gauges[key] = Number(fields[0] || 0);
+ if (gauges[key] && fields[0].match(/^[-+]/)) {
+ gauges[key] += Number(fields[0] || 0);
+ } else {
+ gauges[key] = Number(fields[0] || 0);
+ }
} else if (fields[1].trim() == "s") {
if (! sets[key]) {
sets[key] = new set.Set();
View
70 test/graphite_tests.js
@@ -298,5 +298,75 @@ module.exports = {
});
});
});
+ },
+
+ gauges_are_valid: function(test) {
+ test.expect(3);
+
+ var testvalue = 70;
+ var me = this;
+ this.acceptor.once('connection', function(c) {
+ statsd_send('a_test_value:' + testvalue + '|g', me.sock, '127.0.0.1', 8125, function() {
+ collect_for(me.acceptor, me.myflush*2, function(strings) {
+ test.ok(strings.length > 0, 'should receive some data');
+ var hashes = _.map(strings, function(x) {
+ var chunks = x.split(' ');
+ var data = {};
+ data[chunks[0]] = chunks[1];
+ return data;
+ });
+ var numstat_test = function(post) {
+ var mykey = 'statsd.numStats';
+ return _.include(_.keys(post), mykey) && (post[mykey] == 1);
+ };
+ test.ok(_.any(hashes, numstat_test), 'statsd.numStats should be 1');
+
+ var gaugevalue_test = function(post) {
+ var mykey = 'stats.gauges.a_test_value';
+ return _.include(_.keys(post), mykey) && (post[mykey] == testvalue);
+ };
+ test.ok(_.any(hashes, gaugevalue_test), 'stats.gauges.a_test_value should be ' + testvalue);
+
+ test.done();
+ });
+ });
+ });
+ },
+
+ gauge_modifications_are_valid: function(test) {
+ test.expect(3);
+
+ var teststartvalue = 50;
+ var testdeltavalue = '-3';
+ var testresult = teststartvalue + Number(testdeltavalue);
+ var me = this;
+ this.acceptor.once('connection', function(c) {
+ statsd_send('test_value:' + teststartvalue + '|g', me.sock, '127.0.0.1', 8125, function() {
+ statsd_send('test_value:' + testdeltavalue + '|g', me.sock, '127.0.0.1', 8125, function() {
+ collect_for(me.acceptor, me.myflush * 2, function(strings) {
+ test.ok(strings.length > 0, 'should receive some data');
+ var hashes = _.map(strings, function(x) {
+ var chunks = x.split(' ');
+ var data = {};
+ data[chunks[0]] = chunks[1];
+ return data;
+ });
+ var numstat_test = function(post) {
+ var mykey = 'statsd.numStats';
+ return _.include(_.keys(post), mykey) && (post[mykey] == 1);
+ };
+ test.ok(_.any(hashes, numstat_test), 'statsd.numStats should be 1');
+
+ var gaugevalue_test = function(post) {
+ var mykey = 'stats.gauges.test_value';
+ return _.include(_.keys(post), mykey) && (post[mykey] == testresult);
+ };
+ test.ok(_.any(hashes, gaugevalue_test), 'stats.gauges.test_value should be ' + testresult);
+
+ test.done();
+ });
+ });
+ });
+ });
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.