Handle AMD Tctl temperature readings (refs #586)

This commit is contained in:
rcourtman 2025-10-22 12:58:34 +00:00
parent 4ba5dcc785
commit 30879c3b7b
2 changed files with 39 additions and 2 deletions

View file

@ -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
}
}
}

View file

@ -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{}