我是micrometer和prometheus的新手,我正在尝试构建我的第一个hello-world
应用程序,该应用程序将使用测微计和普罗米修斯作为监视后端进行监视。但是我看不到我的应用程序(Counter
和Timer
s所显示的指标出现在Prometheus端点上。
我正在关注this普罗米修斯教程。我还按照this视频观看了千分尺入门。
我从this链接下载了prometheus,将其提取,然后使用命令./prometheus --config.file=prometheus.yml
运行prometheus进行报废。我在此配置文件中将目标设置为targets: ['localhost:9090']
然后我运行了如下的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();
}
}
运行./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
。
在我看来,我缺少明显的东西(因为我是这两个主题的初学者)。
有人可以指出我所缺少的吗?
我找不到(在我的主类中的什么地方),我必须配置URI以为普罗米修斯发布。即使我正在发布到http://localhost:9090
(可能默认将其隐藏在千分尺的某个位置),我也找不到它。
答案 0 :(得分:3)
目标:['localhost:9090']
这是普罗米修斯被要求刮itself自己的东西。
您需要为Java应用程序的HTTP端点添加目标。