I have main() function which spawns two separate sub-processes. These both sub-process shares metrics. How can I share metrics for both process and keep it updating? Here, is my snippet for more understanding.
from multiprocessing import Process
import prometheus_client as prom
from prometheus_client import Counter
# Metrics
c1 = prom.gauge('Counter1', 'Number of Request')
c2 = prom.gauge('Gauge1', 'Processing time in Seconds')
def process_abc():
while True:
#Some operations
c1.set(some_value)
c2.set(some_value)
time.sleep(10)
def process_xyz():
while True:
#Some operations
c1.set(some_value)
c2.set(some_value)
time.sleep(10)
def main():
prom.start_http_server(8080)
Process(target=process_abc).start()
Process(target=process_xyz).start()
if __name__ == "__main__":
main()
I was able to see metrics name at endpoint but count is always zero means it's never updated by sub-process.