mdlayher / apcupsd_exporter

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

apcupsd_exporter: battery date format ambiguity causes scrape failures #7

Closed ilosaurus closed 4 years ago

ilosaurus commented 5 years ago

Hello mdlayher, thanks to create exporter for apcupsd, now i try this exporter in my enviroment. I get some error after running apcupsd exporter, this error like this.

An error has occurred:

error collecting metric Desc{fqName: "apcupsd_battery_volts", help: "Current UPS battery voltage.", constLabels: {}, variableLabels: [hostname ups_name model]}: parsing time "04/01/01" as "2006-01-02": cannot parse "1/01" as "2006"

root@prometheus:/opt# ./apcupsd_exporter -h
Usage of ./apcupsd_exporter:
  -apcupsd.addr string
        address of apcupsd Network Information Server (NIS) (default ":3551")
  -apcupsd.network string
        network of apcupsd Network Information Server (NIS): typically "tcp", "tcp4", or "tcp6" (default "tcp")
  -telemetry.addr string
        address for apcupsd exporter (default ":9162")
  -telemetry.path string
        URL path for surfacing collected metrics (default "/metrics")
root@prometheus:/opt# ./apcupsd_exporter -apcupsd.addr localhost:3551
2019/03/19 10:18:25 starting apcupsd exporter on ":9162" for server tcp://localhost:3551

2019/03/19 10:18:34 [ERROR] failed collecting UPS metric Desc{fqName: "apcupsd_battery_volts", help: "Current UPS battery voltage.", constLabels: {}, variableLabels: [hostname ups_name model]}: parsing time "04/01/01" as "2006-01-02": cannot parse "1/01" as "2006"
2019/03/19 10:18:35 [ERROR] failed collecting UPS metric Desc{fqName: "apcupsd_battery_volts", help: "Current UPS battery voltage.", constLabels: {}, variableLabels: [hostname ups_name model]}: parsing time "04/01/01" as "2006-01-02": cannot parse "1/01" as "2006"
root@prometheus:/opt# apcaccess status
APC      : 001,048,1110
DATE     : 2019-03-19 09:50:33 +0800  
HOSTNAME : prometheus
VERSION  : 3.14.12 (29 March 2014) debian
UPSNAME  : APC MGE Galaxy 3500
CABLE    : Ethernet Link
DRIVER   : PCNET UPS Driver
UPSMODE  : Stand Alone
STARTTIME: 2019-03-19 09:50:29 +0800  
MODEL    : MGE Galaxy 3500 40 kVA
STATUS   : ONLINE 
LINEV    : 228.0 Volts
LOADPCT  : 18.2 Percent
BCHARGE  : 100.0 Percent
TIMELEFT : 90.0 Minutes
MBATTCHG : 5 Percent
MINTIMEL : 3 Minutes
MAXTIME  : 0 Seconds
MAXLINEV : 232.3 Volts
MINLINEV : 221.9 Volts
OUTPUTV  : 219.1 Volts
DWAKE    : 0 Seconds
DSHUTD   : 20 Seconds
DLOWBATT : 2 Minutes
LOTRANS  : 197.0 Volts
HITRANS  : 477.0 Volts
RETPCT   : 0.0 Percent
ITEMP    : 43.5 C
BATTV    : 212.2 Volts
LINEFREQ : 49.9 Hz
LASTXFER : Unacceptable line voltage changes
NUMXFERS : 0
TONBATT  : 0 Seconds
CUMONBATT: 0 Seconds
XOFFBATT : N/A
SELFTEST : NO
STESTI   : OFF
STATFLAG : 0x05000008
REG1     : 0x00
REG2     : 0x00
REG3     : 0x00
MANDATE  : 02/24/17
SERIALNO : QS1708151047
BATTDATE : 04/01/01
NOMOUTV  : 380 Volts
EXTBATTS : 16
BADBATTS : 0
FIRMWARE : 962.0718.I
END APC  : 2019-03-19 10:13:51 +0800 

