summaryrefslogtreecommitdiffstats
path: root/devices
diff options
context:
space:
mode:
authorrare-magma <nun0@posteo.co>2022-06-06 21:18:59 +0200
committerrare-magma <nun0@posteo.co>2022-06-06 21:18:59 +0200
commitb89c1dd748b8ee0913f99cdb16079e0515ae7aba (patch)
tree7747998fed66ed737c5255535dd3c23a1346450c /devices
parentb0fd8ac8cd8ba8f6351fd1ef798ebb9db80fc42a (diff)
add disk temperatures via smart.go / ghw
Diffstat (limited to 'devices')
-rw-r--r--devices/temp_nix.go37
1 files changed, 37 insertions, 0 deletions
diff --git a/devices/temp_nix.go b/devices/temp_nix.go
index 488e16f..db2af8b 100644
--- a/devices/temp_nix.go
+++ b/devices/temp_nix.go
@@ -4,6 +4,11 @@
package devices
import (
+ "log"
+ "regexp"
+
+ smart "github.com/anatol/smart.go"
+ "github.com/jaypipes/ghw"
"github.com/shirou/gopsutil/host"
)
@@ -28,6 +33,38 @@ func getTemps(temps map[string]int) map[string]error {
temps[label] = int(sensor.Temperature)
}
}
+
+ block, err := ghw.Block()
+ if err != nil {
+ log.Print("error getting block device info")
+ return nil
+ }
+
+ var sata = regexp.MustCompile(`sd.?`)
+ var nvme = regexp.MustCompile(`nvme*`)
+ for _, disk := range block.Disks {
+ switch t := disk.Name; {
+ case sata.MatchString(t):
+ dev, err := smart.OpenSata("/dev/" + disk.Name)
+ if err != nil {
+ break
+ }
+ sm, _ := dev.ReadSMARTData()
+ for _, attr := range sm.Attrs {
+ if attr.Id == 194 {
+ temps[disk.Name+"_"+disk.Model] = int(attr.Value)
+ }
+ }
+ case nvme.MatchString(t):
+ dev, err := smart.OpenNVMe("/dev/" + disk.Name)
+ if err != nil {
+ break
+ }
+ sm, _ := dev.ReadSMART()
+ temps[disk.Name+"_"+disk.Model] = int(sm.Temperature)
+ default:
+ }
+ }
return nil
}