prometheus / prometheus/client_python

Default namespace/prefix for all exported metrics?

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

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

feature
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ả

Is there a way to define a default, global prefix for all metrics?

For example instead of:
python_gc_objects_collected_total

I'd like to add the prefix myproject_:
myproject_python_gc_objects_collected_total

I'm currently doing it like that:

_original_generate_latest = prometheus_client.openmetrics.exposition.generate_latest


def init_prometheus(namespace):
    def new_generate_latest(*args, **kwargs):
        original_output = _original_generate_latest(*args, **kwargs).decode('utf-8')
        namespace_prefix = namespace + '_'
        new_output = ''

        for line in original_output.splitlines():
            if not line.startswith('#') and not line.startswith(namespace_prefix):
                new_output += namespace_prefix

            new_output += line + '\n'

        new_output = new_output.encode('utf-8')

        return new_output

    prometheus_client.generate_latest = new_generate_latest

But it doesn't always work. For example, prometheus_client.start_http_server ignores this function for whatever reason.

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 bằng cách lần theo hàm generate_latest được expose và entry point prometheus_client.start_http_server được đề cập trong issue. Xác định các metric được export được tạo ra như thế nào qua từng đường dẫn, và định nghĩa hoàn thành là áp dụng nhất quán một prefix được cấu hình cho tất cả metric được export mà không monkey-patching.

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

Đánh giá

Công nghệ
prometheus, python
Lĩnh vực
observability
Loại issue
Tính năng
Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Khá rõ ràng
Mức phù hợp với người mới
35/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.