1

我正在尝试创建一个自定义插件来跟踪各种事物的计数和速率。我是 Ruby 和 NewRelic 的新手,所以我正在使用 wikimedia 插件并对其进行学习,因为它做了我正在尝试的简化版本。在我的设置中,我有这个——

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

我很快发现我的速率值相当难以理解,因此我向处理器添加了一些调试代码,以查看它在做什么。我很快看到 last_value 和 last_time 被每个连续的费率计算所使用——

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

是否可以以我尝试使用的方式使用 EpochCounter?如果是这样,怎么做?有没有更好的办法?

谢谢!

——马克

4

1 回答 1

0

知道了。愚蠢的复制粘贴错误,但结果我学到了很多关于 ruby​​ 模块和对象的知识 =) 我重用了相同的变量/命名空间。

report_metric("Streaming/Rate/Online Consumers", "consumers/sec", @event_rate.process(total_consumers_online))
report_metric("Streaming/Rate/Offline Consumers", "consumers/sec", @event_rate.process(total_consumers_offline))
report_metric("Streaming/Rate/Events", "events/sec", @event_rate.process(total_events))

本来应该 -

report_metric("Streaming/Rate/Online Consumers", "consumers/sec", @consumer_online_rate.process(total_consumers_online))
report_metric("Streaming/Rate/Offline Consumers", "consumers/sec", @consumer_offline_rate.process(total_consumers_offline))
report_metric("Streaming/Rate/Events", "events/sec", @event_rate.process(total_events))
于 2013-08-09T19:11:09.910 回答