prometheus / prometheus/client_python
Default namespace/prefix for all exported metrics?
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ả
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
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- 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.
- Fork repository và làm thay đổi trên một nhánh.
- 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