• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

Aaron Weiss

  • Home
  • Blog
  • About
  • Contact

network ups tools

Multiple UPS on the same NUT-Server

March 21, 2021 by Aaron Weiss

Previously, I’ve written about using a Raspberry Pi with Network UPS Tools (NUT) to manage multiple computers with one UPS device.

I recently decided to use a second UPS as I started building and configuring a separate Proxmox machine that has been repurposed from my former daily driver computer. My second UPS is a APC XS1300G that is about 5 years old. Originally, protected my entertainment equipment which used to be very elaborate, but now that has been mostly unused for the time being. I also wanted to learn how to manage multiple UPSs in NUT as well.

Adding the Second UPS

My original configuration in the /etc/nut/ups.conf is as follows:

[ups]
driver = usbhid-ups
port = auto
desc = "CyberPower CP825LCD"
pollinterval = 15

As you can see the port was set to auto. This would conflict if I wanted to add a second UPS.

After some frustration, it turns out you just need to specify the vendorid and the productid for all the UPS devices you want to manage. Here’s my original UPS with those codes:

[ups]
driver = usbhid-ups
port = auto
desc = "CyberPower CP825LCD"
vendorid = 0764
productid = 0501
pollinterval = 15

To add my second UPS, I’ve added the below configuration. I’ve also included the serial number (partially redacted to protect the innocent) for additional specificity for NUT. My original UPS device, the CP825, does not display the serial number.

[apcXS1300G]
driver = usbhid-ups
port = auto
desc = "APC Back-UPS 1300G"
serial = 3BXXXXXXXX54
vendorid = 051d
productid = 0002
pollinterval = 15

You’ll need to restart nut in order for the new UPS to appear. Run sudo systemctl restart nut-server. Give it a moment to rediscover all the UPSs.

Once that is done, when I run upsc apcXS1300G, I get the following result:

pi@worker11811-pi:/etc/nut $ upsc apcXS1300G
Init SSL without certificate database
battery.charge: 100
battery.charge.low: 10
battery.charge.warning: 50
battery.date: 2001/09/25
battery.mfr.date: 2016/04/21
battery.runtime: 12960
battery.runtime.low: 120
battery.type: PbAc
battery.voltage: 27.2
battery.voltage.nominal: 24.0
device.mfr: American Power Conversion
device.model: Back-UPS XS 1300G
device.serial: 3BXXXXXXXX54
device.type: ups
driver.name: usbhid-ups
driver.parameter.pollfreq: 30
driver.parameter.pollinterval: 15
driver.parameter.port: auto
driver.parameter.productid: 0002
driver.parameter.serial: 3BXXXXXXXX54
driver.parameter.synchronous: no
driver.parameter.vendorid: 051d
driver.version: 2.7.4
driver.version.data: APC HID 0.96
driver.version.internal: 0.41
input.sensitivity: high
input.transfer.high: 136
input.transfer.low: 88
input.voltage: 124.0
input.voltage.nominal: 120
ups.beeper.status: disabled
ups.delay.shutdown: 20
ups.firmware: 864.L8 .D
ups.firmware.aux: L8
ups.load: 0
ups.mfr: American Power Conversion
ups.mfr.date: 2016/04/21
ups.model: Back-UPS XS 1300G
ups.productid: 0002
ups.realpower.nominal: 780
ups.serial: 3B1616X11054
ups.status: OL
ups.test.result: No test initiated
ups.timer.reboot: 0
ups.timer.shutdown: -1
ups.vendorid: 051d

Monitoring the Second UPS

Next, we need to add the second UPS to be monitored by NUT in the /etc/nut/upsmon.conf file. Look for your original UPS monitor line which will look something like this:

MONITOR ups@localhost 1 username password master

Don’t forget that the username and password are set in the /etc/nut/upsd.users file.

Now you’ll add a second line, but change a few of the settings:
MONITOR ups@localhost 1 username password master
MONITOR apcXS1300G@localhost 2 username password slave

