本文介绍了如何获得尽可能少的石墨图计数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

require 'statsd'

statsd = Statsd.new('localhost', 8125).tap{|sd| sd.namespace = 'account'}

1.times do
  statsd.increment 'hitcount4'
end

sleep 5

5.times do
  statsd.increment 'hitcount4'
end

sleep 10

10.times do
  statsd.increment 'hitcount4'
end

我正在使用红宝石宝石statsd-ruby

我运行了上面的脚本,它成功执行,并且出现了图形,但是我只能看到x轴上的一条线,什么也没有(y轴没有值),如何获取上述脚本的图形?/p>

我想记录每个增量呼叫.

/opt/graphite/statsd/local.js的内容

{
  graphitePort: 2003
, graphiteHost: "127.0.0.1"
, port: 8125
, backends: [ "./backends/graphite", "./backends/repeater", "./backends/console" ]
, repeater: [ { host: '10.1.2.15', port: 8125 } ]
, graphite: { legacyNamespace: false, globalPrefix: "rtpg.testing_server_2" }
, flushInterval: 10
}

/opt/graphite/conf/storage-schemas.conf的内容

[carbon]
pattern = ^carbon\.
retentions = 60:90d

[stats]
pattern = ^stats.*
retentions = 1s:6h,10min:10d,10min:5y

[rtpg]
pattern = ^rtpg.*
retentions = 1s:7d,10s:21d,60s:5y

/opt/graphite/conf/storage-aggregation.conf的内容

[rtpg]
pattern = .*
xFilesFactor = 0
aggregationMethod = sum


[sum]
pattern = \.count$
xFilesFactor = 0
aggregationMethod = sum

使用

我将flush intervel(statsd)更新为6000,并更新了

/opt/graphite/conf/storage-schemas.conf

[carbon]
pattern = ^carbon\.
retentions = 60:90d

[rtpg]
pattern = ^rtpg.*
retentions = 1m:6h,1m:7d,10m:5y

并在我的脚本中运行whisper-resize.py并将更新的计数器名称更新为"hitcount6",然后再次运行该脚本,创建了一个新图形,问题仍然存在,实际上我要的是石墨像第一个那样显示确切的计数增量,然后睡眠5分钟,然后再进行5次增量,依此类推,我不想平均数据,最后我将创建一个XML报告,其中包含调用了增量方法的次数.$ whisper-info.py/opt/graphite/storage/whisper/rtpg/testing_server_2/counters/account/hitcount6/count.wsp

maxRetention: 604800
xFilesFactor: 0.0
aggregationMethod: sum
fileSize: 120988

Archive 0
retention: 604800
secondsPerPoint: 60
points: 10080
size: 120960
offset: 28
解决方案

长话短说:使用Graphite作为后端时,您不能以小于1秒的时间间隔刷新Statsd .

由于您指定了10ms的flushInterval,因此StatsD将每10毫秒刷新一次聚合数据点,其中Graphite将从100中减少99(除了10ms刷新中的所有一次).

