FileNotFoundError Prometheus Python Client write_to_textfile

395 views Asked by At

I want to log something to a text file using the Prometheus Python Client, with the below code. Just these three lines for testing purposes:

from prometheus_client import CollectorRegistry, write_to_textfile

registry = CollectorRegistry()
write_to_textfile('~/log.prom', registry)

when running the script an error is thrown that the file does not exist. The file ~/log.prom exists, but ~/log.prom.3872.139652924150208 does not... this filename also changes every time when running the script.

Traceback (most recent call last):
  File "/home/joost/log-to-text.py", line 4, in <module>
    write_to_textfile('~/log.prom', registry)
  File "/home/joost/.local/lib/python3.10/site-packages/prometheus_client/exposition.py", line 303, in write_to_textfile
    with open(tmppath, 'wb') as f:
FileNotFoundError: [Errno 2] No such file or directory: '~/log.prom.3872.139652924150208'

Not sure what is messing this up, just following the code snippet in the github documentation https://github.com/prometheus/client_python#node-exporter-textfile-collector

0

There are 0 answers