mdlayher / apcupsd_exporter

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

invalid duration Noalarm #3

Closed Atomicbeast101 closed 6 years ago

Atomicbeast101 commented 6 years ago

Greetings, I tried testing apcupsd_exporter on my proxmox v5.0-32 server with apcupsd running and received this error when trying to access the metrics through browser:

2017/11/09 14:32:48 [ERROR] failed collecting UPS metric Desc{fqName: "apcupsd_battery_volts", help: "Current UPS battery voltage.", constLabels: {}, variableLabels: [hostname ups_name model]}: time: invalid duration Noalarm

I know apcupsd works perfectly as I'm able to get info on my UPS server using apcaccess status easily. Any idea what's up with that?

mdlayher commented 6 years ago

Looks like some special case I didn't account for in my duration person. Can you paste the output of apcaccess for me?

mdlayher commented 6 years ago

*duration parsing, oops, mobile.

Atomicbeast101 commented 6 years ago

Sure, here's the output from apcaccess status:

APC      : 001,036,0877
DATE     : 2017-11-09 15:06:01 -0600
HOSTNAME : ADAM-PROXMOX
VERSION  : 3.14.14 (31 May 2016) debian
UPSNAME  : ADAM-UPS
CABLE    : USB Cable
DRIVER   : USB UPS Driver
UPSMODE  : Stand Alone
STARTTIME: 2017-11-09 14:59:30 -0600
MODEL    : Back-UPS RS 1500G
STATUS   : ONLINE
LINEV    : 121.0 Volts
LOADPCT  : 18.0 Percent
BCHARGE  : 100.0 Percent
TIMELEFT : 35.5 Minutes
MBATTCHG : 5 Percent
MINTIMEL : 10 Minutes
MAXTIME  : 0 Seconds
SENSE    : Medium
LOTRANS  : 88.0 Volts
HITRANS  : 147.0 Volts
ALARMDEL : No alarm
BATTV    : 27.2 Volts
LASTXFER : Automatic or explicit self test
NUMXFERS : 0
TONBATT  : 0 Seconds
CUMONBATT: 0 Seconds
XOFFBATT : N/A
SELFTEST : NO
STATFLAG : 0x05000008
SERIALNO : 4B1720P23467
BATTDATE : 2017-05-21
NOMINV   : 120 Volts
NOMBATTV : 24.0 Volts
NOMPOWER : 865 Watts
FIRMWARE : 865.L6 .D USB FW:L6
END APC  : 2017-11-09 15:06:15 -0600
mdlayher commented 6 years ago

Okay, just pushed https://github.com/mdlayher/apcupsd/commit/d7ac62064afac43aae52945ab9b105fb0dbb8a9e in my package which should fix it. Can you pull the latest version of that and then rebuild the exporter?

Atomicbeast101 commented 6 years ago

Sorry, took a bit to figure out how to compile it. Works now! Thank you so much for making the changes.

ncrmro commented 6 years ago

Trying to build the latest version, any chance I could get a few build steps

mdlayher commented 6 years ago

Hi, you'll need a working Go toolchain: https://golang.org/dl/. After that, this should build with no problems.

ncrmro commented 6 years ago

@mdlayher I've attempted to build on gitlab and download the binary as an artifact and in OSX using homebrew golang .

Gitlab CI Build Log

OSX local fires this when I try go build ./...

I've tried to list a bunch of dirs but can seem to find the binary.

# _/Users/ncrmro/programming/forks/apcupsd_exporter/cmd/apcupsd_exporter
cmd/apcupsd_exporter/main.go:31:45: cannot use apcupsdexporter.New(fn) (type *apcupsdexporter.Exporter) as type "github.com/prometheus/client_golang/prometheus".Collector in argument to "github.com/prometheus/client_golang/prometheus".MustRegister:
        *apcupsdexporter.Exporter does not implement "github.com/prometheus/client_golang/prometheus".Collector (wrong type for Collect method)
                have Collect(chan<- "github.com/mdlayher/apcupsd_exporter/vendor/github.com/prometheus/client_golang/prometheus".Metric)
                want Collect(chan<- "github.com/prometheus/client_golang/prometheus".Metric)
cmd/apcupsd_exporter/main.go:47:9: cannot use func literal (type func() (*"github.com/mdlayher/apcupsd".Client, error)) as type apcupsdexporter.ClientFunc in return argument

Apologies very little experience building go binaries.

mdlayher commented 6 years ago

Looking at your directory structure, you're trying to build outside of a standard GOPATH setup. Sorry, I don't have time to help debug this further. Please follow the documentation on golang.org for how to build Go programs.

przemas75 commented 6 years ago

i have such error with the new build:

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

apcaccess status is:

