1// +build darwin 2// +build cgo 3 4package host 5 6// #cgo LDFLAGS: -framework IOKit 7// #include <stdio.h> 8// #include <string.h> 9// #include "include/smc.c" 10import "C" 11import "context" 12 13func SensorsTemperatures() ([]TemperatureStat, error) { 14 return SensorsTemperaturesWithContext(context.Background()) 15} 16 17func SensorsTemperaturesWithContext(ctx context.Context) ([]TemperatureStat, error) { 18 temperatureKeys := []string{ 19 C.AMBIENT_AIR_0, 20 C.AMBIENT_AIR_1, 21 C.CPU_0_DIODE, 22 C.CPU_0_HEATSINK, 23 C.CPU_0_PROXIMITY, 24 C.ENCLOSURE_BASE_0, 25 C.ENCLOSURE_BASE_1, 26 C.ENCLOSURE_BASE_2, 27 C.ENCLOSURE_BASE_3, 28 C.GPU_0_DIODE, 29 C.GPU_0_HEATSINK, 30 C.GPU_0_PROXIMITY, 31 C.HARD_DRIVE_BAY, 32 C.MEMORY_SLOT_0, 33 C.MEMORY_SLOTS_PROXIMITY, 34 C.NORTHBRIDGE, 35 C.NORTHBRIDGE_DIODE, 36 C.NORTHBRIDGE_PROXIMITY, 37 C.THUNDERBOLT_0, 38 C.THUNDERBOLT_1, 39 C.WIRELESS_MODULE, 40 } 41 var temperatures []TemperatureStat 42 43 C.open_smc() 44 defer C.close_smc() 45 46 for _, key := range temperatureKeys { 47 temperatures = append(temperatures, TemperatureStat{ 48 SensorKey: key, 49 Temperature: float64(C.get_temperature(C.CString(key))), 50 }) 51 } 52 return temperatures, nil 53} 54