mirror of
https://github.com/prometheus/node_exporter.git
synced 2024-12-25 05:34:10 -08:00
update procfs to v0.0.2 (#1376)
Signed-off-by: Paul Gier <pgier@redhat.com>
This commit is contained in:
parent
0759c0ac01
commit
2bc133cd48
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
2
go.mod
2
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
|
||||
|
|
4
go.sum
4
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=
|
||||
|
|
|
@ -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 {
|
||||
|
|
11
vendor/github.com/prometheus/procfs/README.md
generated
vendored
11
vendor/github.com/prometheus/procfs/README.md
generated
vendored
|
@ -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`.
|
||||
|
|
6
vendor/github.com/prometheus/procfs/bcache/get.go
generated
vendored
6
vendor/github.com/prometheus/procfs/bcache/get.go
generated
vendored
|
@ -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) {
|
||||
|
|
12
vendor/github.com/prometheus/procfs/buddyinfo.go
generated
vendored
12
vendor/github.com/prometheus/procfs/buddyinfo.go
generated
vendored
|
@ -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
|
||||
|
|
6
vendor/github.com/prometheus/procfs/fs.go
generated
vendored
6
vendor/github.com/prometheus/procfs/fs.go
generated
vendored
|
@ -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) {
|
||||
|
|
28
vendor/github.com/prometheus/procfs/ipvs.go
generated
vendored
28
vendor/github.com/prometheus/procfs/ipvs.go
generated
vendored
|
@ -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
|
||||
|
|
74
vendor/github.com/prometheus/procfs/mdstat.go
generated
vendored
74
vendor/github.com/prometheus/procfs/mdstat.go
generated
vendored
|
@ -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)
|
||||
|
|
18
vendor/github.com/prometheus/procfs/net_dev.go
generated
vendored
18
vendor/github.com/prometheus/procfs/net_dev.go
generated
vendored
|
@ -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"))
|
||||
}
|
||||
|
||||
|
|
6
vendor/github.com/prometheus/procfs/nfs/nfs.go
generated
vendored
6
vendor/github.com/prometheus/procfs/nfs/nfs.go
generated
vendored
|
@ -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) {
|
||||
|
|
11
vendor/github.com/prometheus/procfs/proc.go
generated
vendored
11
vendor/github.com/prometheus/procfs/proc.go
generated
vendored
|
@ -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
|
||||
}
|
||||
|
|
4
vendor/github.com/prometheus/procfs/proc_io.go
generated
vendored
4
vendor/github.com/prometheus/procfs/proc_io.go
generated
vendored
|
@ -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"))
|
||||
|
|
7
vendor/github.com/prometheus/procfs/proc_limits.go
generated
vendored
7
vendor/github.com/prometheus/procfs/proc_limits.go
generated
vendored
|
@ -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
|
||||
|
|
4
vendor/github.com/prometheus/procfs/proc_ns.go
generated
vendored
4
vendor/github.com/prometheus/procfs/proc_ns.go
generated
vendored
|
@ -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/<pid>/ns/* to get the namespaces of which the
|
||||
// Namespaces reads from /proc/<pid>/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
|
||||
|
|
17
vendor/github.com/prometheus/procfs/proc_psi.go
generated
vendored
17
vendor/github.com/prometheus/procfs/proc_psi.go
generated
vendored
|
@ -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/<resource>
|
||||
func (fs FS) NewPSIStatsForResource(resource string) (PSIStats, error) {
|
||||
// PSIStatsForResource reads pressure stall information for the specified
|
||||
// resource from /proc/pressure/<resource>. 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)
|
||||
|
|
9
vendor/github.com/prometheus/procfs/proc_stat.go
generated
vendored
9
vendor/github.com/prometheus/procfs/proc_stat.go
generated
vendored
|
@ -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
|
||||
}
|
||||
|
|
36
vendor/github.com/prometheus/procfs/stat.go
generated
vendored
36
vendor/github.com/prometheus/procfs/stat.go
generated
vendored
|
@ -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 {
|
||||
|
|
14
vendor/github.com/prometheus/procfs/sysfs/class_power_supply.go
generated
vendored
14
vendor/github.com/prometheus/procfs/sysfs/class_power_supply.go
generated
vendored
|
@ -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)
|
||||
|
|
4
vendor/github.com/prometheus/procfs/sysfs/class_thermal.go
generated
vendored
4
vendor/github.com/prometheus/procfs/sysfs/class_thermal.go
generated
vendored
|
@ -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
|
||||
|
|
6
vendor/github.com/prometheus/procfs/sysfs/fs.go
generated
vendored
6
vendor/github.com/prometheus/procfs/sysfs/fs.go
generated
vendored
|
@ -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) {
|
||||
|
|
14
vendor/github.com/prometheus/procfs/sysfs/net_class.go
generated
vendored
14
vendor/github.com/prometheus/procfs/sysfs/net_class.go
generated
vendored
|
@ -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/<iface>.
|
||||
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/<iface>.
|
||||
func (fs FS) NewNetClass() (NetClass, error) {
|
||||
// NetClass returns info for all net interfaces (iface) read from /sys/class/net/<iface>.
|
||||
func (fs FS) NetClass() (NetClass, error) {
|
||||
devices, err := fs.NetClassDevices()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
14
vendor/github.com/prometheus/procfs/sysfs/system_cpu.go
generated
vendored
14
vendor/github.com/prometheus/procfs/sysfs/system_cpu.go
generated
vendored
|
@ -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]*"))
|
||||
|
|
6
vendor/github.com/prometheus/procfs/xfs/xfs.go
generated
vendored
6
vendor/github.com/prometheus/procfs/xfs/xfs.go
generated
vendored
|
@ -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) {
|
||||
|
|
2
vendor/modules.txt
vendored
2
vendor/modules.txt
vendored
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue