【问题标题】:How to add labels to Prometheus Summary metric in Java如何在 Java 中为 Prometheus Summary 指标添加标签
【发布时间】:2018-01-16 17:54:33
【问题描述】:

计数器和仪表允许向它们添加标签。当我尝试将标签添加到摘要时,我收到“标签数量不正确”错误。

这就是我正在尝试的:

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

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

我查看了摘要 github 源代码,但找不到答案。标签是如何添加到摘要中的?

【问题讨论】:

    标签: java summary prometheus


    【解决方案1】:

    你需要provide the labelname in the metric:

    private static final Summary latencySummary = Summary.build()
        .name("latency_seconds")
        .help("All latencies.")
        .labelNames("api")
        .register();
    

    【讨论】:

    • 如何添加多个标签? @brian-巴西
    • 试试 .labelNames("label1","label2")
    【解决方案2】:

    下面是另一个例子,我们可以看到如何定义标签和设置实际值:

    Gauge mem_usage = Gauge.build().name("mem_usage").help("Memory usage").labelNames("label1", "label2").register();
    mem_usage.labels("label1_value1", "label2_value2").set(1000);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-08-09
      • 1970-01-01
      • 2022-12-20
      • 1970-01-01
      • 2018-09-24
      相关资源
      最近更新 更多