I'm going to gather metrics from my UPS.


Things I'm using here:

  • NUT
  • Telegraf
  • InfluxDB
  • Grafana

So, there's a program called NUT (Network UPS Tools) which let you gather data from UPS equipped with RS-232/USB data port.

In this case I'm working with IPPON Back Comfo Pro 600 via USB. In command line you use sudo or just impersonate as root user.

First, let's install NUT:

apt install nut

Now add your UPS config to NUT:

# tail -n5 /etc/nut/ups.conf

driver = blazer_usb
port = auto
desc = "IPPON 600 UPS, USB interface"

Enable network interface for upsd:

# grep ^LISTEN /etc/nut/upsd.conf


Add upsd user accounts:

# cat /etc/nut/upsd.users

        password = passwordmaster
        allowfrom = localhost
        upsmon master
        password = passwordslave
        allowfrom = localhost
        upsmon slave
        password = passwordadmin
        allowfrom = localhost
        actions = SET
        instcmds = ALL

Add monitor entry to upsmon conf.

I'm not going to change any settings or perform any actions so using slave for monitoring and not configuring anything more.

# grep ^MONITOR /etc/nut/upsmon.conf

MONITOR ippon@localhost 1 upsslave passwordslave slave

Check the things out:

# Starting daemon
service nut-server restart

# Checking visibility of my device
upsc -l

# Gathering all the sensitive data
upsc ippon

battery.charge: 100
input.voltage: 211.7
output.voltage: 211.7
ups.temperature: 25.0

Now let's setup Telegraf metrics gathering with this script (should be executable):

# cat /opt/ups_metrics.sh




  M_CHARGE=$(${GATHER_COMMAND} | grep battery.charge | cut -d' ' -f2)
  M_INVOLT=$(${GATHER_COMMAND} | grep input.voltage | cut -d' ' -f2)
  M_OUTVOLT=$(${GATHER_COMMAND} | grep output.voltage | cut -d' ' -f2)
  M_TEMPERATURE=$(${GATHER_COMMAND} | grep ups.temperature | cut -d' ' -f2)

  # cpu,host=server01,region=uswest value=1 1434055562000000000

  echo ups,host=$(hostname --fqdn),ups=${UPS_NAME} ${METRICS} $(date +%s)
) 2>/dev/null

You could alternate the script knowing bash syntax and InfluxData line protocol scpecs.

Then we add this script as input for our telegraf daemon (which supposed to be setup with proper DB output):

# grep -A 4 inputs.exec /etc/telegraf/telegraf.conf

  commands = [
  data_format = "influx"

Restart the daemon and enjoy your graphs. :)


comments powered by Disqus