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,
localhost:8090/render?target=rtpg.testing_server_2.counters.account.hitcount4.count&format=raw
output on browser =>
..........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
with
//localhost:8090/render?target=rtpg.testing_server_2.counters.account.hitcount4.count&format=json
output =>
....................[0.0, 1381608024], [0.0, 1381608025], [0.0, 1381608026], [0.0, 1381608027], [0.0, 1381608028], [0.0, 1381608029], [0.0, 1381608030], [0.0, 1381608031], [0.0, 1381608032], [0.0, 1381608033], [0.0, 1381608034], [0.0, 1381608035], [0.0, 1381608036], [0.0, 1381608037], [0.0, 1381608038], [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]]}]
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.
来源:https://stackoverflow.com/questions/19318461/how-to-get-least-possible-count-on-graphite-graph