问题描述
我正在使用Prometheus内置的VertX Metrics。 这是我的代码设置:
try {
MicrometerMetricsOptions options = new MicrometerMetricsOptions()
.setPrometheusOptions(new VertxPrometheusOptions().setEnabled(true))
.setEnabled(true);
Vertx vert = Vertx.vertx(new VertxOptions().setMetricsOptions(options));
vert.deployVerticle(ExecBlocking.class,new DeploymentOptions());
} catch(Exception e){
System.out.println("Error: " + e);
}
但是当我在localhost:8080上运行vertx实例时,找不到事件总线指标,HTTP客户端指标,Net客户端指标。(这些指标在 GET localhost:8080 / metrics,只需查看 HTTP Server指标和 Vert.x池指标
我的问题: 如何在 GET localhost:8080 / metrics
上查看缺少的指标(事件总线,Net,HTTP客户端)谢谢。
解决方法
我发现:
指标(事件总线,...)仅在发生有关这些指标的事件时才显示在GET上。
所以我确实测试了将消息发送到事件总线,然后可以在GET指标请求中查看与事件总线相关的指标。
我部署了一个垂直板将消息发送到事件总线:
public class EventBusProducer extends AbstractVerticle {
@Override
public void start() throws Exception {
vertx.setPeriodic(1000,x -> {
Greetings.get(vertx,greetingResult -> vertx.eventBus().send("greeting",greetingResult.result()));
});
}
}
class Greetings {
private static final String[] GREETINGS = {
"Hello world!","Bonjour monde!","Hallo Welt!","Hola Mundo!"
};
private static final Random RND = new Random();
private Greetings() {
}
static void get(Vertx vertx,Handler<AsyncResult<String>> responseHandler) {
vertx.executeBlocking(fut -> {
// Simulate worker pool processing time between 200ms and 2s
int processingTime = RND.nextInt(1800) + 200;
try {
Thread.sleep(processingTime);
} catch (InterruptedException e) {
e.printStackTrace();
}
fut.complete(GREETINGS[RND.nextInt(4)]);
},responseHandler);
}
}