Class: Meter::Backend
- Inherits:
-
Object
- Object
- Meter::Backend
- Defined in:
- lib/meter/backend.rb
Overview
Statsd: A DogStatsd client (www.datadoghq.com)
Instance Attribute Summary collapse
-
#host ⇒ Object
StatsD host.
-
#namespace ⇒ Object
A namespace to prepend to all statsd calls.
-
#port ⇒ Object
StatsD port.
Class Method Summary collapse
- .logger ⇒ Object
-
.VERSION ⇒ Object
Return the current version of the library.
Instance Method Summary collapse
-
#count(stat, count, opts = {}) ⇒ Object
Sends an arbitrary count for the given stat to the statsd server.
-
#decrement(stat, opts = {}) ⇒ Object
Sends a decrement (count = -1) for the given stat to the statsd server.
-
#gauge(stat, value, opts = {}) ⇒ Object
Sends an arbitary gauge value for the given stat to the statsd server.
-
#histogram(stat, value, opts = {}) ⇒ Object
Sends a value to be tracked as a histogram to the statsd server.
-
#increment(stat, opts = {}) ⇒ Object
Sends an increment (count = 1) for the given stat to the statsd server.
-
#initialize(host = '127.0.0.1', port = 8125) ⇒ Backend
constructor
A new instance of Backend.
-
#set(stat, value, opts = {}) ⇒ Object
Sends a value to be tracked as a set to the statsd server.
-
#time(stat, opts = {}) { ... } ⇒ Object
Reports execution time of the provided block using #timing.
-
#timing(stat, ms, opts = {}) ⇒ Object
Sends a timing (in ms) for the given stat to the statsd server.
Constructor Details
#initialize(host = '127.0.0.1', port = 8125) ⇒ Backend
Returns a new instance of Backend.
44 45 46 47 48 |
# File 'lib/meter/backend.rb', line 44 def initialize(host = '127.0.0.1', port = 8125) self.host, self.port = host, port @prefix = nil @socket = UDPSocket.new end |
Instance Attribute Details
#host ⇒ Object
StatsD host. Defaults to 127.0.0.1.
28 29 30 |
# File 'lib/meter/backend.rb', line 28 def host @host end |
#namespace ⇒ Object
A namespace to prepend to all statsd calls.
25 26 27 |
# File 'lib/meter/backend.rb', line 25 def namespace @namespace end |
#port ⇒ Object
StatsD port. Defaults to 8125.
31 32 33 |
# File 'lib/meter/backend.rb', line 31 def port @port end |
Class Method Details
.logger ⇒ Object
33 34 35 |
# File 'lib/meter/backend.rb', line 33 def self.logger Meter.config.logger end |
.VERSION ⇒ Object
Return the current version of the library.
38 39 40 |
# File 'lib/meter/backend.rb', line 38 def self.VERSION "1.1.0" end |
Instance Method Details
#count(stat, count, opts = {}) ⇒ Object
Sends an arbitrary count for the given stat to the statsd server.
92 93 94 |
# File 'lib/meter/backend.rb', line 92 def count(stat, count, opts={}) send_stats stat, count, :c, opts end |
#decrement(stat, opts = {}) ⇒ Object
Sends a decrement (count = -1) for the given stat to the statsd server.
81 82 83 |
# File 'lib/meter/backend.rb', line 81 def decrement(stat, opts={}) count stat, -1, opts end |
#gauge(stat, value, opts = {}) ⇒ Object
Sends an arbitary gauge value for the given stat to the statsd server.
This is useful for recording things like available disk space, memory usage, and the like, which have different semantics than counters.
109 110 111 |
# File 'lib/meter/backend.rb', line 109 def gauge(stat, value, opts={}) send_stats stat, value, :g, opts end |
#histogram(stat, value, opts = {}) ⇒ Object
Sends a value to be tracked as a histogram to the statsd server.
122 123 124 |
# File 'lib/meter/backend.rb', line 122 def histogram(stat, value, opts={}) send_stats stat, value, :h, opts end |
#increment(stat, opts = {}) ⇒ Object
Sends an increment (count = 1) for the given stat to the statsd server.
70 71 72 |
# File 'lib/meter/backend.rb', line 70 def increment(stat, opts={}) count stat, 1, opts end |
#set(stat, value, opts = {}) ⇒ Object
Sends a value to be tracked as a set to the statsd server.
165 166 167 |
# File 'lib/meter/backend.rb', line 165 def set(stat, value, opts={}) send_stats stat, value, :s, opts end |
#time(stat, opts = {}) { ... } ⇒ Object
Reports execution time of the provided block using #timing.
150 151 152 153 154 155 |
# File 'lib/meter/backend.rb', line 150 def time(stat, opts={}) start = Time.now result = yield timing(stat, ((Time.now - start) * 1000).round, opts) result end |
#timing(stat, ms, opts = {}) ⇒ Object
Sends a timing (in ms) for the given stat to the statsd server. The sample_rate determines what percentage of the time this report is sent. The statsd server then uses the sample_rate to correctly track the average timing for the stat.
136 137 138 |
# File 'lib/meter/backend.rb', line 136 def timing(stat, ms, opts={}) send_stats stat, ms, :ms, opts end |