Here I’ve added the UPS name that was added to the ups.conf, “apcXS1300G”, sequentially increased the number to “2”, and then changed “master” to “slave”.

Unfortunately, NUT has yet to update their terminology to more modern naming of primary and secondary devices.

After adding that, you’ll want to restart the monitor server with sudo systemctl restart nut-monitor as well as the driver. This will again restart the connections to both UPS devices and should show they are now established.
sudo systemctl restart nut-monitor
sudo upsdrvctl stop
sudo upsdrvctl start

Head on over to your browser and type in your upsstates.cgi path. For me, it is http://192.168.1.3:8080/cgi-bin/nut/upsstats.cgi becuase my PiHole installation uses Litehttp, so I had to configure Apache to use the 8080 port. If you are using default NUT configuration, no need to enter a port. And you’ll see the following:

2 UPS devices in NUT UPSSTATS
Click to enlarge.

Now you can connect any of your devices to be monitored by the NUT to utilize the new UPS.

Overtime, I expect to switch all my homelab devices to the APC XS 1300G as it handles more load and capacity. So if you do get to a point where your homelab requires more than one UPS device, this is the way to add a second UPS to NUT.

Filed Under: Uncategorized Tagged With: network ups tools, nut, ups

Using Raspberry Pi For PiHole Ad Blocking and Network UPS Tool Monitoring

September 5, 2020 by Aaron Weiss

When I first built my FreeNAS machine, I bought an UPS device to give it backup power in case of a power outage. But my primary computer also had a UPS device.

Recently, in order to minimize the amount of equipment that I have, I decided I only wanted to have one UPS. After searching for solutions, I was pointed to Network UPS Tools (NUT), which is open source software that can manage UPS units and the machines they power. This way I can have my primary computer and NAS connected to the same UPS unit, and control them both during certain power events.

Before this, I also started to run PiHole on a VM with my NAS, but I quickly found two issues. First, if the VM halted for some reason, my entire network would too. Also, if I needed to restart my NAS for any reason, the network would also go down.

This finally gave me two solid reasons and goals to justify the purchase a Raspberry Pi. Luckily, the Raspberry Pi 4B 2GB model had just become the primary model at $35, so I knew I’d have plenty of performance to run these two applications.

Since I was not only looking to minimize my homelab’s physical footprint, I also wanted to keep cords and cables to a minimum. So I also decided to get a Power-Over-Ethernet Switch that would allow me to power my Raspberry Pis with just an ethernet connection. I also wanted to reduce the amount of Ethernet wire lengths to make cable management easier, so I purchased a Cat 6 crimper to create my own ethernet cable lengths.

Finally, this new RaspberryPi would allow me to run cron jobs that control scripts on remote machines from the Pi as well such as  my Digital Ocean Snapshot script.

So to sum up my goals:

  • Run NUT server to monitor my NAS and Windows 10 machine
  • Run PiHole
  • Execute cron jobs

Network UPS Tools Equipment

Below are all the items I purchased for this project.

ItemQuantityPriceStore
Raspberry Pi 4 2GB2$70PiShop
Rasberry Pi Case1$5PiShop
POE Hat2$41.90PiShop
16GB SD Card3$17.97Amazon
High Pi Case1$9.95PiShop
SD to USB Card Reader1$9.99Amazon
Total$154.81

The above doesn’t include shipping or the cost of a mini HDMI cable as I already had one lying around. There’s three SD cards in this list to have one as a backup.

First Raspberry Pi

The Pi and its accessories are incredibly small and easy to put together. The POE switch worked perfectly. I was able to install Raspbian on a SD card and start up the Pi with no issues with the Raspberry Pi Foundation’s Imager Tool. Once I got the basic settings just so, including assigning a static IP address. I disconnected the HDMI and connected via VNC instead, using VNC Viewer.

