mirror of
https://github.com/prometheus-community/smartctl_exporter.git
synced 2024-11-23 01:43:07 +01:00
Merge pull request #93 from lahwaacz/master
Fix runtime error: index out of range in mineVersion
This commit is contained in:
commit
61e28093f6
3 changed files with 10 additions and 9 deletions
5
main.go
5
main.go
|
@ -49,12 +49,11 @@ func (i SMARTctlManagerCollector) Describe(ch chan<- *prometheus.Desc) {
|
|||
func (i SMARTctlManagerCollector) Collect(ch chan<- prometheus.Metric) {
|
||||
info := NewSMARTctlInfo(ch)
|
||||
for _, device := range i.Devices {
|
||||
if json, err := readData(i.logger, device); err == nil {
|
||||
json := readData(i.logger, device)
|
||||
if json.Exists() {
|
||||
info.SetJSON(json)
|
||||
smart := NewSMARTctl(i.logger, json, ch)
|
||||
smart.Collect()
|
||||
} else {
|
||||
level.Error(i.logger).Log("msg", "Error collecting SMART data", "err", err.Error())
|
||||
}
|
||||
}
|
||||
info.Collect()
|
||||
|
|
10
readjson.go
10
readjson.go
|
@ -89,9 +89,9 @@ func readSMARTctlDevices(logger log.Logger) gjson.Result {
|
|||
}
|
||||
|
||||
// Select json source and parse
|
||||
func readData(logger log.Logger, device string) (gjson.Result, error) {
|
||||
func readData(logger log.Logger, device string) gjson.Result {
|
||||
if *smartctlFakeData {
|
||||
return readFakeSMARTctl(logger, device), nil
|
||||
return readFakeSMARTctl(logger, device)
|
||||
}
|
||||
|
||||
cacheValue, cacheOk := jsonCache.Load(device)
|
||||
|
@ -103,11 +103,11 @@ func readData(logger log.Logger, device string) (gjson.Result, error) {
|
|||
if !found {
|
||||
level.Warn(logger).Log("msg", "device not found", "device", device)
|
||||
}
|
||||
return j.(JSONCache).JSON, nil
|
||||
return j.(JSONCache).JSON
|
||||
}
|
||||
return gjson.Parse("{}"), fmt.Errorf("smartctl returned bad data for device %s", device)
|
||||
return gjson.Result{}
|
||||
}
|
||||
return cacheValue.(JSONCache).JSON, nil
|
||||
return cacheValue.(JSONCache).JSON
|
||||
}
|
||||
|
||||
// Parse smartctl return code
|
||||
|
|
|
@ -45,7 +45,9 @@ func (smart *SMARTctlInfo) SetJSON(json gjson.Result) {
|
|||
|
||||
// Collect metrics
|
||||
func (smart *SMARTctlInfo) Collect() {
|
||||
smart.mineVersion()
|
||||
if smart.Ready {
|
||||
smart.mineVersion()
|
||||
}
|
||||
}
|
||||
|
||||
func (smart *SMARTctlInfo) mineVersion() {
|
||||
|
|
Loading…
Reference in a new issue