Cyberpower UPS Linux daemon (pwrstat) exporter for prometheus
  • Go 80.3%
  • Dockerfile 9.8%
  • Shell 5.2%
  • Makefile 4.7%
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
maxpeterkaya cc60eb74a2
All checks were successful
Go Build/Test and Docker Push / build (push) Successful in 28s
fix: proper dockerfile copy
2026-09-20 18:27:20 -04:00
.forgejo/workflows ci: add changelog step for tag 2026-08-11 23:40:23 -04:00
grafana Create grafana config folder 2024-04-12 16:47:14 +08:00
image update README.md 2021-07-30 23:23:53 +08:00
pwrstat Add testfile for pwrstat package 2024-04-10 17:40:57 +08:00
scripts fix: ensure daemon starts 2026-09-20 18:27:00 -04:00
.gitignore fix: ignore ide folders 2026-08-11 13:49:50 -04:00
docker-compose.yaml fix: adjust image name to host 2026-08-11 13:53:28 -04:00
Dockerfile fix: proper dockerfile copy 2026-09-20 18:27:20 -04:00
go.mod Add testfile for pwrstat package 2024-04-10 17:40:57 +08:00
go.sum Add clean go.sum 2024-04-10 17:46:54 +08:00
LICENSE Create LICENSE 2021-07-06 18:47:49 +08:00
main.go Fix typo 2024-04-12 16:47:57 +08:00
Makefile fix: rename to current host 2026-08-11 13:50:47 -04:00
pwrstatd.conf example config 2026-08-11 13:49:33 -04:00
README.md fix: adjust image name to host 2026-08-11 13:53:28 -04:00

Pwrstat Exporter

A Prometheus exporter for CyberPower UPS Linux daemon (pwrstat).

Overview

The Pwrstat Exporter enables Prometheus to monitor data from CyberPower Uninterruptible Power Supply (UPS) systems running on Linux. It uses the pwrstat Linux daemon for data acquisition.

Docker Deployment

Prerequisites Docker installed on your system.

Installation

Run the following command to install the Pwrstat Exporter using Docker:

docker run \
  --name pwrstat-exporter \
  --device /dev/bus/usb:/dev/bus/usb \
  --device /dev/usb/hiddev0:/dev/usb/hiddev0 \
  --privileged \
  --restart unless-stopped \
  -p 8088:8088 \
  -d vc.maxkaya.com/maxpeterkaya/pwrstat-exporter:latest

Alternatively, refer to the provided docker-compose.yaml for a Docker Compose setup.

Building from Source

Prerequisites

  • Golang version 1.16 or higher.

Installation

Clone the repository and build the executable:

git clone https://github.com/kerwenwwer/pwrstat-exporter.git
cd pwrstat-exporter
go build && mv pwrstat-exporter /usr/local/bin/

Usage

The pwrstat command requires sudo privileges:

sudo pwrstat-exporter 

To specify arguments:

sudo pwrstat-exporter --web.listen-address 8088 --web.telemetry-path /metrics

Systemd Service Integration

Configuration Create a systemd service configuration file at /etc/systemd/system/pwrstat-exporter.service:

[Unit]
Description=pwrstat-exporter

[Service]
TimeoutStartSec=0
ExecStart=/usr/local/bin/pwrstat-exporter

[Install]
WantedBy=multi-user.target

Reload the systemd daemon, enable the service at startup, and start the service:

sudo systemctl daemon-reload
sudo systemctl enable pwrstat-exporter
sudo service pwrstat-exporter start

Graceful Shutdown

When the UPS loses line power, pwrstatd runs a script that gracefully shuts down servers connected to the UPS before power runs out. By default the script calls an HTTP endpoint:

curl -fsS -X POST "${SHUTDOWN_URL}" -H "X-API-Key: ${SHUTDOWN_API_KEY}"

Configure the endpoint and API key via the container environment:

SHUTDOWN_URL=http://shutdown-svc:8080/shutdown
SHUTDOWN_API_KEY=change-me

The shutdown endpoint is your own small HTTP server that handles the graceful shutdown of the host machine. The script runs inside the container, so the endpoint must be reachable from it, and the API key is visible to anything inside the container.

Timing is controlled by powerfail-duration in pwrstatd.conf — how many seconds pwrstatd waits for the script before shutting down.

Alternatively, to shut servers down over SSH instead, mount your key and override the script to run ssh against each host:

volumes:
  - ~/.ssh:/root/.ssh:ro

Grafana Integration

A custom Grafana dashboard is available for visualizing the data. Import the dashboard using the grafana-dashboard.json file. grafana