I typically name my devices after robots from film history. My FreeNAS is named Maria after the female protagonist in Metropolis, and I’ve maintained that naming convention for many of the Virtual Machines, networking equipment, and now my Pi. I named it Worker11811 after the character whose job was to maintain the Moloch machine.

Installing PiHole

This is an easy step, especially since I had already been running it in a VM. You simply run this code:

curl -sSL https://install.pi-hole.net | bash

That is the basic install and runs your through a few configuration options such as choosing your DNS host (I chose Cloudflare), your static IP address, etc.

PiHole Teleporter
Backing up a PiHole and moving it to another installation is easy with the PiHole Teleporter. Click to enlarge.

Since I already had custom rules and settings from my VM, I used PiHole’s Teleporter to download the settings from the original VM, and then restore it to the newly installed PiHole.

I updated my Router’s DNS settings to point to 192.168.1.3, and boom, PiHole was working as expected.

Installing NUT

The Pi will act as both the NUT server and client server as the Pi will act as both. First, I connected my UPS to my Pi and ran lsusb to ensure it could see the UPS.

pi@worker11811-pi:~ $ lsusb
Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 001 Device 003: ID 0764:0501 Cyber Power System, Inc. CP1500 AVR UPS
Bus 001 Device 002: ID 2109:3431 VIA Labs, Inc. Hub
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

No issues there. It sees my CyberPower UPS.

Installing NUT isn’t difficult on Raspbian as there is a Debian package available, and found a few excellent instructions like this one from Medium:

apt-get update && apt-get install nut nut-client nut-server

Next, I added the following lines to the sudo nano /etc/nut/ups.conf file. I found my USB driver for the UPS using this Hardware Compatibility List. It was the same driver that my FreeNAS was using, so I knew it worked well.

[ups]
driver = usbhid-ups
port = auto
desc = "CyberPower 1350PFLCD"

Next, I created users for each of the clients that will be connecting to this NUT server by editing my /etc/nut/upsd.users file:

[admin]password = ******
actions = SET
instcmds = ALL
[upsmon_worker11811]
password  = ******
upsmon master
[upsmon_maria]
password = *******
upsmon slave
[upsmon_johnny5]
password = ******
upsmon slave

As you can see, there are 4 users. The Admin, worker11811, maria, and Johnny5 (which is my primary Windows 10 machine).

Then I started the nut-client and drivers:

systemctl restart nut-client.service
upsdrvctl stop
upsdrvctl start

Next, I checked to see if I can see the UPS device via the NUT

pi@worker11811-pi:~ $ upsc ups@192.168.1.3
Init SSL without certificate database
battery.charge: 100
battery.charge.low: 10
battery.charge.warning: 20
battery.mfr.date: CPS
battery.runtime: 1470
battery.runtime.low: 600
battery.type: PbAcid
battery.voltage: 24.0
battery.voltage.nominal: 24
device.mfr: CP1350PFCLCD
device.model: CRCA102*AF1
device.serial: CPS
device.type: ups
driver.name: usbhid-ups
driver.parameter.pollfreq: 30
driver.parameter.pollinterval: 2
driver.parameter.port: auto
driver.parameter.synchronous: no
driver.version: 2.7.4
driver.version.data: CyberPower HID 0.4
driver.version.internal: 0.41
input.transfer.high: 139
input.transfer.low: 88
input.voltage: 123.0
input.voltage.nominal: 120
output.voltage: 139.0
ups.beeper.status: disabled
ups.delay.shutdown: 20
ups.delay.start: 30
ups.load: 22
ups.mfr: CP1350PFCLCD
ups.model: CRCA102*AF1
ups.productid: 0501
ups.realpower.nominal: 810
ups.serial: CPS
ups.status: OL
ups.test.result: Done and warning
ups.timer.shutdown: -60
ups.timer.start: -60
ups.vendorid: 0764

Additionally, you can run

upslog

