Class: Statsd::Client
- Inherits:
-
Object
- Object
- Statsd::Client
- Defined in:
- lib/statsd/client.rb
Constant Summary collapse
- VERSION =
File.read( File.join(File.dirname(__FILE__),'..', '..', 'VERSION') ).strip
Instance Attribute Summary collapse
-
#host ⇒ Object
readonly
Returns the value of attribute host.
-
#port ⇒ Object
readonly
Returns the value of attribute port.
Instance Method Summary collapse
-
#decrement(stats, sample_rate = 1) ⇒ Object
Decrements a counter.
-
#increment(stats, sample_rate = 1) ⇒ Object
Increments a counter.
-
#initialize(host = 'localhost', port = 8125) ⇒ Client
constructor
Initializes a Statsd client.
-
#timing(stats, time, sample_rate = 1) ⇒ Object
Sends timing statistics.
-
#update_stats(stats, delta = 1, sample_rate = 1) ⇒ Object
Updates one or more counters by an arbitrary amount.
Constructor Details
#initialize(host = 'localhost', port = 8125) ⇒ Client
Initializes a Statsd client.
85 86 87 |
# File 'lib/statsd/client.rb', line 85 def initialize(host = 'localhost', port = 8125) @host, @port = host, port end |
Instance Attribute Details
#host ⇒ Object (readonly)
Returns the value of attribute host.
79 80 81 |
# File 'lib/statsd/client.rb', line 79 def host @host end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
79 80 81 |
# File 'lib/statsd/client.rb', line 79 def port @port end |
Instance Method Details
#decrement(stats, sample_rate = 1) ⇒ Object
Decrements a counter
111 112 113 |
# File 'lib/statsd/client.rb', line 111 def decrement(stats, sample_rate = 1) update_stats(stats, -1, sample_rate) end |
#increment(stats, sample_rate = 1) ⇒ Object
Increments a counter
103 104 105 |
# File 'lib/statsd/client.rb', line 103 def increment(stats, sample_rate = 1) update_stats(stats, 1, sample_rate) end |
#timing(stats, time, sample_rate = 1) ⇒ Object
Sends timing statistics.
94 95 96 97 |
# File 'lib/statsd/client.rb', line 94 def timing(stats, time, sample_rate = 1) data = "#{time}|ms" update_stats(stats, data, sample_rate) end |
#update_stats(stats, delta = 1, sample_rate = 1) ⇒ Object
Updates one or more counters by an arbitrary amount
120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
# File 'lib/statsd/client.rb', line 120 def update_stats(stats, delta = 1, sample_rate = 1) stats = [stats] unless stats.kind_of?(Array) data = {} delta = delta.to_s stats.each do |stat| # if it's got a |ms in it, we know it's a timing stat, so don't append # the |c. data[stat] = delta.include?('|ms') ? delta : "#{delta}|c" end send(data, sample_rate) end |