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.
73 74 75 |
# File 'lib/statsd/client.rb', line 73 def initialize(host = 'localhost', port = 8125) @host, @port = host, port end |
Instance Attribute Details
#host ⇒ Object (readonly)
Returns the value of attribute host.
67 68 69 |
# File 'lib/statsd/client.rb', line 67 def host @host end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
67 68 69 |
# File 'lib/statsd/client.rb', line 67 def port @port end |
Instance Method Details
#decrement(stats, sample_rate = 1) ⇒ Object
Decrements a counter
99 100 101 |
# File 'lib/statsd/client.rb', line 99 def decrement(stats, sample_rate = 1) update_stats(stats, -1, sample_rate) end |
#increment(stats, sample_rate = 1) ⇒ Object
Increments a counter
91 92 93 |
# File 'lib/statsd/client.rb', line 91 def increment(stats, sample_rate = 1) update_stats(stats, 1, sample_rate) end |
#timing(stats, time, sample_rate = 1) ⇒ Object
Sends timing statistics.
82 83 84 85 |
# File 'lib/statsd/client.rb', line 82 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
108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/statsd/client.rb', line 108 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 |