Thursday, 8 August 2013

Multiple EpochCounter's in a plugin

Multiple EpochCounter's in a plugin

I'm trying to create a custom plugin to track counts and rates of various
things. I'm new to Ruby and NewRelic so I'm taking the wikimedia plugin
and hacking at it to learn since it did a simplified version of what I'm
trying. In my setup, I have this --
def setup_metrics
@doc_creation_rate = NewRelic::Processor::EpochCounter.new
@consumer_online_rate = NewRelic::Processor::EpochCounter.new
@consumer_offline_rate = NewRelic::Processor::EpochCounter.new
@event_rate = NewRelic::Processor::EpochCounter.new
@task_queue_rate = NewRelic::Processor::EpochCounter.new
end
I quickly found that my rate values were fairly incomprehensible so I
added some debugging code to the processor to see what it was doing. I saw
quickly that the last_value and last_time were being used by each
successive rate calc --
last value: 0.0, last time: Thu Aug 08 18:03:28 -0500 2013, cur value:
33.0, cur time; Thu Aug 08 18:04:27 -0500 2013, rate: 0.553659969226572
last value: 33.0, last time: Thu Aug 08 18:04:27 -0500 2013, cur value:
9.0, cur time; Thu Aug 08 18:04:27 -0500 2013, rate: -172661.870503597
last value: 9.0, last time: Thu Aug 08 18:04:27 -0500 2013, cur value:
9.0, cur time; Thu Aug 08 18:04:27 -0500 2013, rate: 0.0
last value: 9.0, last time: Thu Aug 08 18:04:27 -0500 2013, cur value:
0.0, cur time; Thu Aug 08 18:04:27 -0500 2013, rate: -94736.8421052632
last value: 0.0, last time: Thu Aug 08 18:04:27 -0500 2013, cur value:
4012.0, cur time; Thu Aug 08 18:04:27 -0500 2013, rate: 62687500.0
last value: 4012.0, last time: Thu Aug 08 18:04:27 -0500 2013, cur value:
0.0, cur time; Thu Aug 08 18:04:27 -0500 2013, rate: -42680851.0638298
Is it possible to use EpochCounter in the way that I'm trying to use it?
If so, how? Is there a better way?
Thanks!
-- Marc

No comments:

Post a Comment