Confused about label names/values

22 views
Skip to first unread message

John Dexter

unread,
Oct 6, 2020, 7:17:32 AM10/6/20
to Prometheus Users
I've been looking at examples in the Java and C++ client libs, and it doesn't mirror my understanding of label rules:

I thought:
  1. each metric could have zero or more named labels
  2. each label must have a pre-determined set of allowed values
  3. when setting a metric value, all label dimensions must be specified from these allowed values
But the examples don't work that way:
Counter calculationsCounter = Counter.build() .name("my_library_calculations_total").help("Total calls.") .labelNames("key").register();
...
  void processThatCalculates(String key) { calculationsCounter.labels(key).inc(); // Run calculations. } }

In this example, I don't see where "key" allowed values are enumerated. I also don't see how labels(key) knows which label it is referring to. I might have multiple labels.

I wish I could find a non-trivial example which shows what the output scrape would look like. Can anyone help?

Brian Brazil

unread,
Oct 6, 2020, 7:27:36 AM10/6/20
to John Dexter, Prometheus Users
On Tue, 6 Oct 2020 at 12:17, John Dexter <john....@jdxsolutions.com> wrote:
I've been looking at examples in the Java and C++ client libs, and it doesn't mirror my understanding of label rules:

I thought:
  1. each metric could have zero or more named labels
  2. each label must have a pre-determined set of allowed values

This is a should, not a must. Sometimes you just can't know in advance what the label values would be.
 
  1. when setting a metric value, all label dimensions must be specified from these allowed values

And accordingly here this is also a should.
 
But the examples don't work that way:
Counter calculationsCounter = Counter.build() .name("my_library_calculations_total").help("Total calls.") .labelNames("key").register();
...
  void processThatCalculates(String key) { calculationsCounter.labels(key).inc(); // Run calculations. } }

In this example, I don't see where "key" allowed values are enumerated. I also don't see how labels(key) knows which label it is referring to. I might have multiple labels.

labels takes a varidic of strings, which matches the order of labels you passed to labelNames.

Brian
 

I wish I could find a non-trivial example which shows what the output scrape would look like. Can anyone help?

--
You received this message because you are subscribed to the Google Groups "Prometheus Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to prometheus-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/prometheus-users/f221c413-04cf-495b-9ae5-2d825477bab7n%40googlegroups.com.


--
Reply all
Reply to author
Forward
0 new messages