Skip to content

Commit

Permalink
Update json reading logging (prometheus-community#198)
Browse files Browse the repository at this point in the history
Update the smartctl command reading and parsing of json logging to make
for easier debugging of slow devices by adding a duration to the debug
logging.

For prometheus-community#197

Signed-off-by: SuperQ <[email protected]>
Signed-off-by: mort <[email protected]>
  • Loading branch information
SuperQ authored and zxzharmlesszxz committed Mar 5, 2024
1 parent 9fbb4c6 commit 6b5f02b
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion readjson.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,15 @@ 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)
start := time.Now()
out, err := exec.Command(*smartctlPath, "--json", "--info", "--health", "--attributes", "--tolerance=verypermissive", "--nocheck=standby", "--format=brief", "--log=error", device).Output()
if err != nil {
level.Warn(logger).Log("msg", "S.M.A.R.T. output reading", "err", err, "device", device)
}
json := parseJSON(string(out))
rcOk := resultCodeIsOk(logger, device, json.Get("smartctl.exit_status").Int())
jsonOk := jsonIsOk(logger, json)
level.Debug(logger).Log("msg", "Collected S.M.A.R.T. json data", "device", device, "duration", time.Since(start))
return json, rcOk && jsonOk
}

Expand Down

0 comments on commit 6b5f02b

Please sign in to comment.