Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

runtime error: index out of range in mineVersion on v0.8.0 #81

Closed
lahwaacz opened this issue Oct 9, 2022 · 3 comments · Fixed by #93
Closed

runtime error: index out of range in mineVersion on v0.8.0 #81

lahwaacz opened this issue Oct 9, 2022 · 3 comments · Fixed by #93

Comments

@lahwaacz
Copy link
Contributor

lahwaacz commented Oct 9, 2022

I'm getting this error on v0.8.0:

prometheus-smartctl-exporter[100066]: ts=2022-10-09T08:30:40.463Z caller=main.go:94 level=info msg="Starting systemd_exporter" version="(version=, branch=, revision=)"
prometheus-smartctl-exporter[100066]: ts=2022-10-09T08:30:40.463Z caller=main.go:95 level=info msg="Build context" build_context="(go=go1.19.2, user=, date=)"
prometheus-smartctl-exporter[100066]: ts=2022-10-09T08:30:40.463Z caller=main.go:100 level=info msg="No devices specified, trying to load them automatically"
prometheus-smartctl-exporter[100066]: ts=2022-10-09T08:30:40.474Z caller=main.go:105 level=info msg="Found device" device=/dev/sda
prometheus-smartctl-exporter[100066]: ts=2022-10-09T08:30:40.488Z caller=main.go:128 level=info msg="Listening on" address=0.0.0.0:9633
prometheus-smartctl-exporter[100066]: ts=2022-10-09T08:30:40.490Z caller=tls_config.go:195 level=info msg="TLS is disabled." http2=false
prometheus-smartctl-exporter[100066]: ts=2022-10-09T08:40:45.346Z caller=readjson.go:69 level=warn msg="S.M.A.R.T. output reading" err="exit status 2"
prometheus-smartctl-exporter[100066]: ts=2022-10-09T08:40:45.346Z caller=readjson.go:122 level=error msg="Device open failed, device did not return an IDENTIFY DEVICE structure, or device is in a low-power mode"
prometheus-smartctl-exporter[100066]: ts=2022-10-09T08:40:45.346Z caller=main.go:57 level=error msg="Error collecting SMART data" err="smartctl returned bad data for device /dev/sda"
prometheus-smartctl-exporter[100066]: panic: runtime error: index out of range [0] with length 0
prometheus-smartctl-exporter[100066]: goroutine 57 [running]:
prometheus-smartctl-exporter[100066]: main.(*SMARTctlInfo).mineVersion(0xc0003a7e08)
prometheus-smartctl-exporter[100066]:         github.com/prometheus-community/smartctl_exporter/smartctlinfo.go:59 +0xba5
prometheus-smartctl-exporter[100066]: main.(*SMARTctlInfo).Collect(...)
prometheus-smartctl-exporter[100066]:         github.com/prometheus-community/smartctl_exporter/smartctlinfo.go:48
prometheus-smartctl-exporter[100066]: main.SMARTctlManagerCollector.Collect({{0x0, 0x0}, 0x0, {0xc000218e50, 0x1, 0x1}, {0x55fb044ea940, 0xc000242dc0}}, 0xc00036a060?)
prometheus-smartctl-exporter[100066]:         github.com/prometheus-community/smartctl_exporter/main.go:60 +0xd2
prometheus-smartctl-exporter[100066]: github.com/prometheus/client_golang/prometheus.(*wrappingCollector).Collect.func1()
prometheus-smartctl-exporter[100066]:         github.com/prometheus/[email protected]/prometheus/wrap.go:131 +0x2e
prometheus-smartctl-exporter[100066]: created by github.com/prometheus/client_golang/prometheus.(*wrappingCollector).Collect
prometheus-smartctl-exporter[100066]:         github.com/prometheus/[email protected]/prometheus/wrap.go:130 +0x8d

It seems that if there is no device after #74, there is no data for mineVersion to work?

@SuperQ
Copy link
Contributor

SuperQ commented Oct 9, 2022

Your actual error is this:

prometheus-smartctl-exporter[100066]: ts=2022-10-09T08:40:45.346Z caller=readjson.go:122 level=error msg="Device open failed, device did not return an IDENTIFY DEVICE structure, or device is in a low-power mode"
prometheus-smartctl-exporter[100066]: ts=2022-10-09T08:40:45.346Z caller=main.go:57 level=error msg="Error collecting SMART data" err="smartctl returned bad data for device /dev/sda"

You will need to find out why your device is returning bad data.

@lahwaacz
Copy link
Contributor Author

Hmm, so readSmartctl prints caller=readjson.go:69 level=warn msg="S.M.A.R.T. output reading" err="exit status 2" which means that the device is in standby mode. Then resultCodeIsOk prints caller=readjson.go:122 level=error msg="Device open failed, device did not return an IDENTIFY DEVICE structure, or device is in a low-power mode" and returns false. Then readData gets ok = false and treats the result as "bad data", so it prints level=error msg="Error collecting SMART data" err="smartctl returned bad data for device /dev/sda" and returns an empty json. Then the program continues, but fails in the case there is no other disk.

I admit this is rather weird case, since the root filesystem is mounted from /dev/sda and when the device goes into standby, the exporter's execution of the smartctl command does not wake it up.

@lahwaacz
Copy link
Contributor Author

@SuperQ @k0ste any ideas? 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants