Prometheus 函数装饰器,带有在运行时初始化的标签
Prometheus function decorator with labels initialized during runtime
我已经看过这个帖子:https://github.com/prometheus/client_python/issues/157
我想知道是否有一种方法可以将函数装饰器语法与稍后实例化的标签一起使用?我需要先从另一个服务中获取标签值。我目前正在填写一些虚拟值,这些值会给我重复的指标,但这实际上不起作用:
inference_time_created{edge="EMPTY_SCOPE",line="EMPTY_SCOPE",module="EMPTY_SCOPE",plant="EMPTY_SCOPE",workload="EMPTY_SCOPE"} 1.6311126626366935e+09
inference_time_created{edge="ACTUAL_VALUE",line="ACTUAL_VALUE",module="ACTUAL_VALUE",plant="ACTUAL_VALUE",workload="ACTUAL_VALUE"} 1.6311126626709173e+09
所以我的问题是,是否有办法在端点上不使用 EMPTY_SCOPE 指标。
这是我正在做的事情的基本思路:
scope_keys = ["plant", "edge", "line", "workload", "module"]
scope_values = ["EMPTY_SCOPE"] * 5
inference_time_created= Gauge('inference_time', 'How long (in seconds) does it take for an inference', scope_keys)
inference_time_created_labeled = inference_time_created.labels(*scope_values)
def set_metrics_scope(scope): # this function gets called later in the main code
scope_values = scope
inference_time_created_labeled = inference_time_created.labels(*scope_values)
@inference_time_created_labeled.time()
def inference():
# do some calculations
无法弄清楚如何使用函数装饰器来做到这一点,而是使用有效的上下文管理器符号。
我已经看过这个帖子:https://github.com/prometheus/client_python/issues/157 我想知道是否有一种方法可以将函数装饰器语法与稍后实例化的标签一起使用?我需要先从另一个服务中获取标签值。我目前正在填写一些虚拟值,这些值会给我重复的指标,但这实际上不起作用:
inference_time_created{edge="EMPTY_SCOPE",line="EMPTY_SCOPE",module="EMPTY_SCOPE",plant="EMPTY_SCOPE",workload="EMPTY_SCOPE"} 1.6311126626366935e+09
inference_time_created{edge="ACTUAL_VALUE",line="ACTUAL_VALUE",module="ACTUAL_VALUE",plant="ACTUAL_VALUE",workload="ACTUAL_VALUE"} 1.6311126626709173e+09
所以我的问题是,是否有办法在端点上不使用 EMPTY_SCOPE 指标。
这是我正在做的事情的基本思路:
scope_keys = ["plant", "edge", "line", "workload", "module"]
scope_values = ["EMPTY_SCOPE"] * 5
inference_time_created= Gauge('inference_time', 'How long (in seconds) does it take for an inference', scope_keys)
inference_time_created_labeled = inference_time_created.labels(*scope_values)
def set_metrics_scope(scope): # this function gets called later in the main code
scope_values = scope
inference_time_created_labeled = inference_time_created.labels(*scope_values)
@inference_time_created_labeled.time()
def inference():
# do some calculations
无法弄清楚如何使用函数装饰器来做到这一点,而是使用有效的上下文管理器符号。