我正在使用Python Prometheus库来检测我的应用程序。让我们假设我有以下代码:
from prometheus_client import start_http_server, Counter
data = {}
data['locations'] = 'berlin'
for i in data['location']
metric = Counter("location_service_" + i + "_http_requests_count", "This metric tracks the requests from location: " + i)
metric.inc(1)我正在为“度量”而苦苦挣扎,我如何才能基于"location“值来实现这个动态呢?
发布于 2021-11-11 08:15:02
最好使用标签,而不是更改指标名称。使用标签可以更轻松地创建仪表板/警报。下面是操作步骤:
from prometheus_client import start_http_server, Counter
label_names = ['location']
c = Counter("metric_name", "metric_descr", labelnames=label_names)
c.labels(location="berlin").inc()然后您可以像这样查询此指标的值:
metric_name{location="berlin"}有关查询here的更多信息,我还鼓励您阅读有关命名的best practices。
https://stackoverflow.com/questions/69924757
复制相似问题