我正在尝试为短暂的 Spring Cloud Data Flow 任务建立监控。由于 SCDF 的更新版本,建议使用rsocket 代理 prometheus。
根据 helm 图表,我能够部署 rsocket 代理。连接正常,代理自己的指标在 prometheus 中可用。但我仍在努力在申请期间公开自己的仪表。
我包括了所需的依赖项:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>io.micrometer.prometheus</groupId>
<artifactId>prometheus-rsocket-spring</artifactId>
<version>1.0.0</version>
</dependency>
<-- Next two: required or not? -->
<dependency>
<groupId>io.micrometer.prometheus</groupId>
<artifactId>prometheus-rsocket-client</artifactId>
<version>1.0.0</version>
</dependency>
<dependency>
<groupId>io.rsocket</groupId>
<artifactId>rsocket-transport-netty</artifactId>
</dependency>
在应用程序中,我在代码中添加了一个简单的计数器:
private PrometheusMeterRegistry meterRegistry = new PrometheusMeterRegistry(PrometheusConfig.DEFAULT);
private PrometheusRSocketClient client;
private Counter reqCounter;
@PostConstruct
public void initMontitor() {
client = PrometheusRSocketClient.build(meterRegistry, TcpClientTransport.create("scdf-dev-prometheus-proxy.batch-dev", 7001))
.connect();
reqCounter = meterRegistry.counter("batch.example.count", "client", "example");
}
@PreDestroy
public void releaseMontitor() {
client.pushAndClose();
}
@Override
public Result process(Usage usage) {
reqCounter.increment();
/// ...
}
应用程序运行没有任何问题。但是无论是在 prometheus 本身上,还是在代理的 /metrics/connected 端点上,都看不到任何指标。少了什么东西?
编辑:好的,同时我发现我的任务和 RSocket 代理之间的通信正在工作。但与文档“......将保留它们[指标]直到普罗米修斯下一次刮擦”相反,一旦我的应用程序结束,我在'metrics/connected'端点的指标就消失了。