如何获取事件总线指标 Vertx 与 Prometheus 集成
How to get Event bus metrics Vertx integrate with Prometheus
我正在使用 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 实例时,我找不到 Event Bus Metric、HTTP Client Metric、Net Client Metric..(这些指标在 GET localhost:8080/metrics 上看不到,只看 HTTP Server Metric 和 Vert.x 池指标
我的问题:
如何在 GET localhost:8080/metrics
上查看缺少的指标(事件总线、网络、HTTP 客户端)
提前致谢。
我发现:
指标(事件总线,...)仅在发生有关这些指标的事件时才显示在 GET 上。
所以我测试了将消息发送到事件总线,然后我可以在 GET 指标请求上查看与事件总线相关的指标。
我部署了一个 Verticle 来将消息发送到事件总线:
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);
}
}
我正在使用 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 实例时,我找不到 Event Bus Metric、HTTP Client Metric、Net Client Metric..(这些指标在 GET localhost:8080/metrics 上看不到,只看 HTTP Server Metric 和 Vert.x 池指标
我的问题: 如何在 GET localhost:8080/metrics
上查看缺少的指标(事件总线、网络、HTTP 客户端)提前致谢。
我发现:
指标(事件总线,...)仅在发生有关这些指标的事件时才显示在 GET 上。
所以我测试了将消息发送到事件总线,然后我可以在 GET 指标请求上查看与事件总线相关的指标。
我部署了一个 Verticle 来将消息发送到事件总线:
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);
}
}