Oded
Oded

Reputation: 434

How does Prometheus labeling syntax works?

I'm new to Prometheus and I have a very basic question.

What is the syntax to add a label to my Metrics? I tried the following:

1. Gauge.build().name(name).labelNames("label"="someLabel").help(helpMsg).register(registry);
2. Gauge.build().name(name).labelNames(label=someLabel).help(helpMsg).register(registry);
4. Gauge.build().name(name).labelNames("someLabel").help(helpMsg).register(registry);

The docs say String value, which I tried...

Someone?

Upvotes: 2

Views: 2140

Answers (1)

DazWilkin
DazWilkin

Reputation: 40296

Your question lacks helpful detail to aid answering.

I assume you're using the Java SDK.

Here's the link to the documentation:

https://github.com/prometheus/client_java#labels

It appears you should use:

g = Gauge.build()
  .name(name)
  .labelNames("someLabel")
  .help(helpMsg)
  .register(registry);

And then, when you update your gauge (g), you need to specify the label(s) value(s):

g
  .labels("someLabelValue")
  .set(...);

Upvotes: 2

Related Questions