Collectd: a good place to save rrd file?

Hello ! I recently installed luci-app-statistics etc and it's working fine. Now, according to the documentation, the rrd files are saved under tmp, and are doomed to vanish upon rebooting of the router. The standard way to get around is to put a USB stick on the router and save them there. But my OpenWRT is Raspberry pi 4 with 32 GB SD card, I think I should be able to save the rrd files somewhere in SD card without making OpenWRT stop working. But I am not sure where the right place is. On my disk-utility, I see a partition "boot", and "linux", and I figure that "boot" is where OpenWRT lives. But I have
bin dev lib mnt proc root sys usr www
boot etc lib64 overlay rom sbin tmp var

and they seem to be all there for OpenWRT, not just boot.
I would very much appreciate if someone could tell me where the right/safe place is.

I also have another Raspi 4 ("Raspi-Unifi"), where I run Unifi Controller. I installed "samba" there and tried to see if I could save the files there, but didn't manage to figure out....

I would like to be able to see the statistics for a year or so.

The directories /root, /usr/share or /etc are all suitable places. You could even create a custom top level directory like /rrd or /data.

Actually any place would work except for the following well known locations:

  • /boot (might be mounted onto a small partition)
  • /www (data is publicly exposed via HTTP)
  • /tmp (is a tmpfs vanishing on reboot)
  • /var (is a symlink to /tmp)
  • /lib, /usr/lib (should only contain libs, but technically doable)
  • /bin, /sbin, /usr/bin, /usr/sbin (should only contain executables, but technically doable)
  • /mnt (used by auto mount, might get shadowed by mounted partitions)
3 Likes

You might still consider that saving the database every 30 seconds causes it to be written almost 3000 times per day. That will wear down the flash to some extent.

I use cron to write the database once per day to flash, as a backup (which I can restore after reboots). That mitigates the write frequency to flash while helps in keeping long-term data.

Note that I do not aim for 100% data, but merely the ability to monitor long-term trends over the year, so a loss of a few days e.g. after a faulty firmware version is ok for me.

See the scripts in:

3 Likes

Thank you very much for your information and advice, both of you ! I had very little idea about these directories, I was always wondering why certain files are usually in certain directories.
Now in practice, what @hnyman suggests sounds good to me. Since my OpenWRT is on SD card, I should avoid writing things very often. I am also interested in general trend (of bandwidth usage) and don't mind losing data for some time, having a back up once a day is enough. I looked at the other page and just did what you prescribed :slight_smile: Pretty nice :slight_smile: Now, one question: am I right that
storeStats.sh is taken care of by cron, but you execute restoreStats.sh manually whenever you rebooted the router ? (thus the graphs will appear as usual, only with a gap of several hours between the last backup and the reboot) Can it be set to be executed upon boot ?
Now I see, someone else @ user674574 modified your script so that it will restore the data automatically upon booting.... I already set up everything using your scripts and am feeling lazy to change much.... I'm not going to reboot the router so often (actually almost never... should I reboot it regularly?) so for now I'm just going to remember to execute restoreStats.sh.

I think I would like cron to sftp or scp the backup files to my other Raspi (with Unifi Controller) once a month. Can cron do something which requires login name and password ? (or rather, can a .sh file do something like this ?)

Yes.
That has been enough for me.
(And usually I manually store that stats before sysupgrades, so that I lose as little as possible)

Feel free to modify those for your needs, e.g. the autoload at startup. I build so often and test various things , that I have not looked into that (as want to keep the automatic boot near the defaults).

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.