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

panic: index out of range #19

Closed
Junyi-99 opened this issue Apr 3, 2021 · 6 comments
Closed

panic: index out of range #19

Junyi-99 opened this issue Apr 3, 2021 · 6 comments

Comments

@Junyi-99
Copy link

Junyi-99 commented Apr 3, 2021

When I start the program, then go to browser http://myip:9633/metrics
The program raise an error.

Here is the log:

➜  bin git:(master) ✗ sudo ./smartctl_exporter --config=./config.yaml
[Warning] S.M.A.R.T. output reading error: exit status 1
[Warning] The device self-test log contains records of errors. [ATA only] Failed self-tests outdated by a newer successful extended self-test are ignored.
[Error] /dev/sda: Unknown USB bridge [0x0951:0x1666 (0x1075)]
[Error] smartctl returned bad data for device /dev/sda
[Warning] S.M.A.R.T. output reading error: exit status 4
[Warning] SMART status check returned 'DISK OK' but we found that some (usage or prefail) Attributes have been <= threshold at some time in the past.
[Info] Starting on 0.0.0.0:9633/metrics
[Warning] S.M.A.R.T. output reading error: exit status 1
[Warning] The device self-test log contains records of errors. [ATA only] Failed self-tests outdated by a newer successful extended self-test are ignored.
[Error] /dev/sda: Unknown USB bridge [0x0951:0x1666 (0x1075)]
[Error] smartctl returned bad data for device /dev/sda
[Error] Too early collect called for device /dev/sdb
panic: runtime error: index out of range

goroutine 38 [running]:
main.(*SMARTctlInfo).mineVersion(0xc3af64)
	/home/pi/smartctl_exporter/smartctlinfo.go:46 +0x4c0
main.(*SMARTctlInfo).Collect(0xc3af64)

Here are my dir structure

➜  bin git:(master) ✗ tree ./
./
├── config.yaml
└── smartctl_exporter

0 directories, 2 files

Here are the content of config.yaml

smartctl_exporter:
  bind_to: "0.0.0.0:9633"
  url_path: "/metrics"
  fake_json: no
  smartctl_location: /usr/local/sbin/smartctl
  collect_not_more_than_period: 120s
  devices:
  - /dev/sda
  - /dev/sdb
  #- /dev/sdc
  #- /dev/sdd
  #- /dev/sde
  #- /dev/sdf

The smartctl version is:

➜  bin git:(master) ✗ smartctl --version
smartctl 7.2 2020-12-30 r5155 [armv7l-linux-5.10.17-v7l+] (local build)
Copyright (C) 2002-20, Bruce Allen, Christian Franke, www.smartmontools.org

smartctl comes with ABSOLUTELY NO WARRANTY. This is free
software, and you are welcome to redistribute it under
the terms of the GNU General Public License; either
version 2, or (at your option) any later version.
See http://www.gnu.org for further details.

smartmontools release 7.2 dated 2020-12-30 at 16:48:30 UTC
smartmontools SVN rev 5155 dated 2020-12-30 at 16:49:18
smartmontools build host: armv7l-unknown-linux-gnueabihf
smartmontools build with: C++14, GCC 8.3.0
smartmontools configure arguments: [no arguments given]
@radicalgeek
Copy link

radicalgeek commented May 3, 2021

I am seeing this same issue. Pretty much the same config as you, also running on armv7l (openwrt 19.07.7)
here is my config yaml in /etc/smartctl_exporter.yaml:

`
smartctl_exporter:
bind_to: "0.0.0.0:9633"
url_path: "/metrics"
fake_json: no
smartctl_location: /usr/sbin/smartctl
collect_not_more_than_period: 40s
devices:

  • /dev/sda
    `

I have the binary in /usr/bin

smartctl 7.0 2018-12-30 r4883 [armv7l-linux-4.14.221] (localbuild)

It seems to run fine for a moment, and sometimes I get to see the metrics in the browser. Here is the error:

