xmtop/devices/temp_linux.go

30 lines
678 B
Go
Raw Normal View History

// +build linux
package devices
2018-05-16 04:48:26 +08:00
import (
"strings"
psHost "github.com/shirou/gopsutil/host"
)
func init() {
RegisterTemp(getTemps)
}
func getTemps(temps map[string]int) map[string]error {
sensors, err := psHost.SensorsTemperatures()
if err != nil {
return map[string]error{"psHost": err}
}
2018-05-16 04:48:26 +08:00
for _, sensor := range sensors {
// only sensors with input in their name are giving us live temp info
2018-11-30 09:37:41 +08:00
if strings.Contains(sensor.SensorKey, "input") && sensor.Temperature != 0 {
2018-05-16 04:48:26 +08:00
// removes '_input' from the end of the sensor name
label := sensor.SensorKey[:strings.Index(sensor.SensorKey, "_input")]
temps[label] = int(sensor.Temperature)
2018-05-16 04:48:26 +08:00
}
}
return nil
2018-05-16 04:48:26 +08:00
}