mdlayher / apcupsd_exporter

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

Panic on startup #11

Closed joneskoo closed 4 years ago

joneskoo commented 4 years ago

Seems to panic sometimes on startup, not sure why. When I start it again it comes back up. Maybe I start the exporter too early in the boot and it can't discover my UPS?

This is an old version but looks like the line is still there.

https://github.com/mdlayher/apcupsd_exporter/blob/e0e3072fbff346aa0e533722f6bbef37d23e819b/cmd/apcupsd_exporter/main.go#L32

-- Logs begin at Mon 2020-05-18 21:31:43 EEST, end at Mon 2020-05-18 23:13:06 EEST. --
May 18 21:32:20 hansu systemd[1]: Started Prometheus apcupsd_exporter.
May 18 21:32:21 hansu apcupsd_exporter[2409]: 2020/05/18 21:32:21 [ERROR] error creating apcupsd client: dial tcp :3551: connect: connection refused
May 18 21:32:21 hansu apcupsd_exporter[2409]: panic: collector has no descriptors
May 18 21:32:21 hansu apcupsd_exporter[2409]: goroutine 1 [running]:
May 18 21:32:21 hansu apcupsd_exporter[2409]: github.com/mdlayher/apcupsd_exporter/vendor/github.com/prometheus/client_golang/prometheus.(*Registry).MustRegister(0xc420094340, 0xc420166040,
May 18 21:32:21 hansu apcupsd_exporter[2409]:         /home/joneskoo/go/src/github.com/mdlayher/apcupsd_exporter/vendor/github.com/prometheus/client_golang/prometheus/registry.go:362 +0x9e
May 18 21:32:21 hansu apcupsd_exporter[2409]: github.com/mdlayher/apcupsd_exporter/vendor/github.com/prometheus/client_golang/prometheus.MustRegister(0xc420166040, 0x1, 0x1)
May 18 21:32:21 hansu apcupsd_exporter[2409]:         /home/joneskoo/go/src/github.com/mdlayher/apcupsd_exporter/vendor/github.com/prometheus/client_golang/prometheus/registry.go:154 +0x53
May 18 21:32:21 hansu apcupsd_exporter[2409]: main.main()
May 18 21:32:21 hansu apcupsd_exporter[2409]:         /home/joneskoo/go/src/github.com/mdlayher/apcupsd_exporter/cmd/apcupsd_exporter/main.go:31 +0x10b
May 18 21:32:21 hansu systemd[1]: apcupsd_exporter.service: Main process exited, code=exited, status=2/INVALIDARGUMENT
May 18 21:32:21 hansu systemd[1]: apcupsd_exporter.service: Failed with result 'exit-code'.
joneskoo commented 4 years ago

I added a dependency to my systemd unit for apcupsd.service, hopefully that resolves the root cause. Maybe could handle the "can't connect" without a panic?

mdlayher commented 4 years ago

I did a bunch of cleanup as of today and I believe this is now fixed via https://github.com/mdlayher/apcupsd_exporter/commit/43387c6d027ff9d23dbbb5774b5a7c913e778845.