Metrics client for Ruby apps
Adaptation of statsd-instrument for the (yet unreleased) metrics server.
Configuration
Metrics.server = 'statsd.myservice.com:8125'
Metrics.logger = Rails.logger
Metrics.mode = :production
Metrics.default_sample_rate = 0.1 # Sample 10% of events. By default all events are reported.
Usage
Metrics.measure
# You can pass a key and a ms value
Metrics.measure('GoogleBase.insert', 2.55)
# or more commonly pass a block that calls your code
Metrics.measure('GoogleBase.insert') do
GoogleBase.insert(product)
end
or with metaprogramming:
GoogleBase.extend Metrics::Instrument
GoogleBase.metrics_measure :insert, 'GoogleBase.insert'
Metaprogramming methods
metrics_count
adds '1' to the metricmetrics_count_if
adds '1' to the metric if method returned something that evaulates to true. Takes optional block to evaluate the returned value.metrics_count_success
adds '1' tometric.success
for successful calls andmetrics.failure
for failed calls.