feat: fan RPM monitoring (#2032)

Adds fan RPM monitoring as a peer to the existing temperature collection, addressing #1918.

---------

Co-authored-by: henrygd <hank@henrygd.me>
This commit is contained in:
Maxim Lepekha
2026-08-15 21:59:07 +02:00
committed by GitHub
parent eb5dd230cf
commit eebcd56462
13 changed files with 361 additions and 3 deletions

View File

@@ -191,6 +191,8 @@ func AverageSystemStatsSlice(records []system.Stats) system.Stats {
// accumulate cpu breakdown [user, system, iowait, steal, idle]
var cpuBreakdownSums []float64
tempCount := float64(0)
var fanSums map[string]uint64
fanCount := uint64(0)
// Accumulate totals
for i := range records {
@@ -282,6 +284,17 @@ func AverageSystemStatsSlice(records []system.Stats) system.Stats {
}
}
// Accumulate fan speeds
if stats.Fans != nil {
if fanSums == nil {
fanSums = make(map[string]uint64, len(stats.Fans))
}
fanCount++
for key, value := range stats.Fans {
fanSums[key] += uint64(value)
}
}
// Accumulate extra filesystem stats
if stats.ExtraFs != nil {
if sum.ExtraFs == nil {
@@ -387,6 +400,14 @@ func AverageSystemStatsSlice(records []system.Stats) system.Stats {
}
}
// Average fan speeds
if fanSums != nil && fanCount > 0 {
sum.Fans = make(map[string]uint16, len(fanSums))
for key, value := range fanSums {
sum.Fans[key] = uint16(value / fanCount)
}
}
// Average extra filesystem stats
if sum.ExtraFs != nil {
for key := range sum.ExtraFs {

View File

@@ -291,6 +291,28 @@ func TestAverageSystemStatsSlice_Temperatures(t *testing.T) {
assert.Equal(t, 80.0, result.Temperatures["gpu"])
}
// Tests that fan speeds are averaged and records without fan data are excluded.
func TestAverageSystemStatsSlice_Fans(t *testing.T) {
input := []system.Stats{
{
Fans: map[string]uint16{"cpu": 60_000, "case": 1_000},
},
{
Fans: map[string]uint16{"cpu": 50_000, "case": 2_000},
},
{
// No fan data - should not affect fan averaging
Cpu: 30.0,
},
}
result := records.AverageSystemStatsSlice(input)
require.NotNil(t, result.Fans)
assert.Equal(t, uint16(55_000), result.Fans["cpu"])
assert.Equal(t, uint16(1_500), result.Fans["case"])
}
func TestAverageSystemStatsSlice_NetworkInterfaces(t *testing.T) {
input := []system.Stats{
{