prometheus / prometheus/client_python

Duplicated timeseries in CollectorRegistry with Multiprocess Gunicorn

Đang mở
#815 2 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Ngôn ngữ chính
Python
Star
4.4k
Fork
876
Merge trung bình
8 ngày 4 giờ
Pull request đã merge (30 ngày)
1

Mô tả

I know this is a subject that comes up somewhat frequently but for the love of me I can't figure out what I'm doing wrong.

  1. I have a service in Amazon ECS thats running a single task with multiple workers (actually the problem happens in my other service that just has one worker also).

  2. I've created the directory and set the PROMETHEUS_MULTIPROC_DIR in the Dockerfile:

RUN mkdir -p /tmp/prom-metrics
ENV PROMETHEUS_MULTIPROC_DIR /tmp/prom-metrics
  1. I'm using the sample code in the README to create the registry in the /metrics request and return it:
registry = CollectorRegistry()
if getenv('PROMETHEUS_MULTIPROC_DIR'):
  multiprocess.MultiProcessCollector(registry)
data = generate_latest(registry)
status = '200 OK'
response_headers = [
    ('Content-type', CONTENT_TYPE_LATEST),
    ('Content-Length', str(len(data))),
]
return Response(data, status, response_headers)
  1. I've created the gunicorn.conf.py file with the sample from the README and passed it into my gunicorn startup script via -c:
from prometheus_client import multiprocess

def child_exit(server, worker):
    multiprocess.mark_process_dead(worker.pid)

In my two services, gunicorn starts them as follows:

# app 1 with workers
gunicorn -c /app/utils/gunicorn.conf.py -b :5000 -t 3600 --keep-alive 60 --threads 8 --workers 3 app:app

# app 2 without workers
gunicorn -c /app/utils/gunicorn.conf.py -b :5000 -t 3600 --keep-alive 60 --threads 8 app:app

The service boots successfully and accepts some metrics which are definitely collected in multiprocess mode, seeing as the HELP line simply displays Multiprocess metric.

This works for a few calls but eventually I get the dreaded Duplicated timeseries in CollectorRegistry error and no additional metrics are populated.

What might I be doing wrong?

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Hướng nghiên cứu

Bắt đầu với ví dụ về metrics multiprocess trong README và cấu hình gunicorn.conf.py được tham chiếu, sau đó tái hiện lỗi bằng các thiết lập trong Dockerfile và các lệnh Gunicorn được hiển thị. Công việc được xem là hoàn tất khi xác định được nguyên nhân của lỗi timeseries trùng lặp và ghi lại hoặc sửa cấu hình để /metrics tiếp tục trả về metrics.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
docker, prometheus, python
Lĩnh vực
observability
Loại issue
Lỗi
Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Cần làm rõ
Mức phù hợp với người mới
25/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.