Hope you have free time to check the issue. Previously I was very grateful for the creation of apcupsd_exporter, hopefully it can be useful for many people.

Thanks mdlayher.

gebn commented 5 years ago

What's the output of cat /etc/debian_version? I suspect you're running Jessie, which has an old version of apcupsd that exposes BATTDATE in a different format to the one this exporter is expecting.

ilosaurus commented 5 years ago

Hello gebn, tq for reply, my enviroment using ubuntu 16.04 with debian version strech

root@prometheus:/home/prometheus#  cat /etc/debian_version 
stretch/sid
root@prometheus:/home/prometheus# apcaccess  | grep BATT
: Warning: old configuration file found.

: Expected: "## apcupsd.conf v1.1 ##"
: Found:    "UPSNAME APC MGE Galaxy 3500
"

: Please check new file format and
: modify accordingly the first line
: of config file.

: Processing config file anyway.
MBATTCHG : 5 Percent
DLOWBATT : 2 Minutes
BATTV    : 210.8 Volts
TONBATT  : 0 Seconds
CUMONBATT: 0 Seconds
XOFFBATT : N/A
BATTDATE : 04/01/01
EXTBATTS : 16
BADBATTS : 0
root@prometheus:/home/prometheus# 

output in BATTDATE is 04/01/01, how to change this value?

gebn commented 5 years ago

Ah ok, so Xenial is also constrained to 3.14.12. Is it possible for you to update to Bionic?

I’m slightly confused as, on the surface, the underlying library used by this exporter has handling for several date formats internally, but it appears they are not in play here. Perhaps @mdlayher can shed some light.

Regardless, it would be worth fixing that legacy config warning.

mdlayher commented 5 years ago

Apologies for the late reply here. I'm actually not even sure how to interpret "01/01/04" as a date, because of the ambiguity between American and European style dates, and I'm starting to think it isn't even worth parsing these dates since we don't use them for metrics anyway.

A patch needs to be applied in https://github.com/mdlayher/apcupsd. I'm out of town for a couple of days, but PRs welcome.

SergeiCherevko commented 5 years ago

2019/09/04 19:20:31 [ERROR] failed collecting UPS metric Desc{fqName: "apcupsd_battery_volts", help: "Current UPS battery voltage.", constLabels: {}, variableLabels: [hostname ups_name model]}: can't parse time: "08/04/2018"

how fix this? How should I do with https://github.com/mdlayher/apcupsd ? Can anyone help me? I should merge this repos in one folder or what? :(

mdlayher commented 5 years ago

The code that parses battery dates or whichever date is being treated as invalid should be updated in https://github.com/mdlayher/apcupsd to return the date as a string instead. Once that is merged, the library should be bumped in the go.mod here and all should work at that point.

Piknik1990 commented 4 years ago

The BATTDATE parameter was changed in apcupsd version 3.14.15-5 again. Right now it's look like this:

REG3     : 0x00
MANDATE  : 11/14/2019
SERIALNO : AS1943175
BATTDATE : 11/14/2019
NOMOUTV  : 230 Volts

And, of course, I got a follow error message:

apcupsd-exporter[59274]: 2020/01/28 05:43:31 [ERROR] failed collecting UPS metric Desc{fqName: "apcupsd_battery_volts", help: "Current UPS battery voltage.", constLabels: {}, variableLabels: [hostname ups_name model]}: invalid time duration

It's need to fix with compatibility to both versions of this parameters. Old: MM/DD/YY New: MM/DD/YYYY

Tech info:

rpm -qa | grep apc
apcupsd-3.14.14-5.el7.x86_64
# cat /etc/redhat-release 
CentOS Linux release 7.6.1810 (Core)
Piknik1990 commented 4 years ago

I created the Pull Request https://github.com/mdlayher/apcupsd/pull/9#issue-376837352

Also I have a the one question: can you to create a Release here (https://github.com/mdlayher/apcupsd_exporter/releases)? After pulling, of course.

mdlayher commented 4 years ago

This has been fixed.