Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add labels to Prometheus Summary metric in Java

Counters and Gauges allow for labels to be added to them. When I try to add labels to a Summary, I get an "incorrect number of labels" error.

This is what I'm trying:

private static final Summary latencySummary = Summary.build()
            .name("all_latencies")
            .help("all latencies.")
            .register();

latencySummary.labels("xyz_api_latency").observe(timer.elapsedSeconds());

I've looked at the Summary github source code, but can't find the answer. How are labels added to a Summary?

like image 822
kramsiv94 Avatar asked Jan 16 '18 17:01

kramsiv94


People also ask

What is label in Prometheus metrics?

A label is a certain attribute of a metric. Generally, labels are populated by metric producers (servers in the example above). However, in Prometheus, it's possible to enrich a metric with some static labels based on the producer's identity while recording it on the Prometheus node's side.

How do you get the metrics name in Prometheus?

Getting the meaning and type of a metric name This information is not directly accessible via PromQL, but the Prometheus server keeps it in memory for each target and it can be queried via another metadata API endpoint. For example: https://demo.promlabs.com/api/v1/metadata.


1 Answers

You need to provide the labelname in the metric:

private static final Summary latencySummary = Summary.build()
    .name("latency_seconds")
    .help("All latencies.")
    .labelNames("api")
    .register();
like image 62
brian-brazil Avatar answered Sep 19 '22 15:09

brian-brazil