Class: Resque::Metrics::Backends::Statsd
- Inherits:
-
Object
- Object
- Resque::Metrics::Backends::Statsd
- Defined in:
- lib/resque/metrics/backends/statsd.rb
Instance Attribute Summary collapse
-
#metric_prefix ⇒ Object
Returns the value of attribute metric_prefix.
-
#statsd ⇒ Object
Returns the value of attribute statsd.
Instance Method Summary collapse
- #increment_metric(metric, by = 1) ⇒ Object
-
#initialize(statsd, metric_prefix = 'resque') ⇒ Statsd
constructor
A new instance of Statsd.
- #set_metric(metric, val) ⇒ Object
Constructor Details
#initialize(statsd, metric_prefix = 'resque') ⇒ Statsd
Returns a new instance of Statsd.
7 8 9 10 |
# File 'lib/resque/metrics/backends/statsd.rb', line 7 def initialize(statsd, metric_prefix = 'resque') @statsd = statsd @metric_prefix = metric_prefix end |
Instance Attribute Details
#metric_prefix ⇒ Object
Returns the value of attribute metric_prefix.
5 6 7 |
# File 'lib/resque/metrics/backends/statsd.rb', line 5 def metric_prefix @metric_prefix end |
#statsd ⇒ Object
Returns the value of attribute statsd.
5 6 7 |
# File 'lib/resque/metrics/backends/statsd.rb', line 5 def statsd @statsd end |
Instance Method Details
#increment_metric(metric, by = 1) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/resque/metrics/backends/statsd.rb', line 12 def increment_metric(metric, by = 1) if metric =~ /^(.+)(?:_job)?_(time|count)(?::(queue|job):(.*))?$/ event = $1 event = 'complete' if event == 'job' time_or_count = $2 queue_or_job = $3 queue_or_job_name = $4 key = if queue_or_job && queue_or_job_name # ie resque.complete.queue.high.count, resque.failed.job.Index.timing "#{metric_prefix}.#{event}.#{queue_or_job}.#{queue_or_job_name}.#{time_or_count}" else # ie resque.complete.time "#{metric_prefix}.#{event}.#{time_or_count}" end case time_or_count when 'time' statsd.timing key, by when 'count' statsd.increment key, by else raise "Not sure how to increment_metric for a #{time_or_count} metric (#{metric})" end elsif metric =~ /^payload_size(?::(queue|job):(.*))?$/ queue_or_job = $1 queue_or_job_name = $2 key = if queue_or_job && queue_or_job_name # ie resque.complete.queue.high.count, resque.failed.job.Index.timing "#{metric_prefix}.payload_size.#{queue_or_job}.#{queue_or_job_name}.#{time_or_count}" else "#{metric_prefix}.payload_size.#{time_or_count}" end statsd.increment key, by else raise "Not sure how to increment_metric #{metric}" end end |
#set_metric(metric, val) ⇒ Object
51 52 53 54 55 56 57 58 |
# File 'lib/resque/metrics/backends/statsd.rb', line 51 def set_metric(metric, val) if metric =~ /^depth(?::(failed|pending|queue)(?::(.+))?)?$/ key = "#{metric_prefix}.#{metric.gsub(':', '.')}" statsd.gauge key, val else raise "Not sure how to set_metric #{metric}" end end |