Permalink
Browse files

Merge pull request #13 from aredington/master

Add support for the gauge syntax.
  • Loading branch information...
jstorimer committed Apr 20, 2012
2 parents 0e96191 + 0d737f1 commit 0b81f71e6f2c833aac89c0a52bbb1435bee155c7
Showing with 26 additions and 0 deletions.
  1. +7 −0 lib/statsd/instrument.rb
  2. +19 −0 test/statsd-instrument_test.rb
View
@@ -114,6 +114,11 @@ def self.increment(key, delta = 1, sample_rate = default_sample_rate)
write(key, delta, :incr, sample_rate)
end
+ #gaugor:333|g
+ def self.gauge(key, value, sample_rate = default_sample_rate)
+ write(key, value, :g, sample_rate)
+ end
+
private
def self.socket
@@ -130,6 +135,8 @@ def self.write(k,v,op, sample_rate = default_sample_rate)
command << '|c'
when :ms
command << '|ms'
+ when :g
+ command << '|g'
end
command << "|@#{sample_rate}" if sample_rate < 1
@@ -148,6 +148,17 @@ def test_production_mode_should_use_udp_socket
StatsD.mode = :test
end
+ def test_write_supports_gauge_syntax
+ StatsD.unstub(:gauge)
+
+ StatsD.mode = :production
+ StatsD.server = 'localhost:123'
+
+ UDPSocket.any_instance.expects(:send).with('fooy:42|g', 0, 'localhost', 123)
+
+ StatsD.gauge('fooy', 42)
+ end
+
def test_should_not_write_when_disabled
StatsD.enabled = false
StatsD.expects(:logger).never
@@ -187,6 +198,14 @@ def test_statsd_measure_with_explicit_value
StatsD.measure('values.foobar', 42)
end
+ def test_statsd_gauge
+ StatsD.expects(:write).with('values.foobar', 12, :g, 1)
+
+ StatsD.default_sample_rate = 1
+
+ StatsD.gauge('values.foobar', 12)
+ end
+
def test_socket_error_should_not_raise
StatsD.mode = :production
UDPSocket.any_instance.expects(:send).raises(SocketError)

0 comments on commit 0b81f71

Please sign in to comment.