Coder Social home page Coder Social logo

ups-telegraf's Introduction

Description

Get data from USB-connected UPS into InfluxDB using Telegraf

Transforms upsc output like this:

battery.charge: 100
battery.charge.low: 10
battery.charge.warning: 20
battery.mfr.date: CPS
battery.runtime: 3133
battery.runtime.low: 300
battery.type: PbAcid
battery.voltage: 13.1
battery.voltage.nominal: 12

into InfluxDB Line Protocol like this:

ups battery.charge=100,battery.charge.low=10,battery.charge.warning=20,battery.mfr.date="CPS",battery.runtime=2970,battery.runtime.low=300,battery.type="PbAcid",battery.voltage=13.1,battery.voltage.nominal=12

Usage

Edit the script string_measurements variable to reflect your setup. Specifically, add any additional measurement names that your UPS provides to the string_measurements array (in sorted order) so they will be included in the output.

To see all the measurements your UPS provides, run this:

upsc YOUR_UPS_NAME_HERE 2>/dev/null | awk -F':' 'BEGIN {print "string_measurements=["} {print "\"" $1 "\", "} END {print "]"}' |tr -d '\n'

Call the script from telegraf.conf like this

[[inputs.exec]]

   commands = ["python /path/to/getUpsData.py <YOUR_UPS_NAME_HERE>"]
   timeout = "5s"
   data_format = "influx"

Compatibility

Tested on:

  • Cyberpower CP1000AVRLCDa
  • CyberPower SL700U (CyberPowerSL700U.py)
  • Dell UPS 1000T/1920T/1920R HV (DellBadge-Eaton5PX.py)
  • MGE Pulsar 2200

If you're using this with a different UPS, please let me know so I can add it to the list

Contributors

Thanks to the following for helping improve this repo.

  • @openincident
  • @mattster98
  • @Graffics

ups-telegraf's People

Contributors

andros-ua avatar graffics avatar mattster98 avatar sa7mon avatar victorbrca avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

ups-telegraf's Issues

Some modifications for Eaton5E

Hi, I'd needed to do some modifications to getting it work with Eaton 5E. Plus I've changed the output to work as float fields in InfluxDB:

from __future__ import print_function
import subprocess

cmd="upsc eaton5E"

output=""
string_measurements=["battery.charge","battery.runtime","input.voltage","output.voltage","ups.beeper.status","ups.load","ups.status"]

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()
print(output, end='')

Problem executing py file

Hi!
Thank you for your ups-telegraf. I was monitoring my ups with nut and a python script (influx_nut) as a service.. problem is that sometime service is stopped.
I use telegraf container with my mikrotik router, raspberry pi's and container and i'm very happy.
Then i thinked why not monitoring nut with telegraf and i found you.
Well... when i execute your py file, this runs very well, with python3 ;-) but when i start telegraf container..log report this:

2019-07-26T17:50:01Z I! Starting Telegraf 1.10.4
2019-07-26T17:50:01Z I! Using config file: /etc/telegraf/telegraf.conf
2019-07-26T17:50:01Z I! Loaded inputs: exec
2019-07-26T17:50:01Z I! Loaded aggregators:
2019-07-26T17:50:01Z I! Loaded processors:
2019-07-26T17:50:01Z I! Loaded outputs: influxdb
2019-07-26T17:50:01Z I! Tags enabled: host=BBDD
2019-07-26T17:50:01Z I! [agent] Config: Interval:10s, Quiet:false, Hostname:"BBDD", Flush Interval:10s
2019-07-26T17:50:10Z E! [inputs.exec]: Error in plugin: exec: exec: "python3": executable file not found in $PATH for command 'python3 /etc/nut/saitelegraf/getUpsData.py'
2019-07-26T17:50:20Z E! [inputs.exec]: Error in plugin: exec: exec: "python3": executable file not found in $PATH for command 'python3 /etc/nut/saitelegraf/getUpsData.py'
2019-07-26T17:50:24Z I! [agent] Hang on, flushing any cached metrics before shutdown

I don't undestand why if i execute python file in cli runs well but command inside docker doesn't works.

Thanks in advance

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.