I have a prometheus metric with labels declared like
errors_total = prometheus_client.Counter("errors_total", "Total errors", ["source", "code])
errors_total.labels("source"="initialization", code="100")
errors_total.labels("source"="shutingdown", code="200")
When I increment the metric in the place in the monitored code where the error happens, can I just use it as:
errors_total.labels(source="initialization").inc()
or
errors_total.labels(code="200").inc()
My question is can I just use one label when incrementing the metric?
No, you have to give a value for each of the labels. If you try the code, you'll get an exception:
If you have an event with no value for a label, you can pass a placeholder value. A dash (
"-"
) is the best option as it only takes just one byte, but you can also do with something like"undefined"
,"none"
, or"other"
, depending on the context.