Separate network faults from software drops and fix CPU temperature history
This commit is contained in:
39
cpu.go
39
cpu.go
@@ -3,6 +3,7 @@ package main
|
||||
import (
|
||||
"bufio"
|
||||
"fmt"
|
||||
"math"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
@@ -33,15 +34,16 @@ type CPUStatic struct {
|
||||
|
||||
type CPUMetrics struct {
|
||||
CPUStatic
|
||||
UsagePercent float64 `json:"usagePercent"`
|
||||
FrequencyMHz float64 `json:"frequencyMhz"`
|
||||
Load1 float64 `json:"load1"`
|
||||
Load5 float64 `json:"load5"`
|
||||
Load15 float64 `json:"load15"`
|
||||
Uptime uint64 `json:"uptimeSeconds"`
|
||||
Temperatures []Temperature `json:"temperatures"`
|
||||
TopProcesses []AgentProcess `json:"topProcesses"`
|
||||
CollectedAt time.Time `json:"collectedAt"`
|
||||
UsagePercent float64 `json:"usagePercent"`
|
||||
FrequencyMHz float64 `json:"frequencyMhz"`
|
||||
Load1 float64 `json:"load1"`
|
||||
Load5 float64 `json:"load5"`
|
||||
Load15 float64 `json:"load15"`
|
||||
Uptime uint64 `json:"uptimeSeconds"`
|
||||
TemperatureCelsius *float64 `json:"temperatureCelsius"`
|
||||
Temperatures []Temperature `json:"temperatures"`
|
||||
TopProcesses []AgentProcess `json:"topProcesses"`
|
||||
CollectedAt time.Time `json:"collectedAt"`
|
||||
}
|
||||
|
||||
type Temperature struct {
|
||||
@@ -90,10 +92,11 @@ func (c *cpuCollector) collect() (CPUMetrics, error) {
|
||||
load1, load5, load15, _ := readLoadAverage()
|
||||
uptime, _ := readUptime()
|
||||
|
||||
temperatures := readTemperatures()
|
||||
return CPUMetrics{
|
||||
CPUStatic: c.static, UsagePercent: usage, FrequencyMHz: frequency,
|
||||
Load1: load1, Load5: load5, Load15: load15, Uptime: uptime,
|
||||
Temperatures: readTemperatures(), TopProcesses: collectAgentProcesses(), CollectedAt: time.Now(),
|
||||
Temperatures: temperatures, TemperatureCelsius: cpuTemperature(temperatures), TopProcesses: collectAgentProcesses(), CollectedAt: time.Now(),
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -285,3 +288,19 @@ func isCPUTemperatureChip(name string) bool {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
// cpuTemperature is the hottest CPU sensor, shared by live and historical views.
|
||||
// Do not average Tctl/Tdie with cooler cores or CCDs.
|
||||
func cpuTemperature(temperatures []Temperature) *float64 {
|
||||
var hottest *float64
|
||||
for _, t := range temperatures {
|
||||
if math.IsNaN(t.Celsius) || math.IsInf(t.Celsius, 0) || t.Celsius <= 0 {
|
||||
continue
|
||||
}
|
||||
if hottest == nil || t.Celsius > *hottest {
|
||||
value := t.Celsius
|
||||
hottest = &value
|
||||
}
|
||||
}
|
||||
return hottest
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user