File tree Expand file tree Collapse file tree 2 files changed +47
-61
lines changed Expand file tree Collapse file tree 2 files changed +47
-61
lines changed Original file line number Diff line number Diff line change 13
13
14
14
package prometheus
15
15
16
+ import "github.com/prometheus/procfs"
17
+
16
18
type processCollector struct {
17
19
pid int
18
20
collectFn func (chan <- Metric )
@@ -100,3 +102,48 @@ func (c *processCollector) Describe(ch chan<- *Desc) {
100
102
func (c * processCollector ) Collect (ch chan <- Metric ) {
101
103
c .collectFn (ch )
102
104
}
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
+ }
Load Diff This file was deleted.
You can’t perform that action at this time.
0 commit comments