Skip to content

Commit

Permalink
Merge pull request prometheus#300 from pgier/handle-thermal-zones-eno…
Browse files Browse the repository at this point in the history
…data

sysfs: skip thermal for ENODATA
  • Loading branch information
pgier authored May 27, 2020
2 parents 5bc20c5 + ea166e0 commit 562ee69
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions sysfs/class_thermal.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@
package sysfs

import (
"errors"
"os"
"path/filepath"
"strings"
"syscall"

"github.com/prometheus/procfs/internal/util"
)
Expand All @@ -39,20 +41,20 @@ type ClassThermalZoneStats struct {
func (fs FS) ClassThermalZoneStats() ([]ClassThermalZoneStats, error) {
zones, err := filepath.Glob(fs.sys.Path("class/thermal/thermal_zone[0-9]*"))
if err != nil {
return []ClassThermalZoneStats{}, err
return nil, err
}

var zoneStats = ClassThermalZoneStats{}
stats := make([]ClassThermalZoneStats, len(zones))
for i, zone := range zones {
zoneName := strings.TrimPrefix(filepath.Base(zone), "thermal_zone")

zoneStats, err = parseClassThermalZone(zone)
stats := make([]ClassThermalZoneStats, 0, len(zones))
for _, zone := range zones {
zoneStats, err := parseClassThermalZone(zone)
if err != nil {
return []ClassThermalZoneStats{}, err
if errors.Is(err, syscall.ENODATA) {
continue
}
return nil, err
}
zoneStats.Name = zoneName
stats[i] = zoneStats
zoneStats.Name = strings.TrimPrefix(filepath.Base(zone), "thermal_zone")
stats = append(stats, zoneStats)
}
return stats, nil
}
Expand Down

0 comments on commit 562ee69

Please sign in to comment.