implement intel power stats
This commit is contained in:
@@ -16,11 +16,6 @@ type AMDReader struct {
|
||||
energyState map[string]EnergyState
|
||||
}
|
||||
|
||||
type EnergyState struct {
|
||||
lastEnergy uint64
|
||||
lastTime time.Time
|
||||
}
|
||||
|
||||
func NewAMDReader() (*AMDReader, error) {
|
||||
matches, err := filepath.Glob("/sys/class/hwmon/hwmon*")
|
||||
if err != nil {
|
||||
@@ -82,51 +77,9 @@ func (r *AMDReader) ReadTemperatureSensors() ([]TempSensor, error) {
|
||||
}
|
||||
|
||||
func (r *AMDReader) ReadPowerSensors() ([]PowerSensor, error) {
|
||||
hwmonSensors := r.readHwmonPower()
|
||||
if len(hwmonSensors) > 0 {
|
||||
return hwmonSensors, nil
|
||||
}
|
||||
|
||||
return r.readRaplPower(), nil
|
||||
}
|
||||
|
||||
func (r *AMDReader) readHwmonPower() []PowerSensor {
|
||||
powerSensors := []PowerSensor{}
|
||||
|
||||
getLabel := func(inputPath string) string {
|
||||
labelPath := strings.TrimSuffix(inputPath, "_input") + "_label"
|
||||
if lBytes, err := os.ReadFile(labelPath); err == nil {
|
||||
return strings.TrimSpace(string(lBytes))
|
||||
}
|
||||
return filepath.Base(strings.TrimSuffix(inputPath, "_input"))
|
||||
}
|
||||
|
||||
powerInputs, _ := filepath.Glob(filepath.Join(r.hwmonDir, "power*_input"))
|
||||
for _, inputPath := range powerInputs {
|
||||
valBytes, err := os.ReadFile(inputPath)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
|
||||
microWatts, err := strconv.ParseFloat(strings.TrimSpace(string(valBytes)), 64)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
|
||||
powerSensors = append(powerSensors, PowerSensor{
|
||||
Name: getLabel(inputPath),
|
||||
Watts: microWatts / 1_000_000.0,
|
||||
})
|
||||
}
|
||||
|
||||
energyInputs, _ := filepath.Glob(filepath.Join(r.hwmonDir, "energy*_input"))
|
||||
if len(energyInputs) > 0 {
|
||||
r.calculateEnergyDelta(energyInputs, getLabel, &powerSensors)
|
||||
}
|
||||
|
||||
return powerSensors
|
||||
}
|
||||
|
||||
func (r *AMDReader) readRaplPower() []PowerSensor {
|
||||
powerSensors := []PowerSensor{}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user