简体   繁体   English

当我使用千分尺的PrometheusMeterRegistry时,度量标准没有出现在prometheus终点

[英]Metrics not appearing at prometheus endpoint when I'm using micrometer's PrometheusMeterRegistry

I'm new to micrometer and prometheus and I'm trying to build my first hello-world application to be monitored using micrometer with prometheus as monitoring backend. 我是千分尺普罗米修斯的新手,我正在尝试构建我的第一个hello-world应用程序,使用千分尺和prometheus作为监控后端进行监控。 But I can't see the metrics by my app ( Counter s and Timer s) appearing on the prometheus endpoint. 但我看不到我的应用程序( CounterTimer )出现在prometheus端点上的指标。

I'm following this tutorial for prometheus. 我正在关注prometheus 这个教程。 I also followed this video for getting started with micrometer. 我也按照这个视频开始使用千分尺。

I downloaded prometheus from this link, extracted it and then ran prometheus to scrap using the command: ./prometheus --config.file=prometheus.yml . 我从这个链接下载了prometheus,将其解压缩然后使用以下命令运行prometheus: ./prometheus --config.file=prometheus.yml I'm having target set in this config file as targets: ['localhost:9090'] 我将此配置文件中的目标设置为targets: ['localhost:9090']

Then I ran my Main class which looks like this: 然后我运行了我的Main类,看起来像这样:

import cern.jet.random.Normal;
import cern.jet.random.engine.MersenneTwister64;
import cern.jet.random.engine.RandomEngine;
import io.micrometer.core.instrument.Counter;
import io.micrometer.core.instrument.Gauge;
import io.micrometer.core.instrument.Timer;
import io.micrometer.core.instrument.composite.CompositeMeterRegistry;
import io.micrometer.core.instrument.logging.LoggingMeterRegistry;
import io.micrometer.jmx.JmxMeterRegistry;
import io.micrometer.prometheus.PrometheusMeterRegistry;
import reactor.core.publisher.Flux;

import java.time.Duration;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;

public class Main {

    public static void main(String[] args) throws InterruptedException {
        CompositeMeterRegistry compositeMeterRegistry = new CompositeMeterRegistry();

        LoggingMeterRegistry loggingMeterRegistry = SampleMeterRegistries.loggingMeterRegistry();
        JmxMeterRegistry jmxMeterRegistry = SampleMeterRegistries.jmxMeterRegistry();
//        AtlasMeterRegistry atlasMeterRegistry = SampleMeterRegistries.atlasMeterRegistry();
        PrometheusMeterRegistry prometheusMeterRegistry = SampleMeterRegistries.prometheus();

        compositeMeterRegistry.add(loggingMeterRegistry);
        compositeMeterRegistry.add(jmxMeterRegistry);
//        compositeMeterRegistry.add(atlasMeterRegistry);
        compositeMeterRegistry.add(prometheusMeterRegistry);


        AtomicInteger latencyForThisSecond = new AtomicInteger(0);
        Gauge gauge = Gauge.builder("my.guage", latencyForThisSecond, n -> n.get())
                .register(compositeMeterRegistry);

        Counter counter = Counter
                .builder("my.counter")
                .description("some description")
                .tags("dev", "performance")
                .register(compositeMeterRegistry);

        Timer timer = Timer.builder("timer")
                .publishPercentileHistogram()
                .sla(Duration.ofMillis(270))
                .register(compositeMeterRegistry);

        // colt/colt/1.2.0 is to be added for this.
        RandomEngine randomEngine = new MersenneTwister64(0);
        Normal incomingRequests = new Normal(0, 1, randomEngine);
        Normal duration = new Normal(250, 50, randomEngine);

        latencyForThisSecond.set(duration.nextInt());

        // For Flux you require io.projectreactor/reactor-core/3.2.3.RELEASE
        Flux.interval(Duration.ofSeconds(1))
                .doOnEach(d -> {
                    if (incomingRequests.nextDouble() + 0.4 > 0) {
                        timer.record(latencyForThisSecond.get(), TimeUnit.MILLISECONDS);
                    }
                }).blockLast();

    }
}

When I run ./prometheus --config.file=prometheus.yml , I can access the endpoint http://localhost:9090/metrics and also http://localhost:9090/graph . 当我运行./prometheus --config.file=prometheus.yml ,我可以访问端点http://localhost:9090/metrics以及http://localhost:9090/graph But when I try to execute the query on http://localhost:9090/graph sum(timer_duration_seconds_sum) / sum(timer_duration_seconds_count) it says no datapoints found . 但是当我尝试在http://localhost:9090/graph sum(timer_duration_seconds_sum) / sum(timer_duration_seconds_count)上执行查询时,它表示no datapoints found

It seems to me that I'm missing something obvious (as I'm a beginner to both of these topics). 在我看来,我错过了一些明显的东西(因为我是这两个主题的初学者)。

Can someone please point out what I'm missing? 有人可以指出我错过了什么吗?

I couldn't find (where in my Main class) I have to configure the URI to publish for prometheus. 我找不到(在我的Main类中的哪个地方)我必须配置要为prometheus发布的URI。 Even if I'm publishing to http://localhost:9090 (which might be default hidden somewhere by micrometer) I couldn't find it. 即使我发布到http://localhost:9090 (可能默认隐藏在微米的某个地方),我也找不到它。

targets: ['localhost:9090'] 目标:['localhost:9090']

That's Prometheus being asked to scrape itself. 这是普罗米修斯被要求刮掉自己。

You need to add a target for the Java application's HTTP endpoint. 您需要为Java应用程序的HTTP端点添加目标。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Prometheus端点中不提供使用Micrometer的自定义指标 - Custom metrics using Micrometer is not available in Prometheus endpoint 使用micrometer.io更改普罗米修斯终点 - Change prometheus endpoint using micrometer.io jersey 应用程序中的千分尺 Prometheus 指标(非弹簧) - Micrometer Prometheus metrics in jersey application (Non spring) 如何使用 Micrometer 格式和 /actuator/prometheus 将 Apache Camel 指标(如 metrics:timer:simple.timer)输出到 Prometheus - How to output Apache Camel metrics like metrics:timer:simple.timer to Prometheus using Micrometer format with /actuator/prometheus 千分尺相当于普罗米修斯的标签 - Micrometer's equivalent of Prometheus' labels 使用 Jax-Rs 将 Prometheus Metrics Endpoint 添加到 Java 应用程序 - Add Prometheus Metrics Endpoint to Java App Using Jax-Rs 我如何向普罗米修斯报告 Kafka Producer 的指标(使用 spring boot) - How can I Report Kafka Producer's metrics to prometheus(using spring boot) 如何在默认端点/指标下覆盖普罗米修斯 - How to override prometheus by default endpoint /metrics 使用Micrometer指标运行SpringBoot 2应用程序时出错 - Error when running SpringBoot 2 application with Micrometer metrics 如何更改千分尺中的指标命名 - How can I change metrics naming in Micrometer
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM