Playing with rrdtool counter resets
December 2014.
Creating and plotting some data normally
Let's create a standard rdd file, with a counter:
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.
#!/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!
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"
So far, so good.
Having a counter reset
Now, let's recreate the same data, but with a counter reset in the middle.
if ($x == 1000) {
$counter = 0;
}
The dreaded spike appears!
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).
php removespikes.php -d -A=avg -M=variance -P=5000 -R=test.rrd
The spike is then replaced by a small innocent glitch.
To prevent counter reset spikes, you should use DERIVE instead of COUNTER. Tuning the rrd file solves the problem.
rrdtool tune test.rrd --data-source-type something:DERIVE