which will check the UPS’s status every 30 seconds:

pi@worker11811-pi:/usr/local/bin $ upslog
Network UPS Tools upslog 2.7.4
logging status of ups@localhost to - (30s intervals)
Init SSL without certificate database
20200905 115423 100 123.0 20 [OL] NA NA
20200905 115453 100 123.0 23 [OL] NA NA
20200905 115505 100 123.0 23 [OL] NA NA
Signal 2: exiting

Lastly, we can check to see if NUT sees the same machine as a client:

pi@worker11811-pi:~ $ upsc -c ups
Init SSL without certificate database
127.0.0.1

The 127.0.0.1 stands for the home machine which is my worker11811 Raspberry Pi. We’ll be using the same command a few more times later.

Updating FreeNAS UPS Settings to become a NUT Client

Now that NUT is working, I had to update the FreeNAS settings. FreeNAS comes with NUT already, making this super easy to update. I made the following changes:

  • Switched UPS Mode from Master to Slave (I hate this terminology)
  • Added the Remote Host IP to 192.168.1.3 which is my Pi’s internal network address
  • Added the Monitor Username and Password
FreeNAS UPS Settings
Click to enlarge.

After saving, I immediately noticed that my FreeNAS recognized the connection to my NUT Server on my Pi via the shell.

To double-check, I ran the same

upsc ups@192.168.1.3

command on the FreeNAS shell, and received the same results when I initially ran it on the Pi. Of course, we’ll run the same client command as before:

pi@worker11811-pi:~ $ upsc -c ups
Init SSL without certificate database
192.168.1.9
127.0.0.1

Now it sees my FreeNAS IP address so I’m in good shape here.

Adding Windows 10 as a NUT Client

This is where the real headaches occurred for me at first. Windows support is severely lacking. I was only able to find an ancient winNUT Google Code repository and a MSI installer directly on the NUT site. After attempting to get both to work and nearly a week of frustration, I uninstalled both.

I stumbled upon this Github repo called WinNut-Client which has a super-simple interface to setup your Windows machine connection to your NUT server. After downloading the MSI file, installing, and setting up the config I had my Windows machine capturing the UPS data and was able to setup the settings to choose when and how I want this machine to shutdown. There’s even a hibernate option which I prefer over a full shutdown which I prefer if I’m away from my computer.

WinNUT Client Options

You can also choose how the service starts at the machine’s startup, how often it looks for updates, etc. What I didn’t see is the client appear on my NUT Server, so I opened an Issue on the Github repo to get clarification.

WinNut Client Status
Click to enlarge.

Monitoring the UPS with NUT

NUT comes with several CGI programs that can be viewed in a browser. However, I had issues attempting to log into http://192.168.1.3/cgi-bin/nut/upsstats.cgi. After some time, I realized that PiHole uses Litehttp web server that already uses port 80. Wherease, NUT uses Apache. I updated

/etc/apache2/ports.conf

and changed

Listen 80

to

Listen 8080

and restarted Apache. Going to http://192.168.1.3:8080/cgi-bin/nut/upsstats.cgi brought up a result that reminded me of the internet’s nascent days:

NUT Monitoring Page
Example of the Network UPS Tools Stats Page. Click to enlarge.
UPS Stats Chart
Example of the individual UPS stats. Click to enlarge.

Regardless, my UPS’s stats were easily revealed to me.

Issues

Temperatures

The 4th generation Pis run rather hot, more so with the POE hat, which even comes with a fan that sits right on top of the CPU. When inside the official case, the temperatures were reaching the high 70s in Celsius. This was quite worrying. I ended up purchasing the HighPi case which is meant to provide extra room for taller hats. I figured this would be an excellent way to hopefully get more air to the Pi. This ended up reducing the temperatures, but not to where I really prefer.