首先,将其设置为较低的值将破坏Statsd的某些目的,因为它旨在充当可减少石墨负载的聚集器. Second ,将其设置为小于1秒的任何值都会导致丢失度量标准数据.这是因为可以在Graphite中存储的最高精度为1秒.因此,您每秒将向石墨发送100个数据点,而Graphite将仅存储其中的1个.您必须非常幸运地看到间隔内的任何数据(因为它将采用最后一个指标(覆盖其他指标).

您必须使StatsD中的刷新间隔与Graphite中最精确的模式设置相匹配(在存储方案配置中).您可以走的最低时间是一秒钟,但建议使用10秒,以便StatsD可以代表您进行一些重要的汇总工作.

我建议您将最佳(第一)精度更改为10秒,即保留时间(10s:6h10s:7d)(以及将Statsd flushInterval更改为10000 ms),以便Statsd和石墨排列整齐.

下一步,进行上述更改,然后调整耳语文件的大小,以确保已完成设置.也许在存储度量(在低语=石墨的存储)之后更改了石墨架构或聚合设置,并且仍然需要删除该度量的.wsp文件(石墨将重新创建它们)或运行whisper-resize.py.耳语文件位于/graphite/storage/whisper/.

最后验证设置.您可以通过在.wsp文件上运行whisper-info.py来针对某些耳语数据验证设置.在/graphite/storage/whisper/中找到其中一个指标的.wsp文件运行:whisper-info.py my_metric_data.wsp. whisper-info.py的输出应该告诉您有关存储设置如何工作的更多信息.

require 'statsd'

statsd = Statsd.new('localhost', 8125).tap{|sd| sd.namespace = 'account'}

1.times do
  statsd.increment 'hitcount4'
end

sleep 5

5.times do
  statsd.increment 'hitcount4'
end

sleep 10

10.times do
  statsd.increment 'hitcount4'
end

i am using ruby gem statsd-ruby

i ran the above script it executes successfully, and the graph appears but i can just see the a line over the x-axis and nothing (no value for y-axis), how to get the graph for above script?

i want to record each increment call.

contents of /opt/graphite/statsd/local.js

{
  graphitePort: 2003
, graphiteHost: "127.0.0.1"
, port: 8125
, backends: [ "./backends/graphite", "./backends/repeater", "./backends/console" ]
, repeater: [ { host: '10.1.2.15', port: 8125 } ]
, graphite: { legacyNamespace: false, globalPrefix: "rtpg.testing_server_2" }
, flushInterval: 10
}

contents of /opt/graphite/conf/storage-schemas.conf

[carbon]
pattern = ^carbon\.
retentions = 60:90d

[stats]
pattern = ^stats.*
retentions = 1s:6h,10min:10d,10min:5y

[rtpg]
pattern = ^rtpg.*
retentions = 1s:7d,10s:21d,60s:5y

contents of /opt/graphite/conf/storage-aggregation.conf

[rtpg]
pattern = .*
xFilesFactor = 0
aggregationMethod = sum


[sum]
pattern = \.count$
xFilesFactor = 0
aggregationMethod = sum

with,

with

i updated flush intervel(statsd) to 6000, and updated

/opt/graphite/conf/storage-schemas.conf

[carbon]
pattern = ^carbon\.
retentions = 60:90d

[rtpg]
pattern = ^rtpg.*
retentions = 1m:6h,1m:7d,10m:5y

and ran whisper-resize.py and updated counter name to 'hitcount6' in my script and ran the script again, a new graph was created, the problem still exists, actually what i want is graphite to show exact count like first increment, then sleep of 5 minutes and then 5 increments and so on, i don't want to average my data, finally i will create a xml report of how many times increment method was invoked.$ whisper-info.py /opt/graphite/storage/whisper/rtpg/testing_server_2/counters/account/hitcount6/count.wsp

maxRetention: 604800
xFilesFactor: 0.0
aggregationMethod: sum
fileSize: 120988

Archive 0
retention: 604800
secondsPerPoint: 60
points: 10080
size: 120960
offset: 28
解决方案

Long story short: You cannot flush Statsd at an interval lower than 1 second when using Graphite as the backend.

Because you've specified a flushInterval of 10 ms, StatsD will flush the aggregated data-point every 10 milliseconds of which Graphite will drop 99 out of 100 (all but one of the 10ms flushes).

First, setting it this low defeats some of the purpose of Statsd in that it is intended to act as an aggregator that can reduce load on graphite. Second, setting it to anything lower than 1 second will result in lost metric data. This is because the finest precision that you can store in Graphite is 1 second. So you'll send 100 data points to graphite per second and Graphite will only store 1 of them. You'd have to be pretty lucky to see any data (as it will take the last metric (overwriting the others) for the interval.

You must match the flush interval in StatsD to the finest precision schema setting in Graphite (in the storage-schema configuration). The lowest you can go is one second, but 10 seconds is recommended so that StatsD can do some significant aggregation work on your behalf.

I'd recommend you change the finest (first) precision to 10 seconds, i.e. 10s:6h and 10s:7d for the retentions (and the Statsd flushInterval to 10000 ms) so that Statsd and Graphite line up nicely.

Next, make the above change and then resize the whisper files to ensure the settings have taken. Perhaps you changed the graphite schema or aggregation settings after metrics were stored (in whisper = graphite's storage) and you still need to either delete the .wsp files for the metric (graphite will recreate them) or run whisper-resize.py. The whisper files are in /graphite/storage/whisper/.

Finally, validate the settings. You can verify the settings against some whisper data by running whisper-info.py on a .wsp file. Find the .wsp file for one of your metrics in /graphite/storage/whisper/Run: whisper-info.py my_metric_data.wsp. whisper-info.py output should tell you more about how the storage settings are working.

这篇关于如何获得尽可能少的石墨图计数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-28 16:19