Some uninterruptible power supplies offer a serial interface. The Network UPS Tools project provides an ability to interact with such devices, usually via USB. On FreeBSD NUT is available as a port and it is possible to install from the package manager:
pkg info nut
nut-2.8.0_16
Name : nut
Version : 2.8.0_16
Installed on : Fri Jan 27 18:24:41 2023 EST
Origin : sysutils/nut
Architecture : FreeBSD:13:amd64
Prefix : /usr/local
Categories : sysutils
Licenses : GPLv3+ and GPLv2+ and GPLv1+ and ART10
Maintainer : cy@FreeBSD.org
WWW : https://www.networkupstools.org/
Comment : Network UPS Tools
sudo pkg install nut
In my case I have the CyberPower EC750G device so the configuration /usr/local/etc/nut/ups.conf looks as follows:
[CPS_EC750G]
driver = usbhid-ups
port = auto
It is also required to set devfs rules for the UPS device. Upon latest installation NUT runs under nut:nut user:group. The user:group is for the port installation from GhostBSD. The user:group for the port from FreeBSD is uucp:uucp. To find USB serial connection one run the following command:
sudo usbconfig
ugen0.17: <CPS EC750G> at usbus0, cfg=0 md=HOST spd=LOW (1.5Mbps) pwr=ON (50mA)
Given the above information we can configure the devfs rules as follows:
/etc/devfs.conf
perm ugen0.17 0770
own ugen0.17 nut:nut
/etc/devfs.rules
nut_usb=10]
add path 'ugen0.17' group nut user nut mode 0770
add path 'usb/0.17.0' group nut user nut mode 0770
Now we can configure NUT service as follows
sudo sysrc devfs_system_rules="nut_usb"
sudo sysrc nut_enable=YES
sudo sysrc upslog_enable=YES
sudo sysrc upsmon_enable=YES
Finally we can start up NUT and check with UPS client we can connect to our device
sudo service restart nut
upsc -l
CPS_EC750G
By default NUT listens binds to local loopback interface and listens on port 3493. This is configurable in /usr/local/etc/nut/upsd.conf
netstat -an|grep tcp|grep 3493
tcp6 0 0 ::1.3493 *.* LISTEN
tcp4 0 0 127.0.0.1.3493 *.* LISTEN
Additionally there is also nut_exporter available in the FreeBSD port collection if one would like to add UPS metrics to Prometheus and consequently to Grafana in order to visualize battery capacity, power usage, etc.
pkg info nut_exporter
nut_exporter-2.5.2
Name : nut_exporter
Version : 2.5.2
Installed on : Sat Jan 28 14:12:44 2023 EST
Origin : sysutils/nut_exporter
Architecture : FreeBSD:13:amd64
Prefix : /usr/local
Categories : sysutils
Licenses : APACHE20
Maintainer : bsd@j-star.org
WWW : https://github.com/DRuggeri/nut_exporter
Comment : Prometheus exporter for the Network UPS Tools server
This exporter listens on port 9199 and makes NUT metrics available via /ups_metrics URL path.
The Prometheus YAML configuration to add the NUT metrics looks as follows:
- job_name: "nut"
static_configs:
- targets: ["localhost:9199"]
metrics_path: /ups_metrics