I was able to find instructions to configure the Pi to manage the POE fan speeds to keep the fan from being on all the time. Otherwise, there’s a high-pitched whine. Of course, as I was testing this, I had to restart the Pi each time. So there’s a balance between the speed of the fan and the temperatures that I feel are appropriate. The goal is generally to keep the CPU below 80 degrees as that is when the CPU begins to throttle performance.

Network downtime with reboots

The first issue I encountered was that if I need to reboot my Pi when I was working on it or installing generally updates, it would take down my network for about a minute. This was essentially the same problem I experienced prior to this project. So, I really hadn’t fixed this problem.

Second Raspberry Pi

The downtime issues is where I realized that I’d prefer to have a second PiHole machine in order to have 100% uptime. Therefore, I purchased another Pi and POE hat, but chose to remain with the official Pi case I already had. To continue the Metropolis naming scheme, I named this one Rotwang after the primary antagonist.

I ran through the same processes as before, except I chose not to run a graphic interface with this Pi, using just SSH to manage the device. After I installed PiHole, and ran the Transporter process to have mirror settings through the web interface.

I had found this Reddit post of someone sharing their script on how to keep two PiHoles synced. I don’t believe it works that well, but essentially, if one Pi goes down or is rebooted, I still have a network connection.

While writing this post, I recently stumbled upon this post about sycning two PiHoles, that might be a better option than what I have now. I expect to try it out sometime in the future. (EDIT/UPDATE [Sept. 7th, 2020]: This script works as described and is super easy to install and run.)

Backing up the Pis & Data Recovery

One thing I learned quickly is that the Pis don’t have a power off button. So if they lose power abruptly without powering down, it could corrupt the SD Card data.

I found this super-simple Pi backup script on GitHub, and it’s been working like a charm. I have these backups sent to their respective folders on my FreeNAS, so they are always in a safe place.

Even recently this has been helpful. In attempting to make some changes to one of the Pis, it wouldn’t reboot. Instead of getting mad, I was able to write the backup image to the backup SD card and reboot with no issues.

Conclusion

Entering into the Raspberry Pi universe has been fun and I see why these little guys are so popular. Anytime I start to find myself relying on a Virtual Machine in my FreeNAS machine, I start to consider whether or not it’s better to run that application on one of these Pis or add an additional one.

I still worry about the temperatures for both Pis, which are running in the low 70 degree Celcius range. After removing both Pis from their cases for a few days and found them to operate within the 50 degree range, which is much more reasonable to me. I am considering a Cloudlet case such as this one  where I can have all the Pis setup in an array with plenty of airflow and the ability to run a POE switch near by.

Worker11811 Temperature
Rotwang Pi Temperatures

Overall, I’m super happy with this setup, and I recognize that I certainly over-engineered this entirely. I spent over $150 just to have one less UPS near my gear. Honestly, I could have just added a Serial Connect from the UPS to the NAS and maintained the USB connection to my Windows machine. I’ve learned a lot and I’m happy with what I’ve accomplished.

Filed Under: Projects Tagged With: nas, network ups tools, networking, pihole, raspberry pi, winnut

Primary Sidebar

Recent Posts

  • TrueNAS Virtual Machine with Ubuntu 18.04 Halting with Signal 11
  • Proxmox ZFS Disk Replacement and Drive Expansion
  • How To Create ZFS Backups in Proxmox
  • Multiple UPS on the same NUT-Server
  • Learning Graylog for Fun and Profit

Categories

  • Film & Television
  • Google Analytics
  • Guitar
  • Lifestyle
  • Projects
  • Proxmox
  • Search Engine Optimization
  • Technology
  • TrueNAS
  • Uncategorized
  • Website Administration
  • WordPress
  • Home
  • Blog
  • About Aaron Weiss
  • Contact
  • Privacy Policy
  • Affiliate Disclosure

© Aaron Weiss. Built with WordPress using the Genesis Framework. Hosted on a2 Hosting and DigitalOcean. Aaron Weiss's LinkedIn Profile