Markham Lee
Published © MIT

Real Tiime Monitoring of UPS Devices

Simple way of monitoring a UPS device managed with Network Monitoring Tools (NUT), with standard Python and no additional libraries.

BeginnerProtip1 hour197
Real Tiime Monitoring of UPS Devices

Things used in this project

Hardware components

CyberPower PC UPS PFC1500LCDa
×1
Raspberry Pi 4 Model B
Raspberry Pi 4 Model B
×1

Software apps and online services

Eclipse-Mosquitto
Node-RED
Node-RED
InfluxDB
Grafana

Story

Read more

Code

Simple UPS Monitoring

Python
import os
from pprint import pp
import subprocess as sp

# IP of your server running NUT, you can hard code for initial testing
UPS_IP = os.environ['UPS_IP']

# name you gave your UPS during setup, you can hard code for testing
UPS_ID = os.environ['UPS_ID']

# define the command, same one you'd use at the command line
CMD = "upsc " + UPS_ID + "@" + UPS_IP

# run command using subprocess library, clean up output
data = sp.check_output(CMD, shell=True)
data = data.decode("utf-8").strip().split("\n")

# parse data into a list of lists, each pair of values will be in its own list
initial_list = [i.split(':') for i in data]

# convert the list into python dictionary, each list in the list of lists
# becomes a key value pair
test_dict = dict(initial_list)

# print out the dictionary to see the values
pp(test_dict)

Production Version

Docker container deployed on Kubernetes, but can be deployed with any container orchestration or management tool. E.g., Docker desktop or Portainer

Credits

Markham Lee

Markham Lee

1 project • 0 followers
I am a data and machine learning engineer, whose areas of interest areas include computer vision, edge computing, IoT and machine learning.

Comments