diff --git a/internal/monitoring/temperature.go b/internal/monitoring/temperature.go index 256ef9f..0a921c7 100644 --- a/internal/monitoring/temperature.go +++ b/internal/monitoring/temperature.go @@ -297,11 +297,18 @@ func (tc *TemperatureCollector) parseCPUTemps(chipMap map[string]interface{}, te continue } - // Look for Package id (Intel) or Tdie (AMD) - if strings.Contains(sensorName, "Package id") || strings.Contains(sensorName, "Tdie") { + sensorNameLower := strings.ToLower(sensorName) + + // Look for Package id (Intel) or Tdie/Tctl (AMD control loop temperature) + if strings.Contains(sensorName, "Package id") || + strings.Contains(sensorName, "Tdie") || + strings.Contains(sensorNameLower, "tctl") { if tempVal := extractTempInput(sensorMap); !math.IsNaN(tempVal) { temp.CPUPackage = tempVal foundPackageTemp = true + if tempVal > temp.CPUMax { + temp.CPUMax = tempVal + } } } diff --git a/internal/monitoring/temperature_test.go b/internal/monitoring/temperature_test.go index d2d58eb..5712f6b 100644 --- a/internal/monitoring/temperature_test.go +++ b/internal/monitoring/temperature_test.go @@ -133,6 +133,36 @@ func TestParseSensorsJSON_WithCpuAndNvmeData(t *testing.T) { } } +func TestParseSensorsJSON_WithAmdTctlOnly(t *testing.T) { + collector := &TemperatureCollector{} + + jsonStr := `{ + "k10temp-pci-00c3": { + "Tctl": {"temp1_input": 55.4} + } + }` + + temp, err := collector.parseSensorsJSON(jsonStr) + if err != nil { + t.Fatalf("unexpected error parsing sensors output: %v", err) + } + if temp == nil { + t.Fatalf("expected temperature struct, got nil") + } + if !temp.Available { + t.Fatalf("expected temperature to be available when Tctl reading present") + } + if !temp.HasCPU { + t.Fatalf("expected HasCPU to be true when AMD Tctl is present") + } + if temp.CPUPackage != 55.4 { + t.Fatalf("expected cpu package temperature 55.4, got %.2f", temp.CPUPackage) + } + if temp.CPUMax != 55.4 { + t.Fatalf("expected cpu max temperature to follow Tctl value, got %.2f", temp.CPUMax) + } +} + func TestParseSensorsJSON_RPiWrapper(t *testing.T) { collector := &TemperatureCollector{}