I have a python application that runs periodically. Sometimes I call a second or third instance of the application to run concurrently. It is basically a job. Included in my app are a prometheus Counter and the initialization of the prometheus_http_server. Everything works fine, however, when a second instance of my application is ran, the new instance immediately fails because the prometheus web server port is already assigned. That part makes sense, but how do I initialize the prometheus http server to view the metrics scraped from multiple instances of the same application?
If I don't initialize the web server in the same app as my counter metrics, where do my counter metrics go and how can I access them? Can I point my counter metrics somewhere outside of my application? Is there a way for a prometheus server instance to collect metrics from different apps?
I have read the the entire readme for the python client library but it is scant and terse so it has not been very useful. I'm certain there is an elegant way to achieve this but I'm not sure how.
Here is a pseudo-code version of my app:
from prometheus_client import start_http_server, Counter
def time_consuming_task():
c = Counter('name', 'description')
my_process()
my_other_process()
c.inc()
def main():
start_http_server()
time_consuming_task()
if __name__ == '__main__':
main()