33from __future__ import unicode_literals
44
55import os
6- import time
7- import threading
86
97from . import core
108try :
11- import resource
12- _PAGESIZE = resource .getpagesize ()
9+ import resource
10+ _PAGESIZE = resource .getpagesize ()
1311except ImportError :
14- # Not Unix
15- _PAGESIZE = 4096
12+ # Not Unix
13+ _PAGESIZE = 4096
1614
1715
1816class ProcessCollector (object ):
@@ -38,7 +36,7 @@ def __init__(self, namespace='', pid=lambda: 'self', proc='/proc', registry=core
3836 except IOError :
3937 pass
4038 if registry :
41- registry .register (self )
39+ registry .register (self )
4240
4341 def _boot_time (self ):
4442 with open (os .path .join (self ._proc , 'stat' )) as stat :
@@ -50,27 +48,25 @@ def collect(self):
5048 if not self ._btime :
5149 return []
5250
53- try :
54- pid = os .path .join (self ._proc , str (self ._pid ()).strip ())
55- except :
56- # File likely didn't exist, fail silently.
57- raise
58- return []
51+ pid = os .path .join (self ._proc , str (self ._pid ()).strip ())
5952
6053 result = []
6154 try :
6255 with open (os .path .join (pid , 'stat' )) as stat :
6356 parts = (stat .read ().split (')' )[- 1 ].split ())
6457 vmem = core .GaugeMetricFamily (self ._prefix + 'virtual_memory_bytes' ,
65- 'Virtual memory size in bytes.' , value = float (parts [20 ]))
66- rss = core .GaugeMetricFamily (self ._prefix + 'resident_memory_bytes' , 'Resident memory size in bytes.' , value = float (parts [21 ]) * _PAGESIZE )
58+ 'Virtual memory size in bytes.' , value = float (parts [20 ]))
59+ rss = core .GaugeMetricFamily (self ._prefix + 'resident_memory_bytes' , 'Resident memory size in bytes.' ,
60+ value = float (parts [21 ]) * _PAGESIZE )
6761 start_time_secs = float (parts [19 ]) / self ._ticks
6862 start_time = core .GaugeMetricFamily (self ._prefix + 'start_time_seconds' ,
69- 'Start time of the process since unix epoch in seconds.' , value = start_time_secs + self ._btime )
63+ 'Start time of the process since unix epoch in seconds.' ,
64+ value = start_time_secs + self ._btime )
7065 utime = float (parts [11 ]) / self ._ticks
7166 stime = float (parts [12 ]) / self ._ticks
7267 cpu = core .CounterMetricFamily (self ._prefix + 'cpu_seconds_total' ,
73- 'Total user and system CPU time spent in seconds.' , value = utime + stime )
68+ 'Total user and system CPU time spent in seconds.' ,
69+ value = utime + stime )
7470 result .extend ([vmem , rss , start_time , cpu ])
7571 except IOError :
7672 pass
@@ -80,10 +76,12 @@ def collect(self):
8076 for line in limits :
8177 if line .startswith ('Max open file' ):
8278 max_fds = core .GaugeMetricFamily (self ._prefix + 'max_fds' ,
83- 'Maximum number of open file descriptors.' , value = float (line .split ()[3 ]))
79+ 'Maximum number of open file descriptors.' ,
80+ value = float (line .split ()[3 ]))
8481 break
8582 open_fds = core .GaugeMetricFamily (self ._prefix + 'open_fds' ,
86- 'Number of open file descriptors.' , len (os .listdir (os .path .join (pid , 'fd' ))))
83+ 'Number of open file descriptors.' ,
84+ len (os .listdir (os .path .join (pid , 'fd' ))))
8785 result .extend ([open_fds , max_fds ])
8886 except IOError :
8987 pass
0 commit comments