Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions prometheus/process_collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

package prometheus

import "github.com/prometheus/procfs"

type processCollector struct {
pid int
collectFn func(chan<- Metric)
Expand Down Expand Up @@ -100,3 +102,48 @@ func (c *processCollector) Describe(ch chan<- *Desc) {
func (c *processCollector) Collect(ch chan<- Metric) {
c.collectFn(ch)
}

func processCollectSupported() bool {
if _, err := procfs.NewStat(); err == nil {
return true
}
return false
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This indirection isn't really necessary anymore. You can replace the if processCollectSupported with the condition above.


// TODO(ts): Bring back error reporting by reverting 7faf9e7 as soon as the
// client allows users to configure the error behavior.
func (c *processCollector) processCollect(ch chan<- Metric) {
pid, err := c.pidFn()
if err != nil {
return
}

p, err := procfs.NewProc(pid)
if err != nil {
return
}

if stat, err := p.NewStat(); err == nil {
c.cpuTotal.Set(stat.CPUTime())
ch <- c.cpuTotal
c.vsize.Set(float64(stat.VirtualMemory()))
ch <- c.vsize
c.rss.Set(float64(stat.ResidentMemory()))
ch <- c.rss

if startTime, err := stat.StartTime(); err == nil {
c.startTime.Set(startTime)
ch <- c.startTime
}
}

if fds, err := p.FileDescriptorsLen(); err == nil {
c.openFDs.Set(float64(fds))
ch <- c.openFDs
}

if limits, err := p.NewLimits(); err == nil {
c.maxFDs.Set(float64(limits.OpenFiles))
ch <- c.maxFDs
}
}
63 changes: 0 additions & 63 deletions prometheus/process_collector_procfs.go

This file was deleted.

24 changes: 0 additions & 24 deletions prometheus/process_collector_rest.go

This file was deleted.