Closed ChaoHsupin closed 1 year ago
I have exactly same error. This is command that I run:
smartctl_exporter.exe --config=smartctl_exporter.yaml
Contents of smartctl_exporter.yaml:
smartctl_exporter:
bind_to: "[::1]:9633"
url_path: "/metrics"
fake_json: no
smartctl_location: "smartctl.exe"
collect_not_more_than_period: 120s
devices:
- /dev/sda
- /dev/sdb
Looks like that smartctl.exe is called properly, the executable is in PATH environment variable, but something is wrong when trying to query disks. I tried with single disk with same error.
I have exactly same error. This is command that I run:
smartctl_exporter.exe --config=smartctl_exporter.yaml
Contents of smartctl_exporter.yaml:
smartctl_exporter: bind_to: "[::1]:9633" url_path: "/metrics" fake_json: no smartctl_location: "smartctl.exe" collect_not_more_than_period: 120s devices: - /dev/sda - /dev/sdb
Looks like that smartctl.exe is called properly, the executable is in PATH environment variable, but something is wrong when trying to query disks. I tried with single disk with same error.
@andonovski I read the source code. There is a piece of code that can only be executed in the Linux environment. Because everything is file under Linux, there is a segment code to try hardware as a file to obtain information, and this code is not supported under Windows. So I changed the code and compiled a little, and passed it.
This is the code that needs to be modified:readjson.go
func readData(device string) (gjson.Result, error) {
if options.SMARTctl.FakeJSON {
return readFakeSMARTctl(device), nil
}
// "os.Stat(device)" only be executed in the Linux environment.
if _, err := os.Stat(device); err == nil {
cacheValue, cacheOk := jsonCache[device]
if !cacheOk || time.Now().After(cacheValue.LastCollect.Add(options.SMARTctl.CollectPeriodDuration)) {
json, ok := readSMARTctl(device)
if ok {
jsonCache[device] = JSONCache{JSON: json, LastCollect: time.Now()}
return jsonCache[device].JSON, nil
}
return gjson.Parse("{}"), fmt.Errorf("smartctl returned bad data for device %s", device)
}
return cacheValue.JSON, nil
}
return gjson.Parse("{}"), fmt.Errorf("Device %s unavialable", device)
}
@ChaoHsupin, great find. I am just a bit confused, the code you posted here is changed code, and it will work on Windows? I am not developer, just ordinary sysadmin, not even sure how would I compile this under Windows. Hopefully this will be merged by devs in the master.
@ChaoHsupin, great find. I am just a bit confused, the code you posted here is changed code, and it will work on Windows? I am not developer, just ordinary sysadmin, not even sure how would I compile this under Windows. Hopefully this will be merged by devs in the master. @andonovski
65
Hi @ChaoHsupin. It's been a minute since the PR was merged. Is this still an issue?
Thanks for your work!
Because I encountered some mistakes, I would like to know the exporter support Windows deployment?thanks!
This is log about run in Windows server 2016:
This is run command
smartctl -a /dev/sda