diff --git a/devices/temp_freebsd.go b/devices/temp_freebsd.go index 196a6d7..d246c0e 100644 --- a/devices/temp_freebsd.go +++ b/devices/temp_freebsd.go @@ -3,6 +3,7 @@ package devices import ( + "log" "os/exec" "strconv" "strings" @@ -11,6 +12,10 @@ import ( ) func init() { + if len(devs()) == 0 { + log.Println("temp: no thermal sensors found") + return + } RegisterTemp(update) RegisterDeviceList(Temperatures, devs, devs) } @@ -50,8 +55,19 @@ func update(temps map[string]int) map[string]error { func devs() []string { rv := make([]string, 0, len(sensorOIDS)) + // Check that thermal sensors are really available; they aren't in VMs + bs, err := exec.Command("sysctl", "-a").Output() + if err != nil { + log.Printf("temp: failure to get system information %s", err.Error()) + return []string{} + } for k, _ := range sensorOIDS { - rv = append(rv, k) + idx := strings.Index(string(bs), k) + if idx < 0 { + log.Println("temp: no device %s found", k) + } else { + rv = append(rv, k) + } } return rv }