mirror of
https://github.com/prometheus/node_exporter
synced 2025-01-10 07:29:34 +00:00
Reduce nesting in sanity check
This commit is contained in:
parent
8913d71ca4
commit
e6ffeb4907
@ -86,15 +86,14 @@ func getLoad() (loads []float64, err error) {
|
||||
func parseLoad(data string) (loads []float64, err error) {
|
||||
loads = make([]float64, 3)
|
||||
parts := strings.Fields(data)
|
||||
if len(parts) >= 3 {
|
||||
for i, load := range parts[0:3] {
|
||||
loads[i], err = strconv.ParseFloat(load, 64)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("could not parse load '%s': %s", load, err)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if len(parts) < 3 {
|
||||
return nil, fmt.Errorf("unexpected content in %s", procFilePath("loadavg"))
|
||||
}
|
||||
for i, load := range parts[0:3] {
|
||||
loads[i], err = strconv.ParseFloat(load, 64)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("could not parse load '%s': %s", load, err)
|
||||
}
|
||||
}
|
||||
return loads, nil
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user