当我使用千分尺的 PrometheusMeterRegistry 时,指标没有出现在普罗米修斯端点
Metrics not appearing at prometheus endpoint when I'm using micrometer's PrometheusMeterRegistry
我是 micrometer and prometheus 的新手,我正在尝试构建我的第一个 hello-world
应用程序,以使用 micrometer 和 prometheus 作为监控后端进行监控。但是我看不到我的应用程序(Counter
s 和 Timer
s)出现在普罗米修斯端点上的指标。
我正在观看 this tutorial for prometheus. I also followed this 千分尺入门视频。
我从 this link 下载了 prometheus,将其解压缩,然后 运行 prometheus 使用以下命令进行抓取:./prometheus --config.file=prometheus.yml
。我在此配置文件中将目标设置为 targets: ['localhost:9090']
然后我 运行 我的 Main class 看起来像这样:
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();
}
}
当我 运行 ./prometheus --config.file=prometheus.yml
时,我可以访问端点 http://localhost:9090/metrics
以及 http://localhost:9090/graph
。但是当我尝试在 http://localhost:9090/graph
sum(timer_duration_seconds_sum) / sum(timer_duration_seconds_count)
上执行查询时,它说 no datapoints found
.
在我看来,我遗漏了一些明显的东西(因为我是这两个主题的初学者)。
有人可以指出我遗漏了什么吗?
我找不到(在我的 Main class 中的位置)我必须配置 URI 以便为 prometheus 发布。即使我发布到 http://localhost:9090
(默认情况下可能被千分尺隐藏在某处)我也找不到它。
targets: ['localhost:9090']
那是普罗米修斯被要求抓取自己。
您需要为 Java 应用程序的 HTTP 端点添加一个目标。
我是 micrometer and prometheus 的新手,我正在尝试构建我的第一个 hello-world
应用程序,以使用 micrometer 和 prometheus 作为监控后端进行监控。但是我看不到我的应用程序(Counter
s 和 Timer
s)出现在普罗米修斯端点上的指标。
我正在观看 this tutorial for prometheus. I also followed this 千分尺入门视频。
我从 this link 下载了 prometheus,将其解压缩,然后 运行 prometheus 使用以下命令进行抓取:./prometheus --config.file=prometheus.yml
。我在此配置文件中将目标设置为 targets: ['localhost:9090']
然后我 运行 我的 Main class 看起来像这样:
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();
}
}
当我 运行 ./prometheus --config.file=prometheus.yml
时,我可以访问端点 http://localhost:9090/metrics
以及 http://localhost:9090/graph
。但是当我尝试在 http://localhost:9090/graph
sum(timer_duration_seconds_sum) / sum(timer_duration_seconds_count)
上执行查询时,它说 no datapoints found
.
在我看来,我遗漏了一些明显的东西(因为我是这两个主题的初学者)。
有人可以指出我遗漏了什么吗?
我找不到(在我的 Main class 中的位置)我必须配置 URI 以便为 prometheus 发布。即使我发布到 http://localhost:9090
(默认情况下可能被千分尺隐藏在某处)我也找不到它。
targets: ['localhost:9090']
那是普罗米修斯被要求抓取自己。
您需要为 Java 应用程序的 HTTP 端点添加一个目标。