summaryrefslogtreecommitdiffstats
path: root/devices/temp_freebsd.go
diff options
context:
space:
mode:
authorSean E. Russell <ser@ser1.net>2020-02-27 18:51:28 -0600
committerSean E. Russell <ser@ser1.net>2020-02-28 07:06:51 -0600
commit7a89225d729d4c54c5bc95b21979f48f9cd046b1 (patch)
tree10bf143324cf553765d7002d0eb82abc21c72bb1 /devices/temp_freebsd.go
parent4fce1654c5c263797205997e7635c7d06c393a85 (diff)
Abstracts CPU & mem devices.
Finishes device refactoring: temps Refactoring to allow updating maps. Simpler, and optimizable.
Diffstat (limited to 'devices/temp_freebsd.go')
-rw-r--r--devices/temp_freebsd.go45
1 files changed, 45 insertions, 0 deletions
diff --git a/devices/temp_freebsd.go b/devices/temp_freebsd.go
new file mode 100644
index 0000000..ba47474
--- /dev/null
+++ b/devices/temp_freebsd.go
@@ -0,0 +1,45 @@
+// +build freebsd
+
+package devices
+
+import (
+ "os/exec"
+ "strconv"
+ "strings"
+
+ "github.com/xxxserxxx/gotop/utils"
+)
+
+func init() {
+ RegisterTemp(update)
+}
+
+var sensorOIDS = map[string]string{
+ "dev.cpu.0.temperature": "CPU 0 ",
+ "hw.acpi.thermal.tz0.temperature": "Thermal zone 0",
+}
+
+func update(temps map[string]int) map[string]error {
+ var errors map[string]error
+
+ for k, v := range sensorOIDS {
+ output, err := exec.Command("sysctl", "-n", k).Output()
+ if err != nil {
+ errors[v] = err
+ continue
+ }
+
+ s1 := strings.Replace(string(output), "C", "", 1)
+ s2 := strings.TrimSuffix(s1, "\n")
+ convertedOutput := utils.ConvertLocalizedString(s2)
+ value, err := strconv.ParseFloat(convertedOutput, 64)
+ if err != nil {
+ errors[v] = err
+ continue
+ }
+
+ temps[v] = int(value)
+ }
+
+ return errors
+}