Skip to content

Commit 8ba7a93

Browse files
committed
Merge pull request #103 from prometheus/always-build-proc-collector
Always build the procfs collector.
2 parents 7fcf9f7 + 2b9d181 commit 8ba7a93

File tree

3 files changed

+47
-87
lines changed

3 files changed

+47
-87
lines changed

prometheus/process_collector.go

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313

1414
package prometheus
1515

16+
import "github.com/prometheus/procfs"
17+
1618
type processCollector struct {
1719
pid int
1820
collectFn func(chan<- Metric)
@@ -100,3 +102,48 @@ func (c *processCollector) Describe(ch chan<- *Desc) {
100102
func (c *processCollector) Collect(ch chan<- Metric) {
101103
c.collectFn(ch)
102104
}
105+
106+
func processCollectSupported() bool {
107+
if _, err := procfs.NewStat(); err == nil {
108+
return true
109+
}
110+
return false
111+
}
112+
113+
// TODO(ts): Bring back error reporting by reverting 7faf9e7 as soon as the
114+
// client allows users to configure the error behavior.
115+
func (c *processCollector) processCollect(ch chan<- Metric) {
116+
pid, err := c.pidFn()
117+
if err != nil {
118+
return
119+
}
120+
121+
p, err := procfs.NewProc(pid)
122+
if err != nil {
123+
return
124+
}
125+
126+
if stat, err := p.NewStat(); err == nil {
127+
c.cpuTotal.Set(stat.CPUTime())
128+
ch <- c.cpuTotal
129+
c.vsize.Set(float64(stat.VirtualMemory()))
130+
ch <- c.vsize
131+
c.rss.Set(float64(stat.ResidentMemory()))
132+
ch <- c.rss
133+
134+
if startTime, err := stat.StartTime(); err == nil {
135+
c.startTime.Set(startTime)
136+
ch <- c.startTime
137+
}
138+
}
139+
140+
if fds, err := p.FileDescriptorsLen(); err == nil {
141+
c.openFDs.Set(float64(fds))
142+
ch <- c.openFDs
143+
}
144+
145+
if limits, err := p.NewLimits(); err == nil {
146+
c.maxFDs.Set(float64(limits.OpenFiles))
147+
ch <- c.maxFDs
148+
}
149+
}

prometheus/process_collector_procfs.go

Lines changed: 0 additions & 63 deletions
This file was deleted.

prometheus/process_collector_rest.go

Lines changed: 0 additions & 24 deletions
This file was deleted.

0 commit comments

Comments
 (0)