[英]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. 但我看不到我的应用程序( Counter
和Timer
)出现在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.