blob: 488e16f5af312fee06c06f7ac08827bb21491705 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
//go:build linux || darwin
// +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 {
if _, ok := err.(*host.Warnings); ok {
// ignore warnings
} else {
return map[string]error{"gopsutil host": err}
}
}
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
|