File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1- //go:build !windows
1+ //go:build !windows && !freebsd
22
33package agent
44
Original file line number Diff line number Diff line change 1+ //go:build freebsd
2+
3+ package agent
4+
5+ import (
6+ "context"
7+ "fmt"
8+
9+ "github.com/shirou/gopsutil/v4/sensors"
10+ "golang.org/x/sys/unix"
11+ )
12+
13+ var getSensorTemps getTempsFn = freebsdGetTemps
14+
15+ // freebsdGetTemps reads hardware temperatures from FreeBSD sysctls.
16+ // CPU temps come from dev.cpu.N.temperature (coretemp/amdtemp drivers).
17+ // System temps come from hw.acpi.thermal.tzN.temperature (ACPI thermal zones).
18+ // Values are in deciKelvin; conversion: °C = val/10 - 273.15.
19+ func freebsdGetTemps (_ context.Context ) ([]sensors.TemperatureStat , error ) {
20+ var temps []sensors.TemperatureStat
21+
22+ for i := range 64 {
23+ val , err := unix .SysctlUint32 (fmt .Sprintf ("dev.cpu.%d.temperature" , i ))
24+ if err != nil {
25+ break
26+ }
27+ temps = append (temps , sensors.TemperatureStat {
28+ SensorKey : fmt .Sprintf ("cpu%d" , i ),
29+ Temperature : float64 (val )/ 10.0 - 273.15 ,
30+ })
31+ }
32+
33+ for i := range 16 {
34+ val , err := unix .SysctlUint32 (fmt .Sprintf ("hw.acpi.thermal.tz%d.temperature" , i ))
35+ if err != nil {
36+ break
37+ }
38+ temps = append (temps , sensors.TemperatureStat {
39+ SensorKey : fmt .Sprintf ("tz%d" , i ),
40+ Temperature : float64 (val )/ 10.0 - 273.15 ,
41+ })
42+ }
43+
44+ return temps , nil
45+ }
You can’t perform that action at this time.
0 commit comments