As many folks following me on Twitter have noted, I’ve been building quite a nice vSphere “datacenter” lately. Part of this build was integrating UPS monitoring and automatic shutdown, and I’m pleased with the result. I’m using a Raspberry Pi connected to two UPSes via USB as a NUT server and have installed a native ESX version of upsmon to monitor and react as UPS events happen. Best of all, the whole install cost less than $50!
My Mini Datacenter
My mini datacenter is constructed from the following elements:
- Three Intel NUC servers
- 2x D54250WYKH (fourth generation i5)
- 1x NUC5i3MYHE (fifth generation i3)
- One TP-Link TL-SG2424 switch
- One Raspberry Pi (model 2B) connected to a Drobo
- An old Iomega ix4-200d
- A pair of UPSes
I’m aiming for low power, low noise, low cost, and maximum utility in this mini datacenter. It’s not a lab really, since I’m running pfSense “in production” to manage my Internet access. But it’s definitely not an enterprise build!
I’m running vSphere 6.0 on all this, complete with VSAN (one SSD and one HDD per NUC) for all the “production” virtual machines. The Pi (backed by the Drobo) is serving an NFS datastore for logging, VIBs, and general messing about. The ix4 is hosting a datastore via iSCSI but I’m not using it right now. The two older NUCs have two Ethernet connections (thanks to the Syba Mini-PCIe NIC) but the new one has just one. I’m using 802.1Q VLANs to segment traffic a bit.
If you’re interested in any of the components mentioned here (why I chose them, what I’m doing with them, or how they work) just leave a comment or ask on Twitter. Maybe I’ll write some of that up too!
What is NUT?
Network UPS Tools (NUT) is one of the oldest and most useful open source projects most people have never heard of. Essentially, NUT is an extensible and highly configurable client/server application for monitoring and managing power sources. It includes a set of hardware-specific drivers (e.g. usbhid, apcupsd, snmp), a server daemon (upsd), and clients like upsmon and upsc.
NUT traces its history back to some serious software and hacks from the 1996/1997 era to monitor APC UPSes. Originally called Smart UPS Tools, the name was changed to Network UPS Tools due to the unfortunate similarity of that old name with a particular line of APC UPS products. NUT supports a wide variety of hardware, including most USB-connected UPSes, many of the old serial interfaces, and SNMP UPSes and PDUs. Sadly, many APC UPS models are unsupported because they use the proprietary “Microlink” protocol, though APC has recently begun offering a supported protocol.
A Raspberry Pi NUT Server
As a client/server application, the upsd daemon can run on one machine designated to monitor one or more UPSes and can support multiple clients querying the status of these devices. The tiny Raspberry Pi makes a wonderful NUT server, since it offers USB connectivity, sufficient CPU and memory, and a full Linux environment in a tiny and low-power device. The Raspbian operating system, based on Debian, includes pre-compiled nut-server and nut-client packages.
Since I already had a Raspberry Pi model 2B in my mini datacenter, it was a simple matter to connect my two UPSes to it via USB. I did need to order the proprietary RJ50-to-USB cable for the APC Back-UPS, but this was under $6 delivered from eBay. I plugged in the USB cables, configured NUT, and I was up and running with a fully functional home power monitoring server!
Here’s the simple config I’m using:
- Set “MODE=netserver” in /etc/nut/nut.conf
- Configure my UPSes in /etc/nut/ups.conf
- Set the server to “LISTEN” on its IP address in /etc/nut/upsd.conf
- Create a upsd user and password in /etc/nut/upsd.users
- Configure upsmon to monitor these UPSes by setting “MONITOR” lines in /etc/nut/upsmon.conf
Once all this was set I simply stopped and restarted nut-server and nut-client and my Raspberry Pi NUT server was up and running!
A NUT Client for VMware vSphere
VMware vSphere does not include NUT support, but a VMware ESX native port of upsmon exists and works great. It even supports the latest version of vSphere, 6.0. Thank you, René!
I installed upsmon on all three of my ESX hosts (the NUC servers mentioned above) by downloading René’s package to my NFS datastore and running the install script in an ssh shell on each host. Although the instructions say it won’t require a restart, I found that I did have to reboot all of the servers to load the daemon and set up the configuration variables properly.
Configuring upsmon for ESX involves customizing the following variables:
- UserVars.NutUpsName – The name of one or more UPSes in ups@server notation. If you enter more than one UPS name (separated by a space) the shutdown command will wait until all are exhausted.
- UserVars.NutUser – The upsd username set above.
- UserVars.NutPassword – The upsd password set above.
- UserVars.NutFinalDelay – The number of seconds to allow for a system shutdown after a low battery event is received.
- UserVars.NutSendMail – Enable (1) or disable (0) email from this upsmon instance.
- UserVars.NutMailTo – Email address to use for above.
Set these in the vSphere client by going to each host, clicking Settings, Advanced System Settings, and searching for “nut”.
I connected two of my NUCs to the larger CyberPower UPS and one to the smaller APC. I then configured each host to listed only for the UPS it is connected to. I also configured the NUT package in pfSense to monitor the UPS so it can shut down gracefully if there’s a power outage.
Stephen’s Stance
NUT is a wonderful and extensible power management framework, and the Raspberry Pi is an awesome platform on which to run the UPS monitoring drivers and upsd server daemon. Even if you’re not running vSphere, a Pi running NUT makes sense for the connected servers found everywhere today. My next task will be adding upsmon to the Iomega ix4 and other always-on systems!
Mike Foley says
Great article. An alternative for those that don’t want to add s/w to their ESXi boxen is to consider something like the vPI (http://xtravirt.com/product-information/vpi/) to launch a script on the Pi that connects to ESXi or vCenter and gracefully shuts everything down. vPI has the vSphere Perl API stuff plus other goodies like William Lam’s vGhetto stuff. You could load the PI with the vPI distro and then install NUT on that.
Petr Klus says
Hi,
Is there any way to see that the system is actually working? I’ve installed everything on the ESXi, host, I can see all the settings and the service to be running, however, is there any way to check that it is indeed receiving information from the PI? (I have also tested remove upsc and I can read the UPS settings as well).
Karting06 says
Hi,
I have 2 questions:
Is your switch connected to the UPS?
How do you power up the PI? USB from the server?
Thanks 🙂
Johannes says
If everything is setup correctly, you can see entries in the /var/syslog.log on the esx like
2016-03-31T13:42:43Z upsmon[8477]: UPS [email protected].x.x on battery
2016-03-31T13:43:34Z upsmon[8477]: UPS [email protected].x.x on line power
(in my case it isn’t a raspi, it’s a qnap nas as ups server)
you have to go to the esx via ssh and then do a
tail -f /var/syslog.log
thinkdez says
Thanks for the information about the reboot. I was very confused after I couldn’t find the variables. I opted for restarting the management agents instead. Once this was done I could see the variables and saved me a OS reboot of my operating VM’s
inator says
Johannes – can you share your QNAP config (vars) please? I’m trying to get this same setup working QNAP > ESXI 6.0. Thanks much!
inator says
I mean ESXI vars please.
Łukasz says
It works as described thanks
Below are ESXI vars which works for me:
UserVars.NutUpsName: qnapups@your_qnap_box_ip
UserVars.NutUser: admin
UserVars.NutPassword: 123456
check your user and password in /etc/config/ups/upsd.users file on your QNAP box (admin/123456 are default ones:)
I’m wondering how can I bring esxi host up once power will back. Do you have any clue? WOL magic packet from nut server for example?
Łukasz says
Question to autor: Do you shutdown Pi (Nut server) while UPS is on LB state? Or just let it power off suddenly and then power up after power back?