sexta-feira, 23 de dezembro de 2016

rrdtool - Playing with rrdtool counter resets

http://zewaren.net/site/node/141 
 
 

Playing with rrdtool counter resets

Not so frequently asked questions and stuff: 

Creating and plotting some data normally

Let's create a standard rdd file, with a counter:
?
1
rrdtool create test.rrd --start $start --step 60 DS:something:COUNTER:600:0:U RRA:AVERAGE:0.5:1:1440
Now let's update it with some values.
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#!/usr/bin/env perl -w
 
use strict;
use warnings;
 
my $start = 1417392000;
my $counter = 0;
 
for my $x (1..60*24) {
    my $time = $start + 60*$x;
    $counter += 1000+ int(250*sin(1/(48)*$x));
    my $command = "rrdtool update test.rrd $time:$counter";
    system($command);
}
Let's graph!
?
1
2
3
rrdtool graph test.png -a PNG --start 1417392000 --end 1417478400 -t "Sure looks like a sine" -v "avg potato per second" \
    DEF:something=test.rrd:something:AVERAGE \
    LINE1:something#111111:"My superb value"
Image
So far, so good.

Having a counter reset

Now, let's recreate the same data, but with a counter reset in the middle.
?
1
2
3
if ($x == 1000) {
    $counter = 0;
}
The dreaded spike appears!
Image
Folder http://oss.oetiker.ch/rrdtool/pub/contrib/ contains many tools to remove spikes from rrd data files. My favorite one is spikekill (spikekill-1.1-1.tar.gz).
?
1
php removespikes.php -d -A=avg -M=variance -P=5000 -R=test.rrd
The spike is then replaced by a small innocent glitch.
Image
To prevent counter reset spikes, you should use DERIVE instead of COUNTER. Tuning the rrd file solves the problem.
?
1
rrdtool tune test.rrd --data-source-type something:DERIVE
 

0 comentários: