RRDs getting future timestamps

Occasionally, I’ll run into issues where RRD will stop recording new statistics data, because somehow the RRDs get a future timestamp. For example, mine have a timestamp of Jan 13 2018 (1515877830). Maybe it has something to do with luci_statistics starting before ntpd has had time to actually perform a sync? This seems to happen reasonably often after a reboot.

Examples:

rrdtool plugin: rrd_update_r failed: /srv/rrd/router1/netlink-eth2.4/if_octets.rrd: illegal attempt to update using time 1511421359 when last update time is 1515877829 (minimum one second step)
rrdtool plugin: rrd_update_r failed: /srv/rrd/router1/netlink-eth2.4/if_packets.rrd: illegal attempt to update using time 1511421359 when last update time is 1515877814 (minimum one second step)
rrdtool plugin: rrd_update_r failed: /srv/rrd/router1/netlink-eth2.5/if_errors.rrd: illegal attempt to update using time 1511421359 when last update time is 1515877814 (minimum one second step)
rrdtool plugin: rrd_update_r failed: /srv/rrd/router1/netlink-eth2.5/if_octets.rrd: illegal attempt to update using time 1511421359 when last update time is 1515877804 (minimum one second step)
rrdtool plugin: rrd_update_r failed: /srv/rrd/router1/netlink-eth2.5/if_packets.rrd: illegal attempt to update using time 1511421359 when last update time is 1515877824 (minimum one second step)
rrdtool plugin: rrd_update_r failed: /srv/rrd/router1/netlink-wlan0/if_errors.rrd: illegal attempt to update using time 1511421359 when last update time is 1515877824 (minimum one second step)
rrdtool plugin: rrd_update_r failed: /srv/rrd/router1/netlink-wlan0/if_octets.rrd: illegal attempt to update using time 1511421359 when last update time is 1515877824 (minimum one second step)
rrdtool plugin: rrd_update_r failed: /srv/rrd/router1/netlink-wlan0/if_packets.rrd: illegal attempt to update using time 1511421359 when last update time is 1515877809 (minimum one second step)
rrdtool plugin: rrd_update_r failed: /srv/rrd/router1/netlink-wlan1/if_errors.rrd: illegal attempt to update using time 1511421359 when last update time is 1515877809 (minimum one second step)
rrdtool plugin: rrd_update_r failed: /srv/rrd/router1/netlink-wlan1/if_octets.rrd: illegal attempt to update using time 1511421359 when last update time is 1515877819 (minimum one second step)
rrdtool plugin: rrd_update_r failed: /srv/rrd/router1/netlink-wlan1/if_packets.rrd: illegal attempt to update using time 1511421359 when last update time is 1515877824 (minimum one second step)

I have to either discard the RRDs entirely, or edit them to remove the bad data.

Would be nice if it were fixed, but currently I’m using this script to fix it:

#!/bin/bash

FILE=$1
TIMESTAMP=`date +%s`

if [ -f $FILE ]
then
        rrdtool dump $1 > $1.xml
        sed -i "s/<lastupdate>.*<\/lastupdate>/<lastupdate> $TIMESTAMP <\/lastupdate>/" $1.xml
        rm $1
        rrdtool restore $1.xml $1
        rm $1.xml
else
        echo "File does not exist: $1"
fi

It’s 2024 and I am still seeing the same error. And not just on reboot (current uptime is 7 days for instance).