How to Collect UPS Data on pfSense with Telegraf

· by Victor Mendonça · Read in about 2 min · (256 words) ·

If you are running Grafana at home to monitor your devices, and you also have pfSense running off a UPS (if you don’t, check out my previous article on How to Setup a USB UPS on pfSense), you may want to pull UPS related data from pfSense.

My Grafana pfSense config


a. Start by logging into your pfSense, go into «System => Package Manager = Available Packages» and install Telegraf

b. Now login to pfSense via ssh, and create a file in /usr/local/bin/ with the content below

Note: Make sure to change the UPS name in cmd="upsc BackUPSES750"

from __future__ import print_function
import subprocess

cmd="upsc BackUPSES750"

p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE)

for line in p.stdout.readlines(): #read and store result in log file
    line = line.decode("utf-8").rstrip()
    key = line[:line.find(":")]
    value = line[line.find(":")+2:]

    if key in string_measurements:
        if value.isalpha():
            value = '"' + value + '"'
        measurement = key + "=" + value
        if output != "":
            measurement = "," + measurement
        output += measurement

output = "ups, " + output.rstrip()

The output data will be as shown below. If you would like to format the output, refer to my instructions on my GitHub Repo -

ups, battery.charge=100,battery.runtime=18405,ups.status="OL"

c. Go back to pfSense UI and go into «Services => Telegraf»

d. Configure Telegraf as your usually would, and under «Additional configuration for Telegraf» add the configuration below:

  commands = ["python2.7 /usr/local/etc/"]
  timeout = "5s"
  data_format = "influx"

e. Restart Telegraf and check your influxdb for the new data being populated

code with