mirror of
https://github.com/shirou/gopsutil.git
synced 2025-05-02 22:17:08 +08:00
commit
d8686bcd5c
@ -635,6 +635,7 @@ func SensorsTemperaturesWithContext(ctx context.Context) ([]TemperatureStat, err
|
|||||||
return temperatures, err
|
return temperatures, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
var warns Warnings
|
||||||
|
|
||||||
// example directory
|
// example directory
|
||||||
// device/ temp1_crit_alarm temp2_crit_alarm temp3_crit_alarm temp4_crit_alarm temp5_crit_alarm temp6_crit_alarm temp7_crit_alarm
|
// device/ temp1_crit_alarm temp2_crit_alarm temp3_crit_alarm temp4_crit_alarm temp5_crit_alarm temp6_crit_alarm temp7_crit_alarm
|
||||||
@ -660,16 +661,19 @@ func SensorsTemperaturesWithContext(ctx context.Context) ([]TemperatureStat, err
|
|||||||
// Get the name of the temperature you are reading
|
// Get the name of the temperature you are reading
|
||||||
name, err := ioutil.ReadFile(filepath.Join(filepath.Dir(file), "name"))
|
name, err := ioutil.ReadFile(filepath.Join(filepath.Dir(file), "name"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return temperatures, err
|
warns.Add(err)
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the temperature reading
|
// Get the temperature reading
|
||||||
current, err := ioutil.ReadFile(file)
|
current, err := ioutil.ReadFile(file)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return temperatures, err
|
warns.Add(err)
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
temperature, err := strconv.ParseFloat(strings.TrimSpace(string(current)), 64)
|
temperature, err := strconv.ParseFloat(strings.TrimSpace(string(current)), 64)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
warns.Add(err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -679,5 +683,5 @@ func SensorsTemperaturesWithContext(ctx context.Context) ([]TemperatureStat, err
|
|||||||
Temperature: temperature / 1000.0,
|
Temperature: temperature / 1000.0,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
return temperatures, nil
|
return temperatures, warns.Reference()
|
||||||
}
|
}
|
||||||
|
25
host/types.go
Normal file
25
host/types.go
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
package host
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Warnings struct {
|
||||||
|
List []error
|
||||||
|
}
|
||||||
|
|
||||||
|
func (w *Warnings) Add(err error) {
|
||||||
|
w.List = append(w.List, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (w *Warnings) Reference() error {
|
||||||
|
if len(w.List) > 0 {
|
||||||
|
return w
|
||||||
|
} else {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (w *Warnings) Error() string {
|
||||||
|
return fmt.Sprintf("Number of warnings: %v", len(w.List))
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user