Skip to content

Commit

Permalink
Merge pull request #45 from Athemis/cputemp_amd
Browse files Browse the repository at this point in the history
Properly report CPU temperature on AMD systems
  • Loading branch information
tobias-kuendig committed Jun 13, 2024
2 parents be4ad33 + 3464a0b commit efb3700
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
4 changes: 2 additions & 2 deletions sensor/cpu.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
)

var (
reCPUTemp = regexp.MustCompile(`(?m)(temp1|Package id|Core \d|CPU)[\s\d]*:\s+.?([\d\.]+)°`)
reCPUTemp = regexp.MustCompile(`(?m)(temp1|Package id|Core \d|CPU|Tctl)[\s\d]*:\s+.?([\d\.]+)°`)
// This is currently unused.
//reCPUTemp2 = regexp.MustCompile(`(?mi)^\s?(?P<name>[^:]+):\s+(?P<value>\d+)`)
reCPUUsage = regexp.MustCompile(`(?m)^\s*cpu(\d+)?.*`)
Expand Down Expand Up @@ -56,7 +56,7 @@ func (c CPUTemp) process(output string) (*entity.Payload, error) {
if len(match) < 3 {
return nil, fmt.Errorf("invalid output form lm-sensors received: %s", output)
}
if strings.EqualFold(match[1], "Package id") || strings.EqualFold(match[1], "CPU") {
if strings.EqualFold(match[1], "Package id") || strings.EqualFold(match[1], "CPU") || strings.EqualFold(match[1], "Tctl") {
p.State = match[2]
} else {
p.Attributes[util.ToSnakeCase(match[1])] = match[2]
Expand Down
5 changes: 5 additions & 0 deletions sensor/cpu_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ func TestCPUTemp(t *testing.T) {
pch_cannonlake-virtual-0
Adapter: Virtual device
temp1: +37.0°C
k10temp-pci-00c3
Adapter: PCI adapter
Tctl: +39.6°C
`
output := &entity.Payload{
State: "99.0",
Expand All @@ -68,6 +72,7 @@ func TestCPUTemp(t *testing.T) {
"core_4": "38.0",
"core_5": "39.0",
"temp_1": "37.0",
"Tctl": "39.6",

Check failure on line 75 in sensor/cpu_test.go

View workflow job for this annotation

GitHub Actions / lint

File is not `gofmt`-ed with `-s` (gofmt)

Check failure on line 75 in sensor/cpu_test.go

View workflow job for this annotation

GitHub Actions / lint

File is not `gofmt`-ed with `-s` (gofmt)
},
}

Expand Down

0 comments on commit efb3700

Please sign in to comment.