mirror of
https://github.com/prometheus-community/smartctl_exporter.git
synced 2024-12-21 02:21:55 +01:00
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:
parent
c8d3e48f3d
commit
e88442081c
1 changed files with 10 additions and 5 deletions
15
readjson.go
15
readjson.go
|
@ -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.Warn(logger).Log("msg", "S.M.A.R.T. output reading error", "err", err)
|
||||
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))
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue