如何最少地计算石墨图

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 

我正在使用ruby gem statsd-ruby

我运行上面的脚本它成功执行,图形出现但我只能看到x轴上的一条线而没有(没有y轴的值),如何获取上述脚本的图形?

我想记录每个增量调用。

/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 

用,

本地主机:8090 /渲染目标= rtpg.testing_server_2.counters.account.hitcount4.count&格式=原始?

浏览器输出=>

………. 0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0, 0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0, 0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0, 0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0, 0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0

//localhost:8090/render?target=rtpg.testing_server_2.counters.account.hitcount4.count&format=json

输出=>

……………….. [0.0,1381608024],[0.0,1381608025],[0.0,1381608026],[0.0,1381608027],[0.0,1381608028], [0.0,138818029],[0.0,138816080],[0.0,1381608031],[0.0,1381608032],[0.0,1381608033],[0.0,1381608034],[0.0,13881608035],[0.0,1381608036],[0.0 ,1381608037],[0.0,1381808038],[0.0,1381608039],[0.0,1381608040],[0.0,1381608041],[0.0,1381608042],[0.0,1381608043],[0.0,1381608044],[0.0,1381608045] ],[0.0,1381608046],[0.0,1381608047],[0.0,1381608048],[0.0,1381608049],[0.0,1381608050],[0.0,1381608051],[0.0,1381608052],[0.0,1381608053], [0.0,1381608054],[0.0,1381608055],[0.0,1381608056]]}]

我将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

因为你已经指定了10毫秒的flushInterval,StatsD将每隔10毫秒刷新一次聚合数据点,其中Graphite将从100个中删除99个(除了10毫秒之一之外的所有刷新)。

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

您必须将StatsD中的刷新间隔与Graphite中的最精确架构设置 (在存储架构配置中)相匹配 。 您可以使用的最低值为1秒,但建议使用10秒,以便StatsD可以代表您执行一些重要的聚合工作。

我建议你将最好的(第一)精度更改为10秒 ,即10s:6h10s:7d用于保留(以及Statsd flushInterval到10000 ms),以便Statsd和Graphite很好地排列。

接下来 ,进行上述更改,然后调整耳语文件的大小以确保已进行设置。 也许您在存储指标后(在whisper = graphite的存储中)更改了石墨架构或聚合设置,您仍然需要删除指标的.wsp文件(graphite会重新创建它们)或运行whisper-resize.py 。 耳语文件是/graphite/storage/whisper/

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