Save luci-statistics/collectd across reboot

I have a lightweight approach, where I use scripts that save/restore the stats to flash. My goal is not to guarantee a full 100% of data, but to merely be able to see developments in the long run (monthly/yearly trends), e.g. memory consumption, CPU temp, etc. (As I run both master and 19.07 in my R7800 intermittently, there are differences in the data in any case.)

Saving collectd data every 30 seconds to flash, either router or USB stick, does not seem viable to be, so I keep the accumulating data quite normally in ramdisk /tmp/rrd.

As I store the stats on the router's flash, the data is neither reset-proof (firstboot clears overlay) nor sysupgrade-proof.

Cron runs the save script once per day to backup data against reboots.

I manually run the save / restore scripts in connection of a sysupgrade. I have configured the stats backup file to be carried along in sysupgrade.

And every few weeks I copy the backup file to external flash.

root@router1:~# cat /etc/storeStats.sh
#!/bin/sh
/etc/init.d/collectd stop
logger -t "LuCI statistics" Create backup archive
mkdir -p /etc/backup.stats
cd /tmp/rrd/$(uname -n)
tar c -zvf /etc/backup.stats/stats.tar.gz *
cp /etc/backup.stats/stats.tar.gz /etc/backup.stats/stats-$(date +%Y%m%dT%H%M).tar.gz
/etc/init.d/collectd start

root@router1:~# cat /etc/restoreStats.sh
#!/bin/sh
/etc/init.d/collectd stop
logger -t "LuCI statistics" collectd stopped, stats being restored
mkdir -p /tmp/rrd/$(uname -n)
cd /tmp/rrd/$(uname -n)
tar x -zvf /etc/backup.stats/stats.tar.gz
/etc/init.d/collectd start


root@router1:~# cat /etc/crontabs/root
0 2 * * * /etc/storeStats.sh

root@router1:~# cat /etc/sysupgrade.conf
## This file contains files and directories that should
## be preserved during an upgrade.
# /etc/example.conf
# /etc/openvpn/
/etc/backup.stats/
3 Likes