mdlayher / apcupsd_exporter

Prometheus exporter that exposes metrics from apcupsd's NIS. MIT Licensed.
MIT License
156 stars 65 forks source link

Metrics for UPS status #16

Closed lahwaacz closed 2 years ago

lahwaacz commented 3 years ago

Is it possible to monitor the UPS status? For example, apcaccess reports the STATUS field:

 STATUS      : UPS status.  One or more of the following (space-
             separated): CAL TRIM BOOST ONLINE ONBATT OVERLOAD LOWBATT
             REPLACEBATT NOBATT SLAVE SLAVEDOWN
             or
             COMMLOST
             or
             SHUTTING DOWN

Having metrics for this would be useful e.g. for alerts on REPLACEBATT, OVERLOAD, etc.

crockk commented 3 years ago

I initially made an issue with this same request, so I will bump this issue instead and leave what I wrote on my issue:

This would be extremely useful to know when a device switches to using the battery. I think something like this other exporter could be merged into this exporter: https://github.com/damomurf/apcupsd-exporter

The apcaccess command outputs STATUS, with values such as:

I'm proposing adding this as a label in apcupsd_info so that it would look something like:

apcupsd_info{status="ONLINE", hostname="xxx", instance="xxx", job="xxx", model="xxx", ups="UnitedScaffold-SBC1"}

Using such a label would allows us to create alerts such as:

   - alert: UPSSwitchedToBattery
     expr: apcupsd_info{status="ONBATT"} == 1

PR #8 would have implemented a similar change but it was closed for some reason.

mdlayher commented 2 years ago

Fixed in https://github.com/mdlayher/apcupsd_exporter/commit/3f531e59fc85ebd86ce9806a1336818c5db18bcb.

Apologies for the delay. The previous PR had a lot of churn and I ended up doing a lot of cleanup myself but let this one slip.