Skip to main content
  1. Posts/

Monitor a UPS with a Mikrotik router via SNMP

·703 words·4 mins·

Cyberpower UPS units saved me from plenty of issues in the past with power outages. However, although I love the units themselves, I found that the quality of replacement batteries varies widely. This leads me to keep a close watch on my UPS units and test them regularly.

Energy conservation ranks high on my list of priorities, too. I monitor the power draw on my UPS units to know about usage spikes or to review electricity consumption after I make changes.

My Raspberry Pi did a great job of monitoring my UPS for my network devices but it failed after a recent reboot. My network woes from September left me with a Mikrotik hEXs running my home network and I noticed it had a USB port.

Can you monitor a UPS with a Mikrotik device and query its status remotely? You can!

Initial setup #

My Cyberpower CP1500AVRLCD has a USB port on the back for monitoring and control. The hEXs router has a USB-A port on the side that can be used for mass storage, LTE modems, and yes – UPS units.

However, UPS monitoring does not come standard with RouterOS 7.x and it must be installed via a separate package. Follow these steps to get started:

  1. Identify the CPU architecture of your Mikrotik. It should be shown on the product page. The Mikrotik hEXs is a MMIPS (microMIPS) device.
  2. Go to the RouterOS download page and download the Extra packages file for your architecture.
  3. Unpack the zip file you downloaded and locate the ups-7.x-mmips.npk package.
  4. Upload the ups-7.x-mmips.npk file via your preferred method. FTP, ssh, and the web interface work well for this.
  5. Reboot your Mikrotik device.

Enable monitoring #

After the reboot, your Mikrotik should now have a /system/ups entry on the command line. Let’s add monitoring for our UPS:

[major@hexs] > /system/ups
[major@hexs] /system/ups> add name=ups min-runtime=never port=usbhid1

If you don’t know what your port is called, type in add port= and press TAB to see the available ports. Refer to the Mikrotik System/UPS manual for more help here.

I set the min-runtime to never which means that the Mikrotik will never hibernate even if the UPS power runs low. It uses so little power and it’s so critical for my home network that it should be the last system to go offline during an outage.

All that’s left is to enable read-only SNMP so that we can monitor the UPS remotely. Back to the Mikrotik command line:

[major@hexs] > /snmp/set enabled=yes

This enables unrestricted read-only SNMP access for your entire network without authentication under the community name public. I restrict SNMP access with firewall rules but you may want to consider further restrictions on your SNMP community.

Getting data #

From another machine on the network, I dumped all of the SNMP data from the Mikrotik into a file:

$ snmpwalk -v2c -c public | tee -a /tmp/snmpwalk.txt

Then I looked for my UPS’ model name:

$ grep LCD /tmp/snmpwalk.txt 
SNMPv2-SMI::mib- = STRING: "CP1500AVRLCDa"

Let’s see if the first entry gives us the data we need:

> $ grep "^SNMPv2-SMI::mib-2.33" /tmp/snmpwalk.txt 
SNMPv2-SMI::mib- = STRING: "CP1500AVRLCDa"
SNMPv2-SMI::mib- = ""
SNMPv2-SMI::mib- = INTEGER: 2
SNMPv2-SMI::mib- = INTEGER: 103
SNMPv2-SMI::mib- = INTEGER: 100
SNMPv2-SMI::mib- = INTEGER: 0
SNMPv2-SMI::mib- = INTEGER: 0
SNMPv2-SMI::mib- = INTEGER: 1
SNMPv2-SMI::mib- = INTEGER: 0
SNMPv2-SMI::mib- = INTEGER: 122
SNMPv2-SMI::mib- = INTEGER: 1
SNMPv2-SMI::mib- = INTEGER: 122
SNMPv2-SMI::mib- = INTEGER: 8
SNMPv2-SMI::mib- = Gauge32: 0

What the heck do all these numbers mean? A quick trip to a MIB browser shows us that there are a few important items here:

  • upsOutputPercentLoad is (8%)
  • upsOutputVoltage is (122V)
  • upsEstimatedChargeRemaining is (100%)

These are the three numbers I care most about. However, the percent load of 8% isn’t terribly useful. I’d rather have watts.

Let’s write a script to get the value, and convert the percentage to watts:

set -euo pipefail

# From the CP1500AVRLCDa spec sheet

# SNMP MIB for load percentage

# Get the load integer only.
CURRENT_LOAD=$(snmpget -Oqv -v2c -c public $SNMP_MIB)

# Convert the percentage into wattage consumed right now.


Let’s test the script!

$ ./

Awesome! 🎉