fix issue with intel cpu temperature label order
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
@@ -48,13 +49,10 @@ func (r *HwmonDriver) Render(term common.Terminal) error {
|
||||
}
|
||||
|
||||
temps := t.([]TemperatureSensor)
|
||||
term.Subheader("Temperature")
|
||||
term.Subheader(fmt.Sprintf("Temperature %s", r.hwmonDir))
|
||||
|
||||
for _, sensor := range temps {
|
||||
tempC := 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))
|
||||
term.Print(fmt.Sprintf("%-16s | %.2f °C", sensor.Name, sensor.TempC))
|
||||
}
|
||||
|
||||
return nil
|
||||
@@ -66,6 +64,11 @@ func (r *HwmonDriver) Read() (any, error) {
|
||||
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))
|
||||
|
||||
for _, inputPath := range inputs {
|
||||
@@ -96,3 +99,15 @@ func (r *HwmonDriver) Read() (any, error) {
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ func (r *RaplDriver) Render(term common.Terminal) error {
|
||||
}
|
||||
|
||||
power := p.([]PowerSensor)
|
||||
term.Subheader("Power")
|
||||
term.Subheader("Power /sys/class/powercap/intel-rapl")
|
||||
|
||||
for _, sensor := range power {
|
||||
// \033[K clears from cursor to end of line (prevents lingering chars)
|
||||
|
||||
@@ -25,7 +25,7 @@ func (r *SysDriver) Render(term common.Terminal) error {
|
||||
}
|
||||
|
||||
clock := c.([]ClockSensor)
|
||||
term.Subheader("Frequency")
|
||||
term.Subheader("Frequency /sys/devices/system/cpu/*/cpufreq")
|
||||
|
||||
for _, sensor := range clock {
|
||||
// \033[K clears from cursor to end of line (prevents lingering chars)
|
||||
|
||||
Reference in New Issue
Block a user