小编Pav*_*tov的帖子

Prometheus 如何使用 start_http_server 在多进程应用程序中公开指标

如何使用 start_http_server 公开多进程应用程序中的指标

我在互联网上找到了很多gunicorn的例子,但我想使用start_http_server

我应该如何处理下面的代码才能使其正常工作?

from multiprocessing import Process
import time, os
from prometheus_client import start_http_server, multiprocess, CollectorRegistry, Counter


MY_COUNTER = Counter('my_counter', 'Description of my counter')
os.environ["PROMETHEUS_MULTIPROC_DIR"] = "tmp"

def f():
    print("+1")
    MY_COUNTER.inc()

if __name__ == '__main__':
    start_http_server(8000)
    p = Process(target=f, args=())
    a = p.start()
    p2 = Process(target=f, args=())
    p2.start()
    time.sleep(1)
    print("collect")
    registry = CollectorRegistry()
    data = multiprocess.MultiProcessCollector(registry)
    while True:
        time.sleep(1)
Run Code Online (Sandbox Code Playgroud)

python multiprocessing multiprocess prometheus

6
推荐指数
1
解决办法
6129
查看次数