This is a simple server that read current UPS status from CLI daemon and exports them via HTTP for Prometheus consumption.
Note
The pwrstat CLI and the pwrstatd daemon are responsible for monitoring and controlling the UPS and cannot be separated. Installing pwrstat in a Docker container is a bad decision, because it allows you to manage the UPS, while the exporter should only be responsible for receiving the UPS status. Also pwrstat must be installed on the host machine to manage the UPS. Therefore, only the file containing the output of pwrstat -status should be read.
Note
I use systemd to write the output of pwrstat -status to a file. If you don't want to use systemd, you can do it in any way that is convenient for you.
- Create directory to store status output
sudo mkdir /var/lib/pwrstat_status- Create service and timer
# /etc/systemd/system/pwrstat_status.service
[Unit]
Description=UPS status reader
[Service]
Type=oneshot
StandardOutput=file:/var/lib/pwrstat_status/status
ExecStart=/usr/sbin/pwrstat -status# /etc/systemd/system/pwrstat_status.timer
[Unit]
Description=Export pwrstat data every 5 sec
[Timer]
OnBootSec=5s
OnUnitActiveSec=5s
AccuracySec=1s
[Install]
WantedBy=timers.target- Reload daemon and enable timer
sudo systemctl daemon-reload
sudo systemctl enable --now pwrstat_status.timer
# check status
sudo systemctl status pwrstat_status.serviceservices:
pwrstat_exporter:
image: ghcr.io/milden6/pwrstat-exporter:latest
container_name: pwrstat-exporter
restart: unless-stopped
user: 1000:1000
environment:
- TZ=Europe/Amsterdam
ports:
- 9101:9101
volumes:
- /var/lib/pwrstat_status/status:/var/lib/pwrstat_status/status:ro