python prometheus

问题

  1. 对于sanic app,如果不是全局的共享内存,不同worker是分开统计的,导致从接口获取的数据有随机性(时而来源于worker1,时而来源于worker2),多进程模式支持合并输出,需要通过环境变量指定空目录

    • 多进程模式: os.environ["prometheus_multiproc_dir"] = "."
    • sanic_prometheus: start_http_server不支持多进程模式
      • 如果使用main_process_start初始化metric_init, 对于多worker,worker进程设置的metric inc/observe不生效。因为woker进程是主进程的子进程,inc或者observe是在子进程写入的

参考资料

  1. https://prometheus.io/docs/concepts/metric_types/
  2. https://github.com/prometheus/client_python
  3. https://pyk.medium.com/a-guide-to-instrument-sanic-application-part-1-193b3eb403a
posted @ 2022-04-25 16:50  春树&暮云  阅读(133)  评论(0编辑  收藏  举报