Class: Statsd
- Inherits:
-
Object
- Object
- Statsd
- Defined in:
- lib/statsd.rb
Constant Summary collapse
- Version =
'0.0.6'
Class Attribute Summary collapse
-
.host ⇒ Object
Returns the value of attribute host.
-
.port ⇒ Object
Returns the value of attribute port.
Class Method Summary collapse
-
.decrement(stats, sample_rate = 1) ⇒ Object
stats
can be a string or an array of strings. - .host_ip_addr ⇒ Object
-
.increment(stats, sample_rate = 1) ⇒ Object
stats
can be a string or an array of strings. -
.timing(stat, time = nil, sample_rate = 1) ⇒ Object
stat
to log timing fortime
is the time to log in ms. -
.update_counter(stats, delta = 1, sample_rate = 1) ⇒ Object
stats
can be a string or array of strings.
Class Attribute Details
.host ⇒ Object
Returns the value of attribute host.
10 11 12 |
# File 'lib/statsd.rb', line 10 def host @host end |
.port ⇒ Object
Returns the value of attribute port.
10 11 12 |
# File 'lib/statsd.rb', line 10 def port @port end |
Class Method Details
.decrement(stats, sample_rate = 1) ⇒ Object
stats
can be a string or an array of strings
38 39 40 |
# File 'lib/statsd.rb', line 38 def decrement(stats, sample_rate = 1) update_counter stats, -1, sample_rate end |
.host_ip_addr ⇒ Object
12 13 14 |
# File 'lib/statsd.rb', line 12 def host_ip_addr @host_ip_addr ||= Resolv.getaddress(host) end |
.increment(stats, sample_rate = 1) ⇒ Object
stats
can be a string or an array of strings
33 34 35 |
# File 'lib/statsd.rb', line 33 def increment(stats, sample_rate = 1) update_counter stats, 1, sample_rate end |
.timing(stat, time = nil, sample_rate = 1) ⇒ Object
stat
to log timing for time
is the time to log in ms
23 24 25 26 27 28 29 30 |
# File 'lib/statsd.rb', line 23 def timing(stat, time = nil, sample_rate = 1) if block_given? start_time = Time.now.to_f yield time = ((Time.now.to_f - start_time) * 1000).floor end send_stats("#{stat}:#{time}|ms", sample_rate) end |
.update_counter(stats, delta = 1, sample_rate = 1) ⇒ Object
stats
can be a string or array of strings
43 44 45 46 |
# File 'lib/statsd.rb', line 43 def update_counter(stats, delta = 1, sample_rate = 1) stats = Array(stats) send_stats(stats.map { |s| "#{s}:#{delta}|c" }, sample_rate) end |