mirror of
https://github.com/prometheus-community/smartctl_exporter.git
synced 2024-11-23 01:43:07 +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
|
// Get json from smartctl and parse it
|
||||||
func readSMARTctl(logger log.Logger, device string) (gjson.Result, bool) {
|
func readSMARTctl(logger log.Logger, device string) (gjson.Result, bool) {
|
||||||
level.Debug(logger).Log("msg", "Collecting S.M.A.R.T. counters", "device", device)
|
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 {
|
if err != nil {
|
||||||
level.Warn(logger).Log("msg", "S.M.A.R.T. output reading", "err", err)
|
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 {
|
func readSMARTctlDevices(logger log.Logger) gjson.Result {
|
||||||
level.Debug(logger).Log("msg", "Collecting devices")
|
level.Debug(logger).Log("msg", "Scanning for devices")
|
||||||
out, err := exec.Command(*smartctlPath, "--json", "--scan-open").Output()
|
out, err := exec.Command(*smartctlPath, "--json", "--scan").Output()
|
||||||
if err != nil {
|
if exiterr, ok := err.(*exec.ExitError); ok {
|
||||||
level.Warn(logger).Log("msg", "S.M.A.R.T. output reading error", "err", err)
|
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))
|
return parseJSON(string(out))
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue