我可以在Python中设置Prometheus标签的默认值吗?

Kre*_*zon 7 python python-2.7 prometheus

我正在使用官方 python (2.7) 客户端。

我想用一些标签定义一个指标,但我并不总是让它们发送所有标签。当我只发送其中一些时,我收到错误:

AttributeError:“计数器”对象没有属性“_value”

这是我使用的代码:

c = Counter("counterTest, "explain this counter, labelnames=("label1", "label2",), namespace="namespace") 
c.labels(label1="1").inc(1)
Run Code Online (Sandbox Code Playgroud)

这是 python 库的限制吗?或者这可能是 Prometheus 端的限制?

bri*_*zil 4

您必须始终指定所有标签,否则我们怎么知道您想要增加哪个系列?您可以指定空字符串作为标签值,但这可能会导致用户感到困惑。