I have a service which currently exposes metrics with a prometheus client at port 8000.
I want to change this process to be a controlling parent process, who spawns one (independent) child process per "thing" i.e. the child process is parameterised by thing_id
and the parent calls systemctl start child@thing_id
The metrics exposed are independent per "thing", so I still want to expose these metrics per process, using a label thing
to identify and analyse accordingly.
However it seems I must run start_http_server(8000)
within each service, which will error due to "port already in use". I have tried only starting the server in the parent process, but none of the metrics from the child processes are observed.
I could define some port range and have one http server per process, and increase my number of targets accordingly, but that seems rather clunky.
I have looked into https://github.com/prometheus/client_python/blob/master/prometheus_client/multiprocess.py which I believe may be a solution, but thought there might be an easier way just using subprocessing and systemctl ...