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.
-
#tcp ⇒ Object
readonly
Returns the value of attribute tcp.
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, tcp = false) ⇒ 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, tcp = false) ⇒ Client
Initializes a Statsd client.
90 91 92 |
# File 'lib/statsd/client.rb', line 90 def initialize(host = 'localhost', port = 8125, tcp = false) @host, @port, @tcp = host, port, tcp end |
Instance Attribute Details
#host ⇒ Object (readonly)
Returns the value of attribute host.
83 84 85 |
# File 'lib/statsd/client.rb', line 83 def host @host end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
83 84 85 |
# File 'lib/statsd/client.rb', line 83 def port @port end |
#tcp ⇒ Object (readonly)
Returns the value of attribute tcp.
83 84 85 |
# File 'lib/statsd/client.rb', line 83 def tcp @tcp end |
Instance Method Details
#decrement(stats, sample_rate = 1) ⇒ Object
Decrements a counter
116 117 118 |
# File 'lib/statsd/client.rb', line 116 def decrement(stats, sample_rate = 1) update_stats(stats, -1, sample_rate) end |
#increment(stats, sample_rate = 1) ⇒ Object
Increments a counter
108 109 110 |
# File 'lib/statsd/client.rb', line 108 def increment(stats, sample_rate = 1) update_stats(stats, 1, sample_rate) end |
#timing(stats, time, sample_rate = 1) ⇒ Object
Sends timing statistics.
99 100 101 102 |
# File 'lib/statsd/client.rb', line 99 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
125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/statsd/client.rb', line 125 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 |