Mon May 3 11:18:26 2021 daemon.info smartctl_exporter[3795]: [Error] Too early collect called for device /dev/sda Mon May 3 11:18:26 2021 daemon.err smartctl_exporter[3795]: panic: runtime error: index out of range [0] with length 0 Mon May 3 11:18:26 2021 daemon.err smartctl_exporter[3795]: Mon May 3 11:18:26 2021 daemon.err smartctl_exporter[3795]: goroutine 12 [running]: Mon May 3 11:18:26 2021 daemon.err smartctl_exporter[3795]: main.(*SMARTctlInfo).mineVersion(0x21d3f64) Mon May 3 11:18:26 2021 daemon.err smartctl_exporter[3795]: /home/mark/Code/smartctl_exporter/smartctlinfo.go:46 +0x530 Mon May 3 11:18:26 2021 daemon.err smartctl_exporter[3795]: main.(*SMARTctlInfo).Collect(...) Mon May 3 11:18:26 2021 daemon.err smartctl_exporter[3795]: /home/mark/Code/smartctl_exporter/smartctlinfo.go:35 Mon May 3 11:18:26 2021 daemon.err smartctl_exporter[3795]: main.SMARTctlManagerCollector.Collect(0x2090980) Mon May 3 11:18:26 2021 daemon.err smartctl_exporter[3795]: /home/mark/Code/smartctl_exporter/main.go:37 +0x180 Mon May 3 11:18:26 2021 daemon.err smartctl_exporter[3795]: github.com/prometheus/client_golang/prometheus.(*wrappingCollector).Collect.func1(0x200a140, 0x2090980) Mon May 3 11:18:26 2021 daemon.err smartctl_exporter[3795]: /home/mark/go/pkg/mod/github.com/prometheus/client_golang@v1.7.1/prometheus/wrap.go:127 +0x30 Mon May 3 11:18:26 2021 daemon.err smartctl_exporter[3795]: created by github.com/prometheus/client_golang/prometheus.(*wrappingCollector).Collect Mon May 3 11:18:26 2021 daemon.err smartctl_exporter[3795]: /home/mark/go/pkg/mod/github.com/prometheus/client_golang@v1.7.1/prometheus/wrap.go:126 +0x4c Mon May 3 11:18:26 2021 daemon.info procd: Instance smartctl_exporter::instance1 s in a crash loop 6 crashes, 5 seconds since last crash

Did you manage to resolve your issue?

@radicalgeek
Copy link

When I start the program, then go to browser http://myip:9633/metrics
The program raise an error.

Here is the log:

➜  bin git:(master) ✗ sudo ./smartctl_exporter --config=./config.yaml
[Warning] S.M.A.R.T. output reading error: exit status 1
[Warning] The device self-test log contains records of errors. [ATA only] Failed self-tests outdated by a newer successful extended self-test are ignored.
[Error] /dev/sda: Unknown USB bridge [0x0951:0x1666 (0x1075)]
[Error] smartctl returned bad data for device /dev/sda
[Warning] S.M.A.R.T. output reading error: exit status 4
[Warning] SMART status check returned 'DISK OK' but we found that some (usage or prefail) Attributes have been <= threshold at some time in the past.
[Info] Starting on 0.0.0.0:9633/metrics
[Warning] S.M.A.R.T. output reading error: exit status 1
[Warning] The device self-test log contains records of errors. [ATA only] Failed self-tests outdated by a newer successful extended self-test are ignored.
[Error] /dev/sda: Unknown USB bridge [0x0951:0x1666 (0x1075)]
[Error] smartctl returned bad data for device /dev/sda
[Error] Too early collect called for device /dev/sdb
panic: runtime error: index out of range

goroutine 38 [running]:
main.(*SMARTctlInfo).mineVersion(0xc3af64)
	/home/pi/smartctl_exporter/smartctlinfo.go:46 +0x4c0
main.(*SMARTctlInfo).Collect(0xc3af64)

Here are my dir structure

➜  bin git:(master) ✗ tree ./
./
├── config.yaml
└── smartctl_exporter

0 directories, 2 files

Here are the content of config.yaml

smartctl_exporter:
  bind_to: "0.0.0.0:9633"
  url_path: "/metrics"
  fake_json: no
  smartctl_location: /usr/local/sbin/smartctl
  collect_not_more_than_period: 120s
  devices:
  - /dev/sda
  - /dev/sdb
  #- /dev/sdc
  #- /dev/sdd
  #- /dev/sde
  #- /dev/sdf

The smartctl version is:

➜  bin git:(master) ✗ smartctl --version
smartctl 7.2 2020-12-30 r5155 [armv7l-linux-5.10.17-v7l+] (local build)
Copyright (C) 2002-20, Bruce Allen, Christian Franke, www.smartmontools.org

smartctl comes with ABSOLUTELY NO WARRANTY. This is free
software, and you are welcome to redistribute it under
the terms of the GNU General Public License; either
version 2, or (at your option) any later version.
See http://www.gnu.org for further details.

smartmontools release 7.2 dated 2020-12-30 at 16:48:30 UTC
smartmontools SVN rev 5155 dated 2020-12-30 at 16:49:18
smartmontools build host: armv7l-unknown-linux-gnueabihf
smartmontools build with: C++14, GCC 8.3.0
smartmontools configure arguments: [no arguments given]

