A word on UPSs
When the power in my town unexpectidly went out for 30 minutes last Tuesday I got the urge to purchase my first UPS. The goal for my first unit was to cover the following devices:
- Router/gateway/WI-FI
- Fiber modem
- Server
- NAS
Tuesday's power outage also took out phone data (or made it absurdily slow), which left us completely in the dark as to what happened. (I extend a thanks to my collegeus for keeping me informed over SMS and phone calls.) For this reason I would like to try having my fiber optic modem and router on battery power for the next outage (perhaps once per year). The server and NAS will gain the benefit of safe shutdowns when power is cut and extra surge protection during storms.
It was harder to choose an UPS than I imagine, for the seamingly split reviews (half being praise, half being hatred, on the same product/series) and for UPSs' being something I do not yet know much about. To not draw it out I picked the most popular of the 10 UPSs that my employer sells (gotta take advantage of that tiny employee discount), the APC Back-UPS 1200 VA.
Setting things up
In normal IT-nerd fashion I skipped the manual and got straight to the point:
- Turned off my devices.
- Inserted the UPS's battery fuse.
- Plugged my devices into the UPS and the UPS into the wall.
- Connected the USB cable between the USP and server for control.
- Turned everything on.
The UPS made a loud beep on boot but other than that it was rather eventless. Back on my computer I unlocked the server drives and promptly got to work setting up my new tech.
APC software
First search brought me to apcupsd
, the official software to communicate with the UPS. (I ended up not using this for my final setup.)
sudo apt install apcupsd
With the service is installed and running we can fetch data from the USP.
sudo apcaccess
# VERSION : 3.14.14 (31 May 2016) debian
# CABLE : USB Cable
# MODEL : Back-UPS BX1200MI
# STATUS : ONLINE
# LINEV : 239.0 Volts
# LOADPCT : 9.0 Percent
# BCHARGE : 95.0 Percent
# TIMELEFT : 41.0 Minutes
# BATTV : 11.9 Volts
# NOMPOWER : 650 Watts
# ...
Neat! The device seemed to be working and the battery almost full. No better time for a test run. I ran to the fuse box and switched the circuit breaker for my living/server room. Expecting to hear a boom, there was instead some beeps and a slight humming of a transformer. Looking at my phone, the WI-FI was still going strong. And on my computer the SSH session was still alive and well. Running the apcaccess
command again showed that the UPS indeed also thought it was running on battery power -- status had changed to ONBAT
and the BCHARGE
had started decreasing.
Super cool!
The next step
Having learnt that my new equipment worked I got working on the next step: to find the best way of shutting down my server safely before the battery flatlined.
Looking aroud for a bit I discovered NUT (funny), a project to aggregate all kinds of UPS data formats and communication into one suite. With great support for "monitoring" from other devices and running scripts on "events" it sounded like the way forward.
Installing NUT and setting up some config files was pretty straight forward (see their docs...) and before bedtime I ended up with a functional UPS setup. With NUT client setup on my desktop I can also read the UPS from the terminal, things like the battery percentage.
upsc main@<server name> battery.charge
# 100
Or percentual load on the UPS of the available 650 watts.
upsc main@<server name> ups.load
# 9
The future
- Add the data to Grafana.
- Notify when on battery (I use Gotify to push to all devices).
- Buy another UPS to cover my computer/switch.
- Wait and see if it works, if I'll find it useful and for how long the battery will last.