Update procfs vendor (#1248)
Signed-off-by: Mark Knapp <mknapp@hudson-trading.com>
This commit is contained in:
parent
7d150d5782
commit
7fbdd0ae93
26 changed files with 2200 additions and 156 deletions
99
vendor/github.com/prometheus/procfs/sysfs/class_thermal.go
generated
vendored
Normal file
99
vendor/github.com/prometheus/procfs/sysfs/class_thermal.go
generated
vendored
Normal file
|
|
@ -0,0 +1,99 @@
|
|||
// Copyright 2018 The Prometheus Authors
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
// +build !windows
|
||||
|
||||
package sysfs
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/prometheus/procfs/internal/util"
|
||||
)
|
||||
|
||||
// ClassThermalZoneStats contains info from files in /sys/class/thermal/thermal_zone<zone>
|
||||
// for a single <zone>.
|
||||
// https://www.kernel.org/doc/Documentation/thermal/sysfs-api.txt
|
||||
type ClassThermalZoneStats struct {
|
||||
Name string // The name of the zone from the directory structure.
|
||||
Type string // The type of thermal zone.
|
||||
Temp uint64 // Temperature in millidegree Celsius.
|
||||
Policy string // One of the various thermal governors used for a particular zone.
|
||||
Mode *bool // Optional: One of the predefined values in [enabled, disabled].
|
||||
Passive *uint64 // Optional: millidegrees Celsius. (0 for disabled, > 1000 for enabled+value)
|
||||
}
|
||||
|
||||
// NewClassThermalZoneStats returns Thermal Zone metrics for all zones.
|
||||
func (fs FS) NewClassThermalZoneStats() ([]ClassThermalZoneStats, error) {
|
||||
zones, err := filepath.Glob(fs.Path("class/thermal/thermal_zone[0-9]*"))
|
||||
if err != nil {
|
||||
return []ClassThermalZoneStats{}, 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)
|
||||
if err != nil {
|
||||
return []ClassThermalZoneStats{}, err
|
||||
}
|
||||
zoneStats.Name = zoneName
|
||||
stats[i] = zoneStats
|
||||
}
|
||||
return stats, nil
|
||||
}
|
||||
|
||||
func parseClassThermalZone(zone string) (ClassThermalZoneStats, error) {
|
||||
// Required attributes.
|
||||
zoneType, err := util.SysReadFile(filepath.Join(zone, "type"))
|
||||
if err != nil {
|
||||
return ClassThermalZoneStats{}, err
|
||||
}
|
||||
zonePolicy, err := util.SysReadFile(filepath.Join(zone, "policy"))
|
||||
if err != nil {
|
||||
return ClassThermalZoneStats{}, err
|
||||
}
|
||||
zoneTemp, err := util.ReadUintFromFile(filepath.Join(zone, "temp"))
|
||||
if err != nil {
|
||||
return ClassThermalZoneStats{}, err
|
||||
}
|
||||
|
||||
// Optional attributes.
|
||||
mode, err := util.SysReadFile(filepath.Join(zone, "mode"))
|
||||
if err != nil && !os.IsNotExist(err) && !os.IsPermission(err) {
|
||||
return ClassThermalZoneStats{}, err
|
||||
}
|
||||
zoneMode := util.ParseBool(mode)
|
||||
|
||||
var zonePassive *uint64
|
||||
passive, err := util.ReadUintFromFile(filepath.Join(zone, "passive"))
|
||||
if os.IsNotExist(err) || os.IsPermission(err) {
|
||||
zonePassive = nil
|
||||
} else if err != nil {
|
||||
return ClassThermalZoneStats{}, err
|
||||
} else {
|
||||
zonePassive = &passive
|
||||
}
|
||||
|
||||
return ClassThermalZoneStats{
|
||||
Type: zoneType,
|
||||
Policy: zonePolicy,
|
||||
Temp: zoneTemp,
|
||||
Mode: zoneMode,
|
||||
Passive: zonePassive,
|
||||
}, nil
|
||||
}
|
||||
49
vendor/github.com/prometheus/procfs/sysfs/fixtures.ttar
generated
vendored
49
vendor/github.com/prometheus/procfs/sysfs/fixtures.ttar
generated
vendored
|
|
@ -137,6 +137,55 @@ Lines: 1
|
|||
1
|
||||
Mode: 644
|
||||
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
Directory: fixtures/class/thermal
|
||||
Mode: 775
|
||||
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
Directory: fixtures/class/thermal/thermal_zone0
|
||||
Mode: 775
|
||||
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
Path: fixtures/class/thermal/thermal_zone0/policy
|
||||
Lines: 1
|
||||
step_wise
|
||||
Mode: 664
|
||||
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
Path: fixtures/class/thermal/thermal_zone0/temp
|
||||
Lines: 1
|
||||
49925
|
||||
Mode: 664
|
||||
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
Path: fixtures/class/thermal/thermal_zone0/type
|
||||
Lines: 1
|
||||
bcm2835_thermal
|
||||
Mode: 664
|
||||
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
Directory: fixtures/class/thermal/thermal_zone1
|
||||
Mode: 755
|
||||
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
Path: fixtures/class/thermal/thermal_zone1/mode
|
||||
Lines: 1
|
||||
enabled
|
||||
Mode: 664
|
||||
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
Path: fixtures/class/thermal/thermal_zone1/passive
|
||||
Lines: 1
|
||||
0
|
||||
Mode: 664
|
||||
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
Path: fixtures/class/thermal/thermal_zone1/policy
|
||||
Lines: 1
|
||||
step_wise
|
||||
Mode: 664
|
||||
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
Path: fixtures/class/thermal/thermal_zone1/temp
|
||||
Lines: 1
|
||||
44000
|
||||
Mode: 664
|
||||
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
Path: fixtures/class/thermal/thermal_zone1/type
|
||||
Lines: 1
|
||||
acpitz
|
||||
Mode: 664
|
||||
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
Directory: fixtures/devices
|
||||
Mode: 755
|
||||
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
|
|
|
|||
72
vendor/github.com/prometheus/procfs/sysfs/system_cpu.go
generated
vendored
72
vendor/github.com/prometheus/procfs/sysfs/system_cpu.go
generated
vendored
|
|
@ -16,7 +16,6 @@
|
|||
package sysfs
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
|
@ -26,16 +25,19 @@ import (
|
|||
|
||||
// SystemCPUCpufreqStats contains stats from devices/system/cpu/cpu[0-9]*/cpufreq/...
|
||||
type SystemCPUCpufreqStats struct {
|
||||
Name string
|
||||
CurrentFrequency uint64
|
||||
MinimumFrequency uint64
|
||||
MaximumFrequency uint64
|
||||
TransitionLatency uint64
|
||||
AvailableGovernors string
|
||||
Driver string
|
||||
Govenor string
|
||||
RelatedCpus string
|
||||
SetSpeed string
|
||||
Name string
|
||||
CpuinfoCurrentFrequency *uint64
|
||||
CpuinfoMinimumFrequency *uint64
|
||||
CpuinfoMaximumFrequency *uint64
|
||||
CpuinfoTransitionLatency *uint64
|
||||
ScalingCurrentFrequency *uint64
|
||||
ScalingMinimumFrequency *uint64
|
||||
ScalingMaximumFrequency *uint64
|
||||
AvailableGovernors string
|
||||
Driver string
|
||||
Govenor string
|
||||
RelatedCpus string
|
||||
SetSpeed string
|
||||
}
|
||||
|
||||
// TODO: Add topology support.
|
||||
|
|
@ -74,14 +76,7 @@ func (fs FS) NewSystemCpufreq() ([]SystemCPUCpufreqStats, error) {
|
|||
return []SystemCPUCpufreqStats{}, err
|
||||
}
|
||||
|
||||
if _, err = os.Stat(filepath.Join(cpuCpufreqPath, "scaling_cur_freq")); err == nil {
|
||||
cpufreq, err = parseCpufreqCpuinfo("scaling", cpuCpufreqPath)
|
||||
} else if _, err = os.Stat(filepath.Join(cpuCpufreqPath, "cpuinfo_cur_freq")); err == nil {
|
||||
// Older kernels have metrics named `cpuinfo_...`.
|
||||
cpufreq, err = parseCpufreqCpuinfo("cpuinfo", cpuCpufreqPath)
|
||||
} else {
|
||||
return []SystemCPUCpufreqStats{}, fmt.Errorf("CPU %v is missing cpufreq", cpu)
|
||||
}
|
||||
cpufreq, err = parseCpufreqCpuinfo(cpuCpufreqPath)
|
||||
if err != nil {
|
||||
return []SystemCPUCpufreqStats{}, err
|
||||
}
|
||||
|
|
@ -92,22 +87,28 @@ func (fs FS) NewSystemCpufreq() ([]SystemCPUCpufreqStats, error) {
|
|||
return systemCpufreq, nil
|
||||
}
|
||||
|
||||
func parseCpufreqCpuinfo(prefix string, cpuPath string) (*SystemCPUCpufreqStats, error) {
|
||||
func parseCpufreqCpuinfo(cpuPath string) (*SystemCPUCpufreqStats, error) {
|
||||
uintFiles := []string{
|
||||
prefix + "_cur_freq",
|
||||
prefix + "_max_freq",
|
||||
prefix + "_min_freq",
|
||||
"cpuinfo_cur_freq",
|
||||
"cpuinfo_max_freq",
|
||||
"cpuinfo_min_freq",
|
||||
"cpuinfo_transition_latency",
|
||||
"scaling_cur_freq",
|
||||
"scaling_max_freq",
|
||||
"scaling_min_freq",
|
||||
}
|
||||
uintOut := make([]uint64, len(uintFiles))
|
||||
uintOut := make([]*uint64, len(uintFiles))
|
||||
|
||||
for i, f := range uintFiles {
|
||||
v, err := util.ReadUintFromFile(filepath.Join(cpuPath, f))
|
||||
if err != nil {
|
||||
if os.IsNotExist(err) || os.IsPermission(err) {
|
||||
continue
|
||||
}
|
||||
return &SystemCPUCpufreqStats{}, err
|
||||
}
|
||||
|
||||
uintOut[i] = v
|
||||
uintOut[i] = &v
|
||||
}
|
||||
|
||||
stringFiles := []string{
|
||||
|
|
@ -128,14 +129,17 @@ func parseCpufreqCpuinfo(prefix string, cpuPath string) (*SystemCPUCpufreqStats,
|
|||
}
|
||||
|
||||
return &SystemCPUCpufreqStats{
|
||||
CurrentFrequency: uintOut[0],
|
||||
MaximumFrequency: uintOut[1],
|
||||
MinimumFrequency: uintOut[2],
|
||||
TransitionLatency: uintOut[3],
|
||||
AvailableGovernors: stringOut[0],
|
||||
Driver: stringOut[1],
|
||||
Govenor: stringOut[2],
|
||||
RelatedCpus: stringOut[3],
|
||||
SetSpeed: stringOut[4],
|
||||
CpuinfoCurrentFrequency: uintOut[0],
|
||||
CpuinfoMaximumFrequency: uintOut[1],
|
||||
CpuinfoMinimumFrequency: uintOut[2],
|
||||
CpuinfoTransitionLatency: uintOut[3],
|
||||
ScalingCurrentFrequency: uintOut[4],
|
||||
ScalingMaximumFrequency: uintOut[5],
|
||||
ScalingMinimumFrequency: uintOut[6],
|
||||
AvailableGovernors: stringOut[0],
|
||||
Driver: stringOut[1],
|
||||
Govenor: stringOut[2],
|
||||
RelatedCpus: stringOut[3],
|
||||
SetSpeed: stringOut[4],
|
||||
}, nil
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue