-
Notifications
You must be signed in to change notification settings - Fork 845
MultiProcessCollector.collect() crashing on missing files #425
Copy link
Copy link
Closed
Description
Hello,
When you've used a lot of pids and have a lot of metrics files lying around, there is a high probability that mark_process_dead
client_python/prometheus_client/multiprocess.py
Lines 140 to 147 in 8a4f2de
| def mark_process_dead(pid, path=None): | |
| """Do bookkeeping for when one process dies in a multi-process setup.""" | |
| if path is None: | |
| path = os.environ.get('prometheus_multiproc_dir') | |
| for f in glob.glob(os.path.join(path, 'gauge_livesum_{0}.db'.format(pid))): | |
| os.remove(f) | |
| for f in glob.glob(os.path.join(path, 'gauge_liveall_{0}.db'.format(pid))): | |
| os.remove(f) |
will be called between the
glob.glob call and the self.merge one:client_python/prometheus_client/multiprocess.py
Lines 136 to 137 in 8a4f2de
| files = glob.glob(os.path.join(self._path, '*.db')) | |
| return self.merge(files, accumulate=True) |
leading to:
$ prometheus_multiproc_dir=/tmp/prometheus_metrics python
Python 3.7.3 (default, May 8 2019, 05:31:59)
[GCC 6.3.0 20170516] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from prometheus_client import multiprocess
>>> from prometheus_client import generate_latest, CollectorRegistry
>>> registry = CollectorRegistry()
>>> multiprocess.MultiProcessCollector(registry)
<prometheus_client.multiprocess.MultiProcessCollector object at 0x7ffb0b1efa58>
>>> data = generate_latest(registry)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/grocker/app.venv/lib/python3.7/site-packages/prometheus_client/exposition.py", line 89, in generate_latest
for metric in registry.collect():
File "/home/grocker/app.venv/lib/python3.7/site-packages/prometheus_client/registry.py", line 75, in collect
for metric in collector.collect():
File "/home/grocker/app.venv/lib/python3.7/site-packages/prometheus_client/multiprocess.py", line 30, in collect
return self.merge(files, accumulate=True)
File "/home/grocker/app.venv/lib/python3.7/site-packages/prometheus_client/multiprocess.py", line 43, in merge
d = MmapedDict(f, read_mode=True)
File "/home/grocker/app.venv/lib/python3.7/site-packages/prometheus_client/mmap_dict.py", line 39, in __init__
self._f = open(filename, 'rb' if read_mode else 'a+b')
FileNotFoundError: [Errno 2] No such file or directory: '/tmp/prometheus_metrics/gauge_livesum_37367.db'
An easy fix could be #424.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels