From 2bc133cd486e3af2cc8cb6f8c53a67a82f82a02b Mon Sep 17 00:00:00 2001 From: Paul Gier Date: Wed, 12 Jun 2019 13:47:16 -0500 Subject: [PATCH] update procfs to v0.0.2 (#1376) Signed-off-by: Paul Gier --- collector/buddyinfo.go | 2 +- collector/cpu_linux.go | 2 +- collector/cpufreq_linux.go | 2 +- collector/ipvs_linux.go | 4 +- collector/netclass_linux.go | 2 +- collector/pressure_linux.go | 2 +- collector/processes_linux.go | 2 +- collector/stat_linux.go | 2 +- go.mod | 2 +- go.sum | 4 +- node_exporter_test.go | 6 +- vendor/github.com/prometheus/procfs/README.md | 11 ++- .../prometheus/procfs/bcache/get.go | 6 ++ .../github.com/prometheus/procfs/buddyinfo.go | 12 +-- vendor/github.com/prometheus/procfs/fs.go | 6 ++ vendor/github.com/prometheus/procfs/ipvs.go | 28 +------ vendor/github.com/prometheus/procfs/mdstat.go | 74 +++++++++---------- .../github.com/prometheus/procfs/net_dev.go | 18 +---- .../github.com/prometheus/procfs/nfs/nfs.go | 6 ++ vendor/github.com/prometheus/procfs/proc.go | 11 ++- .../github.com/prometheus/procfs/proc_io.go | 4 +- .../prometheus/procfs/proc_limits.go | 7 ++ .../github.com/prometheus/procfs/proc_ns.go | 4 +- .../github.com/prometheus/procfs/proc_psi.go | 17 +---- .../github.com/prometheus/procfs/proc_stat.go | 9 ++- vendor/github.com/prometheus/procfs/stat.go | 36 ++++++--- .../procfs/sysfs/class_power_supply.go | 14 +--- .../prometheus/procfs/sysfs/class_thermal.go | 4 +- .../github.com/prometheus/procfs/sysfs/fs.go | 6 ++ .../prometheus/procfs/sysfs/net_class.go | 14 +--- .../prometheus/procfs/sysfs/system_cpu.go | 14 +--- .../github.com/prometheus/procfs/xfs/xfs.go | 6 ++ vendor/modules.txt | 2 +- 33 files changed, 167 insertions(+), 172 deletions(-) diff --git a/collector/buddyinfo.go b/collector/buddyinfo.go index 9ac790fc..f6dd5dbf 100644 --- a/collector/buddyinfo.go +++ b/collector/buddyinfo.go @@ -55,7 +55,7 @@ func NewBuddyinfoCollector() (Collector, error) { // Update calls (*buddyinfoCollector).getBuddyInfo to get the platform specific // buddyinfo metrics. func (c *buddyinfoCollector) Update(ch chan<- prometheus.Metric) error { - buddyInfo, err := c.fs.NewBuddyInfo() + buddyInfo, err := c.fs.BuddyInfo() if err != nil { return fmt.Errorf("couldn't get buddyinfo: %s", err) } diff --git a/collector/cpu_linux.go b/collector/cpu_linux.go index a8b34db4..f915d628 100644 --- a/collector/cpu_linux.go +++ b/collector/cpu_linux.go @@ -155,7 +155,7 @@ func (c *cpuCollector) updateThermalThrottle(ch chan<- prometheus.Metric) error // updateStat reads /proc/stat through procfs and exports cpu related metrics. func (c *cpuCollector) updateStat(ch chan<- prometheus.Metric) error { - stats, err := c.fs.NewStat() + stats, err := c.fs.Stat() if err != nil { return err } diff --git a/collector/cpufreq_linux.go b/collector/cpufreq_linux.go index badc16f7..d2560dc2 100644 --- a/collector/cpufreq_linux.go +++ b/collector/cpufreq_linux.go @@ -80,7 +80,7 @@ func NewCPUFreqCollector() (Collector, error) { // Update implements Collector and exposes cpu related metrics from /proc/stat and /sys/.../cpu/. func (c *cpuFreqCollector) Update(ch chan<- prometheus.Metric) error { - cpuFreqs, err := c.fs.NewSystemCpufreq() + cpuFreqs, err := c.fs.SystemCpufreq() if err != nil { return err } diff --git a/collector/ipvs_linux.go b/collector/ipvs_linux.go index 524bac4d..34c687a8 100644 --- a/collector/ipvs_linux.go +++ b/collector/ipvs_linux.go @@ -106,7 +106,7 @@ func newIPVSCollector() (*ipvsCollector, error) { } func (c *ipvsCollector) Update(ch chan<- prometheus.Metric) error { - ipvsStats, err := c.fs.NewIPVSStats() + ipvsStats, err := c.fs.IPVSStats() if err != nil { // Cannot access ipvs metrics, report no error. if os.IsNotExist(err) { @@ -121,7 +121,7 @@ func (c *ipvsCollector) Update(ch chan<- prometheus.Metric) error { ch <- c.incomingBytes.mustNewConstMetric(float64(ipvsStats.IncomingBytes)) ch <- c.outgoingBytes.mustNewConstMetric(float64(ipvsStats.OutgoingBytes)) - backendStats, err := c.fs.NewIPVSBackendStatus() + backendStats, err := c.fs.IPVSBackendStatus() if err != nil { return fmt.Errorf("could not get backend status: %s", err) } diff --git a/collector/netclass_linux.go b/collector/netclass_linux.go index d02ead65..040ded3a 100644 --- a/collector/netclass_linux.go +++ b/collector/netclass_linux.go @@ -169,7 +169,7 @@ func pushMetric(ch chan<- prometheus.Metric, subsystem string, name string, valu } func (c *netClassCollector) getNetClassInfo() (sysfs.NetClass, error) { - netClass, err := c.fs.NewNetClass() + netClass, err := c.fs.NetClass() if err != nil { return netClass, fmt.Errorf("error obtaining net class info: %s", err) diff --git a/collector/pressure_linux.go b/collector/pressure_linux.go index 90b20f88..df8c2660 100644 --- a/collector/pressure_linux.go +++ b/collector/pressure_linux.go @@ -82,7 +82,7 @@ func NewPressureStatsCollector() (Collector, error) { func (c *pressureStatsCollector) Update(ch chan<- prometheus.Metric) error { for _, res := range psiResources { log.Debugf("collecting statistics for resource: %s", res) - vals, err := c.fs.NewPSIStatsForResource(res) + vals, err := c.fs.PSIStatsForResource(res) if err != nil { log.Debug("pressure information is unavailable, you need a Linux kernel >= 4.20 and/or CONFIG_PSI enabled for your kernel") return nil diff --git a/collector/processes_linux.go b/collector/processes_linux.go index 9b171ace..52a47df2 100644 --- a/collector/processes_linux.go +++ b/collector/processes_linux.go @@ -105,7 +105,7 @@ func (c *processCollector) getAllocatedThreads() (int, map[string]int32, int, er thread := 0 procStates := make(map[string]int32) for _, pid := range p { - stat, err := pid.NewStat() + stat, err := pid.Stat() // PIDs can vanish between getting the list and getting stats. if os.IsNotExist(err) { log.Debugf("file not found when retrieving stats for pid %v: %q", pid, err) diff --git a/collector/stat_linux.go b/collector/stat_linux.go index 13a4b019..cd79e38c 100644 --- a/collector/stat_linux.go +++ b/collector/stat_linux.go @@ -80,7 +80,7 @@ func NewStatCollector() (Collector, error) { // Update implements Collector and exposes kernel and system statistics. func (c *statCollector) Update(ch chan<- prometheus.Metric) error { - stats, err := c.fs.NewStat() + stats, err := c.fs.Stat() if err != nil { return err } diff --git a/go.mod b/go.mod index cda7bdbf..717ee8ef 100644 --- a/go.mod +++ b/go.mod @@ -18,7 +18,7 @@ require ( github.com/prometheus/client_golang v0.9.2 github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90 github.com/prometheus/common v0.3.0 - github.com/prometheus/procfs v0.0.0-20190529155944-65bdadfa96ae + github.com/prometheus/procfs v0.0.2 github.com/siebenmann/go-kstat v0.0.0-20160321171754-d34789b79745 github.com/sirupsen/logrus v1.4.2 // indirect github.com/soundcloud/go-runit v0.0.0-20150630195641-06ad41a06c4a diff --git a/go.sum b/go.sum index dbd4c617..e96c2ecf 100644 --- a/go.sum +++ b/go.sum @@ -65,8 +65,8 @@ github.com/prometheus/common v0.3.0 h1:taZ4h8Tkxv2kNyoSctBvfXEHmBmxrwmIidZTIaHon github.com/prometheus/common v0.3.0/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4= github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= github.com/prometheus/procfs v0.0.0-20181204211112-1dc9a6cbc91a/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= -github.com/prometheus/procfs v0.0.0-20190529155944-65bdadfa96ae h1:kF6Y/ES9NQmW3t400V0XH+lO1jqvCpXBC1XoLDkvuMM= -github.com/prometheus/procfs v0.0.0-20190529155944-65bdadfa96ae/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA= +github.com/prometheus/procfs v0.0.2 h1:6LJUbpNm42llc4HRCuvApCSWB/WfhuNo9K98Q9sNGfs= +github.com/prometheus/procfs v0.0.2/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA= github.com/siebenmann/go-kstat v0.0.0-20160321171754-d34789b79745 h1:IuH7WumZNax0D+rEqmy2TyhKCzrtMGqbZO0b8rO00JA= github.com/siebenmann/go-kstat v0.0.0-20160321171754-d34789b79745/go.mod h1:G81aIFAMS9ECrwBYR9YxhlPjWgrItd+Kje78O6+uqm8= github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo= diff --git a/node_exporter_test.go b/node_exporter_test.go index a0881e9e..f10db7c6 100644 --- a/node_exporter_test.go +++ b/node_exporter_test.go @@ -38,9 +38,13 @@ func TestFileDescriptorLeak(t *testing.T) { if _, err := os.Stat(binary); err != nil { t.Skipf("node_exporter binary not available, try to run `make build` first: %s", err) } - if _, err := procfs.NewStat(); err != nil { + fs, err := procfs.NewDefaultFS() + if err != nil { t.Skipf("proc filesystem is not available, but currently required to read number of open file descriptors: %s", err) } + if _, err := fs.Stat(); err != nil { + t.Errorf("unable to read process stats: %s", err) + } exporter := exec.Command(binary, "--web.listen-address", address) test := func(pid int) error { diff --git a/vendor/github.com/prometheus/procfs/README.md b/vendor/github.com/prometheus/procfs/README.md index 951c043b..6f8850fe 100644 --- a/vendor/github.com/prometheus/procfs/README.md +++ b/vendor/github.com/prometheus/procfs/README.md @@ -19,7 +19,14 @@ point is initialized, and then the stat information is read. ```go fs, err := procfs.NewFS("/proc") -stats, err := fs.NewStat() +stats, err := fs.Stat() +``` + +Some sub-packages such as `blockdevice`, require access to both the proc and sys filesystems. + +```go + fs, err := blockdevice.NewFS("/proc", "/sys") + stats, err := fs.ProcDiskstats() ``` ## Building and Testing @@ -30,7 +37,7 @@ changes to the library, the `make test` command can be used to run the API test ### Updating Test Fixtures The procfs library includes a set of test fixtures which include many example files from -the `/proc` and `/sys` filesystems. These fixtures are included as a ttar (text tar) file +the `/proc` and `/sys` filesystems. These fixtures are included as a [ttar](https://github.com/ideaship/ttar) file which is extracted automatically during testing. To add/update the test fixtures, first ensure the `fixtures` directory is up to date by removing the existing directory and then extracting the ttar file using `make fixtures/.unpacked` or just `make test`. diff --git a/vendor/github.com/prometheus/procfs/bcache/get.go b/vendor/github.com/prometheus/procfs/bcache/get.go index 8d404bd3..a8896bd9 100644 --- a/vendor/github.com/prometheus/procfs/bcache/get.go +++ b/vendor/github.com/prometheus/procfs/bcache/get.go @@ -32,6 +32,12 @@ type FS struct { sys *fs.FS } +// NewDefaultFS returns a new Bcache using the default sys fs mount point. It will error +// if the mount point can't be read. +func NewDefaultFS() (FS, error) { + return NewFS(fs.DefaultSysMountPoint) +} + // NewFS returns a new Bcache using the given sys fs mount point. It will error // if the mount point can't be read. func NewFS(mountPoint string) (FS, error) { diff --git a/vendor/github.com/prometheus/procfs/buddyinfo.go b/vendor/github.com/prometheus/procfs/buddyinfo.go index 5cd22a83..63d4229a 100644 --- a/vendor/github.com/prometheus/procfs/buddyinfo.go +++ b/vendor/github.com/prometheus/procfs/buddyinfo.go @@ -31,18 +31,8 @@ type BuddyInfo struct { Sizes []float64 } -// NewBuddyInfo reads the buddyinfo statistics. -func NewBuddyInfo() ([]BuddyInfo, error) { - fs, err := NewFS(DefaultMountPoint) - if err != nil { - return nil, err - } - - return fs.NewBuddyInfo() -} - // NewBuddyInfo reads the buddyinfo statistics from the specified `proc` filesystem. -func (fs FS) NewBuddyInfo() ([]BuddyInfo, error) { +func (fs FS) BuddyInfo() ([]BuddyInfo, error) { file, err := os.Open(fs.proc.Path("buddyinfo")) if err != nil { return nil, err diff --git a/vendor/github.com/prometheus/procfs/fs.go b/vendor/github.com/prometheus/procfs/fs.go index 5b4a1f0b..0102ab0f 100644 --- a/vendor/github.com/prometheus/procfs/fs.go +++ b/vendor/github.com/prometheus/procfs/fs.go @@ -26,6 +26,12 @@ type FS struct { // DefaultMountPoint is the common mount point of the proc filesystem. const DefaultMountPoint = fs.DefaultProcMountPoint +// NewDefaultFS returns a new proc FS mounted under the default proc mountPoint. +// It will error if the mount point directory can't be read or is a file. +func NewDefaultFS() (FS, error) { + return NewFS(DefaultMountPoint) +} + // NewFS returns a new proc FS mounted under the given proc mountPoint. It will error // if the mount point directory can't be read or is a file. func NewFS(mountPoint string) (FS, error) { diff --git a/vendor/github.com/prometheus/procfs/ipvs.go b/vendor/github.com/prometheus/procfs/ipvs.go index 41e645d2..2d6cb8d1 100644 --- a/vendor/github.com/prometheus/procfs/ipvs.go +++ b/vendor/github.com/prometheus/procfs/ipvs.go @@ -62,18 +62,8 @@ type IPVSBackendStatus struct { Weight uint64 } -// NewIPVSStats reads the IPVS statistics. -func NewIPVSStats() (IPVSStats, error) { - fs, err := NewFS(DefaultMountPoint) - if err != nil { - return IPVSStats{}, err - } - - return fs.NewIPVSStats() -} - -// NewIPVSStats reads the IPVS statistics from the specified `proc` filesystem. -func (fs FS) NewIPVSStats() (IPVSStats, error) { +// IPVSStats reads the IPVS statistics from the specified `proc` filesystem. +func (fs FS) IPVSStats() (IPVSStats, error) { file, err := os.Open(fs.proc.Path("net/ip_vs_stats")) if err != nil { return IPVSStats{}, err @@ -131,18 +121,8 @@ func parseIPVSStats(file io.Reader) (IPVSStats, error) { return stats, nil } -// NewIPVSBackendStatus reads and returns the status of all (virtual,real) server pairs. -func NewIPVSBackendStatus() ([]IPVSBackendStatus, error) { - fs, err := NewFS(DefaultMountPoint) - if err != nil { - return []IPVSBackendStatus{}, err - } - - return fs.NewIPVSBackendStatus() -} - -// NewIPVSBackendStatus reads and returns the status of all (virtual,real) server pairs from the specified `proc` filesystem. -func (fs FS) NewIPVSBackendStatus() ([]IPVSBackendStatus, error) { +// IPVSBackendStatus reads and returns the status of all (virtual,real) server pairs from the specified `proc` filesystem. +func (fs FS) IPVSBackendStatus() ([]IPVSBackendStatus, error) { file, err := os.Open(fs.proc.Path("net/ip_vs")) if err != nil { return nil, err diff --git a/vendor/github.com/prometheus/procfs/mdstat.go b/vendor/github.com/prometheus/procfs/mdstat.go index 6ac7a12f..71c10678 100644 --- a/vendor/github.com/prometheus/procfs/mdstat.go +++ b/vendor/github.com/prometheus/procfs/mdstat.go @@ -42,64 +42,64 @@ type MDStat struct { BlocksSynced int64 } -// ParseMDStat parses an mdstat-file and returns a struct with the relevant infos. -func (fs FS) ParseMDStat() (mdstates []MDStat, err error) { - mdStatusFilePath := fs.proc.Path("mdstat") - content, err := ioutil.ReadFile(mdStatusFilePath) +// MDStat parses an mdstat-file (/proc/mdstat) and returns a slice of +// structs containing the relevant info. More information available here: +// https://raid.wiki.kernel.org/index.php/Mdstat +func (fs FS) MDStat() ([]MDStat, error) { + data, err := ioutil.ReadFile(fs.proc.Path("mdstat")) if err != nil { - return []MDStat{}, fmt.Errorf("error parsing %s: %s", mdStatusFilePath, err) + return nil, fmt.Errorf("error parsing mdstat %s: %s", fs.proc.Path("mdstat"), err) } + mdstat, err := parseMDStat(data) + if err != nil { + return nil, fmt.Errorf("error parsing mdstat %s: %s", fs.proc.Path("mdstat"), err) + } + return mdstat, nil +} - mdStates := []MDStat{} - lines := strings.Split(string(content), "\n") +// parseMDStat parses data from mdstat file (/proc/mdstat) and returns a slice of +// structs containing the relevant info. +func parseMDStat(mdstatData []byte) ([]MDStat, error) { + mdStats := []MDStat{} + lines := strings.Split(string(mdstatData), "\n") for i, l := range lines { - if l == "" { - continue - } - if l[0] == ' ' { - continue - } - if strings.HasPrefix(l, "Personalities") || strings.HasPrefix(l, "unused") { + if strings.TrimSpace(l) == "" || l[0] == ' ' || + strings.HasPrefix(l, "Personalities") || strings.HasPrefix(l, "unused") { continue } - mainLine := strings.Split(l, " ") - if len(mainLine) < 3 { - return mdStates, fmt.Errorf("error parsing mdline: %s", l) + deviceFields := strings.Fields(l) + if len(deviceFields) < 3 { + return nil, fmt.Errorf("not enough fields in mdline (expected at least 3): %s", l) } - mdName := mainLine[0] - activityState := mainLine[2] + mdName := deviceFields[0] + activityState := deviceFields[2] if len(lines) <= i+3 { - return mdStates, fmt.Errorf( - "error parsing %s: too few lines for md device %s", - mdStatusFilePath, - mdName, - ) + return mdStats, fmt.Errorf("missing lines for md device %s", mdName) } - active, total, size, err := evalStatusline(lines[i+1]) + active, total, size, err := evalStatusLine(lines[i+1]) if err != nil { - return mdStates, fmt.Errorf("error parsing %s: %s", mdStatusFilePath, err) + return nil, err } - // j is the line number of the syncing-line. - j := i + 2 + syncLineIdx := i + 2 if strings.Contains(lines[i+2], "bitmap") { // skip bitmap line - j = i + 3 + syncLineIdx++ } - // If device is syncing at the moment, get the number of currently + // If device is recovering/syncing at the moment, get the number of currently // synced bytes, otherwise that number equals the size of the device. syncedBlocks := size - if strings.Contains(lines[j], "recovery") || strings.Contains(lines[j], "resync") { - syncedBlocks, err = evalBuildline(lines[j]) + if strings.Contains(lines[syncLineIdx], "recovery") || strings.Contains(lines[syncLineIdx], "resync") { + syncedBlocks, err = evalRecoveryLine(lines[syncLineIdx]) if err != nil { - return mdStates, fmt.Errorf("error parsing %s: %s", mdStatusFilePath, err) + return nil, err } } - mdStates = append(mdStates, MDStat{ + mdStats = append(mdStats, MDStat{ Name: mdName, ActivityState: activityState, DisksActive: active, @@ -109,10 +109,10 @@ func (fs FS) ParseMDStat() (mdstates []MDStat, err error) { }) } - return mdStates, nil + return mdStats, nil } -func evalStatusline(statusline string) (active, total, size int64, err error) { +func evalStatusLine(statusline string) (active, total, size int64, err error) { matches := statuslineRE.FindStringSubmatch(statusline) if len(matches) != 4 { return 0, 0, 0, fmt.Errorf("unexpected statusline: %s", statusline) @@ -136,7 +136,7 @@ func evalStatusline(statusline string) (active, total, size int64, err error) { return active, total, size, nil } -func evalBuildline(buildline string) (syncedBlocks int64, err error) { +func evalRecoveryLine(buildline string) (syncedBlocks int64, err error) { matches := buildlineRE.FindStringSubmatch(buildline) if len(matches) != 2 { return 0, fmt.Errorf("unexpected buildline: %s", buildline) diff --git a/vendor/github.com/prometheus/procfs/net_dev.go b/vendor/github.com/prometheus/procfs/net_dev.go index 8249c984..a0b7a011 100644 --- a/vendor/github.com/prometheus/procfs/net_dev.go +++ b/vendor/github.com/prometheus/procfs/net_dev.go @@ -47,23 +47,13 @@ type NetDevLine struct { // are interface names. type NetDev map[string]NetDevLine -// NewNetDev returns kernel/system statistics read from /proc/net/dev. -func NewNetDev() (NetDev, error) { - fs, err := NewFS(DefaultMountPoint) - if err != nil { - return nil, err - } - - return fs.NewNetDev() -} - -// NewNetDev returns kernel/system statistics read from /proc/net/dev. -func (fs FS) NewNetDev() (NetDev, error) { +// NetDev returns kernel/system statistics read from /proc/net/dev. +func (fs FS) NetDev() (NetDev, error) { return newNetDev(fs.proc.Path("net/dev")) } -// NewNetDev returns kernel/system statistics read from /proc/[pid]/net/dev. -func (p Proc) NewNetDev() (NetDev, error) { +// NetDev returns kernel/system statistics read from /proc/[pid]/net/dev. +func (p Proc) NetDev() (NetDev, error) { return newNetDev(p.path("net/dev")) } diff --git a/vendor/github.com/prometheus/procfs/nfs/nfs.go b/vendor/github.com/prometheus/procfs/nfs/nfs.go index 7ee262f6..96e69ca5 100644 --- a/vendor/github.com/prometheus/procfs/nfs/nfs.go +++ b/vendor/github.com/prometheus/procfs/nfs/nfs.go @@ -275,6 +275,12 @@ type FS struct { proc *fs.FS } +// NewDefaultFS returns a new FS mounted under the default mountPoint. It will error +// if the mount point can't be read. +func NewDefaultFS() (FS, error) { + return NewFS(fs.DefaultProcMountPoint) +} + // NewFS returns a new FS mounted under the given mountPoint. It will error // if the mount point can't be read. func NewFS(mountPoint string) (FS, error) { diff --git a/vendor/github.com/prometheus/procfs/proc.go b/vendor/github.com/prometheus/procfs/proc.go index 8e38493a..8a843014 100644 --- a/vendor/github.com/prometheus/procfs/proc.go +++ b/vendor/github.com/prometheus/procfs/proc.go @@ -54,7 +54,7 @@ func NewProc(pid int) (Proc, error) { if err != nil { return Proc{}, err } - return fs.NewProc(pid) + return fs.Proc(pid) } // AllProcs returns a list of all currently available processes under /proc. @@ -76,11 +76,18 @@ func (fs FS) Self() (Proc, error) { if err != nil { return Proc{}, err } - return fs.NewProc(pid) + return fs.Proc(pid) } // NewProc returns a process for the given pid. +// +// Deprecated: use fs.Proc() instead func (fs FS) NewProc(pid int) (Proc, error) { + return fs.Proc(pid) +} + +// Proc returns a process for the given pid. +func (fs FS) Proc(pid int) (Proc, error) { if _, err := os.Stat(fs.proc.Path(strconv.Itoa(pid))); err != nil { return Proc{}, err } diff --git a/vendor/github.com/prometheus/procfs/proc_io.go b/vendor/github.com/prometheus/procfs/proc_io.go index 0251c83b..0ff89b1c 100644 --- a/vendor/github.com/prometheus/procfs/proc_io.go +++ b/vendor/github.com/prometheus/procfs/proc_io.go @@ -39,8 +39,8 @@ type ProcIO struct { CancelledWriteBytes int64 } -// NewIO creates a new ProcIO instance from a given Proc instance. -func (p Proc) NewIO() (ProcIO, error) { +// IO creates a new ProcIO instance from a given Proc instance. +func (p Proc) IO() (ProcIO, error) { pio := ProcIO{} f, err := os.Open(p.path("io")) diff --git a/vendor/github.com/prometheus/procfs/proc_limits.go b/vendor/github.com/prometheus/procfs/proc_limits.go index f04ba6fd..91ee24df 100644 --- a/vendor/github.com/prometheus/procfs/proc_limits.go +++ b/vendor/github.com/prometheus/procfs/proc_limits.go @@ -78,7 +78,14 @@ var ( ) // NewLimits returns the current soft limits of the process. +// +// Deprecated: use p.Limits() instead func (p Proc) NewLimits() (ProcLimits, error) { + return p.Limits() +} + +// Limits returns the current soft limits of the process. +func (p Proc) Limits() (ProcLimits, error) { f, err := os.Open(p.path("limits")) if err != nil { return ProcLimits{}, err diff --git a/vendor/github.com/prometheus/procfs/proc_ns.go b/vendor/github.com/prometheus/procfs/proc_ns.go index 3f8d6d62..c66740ff 100644 --- a/vendor/github.com/prometheus/procfs/proc_ns.go +++ b/vendor/github.com/prometheus/procfs/proc_ns.go @@ -29,9 +29,9 @@ type Namespace struct { // Namespaces contains all of the namespaces that the process is contained in. type Namespaces map[string]Namespace -// NewNamespaces reads from /proc//ns/* to get the namespaces of which the +// Namespaces reads from /proc//ns/* to get the namespaces of which the // process is a member. -func (p Proc) NewNamespaces() (Namespaces, error) { +func (p Proc) Namespaces() (Namespaces, error) { d, err := os.Open(p.path("ns")) if err != nil { return nil, err diff --git a/vendor/github.com/prometheus/procfs/proc_psi.go b/vendor/github.com/prometheus/procfs/proc_psi.go index a23d4c0f..46fe2662 100644 --- a/vendor/github.com/prometheus/procfs/proc_psi.go +++ b/vendor/github.com/prometheus/procfs/proc_psi.go @@ -51,19 +51,10 @@ type PSIStats struct { Full *PSILine } -// NewPSIStatsForResource reads pressure stall information for the specified -// resource. At time of writing this can be either "cpu", "memory" or "io". -func NewPSIStatsForResource(resource string) (PSIStats, error) { - fs, err := NewFS(DefaultMountPoint) - if err != nil { - return PSIStats{}, err - } - - return fs.NewPSIStatsForResource(resource) -} - -// NewPSIStatsForResource reads pressure stall information from /proc/pressure/ -func (fs FS) NewPSIStatsForResource(resource string) (PSIStats, error) { +// PSIStatsForResource reads pressure stall information for the specified +// resource from /proc/pressure/. At time of writing this can be +// either "cpu", "memory" or "io". +func (fs FS) PSIStatsForResource(resource string) (PSIStats, error) { file, err := os.Open(fs.proc.Path(fmt.Sprintf("%s/%s", "pressure", resource))) if err != nil { return PSIStats{}, fmt.Errorf("psi_stats: unavailable for %s", resource) diff --git a/vendor/github.com/prometheus/procfs/proc_stat.go b/vendor/github.com/prometheus/procfs/proc_stat.go index 4c8b03ce..6ed98a8a 100644 --- a/vendor/github.com/prometheus/procfs/proc_stat.go +++ b/vendor/github.com/prometheus/procfs/proc_stat.go @@ -105,7 +105,14 @@ type ProcStat struct { } // NewStat returns the current status information of the process. +// +// Deprecated: use NewStat() instead func (p Proc) NewStat() (ProcStat, error) { + return p.Stat() +} + +// Stat returns the current status information of the process. +func (p Proc) Stat() (ProcStat, error) { f, err := os.Open(p.path("stat")) if err != nil { return ProcStat{}, err @@ -178,7 +185,7 @@ func (s ProcStat) ResidentMemory() int { // StartTime returns the unix timestamp of the process in seconds. func (s ProcStat) StartTime() (float64, error) { fs := FS{proc: s.proc} - stat, err := fs.NewStat() + stat, err := fs.Stat() if err != nil { return 0, err } diff --git a/vendor/github.com/prometheus/procfs/stat.go b/vendor/github.com/prometheus/procfs/stat.go index 44c9af1b..6661ee03 100644 --- a/vendor/github.com/prometheus/procfs/stat.go +++ b/vendor/github.com/prometheus/procfs/stat.go @@ -20,6 +20,8 @@ import ( "os" "strconv" "strings" + + "github.com/prometheus/procfs/internal/fs" ) // CPUStat shows how much time the cpu spend in various stages. @@ -78,16 +80,6 @@ type Stat struct { SoftIRQ SoftIRQStat } -// NewStat returns kernel/system statistics read from /proc/stat. -func NewStat() (Stat, error) { - fs, err := NewFS(DefaultMountPoint) - if err != nil { - return Stat{}, err - } - - return fs.NewStat() -} - // Parse a cpu statistics line and returns the CPUStat struct plus the cpu id (or -1 for the overall sum). func parseCPUStat(line string) (CPUStat, int64, error) { cpuStat := CPUStat{} @@ -149,9 +141,29 @@ func parseSoftIRQStat(line string) (SoftIRQStat, uint64, error) { return softIRQStat, total, nil } -// NewStat returns an information about current kernel/system statistics. +// NewStat returns information about current cpu/process statistics. +// See https://www.kernel.org/doc/Documentation/filesystems/proc.txt +// +// Deprecated: use fs.Stat() instead +func NewStat() (Stat, error) { + fs, err := NewFS(fs.DefaultProcMountPoint) + if err != nil { + return Stat{}, err + } + return fs.Stat() +} + +// NewStat returns information about current cpu/process statistics. +// See https://www.kernel.org/doc/Documentation/filesystems/proc.txt +// +// Deprecated: use fs.Stat() instead func (fs FS) NewStat() (Stat, error) { - // See https://www.kernel.org/doc/Documentation/filesystems/proc.txt + return fs.Stat() +} + +// Stat returns information about current cpu/process statistics. +// See https://www.kernel.org/doc/Documentation/filesystems/proc.txt +func (fs FS) Stat() (Stat, error) { f, err := os.Open(fs.proc.Path("stat")) if err != nil { diff --git a/vendor/github.com/prometheus/procfs/sysfs/class_power_supply.go b/vendor/github.com/prometheus/procfs/sysfs/class_power_supply.go index 64720efa..90c32e58 100644 --- a/vendor/github.com/prometheus/procfs/sysfs/class_power_supply.go +++ b/vendor/github.com/prometheus/procfs/sysfs/class_power_supply.go @@ -102,18 +102,8 @@ type PowerSupply struct { // The map keys are the names of the power supplies. type PowerSupplyClass map[string]PowerSupply -// NewPowerSupplyClass returns info for all power supplies read from /sys/class/power_supply/. -func NewPowerSupplyClass() (PowerSupplyClass, error) { - fs, err := NewFS(DefaultMountPoint) - if err != nil { - return nil, err - } - - return fs.NewPowerSupplyClass() -} - -// NewPowerSupplyClass returns info for all power supplies read from /sys/class/power_supply/. -func (fs FS) NewPowerSupplyClass() (PowerSupplyClass, error) { +// PowerSupplyClass returns info for all power supplies read from /sys/class/power_supply/. +func (fs FS) PowerSupplyClass() (PowerSupplyClass, error) { path := fs.sys.Path("class/power_supply") powerSupplyDirs, err := ioutil.ReadDir(path) diff --git a/vendor/github.com/prometheus/procfs/sysfs/class_thermal.go b/vendor/github.com/prometheus/procfs/sysfs/class_thermal.go index 2d707958..cfe11ad1 100644 --- a/vendor/github.com/prometheus/procfs/sysfs/class_thermal.go +++ b/vendor/github.com/prometheus/procfs/sysfs/class_thermal.go @@ -35,8 +35,8 @@ type ClassThermalZoneStats struct { 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) { +// ClassThermalZoneStats returns Thermal Zone metrics for all zones. +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 diff --git a/vendor/github.com/prometheus/procfs/sysfs/fs.go b/vendor/github.com/prometheus/procfs/sysfs/fs.go index c0cb9b6c..b3354f3d 100644 --- a/vendor/github.com/prometheus/procfs/sysfs/fs.go +++ b/vendor/github.com/prometheus/procfs/sysfs/fs.go @@ -26,6 +26,12 @@ type FS struct { // DefaultMountPoint is the common mount point of the sys filesystem. const DefaultMountPoint = fs.DefaultSysMountPoint +// NewDefaultFS returns a new FS mounted under the default mountPoint. It will error +// if the mount point can't be read. +func NewDefaultFS() (FS, error) { + return NewFS(DefaultMountPoint) +} + // NewFS returns a new FS mounted under the given mountPoint. It will error // if the mount point can't be read. func NewFS(mountPoint string) (FS, error) { diff --git a/vendor/github.com/prometheus/procfs/sysfs/net_class.go b/vendor/github.com/prometheus/procfs/sysfs/net_class.go index c28051e3..909f7fb3 100644 --- a/vendor/github.com/prometheus/procfs/sysfs/net_class.go +++ b/vendor/github.com/prometheus/procfs/sysfs/net_class.go @@ -65,16 +65,6 @@ type NetClassIface struct { // are interface (iface) names. type NetClass map[string]NetClassIface -// NewNetClass returns info for all net interfaces (iface) read from /sys/class/net/. -func NewNetClass() (NetClass, error) { - fs, err := NewFS(DefaultMountPoint) - if err != nil { - return nil, err - } - - return fs.NewNetClass() -} - // NetClassDevices scans /sys/class/net for devices and returns them as a list of names. func (fs FS) NetClassDevices() ([]string, error) { var res []string @@ -95,8 +85,8 @@ func (fs FS) NetClassDevices() ([]string, error) { return res, nil } -// NewNetClass returns info for all net interfaces (iface) read from /sys/class/net/. -func (fs FS) NewNetClass() (NetClass, error) { +// NetClass returns info for all net interfaces (iface) read from /sys/class/net/. +func (fs FS) NetClass() (NetClass, error) { devices, err := fs.NetClassDevices() if err != nil { return nil, err diff --git a/vendor/github.com/prometheus/procfs/sysfs/system_cpu.go b/vendor/github.com/prometheus/procfs/sysfs/system_cpu.go index 4bcf86b2..001039cf 100644 --- a/vendor/github.com/prometheus/procfs/sysfs/system_cpu.go +++ b/vendor/github.com/prometheus/procfs/sysfs/system_cpu.go @@ -46,18 +46,8 @@ type SystemCPUCpufreqStats struct { // TODO: Add thermal_throttle support. -// NewSystemCpufreq returns CPU frequency metrics for all CPUs. -func NewSystemCpufreq() ([]SystemCPUCpufreqStats, error) { - fs, err := NewFS(DefaultMountPoint) - if err != nil { - return []SystemCPUCpufreqStats{}, err - } - - return fs.NewSystemCpufreq() -} - -// NewSystemCpufreq returns CPU frequency metrics for all CPUs. -func (fs FS) NewSystemCpufreq() ([]SystemCPUCpufreqStats, error) { +// SystemCpufreq returns CPU frequency metrics for all CPUs. +func (fs FS) SystemCpufreq() ([]SystemCPUCpufreqStats, error) { var g errgroup.Group cpus, err := filepath.Glob(fs.sys.Path("devices/system/cpu/cpu[0-9]*")) diff --git a/vendor/github.com/prometheus/procfs/xfs/xfs.go b/vendor/github.com/prometheus/procfs/xfs/xfs.go index 8a7288f8..3aad6617 100644 --- a/vendor/github.com/prometheus/procfs/xfs/xfs.go +++ b/vendor/github.com/prometheus/procfs/xfs/xfs.go @@ -177,6 +177,12 @@ type FS struct { sys *fs.FS } +// NewDefaultFS returns a new XFS handle using the default proc and sys mountPoints. +// It will error if either of the mounts point can't be read. +func NewDefaultFS() (FS, error) { + return NewFS(fs.DefaultProcMountPoint, fs.DefaultSysMountPoint) +} + // NewFS returns a new XFS handle using the given proc and sys mountPoints. It will error // if either of the mounts point can't be read. func NewFS(procMountPoint string, sysMountPoint string) (FS, error) { diff --git a/vendor/modules.txt b/vendor/modules.txt index 86bf4f23..0227700a 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -45,7 +45,7 @@ github.com/prometheus/common/version github.com/prometheus/common/expfmt github.com/prometheus/common/model github.com/prometheus/common/internal/bitbucket.org/ww/goautoneg -# github.com/prometheus/procfs v0.0.0-20190529155944-65bdadfa96ae +# github.com/prometheus/procfs v0.0.2 github.com/prometheus/procfs github.com/prometheus/procfs/bcache github.com/prometheus/procfs/nfs