Merge pull request #475 from Oxileo/issue442

Fix #442, trim sensor names and properly handle CentOS in host.SensorsTemperatures()
This commit is contained in:
Lomanic 2017-12-20 20:14:05 +01:00 committed by GitHub
commit 7ec06ec280
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 3 additions and 3 deletions

View File

@ -541,7 +541,7 @@ func SensorsTemperatures() ([]TemperatureStat, error) {
if len(files) == 0 { if len(files) == 0 {
// CentOS has an intermediate /device directory: // CentOS has an intermediate /device directory:
// https://github.com/giampaolo/psutil/issues/971 // https://github.com/giampaolo/psutil/issues/971
files, err = filepath.Glob(common.HostSys("/class/hwmon/hwmon*/temp*_*")) files, err = filepath.Glob(common.HostSys("/class/hwmon/hwmon*/device/temp*_*"))
if err != nil { if err != nil {
return temperatures, err return temperatures, err
} }
@ -557,12 +557,12 @@ func SensorsTemperatures() ([]TemperatureStat, error) {
if err != nil { if err != nil {
return temperatures, err return temperatures, err
} }
temperature, err := strconv.ParseFloat(string(current), 64) temperature, err := strconv.ParseFloat(strings.TrimSpace(string(current)), 64)
if err != nil { if err != nil {
continue continue
} }
temperatures = append(temperatures, TemperatureStat{ temperatures = append(temperatures, TemperatureStat{
SensorKey: string(name), SensorKey: strings.TrimSpace(string(name)),
Temperature: temperature / 1000.0, Temperature: temperature / 1000.0,
}) })
} }