Class: Metriks::Reporter::NewRelic::Sampler
- Inherits:
-
NewRelic::Agent::Sampler
- Object
- NewRelic::Agent::Sampler
- Metriks::Reporter::NewRelic::Sampler
- Defined in:
- lib/metriks/reporter/new_relic/sampler.rb
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Sampler
constructor
A new instance of Sampler.
- #newrelic_name(name) ⇒ Object
- #poll ⇒ Object
- #value_update(metric_name, field_name, new_value) ⇒ Object
Constructor Details
Instance Method Details
#newrelic_name(name) ⇒ Object
46 47 48 |
# File 'lib/metriks/reporter/new_relic/sampler.rb', line 46 def newrelic_name(name) "Custom/" + name.gsub('.', '/') end |
#poll ⇒ Object
11 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 |
# File 'lib/metriks/reporter/new_relic/sampler.rb', line 11 def poll @registry.each do |name, metric| case metric when defined?(Metriks::Gauge) && metric.kind_of?(Metriks::Gauge) NewRelic::Agent.record_metric(newrelic_name(name), metric.value) when Metriks::Timer count = value_update(name, :count, metric.count) do |old,new| new - old end min = value_update(name, :min, metric.min) do |old,new| new < old ? new : old end max = value_update(name, :max, metric.max) do |old,new| new > old ? new : old end value = { :total => metric.mean, :count => count, :min => min, :max => max, # NOTE: we lose the total sum of squares, not in the registry :sum_of_squares => 0 } ::NewRelic::Agent.record_metric(newrelic_name(name), value) when Metriks::Counter count = value_update(name, :count, metric.count) do |old,new| new - old end ::NewRelic::Agent.increment_metric(newrelic_name(name), count) end end end |
#value_update(metric_name, field_name, new_value) ⇒ Object
50 51 52 53 54 55 56 57 58 59 |
# File 'lib/metriks/reporter/new_relic/sampler.rb', line 50 def value_update(metric_name, field_name, new_value) cache_key = "#{metric_name}-#{field_name}" if @cache[cache_key] == nil update = new_value else update = yield(@cache[cache_key], new_value) end @cache[cache_key] = update return update end |