Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Add support for the gauge syntax. #13

Merged
merged 1 commit into from

2 participants

@aredington
  • StatsD.gauge method added
  • Gauge syntax support added to the write method
Alex Redington and Gabriel Horner Add gauge support
- StatsD.gauge method added
- Gauge syntax support added to the write method
0d737f1
@jstorimer jstorimer merged commit 0b81f71 into Shopify:master
@jstorimer
Collaborator

Thanks! I just published v1.2.0 with the changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Apr 17, 2012
  1. Add gauge support

    Alex Redington and Gabriel Horner authored
    - StatsD.gauge method added
    - Gauge syntax support added to the write method
This page is out of date. Refresh to see the latest.
Showing with 26 additions and 0 deletions.
  1. +7 −0 lib/statsd/instrument.rb
  2. +19 −0 test/statsd-instrument_test.rb
View
7 lib/statsd/instrument.rb
@@ -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
View
19 test/statsd-instrument_test.rb
@@ -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)
Something went wrong with that request. Please try again.