Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

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.

Đánh giá

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

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.

Mô tả

feature

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.

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

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.

Issue khác của prometheus/client_python

Tất cả issue của prometheus/client_python

Issue tương tự

Thêm issue về Python

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.