Prometheus-client : how to specify a list of labels

Viewed 13

I use prometheus client, but have issues specifying the correct label values, corresponding to a metric I just created.

import pprint
from prometheus_client import Gauge


# --- At one location, a specific set of labels is defined for a metric.
lbls = ["color", "orientation"]
metric= Gauge ("metricid", "description", lbls)
pprint.pprint(metric._labelnames)

lvalue = {"color" : "red",  "orientation" : "vertical" }
label_values = tuple(str(lvalue[key]) for key in lvalue)
label_values = [str(lvalue[key]) for key in lvalue]
print("----")
pprint.pprint(label_values)
print("----")
metric.labels(label_values).set("99")

The output I get is :

('color', 'orientation')
----
['red', 'vertical']
----
Traceback (most recent call last):
  File "snippet1.py", line 19, in <module>
    metric.labels(label_values).set("99")
  File "/home/gtos/.local/lib/python3.6/site-packages/prometheus_client/metrics.py", line 177, in labels
    raise ValueError('Incorrect label count %d %d '% (len(labelvalues), len(self._labelnames)))
ValueError: Incorrect label count 1 2

Although I pass a list / or tuple with 2 elements, the prometheus client library complains, it consists of only 1 element.

Can someone highlight what I missed?

Rgds

Luc

1 Answers

I resolved it myself by using labels(**lst )

Related