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

Add device type support #107

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ var (
smartctlInterval = kingpin.Flag("smartctl.interval",
"The interval between smarctl polls",
).Default("60s").Duration()
smartctlDeviceType = kingpin.Flag("smartctl.device-type",
"The device type (-d / --device)",
).Default("auto").String()
smartctlDevices = kingpin.Flag("smartctl.device",
"The device to monitor (repeatable)",
).Strings()
Expand Down
9 changes: 5 additions & 4 deletions readjson.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,10 @@ 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", "--info", "--health", "--attributes", "--tolerance=verypermissive", "--nocheck=standby", "--format=brief", device).Output()
func readSMARTctl(logger log.Logger, deviceType string, device string) (gjson.Result, bool) {
level.Debug(logger).Log("msg", "Collecting S.M.A.R.T. counters", "device_type", deviceType, "device", device)
deviceTypeFlag := fmt.Sprintf("--device=%s", deviceType)
out, err := exec.Command(*smartctlPath, "--json", "--info", "--health", "--attributes", "--tolerance=verypermissive", "--nocheck=standby", "--format=brief", deviceTypeFlag, device).Output()
if err != nil {
level.Warn(logger).Log("msg", "S.M.A.R.T. output reading", "err", err)
}
Expand Down Expand Up @@ -96,7 +97,7 @@ func readData(logger log.Logger, device string) gjson.Result {

cacheValue, cacheOk := jsonCache.Load(device)
if !cacheOk || time.Now().After(cacheValue.(JSONCache).LastCollect.Add(*smartctlInterval)) {
json, ok := readSMARTctl(logger, device)
json, ok := readSMARTctl(logger, *smartctlDeviceType, device)
if ok {
jsonCache.Store(device, JSONCache{JSON: json, LastCollect: time.Now()})
j, found := jsonCache.Load(device)
Expand Down