Labels missing in Output #900
-
Hello, i am trying to set both, labels and label values at time of instantiating a prometheus metric e.g. a Gauge. I do this by passing a list of label names via the labelnames parameter and also a list of values by the _labelvalues parameter.
later on I set the value of my Gauge like this: Here is the Output I can see under (localhost:8080/metrics) OUTPUT: However if I'm just setting the labelnames at the time of creating the instance of Gauge and passing the values at the time of setting the value it's working like expected and I can see them in the Output
OUTPUT: I found a way to solve my problem here
where **self.prom_labels_dict automagically converts the dict to keyword arguments for the .labels method Is there a better way to do such things? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Hello, to answer a few of your questions!
You should not be using
The best way to do this is to always use the same number of labels, but set the value of the label you do not need to
It looks like you found the answer in the linked stack overflow, but just to keep all the info in one place: You should be able to pass them in with
The dict option you have is also fully supported. I think that covered everything! Let me know if I missed anything/could make anything clearer. |
Beta Was this translation helpful? Give feedback.
Hello, to answer a few of your questions!
You should not be using
_labelvalues
, it is for internal use only hence being started with an underscore which is the python convention for private variables. Always use.labels()
.The best way to do this is to always use the same number of labels, but set the value of the label you do not need to
""
. Prometheus treats an empty string the same as if the label was missing.