fix issue with intel cpu temperature label order

This commit is contained in:
alu
2026-08-10 10:43:13 -07:00
parent 413b79116e
commit a474ff2511
3 changed files with 22 additions and 7 deletions
+20 -5
View File
@@ -5,6 +5,7 @@ import (
"fmt" "fmt"
"os" "os"
"path/filepath" "path/filepath"
"sort"
"strconv" "strconv"
"strings" "strings"
) )
@@ -48,13 +49,10 @@ func (r *HwmonDriver) Render(term common.Terminal) error {
} }
temps := t.([]TemperatureSensor) temps := t.([]TemperatureSensor)
term.Subheader("Temperature") term.Subheader(fmt.Sprintf("Temperature %s", r.hwmonDir))
for _, sensor := range temps { for _, sensor := range temps {
tempC := sensor.TempC term.Print(fmt.Sprintf("%-16s | %.2f °C", sensor.Name, sensor.TempC))
tempF := (tempC * 9 / 5) + 32
// \033[K clears from cursor to end of line (prevents lingering chars)
term.Print(fmt.Sprintf("%-16s | %.2f °C (%.3f °F)", sensor.Name, tempC, tempF))
} }
return nil return nil
@@ -66,6 +64,11 @@ func (r *HwmonDriver) Read() (any, error) {
return nil, fmt.Errorf("no temperature inputs found in %s", r.hwmonDir) return nil, fmt.Errorf("no temperature inputs found in %s", r.hwmonDir)
} }
// Sort input paths by numerical index (temp1_input, temp2_input, ... temp10_input)
sort.Slice(inputs, func(i, j int) bool {
return extractSensorIndex(inputs[i]) < extractSensorIndex(inputs[j])
})
temps := make([]TemperatureSensor, 0, len(inputs)) temps := make([]TemperatureSensor, 0, len(inputs))
for _, inputPath := range inputs { for _, inputPath := range inputs {
@@ -96,3 +99,15 @@ func (r *HwmonDriver) Read() (any, error) {
return temps, nil return temps, nil
} }
// Helper to extract the integer index from "temp<N>_input"
func extractSensorIndex(path string) int {
base := filepath.Base(path)
trimmed := strings.TrimPrefix(base, "temp")
trimmed = strings.TrimSuffix(trimmed, "_input")
idx, err := strconv.Atoi(trimmed)
if err != nil {
return 0
}
return idx
}
+1 -1
View File
@@ -36,7 +36,7 @@ func (r *RaplDriver) Render(term common.Terminal) error {
} }
power := p.([]PowerSensor) power := p.([]PowerSensor)
term.Subheader("Power") term.Subheader("Power /sys/class/powercap/intel-rapl")
for _, sensor := range power { for _, sensor := range power {
// \033[K clears from cursor to end of line (prevents lingering chars) // \033[K clears from cursor to end of line (prevents lingering chars)
+1 -1
View File
@@ -25,7 +25,7 @@ func (r *SysDriver) Render(term common.Terminal) error {
} }
clock := c.([]ClockSensor) clock := c.([]ClockSensor)
term.Subheader("Frequency") term.Subheader("Frequency /sys/devices/system/cpu/*/cpufreq")
for _, sensor := range clock { for _, sensor := range clock {
// \033[K clears from cursor to end of line (prevents lingering chars) // \033[K clears from cursor to end of line (prevents lingering chars)