How can I update data with RRDtool?
Asked Answered
P

3

6

I am using RRDtool for storing data for displaying graphs. I update the RRD by RRDs::update and this fails when trying to rewrite the information, means update data for a time in the past (e.g. someone moved the system timer back). The error I get is:

ERROR: Cannot update /opt/dashboard/rrd/Disk/192.168.120.168_disk_1.rrd with 
'1228032301:24:24' illegal attempt to update using time 1228032301 when last 
update time is 1228050001 (minimum one second step)

I want to always allow the rewrite, how can I do this?

Psychometry answered 30/11, 2008 at 9:49 Comment(0)
T
4

rrdtool does not write your input into the rrd file. It rather samples what you enter and then stores the resulting datapoints. So providing 'old data' to rrdtool update will not work in the same way, as you can not easily skip back in a sound recording to 'fix' a few bad notes.

Obviously there are ways to alter old data, the way todo this in rrdtool, is to 'dump' the rrd file to xml, modify the content and 'restore' it. Not something one would like todo on a regular basis.

Tarbes answered 20/7, 2012 at 6:32 Comment(0)
P
4

I use following script in such situations:

#!/bin/sh
rrdtool dump "$1" | perl -ne 'BEGIN {$t=`date +%s`; chomp($t);} $a=$_; if ($a =~ /lastupdate.\d+..lastupdate/) { $a =~ s/(lastupdate.)\d+(..lastupdate)/$1$t$2/; } print $a' | rrdtool restore -f - "$1"

It's a little... freaky, but i could not find another automatic solution.

Prejudge answered 25/7, 2012 at 8:44 Comment(0)
B
1

According to the RRD documentation, that timestamp number must increase with each update. Given your constraints, I'd modify your update routine so that if the update fails, you catch the exception and redo the update with the time field set to 'N'. That will make RRDtool use the current time as the update time.

Alternatively, if you don't want to deal with the catch-and-retry code, just modify your update code to always use 'N' as the time value -- then the update will always work.

It may be helpful to have a quick look at the documentation for the RRDtool update command.

Barr answered 30/11, 2008 at 13:42 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.