Skip to content
Merged
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
13 changes: 7 additions & 6 deletions prometheus_client/process_collector.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ def __init__(self, namespace='', pid=lambda: 'self', proc='/proc', registry=core
registry.register(self)

def _boot_time(self):
with open(os.path.join(self._proc, 'stat')) as stat:
with open(os.path.join(self._proc, 'stat'), 'rb') as stat:
for line in stat:
if line.startswith('btime '):
if line.startswith(b'btime '):
return float(line.split()[1])

def collect(self):
Expand All @@ -52,8 +52,9 @@ def collect(self):

result = []
try:
with open(os.path.join(pid, 'stat')) as stat:
parts = (stat.read().split(')')[-1].split())
with open(os.path.join(pid, 'stat'), 'rb') as stat:
parts = (stat.read().split(b')')[-1].split())

vmem = core.GaugeMetricFamily(self._prefix + 'virtual_memory_bytes',
'Virtual memory size in bytes.', value=float(parts[20]))
rss = core.GaugeMetricFamily(self._prefix + 'resident_memory_bytes', 'Resident memory size in bytes.',
Expand All @@ -72,9 +73,9 @@ def collect(self):
pass

try:
with open(os.path.join(pid, 'limits')) as limits:
with open(os.path.join(pid, 'limits'), 'rb') as limits:
for line in limits:
if line.startswith('Max open file'):
if line.startswith(b'Max open file'):
max_fds = core.GaugeMetricFamily(self._prefix + 'max_fds',
'Maximum number of open file descriptors.',
value=float(line.split()[3]))
Expand Down