2022-05-13 20:48:12 +08:00
|
|
|
//go:build linux || darwin
|
2020-06-09 22:03:58 +08:00
|
|
|
// +build linux darwin
|
|
|
|
|
|
|
|
package devices
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/shirou/gopsutil/host"
|
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
devs() // Populate the sensorMap
|
|
|
|
RegisterTemp(getTemps)
|
|
|
|
RegisterDeviceList(Temperatures, devs, defs)
|
|
|
|
}
|
|
|
|
|
|
|
|
func getTemps(temps map[string]int) map[string]error {
|
|
|
|
sensors, err := host.SensorsTemperatures()
|
|
|
|
if err != nil {
|
2022-05-13 20:48:12 +08:00
|
|
|
if _, ok := err.(*host.Warnings); ok {
|
|
|
|
// ignore warnings
|
|
|
|
} else {
|
|
|
|
return map[string]error{"gopsutil host": err}
|
|
|
|
}
|
2020-06-09 22:03:58 +08:00
|
|
|
}
|
|
|
|
for _, sensor := range sensors {
|
|
|
|
label := sensorMap[sensor.SensorKey]
|
|
|
|
if _, ok := temps[label]; ok {
|
|
|
|
temps[label] = int(sensor.Temperature)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Optimization to avoid string manipulation every update
|
|
|
|
var sensorMap map[string]string
|