updated to run on the pi5

This commit is contained in:
2026-08-10 19:07:26 +02:00
parent 14451d4d45
commit 0b92836367
2 changed files with 130 additions and 8 deletions
+31 -8
View File
@@ -76,10 +76,15 @@ sudo apt install nut nut-client nut-server
Also install RRDTool for the historical data collector:
```bash
sudo apt install librrd-dev python3-dev
python3 -m pip install -r requirements.txt
sudo apt install librrd-dev python3-dev python3-venv
cd /opt/ups
python3 -m venv .venv
.venv/bin/python -m pip install -r requirements.txt
```
The collector uses the virtual environment at `/opt/ups/.venv`. Calling its
Python executable directly means cron does not need to activate the environment.
Check the NUT version:
```bash
@@ -538,7 +543,7 @@ The Python collector converts these into numeric values for RRDTool.
The Python program is:
```text
/usr/local/bin/ups_rrd.py
/opt/ups/ups2rrd.py
```
Its job is deliberately simple:
@@ -566,11 +571,12 @@ RRDTool
PNG graphs
```
The script performs three main tasks:
The script performs four main tasks:
1. Create the RRD database if it doesn't exist
2. Read the current UPS values
3. Update the RRD and regenerate the graphs
4. Generate the HTML dashboard
---
@@ -614,7 +620,7 @@ The corresponding configuration is:
The cron job runs the Python script every minute:
```cron
* * * * * /usr/local/bin/ups_rrd.py >> /var/log/ups_rrd.log 2>&1
* * * * * /opt/ups/.venv/bin/python /opt/ups/ups2rrd.py >> /var/log/ups_rrd.log 2>&1
```
Therefore, approximately one measurement is stored every minute.
@@ -767,6 +773,8 @@ are completely different things.
The script creates:
```text
/var/www/html/ups/index.html
/var/www/html/ups/status-3m.png
/var/www/html/ups/battery-1y.png
@@ -784,6 +792,8 @@ The script creates:
If `/var/www/html` is served by the web server, these can therefore be viewed as:
```text
/ups/
/ups/status-3m.png
/ups/battery-1y.png
/ups/battery-5y.png
@@ -794,6 +804,9 @@ If `/var/www/html` is served by the web server, these can therefore be viewed as
/ups/power-5y.png
```
The responsive dashboard groups all graphs on one page and refreshes every
60 seconds. Clicking a graph opens its full-size PNG.
---
# 19. Testing the Python program
@@ -801,7 +814,7 @@ If `/var/www/html` is served by the web server, these can therefore be viewed as
Run it manually:
```bash
sudo /usr/local/bin/ups_rrd.py
sudo /opt/ups/.venv/bin/python /opt/ups/ups2rrd.py
```
A successful run should produce something similar to:
@@ -826,12 +839,22 @@ rrdtool lastupdate /var/lib/rrd/bx950mi.rrd
# 20. Checking cron
The cron entry is:
Install the cron entry in root's crontab because the collector writes to
`/var/lib/rrd` and `/var/www/html/ups`:
```bash
sudo crontab -e
```
Add:
```cron
* * * * * /usr/local/bin/ups_rrd.py >> /var/log/ups_rrd.log 2>&1
* * * * * /opt/ups/.venv/bin/python /opt/ups/ups2rrd.py >> /var/log/ups_rrd.log 2>&1
```
There is no need to run `source`, activate the virtual environment, or use a
wrapper script.
After a few minutes:
```bash