I did not put this down. This open PR fixed it for me:

#18

@baryluk
Copy link

baryluk commented Oct 8, 2021

Same issue on current git master:

root# ./smartctl_exporter --config=./smartctl_exporter.yaml
[Info] Starting on 0.0.0.0:9633/metrics
[Error] Too early collect called for device /dev/sda
[Error] Too early collect called for device /dev/sdb
[Error] Too early collect called for device /dev/sdc
[Error] Too early collect called for device /dev/sdd
[Error] Too early collect called for device /dev/sde
[Error] Too early collect called for device /dev/sdf
[Error] Too early collect called for device /dev/sdg
[Error] Too early collect called for device /dev/sdh
[Error] Too early collect called for device /dev/sdi
[Error] Too early collect called for device /dev/sdj
[Error] Too early collect called for device /dev/sdk
[Error] Too early collect called for device /dev/sdl
panic: runtime error: index out of range [0] with length 0

goroutine 63 [running]:
main.(*SMARTctlInfo).mineVersion(0xc0003c3ec0)
	/home/baryluk/prometheus/smartctl_exporter/smartctlinfo.go:46 +0xbf6
main.(*SMARTctlInfo).Collect(...)
	/home/baryluk/prometheus/smartctl_exporter/smartctlinfo.go:35
main.SMARTctlManagerCollector.Collect(0xc0003ba000)
	/home/baryluk/prometheus/smartctl_exporter/main.go:37 +0x23a
github.com/prometheus/client_golang/prometheus.(*wrappingCollector).Collect.func1(0xc00021a690, 0xc0003ba000)
	/home/baryluk/go/pkg/mod/github.com/prometheus/client_golang@v1.7.1/prometheus/wrap.go:127 +0x3d
created by github.com/prometheus/client_golang/prometheus.(*wrappingCollector).Collect
	/home/baryluk/go/pkg/mod/github.com/prometheus/client_golang@v1.7.1/prometheus/wrap.go:126 +0x6b
root# ls -l /dev/sd
sda   sda1  sdb   sdb1  sdc   sdc1  sdd   sdd1  sde   sde1  sdf   sdf1  sdg   sdg1  sdh   sdh1  sdh2  sdi   sdi1  sdj   sdj1  sdk   sdk1  sdl   sdl1  sdm   sdm1  sdn   sdn1  

@vagifzeynalov
Copy link

There is a bug.

  1. When https://github.com/Sheridan/smartctl_exporter/blob/e27581d56ad80340fb076d3ce22cef337ed76679/readjson.go#L94 returning an empty Json object {}
  2. In https://github.com/Sheridan/smartctl_exporter/blob/e27581d56ad80340fb076d3ce22cef337ed76679/smartctlinfo.go#L46 it is failing because there is no validation for empty jsonVersion and smartctlVersion variables.

@Sheridan Максим, почини пожалуйста, людям очень надо! ;)
To fix it either, the validation must be added, or instead of an empty Json must be returned something like {"json_format_version":[0,0],"smartctl": {"version": [0,0]}

OR simply update YAML config with

  collect_not_more_than_period: 0s

and this problem will be resolved, because readjson.go will always return correct Json object.

@Sheridan would you please fix it? Thanks!

vagifzeynalov pushed a commit to vagifzeynalov/smartctl_exporter that referenced this issue Oct 9, 2021
vagifzeynalov pushed a commit to vagifzeynalov/smartctl_exporter that referenced this issue Oct 9, 2021
vagifzeynalov pushed a commit to vagifzeynalov/smartctl_exporter that referenced this issue Oct 9, 2021
vagifzeynalov added a commit to vagifzeynalov/smartctl_exporter that referenced this issue Oct 9, 2021
vagifzeynalov added a commit to vagifzeynalov/smartctl_exporter that referenced this issue Oct 9, 2021
azrdev pushed a commit to azrdev/smartctl_exporter that referenced this issue Feb 18, 2022
azrdev pushed a commit to azrdev/smartctl_exporter that referenced this issue Feb 18, 2022
@SuperQ
Copy link
Contributor

SuperQ commented Aug 8, 2022

I think this may be fixed with the latest release.

@lahwaacz
Copy link
Contributor

lahwaacz commented Nov 6, 2022

The panic: runtime error: index out of range crash in mineVersion was fixed in #93. The Too early collect called for device error was fixed by the caching thing in #18.

@SuperQ SuperQ closed this as completed Nov 6, 2022
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

No branches or pull requests

6 participants