Adjust smartctl command args (#74)

Update smartctl command arguments to reduce device wakeup from
standby/idle.
* Ignore exit code of 2 for sleeping devices.

Fixes: https://github.com/prometheus-community/smartctl_exporter/issues/61

Signed-off-by: SuperQ <superq@gmail.com>

Signed-off-by: SuperQ <superq@gmail.com>
This commit is contained in:
Ben Kochie 2022-10-03 14:49:32 +02:00 committed by GitHub
parent c8d3e48f3d
commit e88442081c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 10 additions and 5 deletions

View File

@ -64,7 +64,7 @@ func readFakeSMARTctl(logger log.Logger, device string) gjson.Result {
// Get json from smartctl and parse it
func readSMARTctl(logger log.Logger, device string) (gjson.Result, bool) {
level.Debug(logger).Log("msg", "Collecting S.M.A.R.T. counters", "device", device)
out, err := exec.Command(*smartctlPath, "--json", "--xall", device).Output()
out, err := exec.Command(*smartctlPath, "--json", "--info", "--health", "--attributes", "--tolerance=verypermissive", "--nocheck=standby", "--format=brief", device).Output()
if err != nil {
level.Warn(logger).Log("msg", "S.M.A.R.T. output reading", "err", err)
}
@ -75,10 +75,15 @@ func readSMARTctl(logger log.Logger, device string) (gjson.Result, bool) {
}
func readSMARTctlDevices(logger log.Logger) gjson.Result {
level.Debug(logger).Log("msg", "Collecting devices")
out, err := exec.Command(*smartctlPath, "--json", "--scan-open").Output()
if err != nil {
level.Debug(logger).Log("msg", "Scanning for devices")
out, err := exec.Command(*smartctlPath, "--json", "--scan").Output()
if exiterr, ok := err.(*exec.ExitError); ok {
level.Debug(logger).Log("msg", "Exit Status", "exit_code", exiterr.ExitCode())
// The smartctl command returns 2 if devices are sleeping, ignore this error.
if exiterr.ExitCode() != 2 {
level.Warn(logger).Log("msg", "S.M.A.R.T. output reading error", "err", err)
return gjson.Result{}
}
}
return parseJSON(string(out))
}