Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Statsite support #15

Merged
merged 2 commits into from

2 participants

@titanous

This patch adds support for statsite.

@jstorimer
Collaborator

LGTM

@jstorimer jstorimer merged commit 688c503 into from
@titanous

Yeah, my bad, pushed a fix to master.

@jstorimer
Collaborator

Graci.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jun 16, 2012
  1. @titanous

    Add support for statsite

    titanous authored
  2. @titanous
This page is out of date. Refresh to see the latest.
Showing with 34 additions and 7 deletions.
  1. +10 −7 lib/statsd/instrument.rb
  2. +24 −0 test/statsd-instrument_test.rb
View
17 lib/statsd/instrument.rb
@@ -12,11 +12,12 @@ def ms
module StatsD
class << self
attr_accessor :host, :port, :mode, :logger, :enabled, :default_sample_rate,
- :prefix
+ :prefix, :implementation
end
self.enabled = true
self.default_sample_rate = 1
-
+ self.implementation = :statsd
+
TimeoutClass = defined?(::SystemTimer) ? ::SystemTimer : ::Timeout
# StatsD.server = 'localhost:1234'
@@ -114,9 +115,10 @@ 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)
+ # gaugor:333|g
+ # guagor:1234|kv|@1339864935 (statsite)
+ def self.gauge(key, value, sample_rate_or_epoch = default_sample_rate)
+ write(key, value, :g, sample_rate_or_epoch)
end
private
@@ -136,10 +138,11 @@ def self.write(k,v,op, sample_rate = default_sample_rate)
when :ms
command << '|ms'
when :g
- command << '|g'
+ command << (self.implementation == :statsite ? '|kv' : '|g')
end
- command << "|@#{sample_rate}" if sample_rate < 1
+ command << "|@#{sample_rate}" if sample_rate < 1 || (self.implementation == :statsite && sample_rate > 1)
+ command << "\n" if self.implementation == :statsite
if mode.to_s == 'production'
socket_wrapper { socket.send(command, 0, host, port) }
View
24 test/statsd-instrument_test.rb
@@ -159,6 +159,30 @@ def test_write_supports_gauge_syntax
StatsD.gauge('fooy', 42)
end
+ def test_write_supports_statsite_gauge_syntax
+ StatsD.unstub(:gauge)
+
+ StatsD.mode = :production
+ StatsD.server = 'localhost:123'
+ StatsD.implementation = :statsite
+
+ UDPSocket.any_instance.expects(:send).with('fooy:42|kv', 0, 'localhost', 123)
+
+ StatsD.gauge('fooy', 42)
+ end
+
+ def test_write_supports_statsite_gauge_timestamp
+ StatsD.unstub(:gauge)
+
+ StatsD.mode = :production
+ StatsD.server = 'localhost:123'
+ StatsD.implementation = :statsite
+
+ UDPSocket.any_instance.expects(:send).with('fooy:42|kv|@123456', 0, 'localhost', 123)
+
+ StatsD.gauge('fooy', 42, 123456)
+ end
+
def test_should_not_write_when_disabled
StatsD.enabled = false
StatsD.expects(:logger).never
Something went wrong with that request. Please try again.