在春季云数据流任务中为普罗米修斯的Rsocket代理上拥有度量



我正试图为短期的Spring Cloud数据流任务建立一个监控。由于SCDF的更新版本,建议对prometheus使用rsocket代理。

根据helm图表,我能够部署rsocket代理。连接正在发挥作用,普罗米修斯提供了代理自己的指标。但在申请过程中,我仍在努力暴露自己的仪表。

我包含了所需的依赖项:

<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();
/// ...
}

应用程序运行时没有任何问题。但是没有任何度量是可见的,无论是在普罗米修斯本身,还是在代理的/metrics/connected端点上。缺少什么?

编辑:好的,同时我发现,我的任务和RSocket代理之间的通信正在工作。但与文献";。。。将保持它们[度量]直到普罗米修斯的下一次刮擦";,应用程序一结束,我在"metrics/connected"端点上的度量就消失了。

通过设置以下内容,我可以获得自定义的spring-cloud数据流任务,以向prometheus公开执行器。。。

将这些依赖项添加到您的pom或build.gradle

  1. 实现"org.springframework.boot:spring-boot启动器执行器">
  2. 实现组:"io.milter.prometheus",名称:"prometheus-rsockt-spring",版本:"1.3.0">

将以下内容添加到您的应用程序中。yml

management:
security:
enabled: false
endpoints:
web:
exposure:
include: info,prometheus,metrics
endpoint:
info:
enabled: true

最新更新