APC : 001,049,1087 DATE : 2018-08-12 15:56:21 +0200 HOSTNAME : navajo VERSION : 3.14.14 (31 May 2016) debian UPSNAME : navajoaq CABLE : Custom Cable Smart DRIVER : APC Smart UPS (any) UPSMODE : Stand Alone STARTTIME: 2018-08-12 15:56:13 +0200 MODEL : SMART-UPS 1400 STATUS : ONLINE REPLACEBATT LINEV : 0.0 Volts LOADPCT : 0.0 Percent BCHARGE : 0.0 Percent TIMELEFT : 0.0 Minutes MBATTCHG : 5 Percent MINTIMEL : 3 Minutes MAXTIME : 0 Seconds MAXLINEV : 0.0 Volts MINLINEV : 0.0 Volts OUTPUTV : 0.0 Volts SENSE : High DWAKE : 0 Seconds DSHUTD : 180 Seconds DLOWBATT : 2 Minutes LOTRANS : 196.0 Volts HITRANS : 253.0 Volts RETPCT : 0.0 Percent ITEMP : 0.0 C ALARMDEL : No alarm BATTV : 0.0 Volts LINEFREQ : 0.0 Hz NUMXFERS : 0 TONBATT : 0 Seconds CUMONBATT: 0 Seconds XOFFBATT : N/A STESTI : 336 STATFLAG : 0x05000088 DIPSW : 0x00 REG1 : 0x00 REG2 : 0x00 REG3 : 0x00 MANDATE : 01/22/97 SERIALNO : GS9704944560 BATTDATE : 28/01/15 NOMOUTV : 230 Volts NOMBATTV : 24.0 Volts EXTBATTS : 0 FIRMWARE : 70.9.I END APC : 2018-08-12 15:56:23 +0200 root@navajo:~/go# apcaccess status 172.16.8.98:3551|grep BAT MBATTCHG : 5 Percent DLOWBATT : 2 Minutes BATTV : 27.7 Volts TONBATT : 0 Seconds CUMONBATT: 0 Seconds XOFFBATT : N/A BATTDATE : 28/01/15 NOMBATTV : 24.0 Volts EXTBATTS : 0

piyanan commented 5 years ago

I found a way to fix error parsing time like "28/01/15" as "2006-01-02": cannot parse "1/15" as "2006" https://github.com/Piyanan/apcupsd_exporter/commit/1038a7913e685477d8f64a0ea519733eb477835d IF anyone stuck.

mdlayher commented 5 years ago

Manually modifying vendored code isn't the right solution; this has been fixed upstream and the newest code needs to be vendored. I'll do this shortly.

mdlayher commented 5 years ago

Ugh, just realized the dates can also appear with the day first. I'll send another patch and then vendor it all here.

mdlayher commented 5 years ago

See: https://github.com/mdlayher/apcupsd/issues/8. And let's please move discussion to either that issue for date problems, or a new issue for further problems with the exporter.

crockk commented 3 years ago

Don't mean to dig up any graves, but I'm still getting this exact issue:

root@xxx:/home/ncrooks# curl http://localhost:9006/metrics
An error has occurred:

error collecting metric Desc{fqName: "apcupsd_battery_volts", 
help: "Current UPS battery voltage.", constLabels: {}, variableLabels: [hostname ups_name model]}: 
time: invalid duration Noalarm
root@xxx:/home/ncrooks# apcaccess status
APC      : 001,038,0983
DATE     : 2021-06-04 11:58:25 -0700
HOSTNAME : xxx
VERSION  : 3.14.14 (31 May 2016) debian
UPSNAME  : xxx
CABLE    : USB Cable
DRIVER   : USB UPS Driver
UPSMODE  : Stand Alone
STARTTIME: 2021-04-23 13:58:45 -0700
MODEL    : Back-UPS RS 1000MS
STATUS   : ONLINE
LINEV    : 119.0 Volts
LOADPCT  : 10.0 Percent
BCHARGE  : 100.0 Percent
TIMELEFT : 62.8 Minutes
MBATTCHG : 5 Percent
MINTIMEL : 3 Minutes
MAXTIME  : 0 Seconds
SENSE    : Medium
LOTRANS  : 88.0 Volts
HITRANS  : 144.0 Volts
ALARMDEL : No alarm
BATTV    : 27.3 Volts
LASTXFER : Low line voltage
NUMXFERS : 4
XONBATT  : 2021-05-30 04:01:06 -0700
TONBATT  : 0 Seconds
CUMONBATT: 21 Seconds
XOFFBATT : 2021-05-30 04:01:08 -0700
LASTSTEST: 2021-05-21 14:49:58 -0700
SELFTEST : NO
STATFLAG : 0x05000008
SERIALNO : 3B2025X22283
BATTDATE : 2020-06-16
NOMINV   : 120 Volts
NOMBATTV : 24.0 Volts
NOMPOWER : 600 Watts
FIRMWARE : 950.e4 .D USB FW:e4
END APC  : 2021-06-04 11:59:02 -0700

Wasn't sure if I should make a new issue or not. Using the latest release binary.

EDIT: Just noticed the release binary is from 2016... Should maybe consider updating? Would be really nice to have the latest fixes in the binary.