packet:bpq_logging_reduction
Differences
This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
packet:bpq_logging_reduction [2024/05/16 08:58] – created g7taj | packet:bpq_logging_reduction [2025/04/14 20:05] (current) – [Newer versions of Raspberry Pi OS (i.e. Debian 12)] m0mzf | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | LibBPQ logs most bits to / | + | =====Reducing logging writes |
- | This also includes some very chatty | + | Generally speaking, software running under GNU/Linux writes logs using the [[https:// |
- | < | + | Newer Linux distributions use journald, a syslogger built into the love-it-or-hate-it-but-it' |
+ | Like most programs LibBPQ logs most bits to syslog; this also includes some very chatty ' | ||
+ | |||
+ | < | ||
To save SD card writes, you can re-direct this out to RAM (/run - or somewhere else that is RAM on your system) | To save SD card writes, you can re-direct this out to RAM (/run - or somewhere else that is RAM on your system) | ||
+ | |||
+ | ====Older versions of Raspberry Pi OS==== | ||
To do this, you need to create a new file | To do this, you need to create a new file | ||
Line 29: | Line 34: | ||
To use logrotate, to compress the files and only keep 7 days: | To use logrotate, to compress the files and only keep 7 days: | ||
- | Create a file < | + | Create a file < |
Add this to the file | Add this to the file | ||
< | < | ||
Line 38: | Line 43: | ||
}</ | }</ | ||
+ | ====Newer versions of Raspberry Pi OS (i.e. Debian 12)==== | ||
+ | |||
+ | SystemD' | ||
+ | < | ||
+ | du -hd1 / | ||
+ | 153M / | ||
+ | 153M / | ||
+ | </ | ||
+ | |||
+ | They can get extremely large over time, many gigabytes! journald uses some sort of " | ||
+ | |||
+ | So let's get some control of this monster; edit the following file: | ||
+ | < | ||
+ | |||
+ | and uncomment / edit the following lines underneath '' | ||
+ | < | ||
+ | [Journal] | ||
+ | Storage=volatile | ||
+ | SystemMaxUse=200MB | ||
+ | MaxRetentionSec=1week | ||
+ | MaxFileSec=1day | ||
+ | ForwardToSyslog=no | ||
+ | </ | ||
+ | |||
+ | Now that's done restart journald | ||
+ | < | ||
+ | |||
+ | and optionally delete the old journal files | ||
+ | < | ||
+ | |||
+ | There will still be some stuff ending up in /var/log - on a Debian system this will be logs from apt, dpkg etc, and other packages (ginx, mosquitto etc) by default are configured to write directly to it, but all syslogging will now be in RAM and sizes kept under control. As the syslog is in RAM rebooting the Pi / if the Pi crashes all the logs will be lost. If you want persistent log storage (for example on a Pi 5 with an NVMe SSD) then you can get some control by vacuuming / configuring journald - that's beyond the scope of "save your SD card" so there' | ||
+ | |||
+ | To see what linbpq has been saying run | ||
+ | < | ||
+ | |||
+ | and to watch the live log run | ||
+ | < | ||
+ | |||
+ | ====Writing all linbpq packets to syslog==== | ||
+ | |||
+ | If you really want to you can save out all the packets your station has heard to syslog. With some parsing this could be a useful diagnostic tool; here's one way to do it using [[https:// | ||
+ | |||
+ | To do this you'll need to have LinBPQ publishing it's packets to MQTT. To get that set up [[packet: | ||
+ | |||
+ | Install Paho, download, install and compile the software: | ||
+ | < | ||
+ | sudo apt install libpaho-mqtt-dev | ||
+ | mkdir ~/src; cd ~/src | ||
+ | git clone https:// | ||
+ | cd remys_fast_mqtt_logger; | ||
+ | cmake -DCMAKE_BUILD_TYPE=Release | ||
+ | </ | ||
+ | |||
+ | Now that's done create a script to run it: | ||
+ | < | ||
+ | nano packet-syslog.sh && chmod +x packet-syslog.sh | ||
+ | </ | ||
+ | |||
+ | and put this in the script, setting your hostname and mosquitto credentials accordingly | ||
+ | < | ||
+ | #!/bin/bash | ||
+ | / | ||
+ | -b " | ||
+ | -t " | ||
+ | -u " | ||
+ | -p " | ||
+ | > /dev/null 2>&1 | ||
+ | </ | ||
+ | |||
+ | then create a systemd unit file to run it | ||
+ | < | ||
+ | sudo nano / | ||
+ | </ | ||
+ | |||
+ | and fill it with the following | ||
+ | < | ||
+ | [Unit] | ||
+ | Description=Packet Log | ||
+ | |||
+ | [Service] | ||
+ | Environment=TERM=linux | ||
+ | User=root | ||
+ | ExecStart=-/ | ||
+ | |||
+ | [Install] | ||
+ | WantedBy=default.target | ||
+ | </ | ||
+ | |||
+ | Then finally start it up | ||
+ | < | ||
+ | sudo systemctl daemon-reload | ||
+ | sudo systemctl enable packet-syslog.service | ||
+ | sudo systemctl start packet-syslog.service | ||
+ | </ | ||
+ | |||
+ | To watch the packets fly by run | ||
+ | < | ||
+ | Expect this to use up maybe a few MB/day, depending on how busy your node is. |
packet/bpq_logging_reduction.1715849936.txt.gz · Last modified: 2024/05/16 08:58 by g7taj