sources for e1e0 website
git clone https://git.e1e0.net/e1e0.net.git
Log | Files | Refs

commit d5ca71148ad76bfa1a77413c9ebf633272e81705
parent 39c378fd03b625186e7113c0b5eae0cd595fee98
Author: Paco Esteban <paco@e1e0.net>
Date:   Fri, 17 Jan 2020 17:35:04 +0100

upsc prometheus exporter article

Msrc/gophermap | 3++-
Msrc/index.html | 1+
Asrc/upsc-prometheus-exporter.md | 95+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 98 insertions(+), 1 deletion(-)

diff --git a/src/gophermap b/src/gophermap @@ -12,6 +12,7 @@ Sometimes I write things so I do not forget ... o--o-- Random (usually tech) stuff +0upsc (NUT) Prometheus exporter /upsc-prometheus-exporter.md.txt e1e0.net 70 0Notes on Vim register /vim-registers.md.txt e1e0.net 70 0Encrypt a USB flash drive on OpenBSD. /openbsd-encrypt-usb-flash-drive.md.txt e1e0.net 70 0Long Wireless links and monitoring. /long-wireless-links-and-monitoring.md.txt e1e0.net 70 @@ -46,5 +47,5 @@ Have any comments ? Send an email to <comments@e1e0.net> o- o -- -------------------------------------------------------- -- o -- -Last updated: Sun, 22 Dec 2019 20:25:46 +0100 +Last updated: Fri, 17 Jan 2020 15:54:59 +0000 o- o -- -------------------------------------------------------- -- o -- diff --git a/src/index.html b/src/index.html @@ -1,4 +1,5 @@ <ul> +<li><a href="/upsc-prometheus-exporter.html" title="2020-01-17">upsc (NUT) Prometheus exporter</a></li> <li><a href="/vim-registers.html" title="2019-12-06">Notes on Vim registers</a></li> <li><a href="/openbsd-encrypt-usb-flash-drive.html" title="2019-08-24">Encrypt a USB flash drive on OpenBSD.</a></li> <li><a href="/long-wireless-links-and-monitoring.html" title="2019-05-31">Long Wireless links and monitoring</a></li> diff --git a/src/upsc-prometheus-exporter.md b/src/upsc-prometheus-exporter.md @@ -0,0 +1,95 @@ +# upsc (NUT) Prometheus Exporter +2020-01-17 + +I have a cheap [UPS][1] that provides backup power to my main workstation and some +other equipment. This device has a USB interface that provides some data about +the status, battery charge, etc. That means only one device can have that +information and react accordingly when there's a power outage and the battery +goes near depletion. + +To address that I use [NUT][2], so the other devices attached to that ups can +also react on power events. + +There's plenty information on the net about this (probably the hardest part is +finding the driver for your particular unit ...), so I won't talk about that on +this article. + +NUT has a cli tool that can print some data to stdout like this: + + $ upsc ups + Init SSL without certificate database + battery.charge: 100 + battery.voltage: 27.40 + battery.voltage.high: 26.00 + battery.voltage.low: 20.80 + battery.voltage.nominal: 24.0 + device.type: ups + driver.name: blazer_usb + driver.parameter.pollinterval: 2 + driver.parameter.port: auto + driver.parameter.synchronous: no + driver.version: 2.7.4 + driver.version.internal: 0.12 + input.current.nominal: 5.0 + input.frequency: 49.6 + input.frequency.nominal: 50 + input.voltage: 232.8 + input.voltage.fault: 232.8 + input.voltage.nominal: 230 + output.voltage: 232.8 + ups.beeper.status: enabled + ups.delay.shutdown: 30 + ups.delay.start: 180 + ups.load: 10 + ups.productid: 5161 + ups.status: OL + ups.type: offline / line interactive + ups.vendorid: 0665 + +That's a lot of interesting information. What I wanted was a way to monitor +the data exposed by NUT in a way that could be consumed by prometheus, as I use +it for monitoring on my internal network. + +The only thing I could find was [this hack][3] that uses `docker` + `inetd(8)` ++ wrapper scripts + `awk(1)` for parsing and serving the data on a Prometheus +format. + +Although I have to admit that I like simple command line solutions, I think this +is a bit too far for my taste, so I've made a super dumb program in Go that does +exactly that, listens on a port (http) and for any incoming request on +`/metrics` calls `upsc(8)`, parses its output and returns it formatted in a way +Prometheus can understand. + +On a surge of originality, the small program is called `prometheus-upsc-exporter`. +The source code can be found [here][4]. I've also built it for linux arm +(raspberry pi for instance) and created a [repo][5] for it (well, I may use it +in the future for other builds). So it can be downloaded and used directly, +just be sure to check the checksum and signature. + +It produces metrics of the form: + + upsc_battery_charge{instance="nut.host:8081",job="ups"} + upsc_battery_voltage{instance="nut.host:8081",job="ups"} + ... + +With that and a bit of "grafana dashboard fu" I now have metrics on my cheap UPS +and can even generate alerts based on them. + +If you decide to use it, I recommend to take a look at the code first, as +I made some parsing decisions and ignore some info I do not find useful and you +may want to include. + +Take a look at the included man page and the `systemd(1)` servide definition +example for more info. + +Hope somebody find it useful and, as usual, any patches and suggestions are +welcome. + +_Have any comments ? Send an email to the [comments address][999]._ + +[1]: https://en.wikipedia.org/wiki/Uninterruptible_power_supply +[2]: https://networkupstools.org/ +[3]: https://github.com/jzck/prometheus-upsc-exporter +[4]: https://git.e1e0.net/prometheus-upsc-exporter/ +[5]: https://e1e0.net/repo/ +[999]: mailto:comments@e1e0.net?Subject=upsc%20(NUT)%20Prometheus%20Exporter