diff options
Diffstat (limited to 'vendor/github.com/prometheus/procfs/sysfs/class_thermal.go')
-rw-r--r-- | vendor/github.com/prometheus/procfs/sysfs/class_thermal.go | 26 |
1 files changed, 14 insertions, 12 deletions
diff --git a/vendor/github.com/prometheus/procfs/sysfs/class_thermal.go b/vendor/github.com/prometheus/procfs/sysfs/class_thermal.go index cfe11ad..493a531 100644 --- a/vendor/github.com/prometheus/procfs/sysfs/class_thermal.go +++ b/vendor/github.com/prometheus/procfs/sysfs/class_thermal.go | |||
@@ -16,9 +16,11 @@ | |||
16 | package sysfs | 16 | package sysfs |
17 | 17 | ||
18 | import ( | 18 | import ( |
19 | "errors" | ||
19 | "os" | 20 | "os" |
20 | "path/filepath" | 21 | "path/filepath" |
21 | "strings" | 22 | "strings" |
23 | "syscall" | ||
22 | 24 | ||
23 | "github.com/prometheus/procfs/internal/util" | 25 | "github.com/prometheus/procfs/internal/util" |
24 | ) | 26 | ) |
@@ -29,7 +31,7 @@ import ( | |||
29 | type ClassThermalZoneStats struct { | 31 | type ClassThermalZoneStats struct { |
30 | Name string // The name of the zone from the directory structure. | 32 | Name string // The name of the zone from the directory structure. |
31 | Type string // The type of thermal zone. | 33 | Type string // The type of thermal zone. |
32 | Temp uint64 // Temperature in millidegree Celsius. | 34 | Temp int64 // Temperature in millidegree Celsius. |
33 | Policy string // One of the various thermal governors used for a particular zone. | 35 | Policy string // One of the various thermal governors used for a particular zone. |
34 | Mode *bool // Optional: One of the predefined values in [enabled, disabled]. | 36 | Mode *bool // Optional: One of the predefined values in [enabled, disabled]. |
35 | Passive *uint64 // Optional: millidegrees Celsius. (0 for disabled, > 1000 for enabled+value) | 37 | Passive *uint64 // Optional: millidegrees Celsius. (0 for disabled, > 1000 for enabled+value) |
@@ -39,20 +41,20 @@ type ClassThermalZoneStats struct { | |||
39 | func (fs FS) ClassThermalZoneStats() ([]ClassThermalZoneStats, error) { | 41 | func (fs FS) ClassThermalZoneStats() ([]ClassThermalZoneStats, error) { |
40 | zones, err := filepath.Glob(fs.sys.Path("class/thermal/thermal_zone[0-9]*")) | 42 | zones, err := filepath.Glob(fs.sys.Path("class/thermal/thermal_zone[0-9]*")) |
41 | if err != nil { | 43 | if err != nil { |
42 | return []ClassThermalZoneStats{}, err | 44 | return nil, err |
43 | } | 45 | } |
44 | 46 | ||
45 | var zoneStats = ClassThermalZoneStats{} | 47 | stats := make([]ClassThermalZoneStats, 0, len(zones)) |
46 | stats := make([]ClassThermalZoneStats, len(zones)) | 48 | for _, zone := range zones { |
47 | for i, zone := range zones { | 49 | zoneStats, err := parseClassThermalZone(zone) |
48 | zoneName := strings.TrimPrefix(filepath.Base(zone), "thermal_zone") | ||
49 | |||
50 | zoneStats, err = parseClassThermalZone(zone) | ||
51 | if err != nil { | 50 | if err != nil { |
52 | return []ClassThermalZoneStats{}, err | 51 | if errors.Is(err, syscall.ENODATA) { |
52 | continue | ||
53 | } | ||
54 | return nil, err | ||
53 | } | 55 | } |
54 | zoneStats.Name = zoneName | 56 | zoneStats.Name = strings.TrimPrefix(filepath.Base(zone), "thermal_zone") |
55 | stats[i] = zoneStats | 57 | stats = append(stats, zoneStats) |
56 | } | 58 | } |
57 | return stats, nil | 59 | return stats, nil |
58 | } | 60 | } |
@@ -67,7 +69,7 @@ func parseClassThermalZone(zone string) (ClassThermalZoneStats, error) { | |||
67 | if err != nil { | 69 | if err != nil { |
68 | return ClassThermalZoneStats{}, err | 70 | return ClassThermalZoneStats{}, err |
69 | } | 71 | } |
70 | zoneTemp, err := util.ReadUintFromFile(filepath.Join(zone, "temp")) | 72 | zoneTemp, err := util.ReadIntFromFile(filepath.Join(zone, "temp")) |
71 | if err != nil { | 73 | if err != nil { |
72 | return ClassThermalZoneStats{}, err | 74 | return ClassThermalZoneStats{}, err |
73 | } | 75 | } |