Skip to content

Commit 7c97c6f

Browse files
authored
Merge pull request prometheus#300 from pgier/handle-thermal-zones-enodata
sysfs: skip thermal for ENODATA
2 parents 2fd30c4 + e9fcca3 commit 7c97c6f

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

sysfs/class_thermal.go

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,11 @@
1616
package sysfs
1717

1818
import (
19+
"errors"
1920
"os"
2021
"path/filepath"
2122
"strings"
23+
"syscall"
2224

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

45-
var zoneStats = ClassThermalZoneStats{}
46-
stats := make([]ClassThermalZoneStats, len(zones))
47-
for i, zone := range zones {
48-
zoneName := strings.TrimPrefix(filepath.Base(zone), "thermal_zone")
49-
50-
zoneStats, err = parseClassThermalZone(zone)
47+
stats := make([]ClassThermalZoneStats, 0, len(zones))
48+
for _, zone := range zones {
49+
zoneStats, err := parseClassThermalZone(zone)
5150
if err != nil {
52-
return []ClassThermalZoneStats{}, err
51+
if errors.Is(err, syscall.ENODATA) {
52+
continue
53+
}
54+
return nil, err
5355
}
54-
zoneStats.Name = zoneName
55-
stats[i] = zoneStats
56+
zoneStats.Name = strings.TrimPrefix(filepath.Base(zone), "thermal_zone")
57+
stats = append(stats, zoneStats)
5658
}
5759
return stats, nil
5860
}

0 commit comments

Comments
 (0)