You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Spring Cloud Dataflow自定义流应用指标无法在Grafana展示求助

问题描述

使用Spring Cloud Data Flow(SCDF) 2.10.2版本,自定义的Source、Processor或Sink无法将指标暴露到Prometheus/Grafana环境中。

已按照官方自定义流应用教程实现,但尝试多种依赖配置后均无效。使用官方示例应用时指标可正常流向Grafana。

尝试过的依赖:

  1. 添加app-starters-micrometer-common依赖,无效果
<dependency>
    <groupId>org.springframework.cloud.stream.app</groupId>
    <artifactId>app-starters-micrometer-common</artifactId>
    <version>2.1.5.RELEASE</version>
</dependency>
  1. 添加micrometer和prometheus-rsocket依赖,出现NoClassDefFound: io.rsocket.AbstractRSocket异常
<dependency>
    <groupId>io.micrometer</groupId>
    <artifactId>micrometer-registry-prometheus</artifactId>
</dependency>
<dependency>
    <groupId>io.micrometer.prometheus</groupId>
    <artifactId>prometheus-rsocket-spring</artifactId>
    <version>0.9.0</version>
</dependency>

完整pom.xml如下:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.7.10</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>ca.example</groupId>
    <artifactId>data-poller</artifactId>
    <version>1.0.23</version>
    <name>data-poller</name>
    <description>Poller for data</description>
    <properties>
        <java.version>17</java.version>
        <spring-cloud.version>2021.0.6</spring-cloud.version>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-amqp</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-stream</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-stream-binder-rabbit</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-webflux</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-configuration-processor</artifactId>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.postgresql</groupId>
            <artifactId>postgresql</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.amqp</groupId>
            <artifactId>spring-rabbit-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-stream</artifactId>
            <scope>test</scope>
            <classifier>test-binder</classifier>
            <type>test-jar</type>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud.stream.app</groupId>
            <artifactId>app-starters-micrometer-common</artifactId>
            <version>2.1.2.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>io.micrometer</groupId>
            <artifactId>micrometer-registry-prometheus</artifactId>
        </dependency>
        <dependency>
            <groupId>io.micrometer.prometheus</groupId>
            <artifactId>prometheus-rsocket-spring</artifactId>
            <version>0.9.0</version>
        </dependency>
    </dependencies>
    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>${spring-cloud.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>
    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <excludes>
                        <exclude>
                            <groupId>org.projectlombok</groupId>
                            <artifactId>lombok</artifactId>
                        </exclude>
                    </excludes>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dataflow-apps-metadata-plugin</artifactId>
                <version>1.0.2</version>
                <configuration>
                    <storeFilteredMetadata>true</storeFilteredMetadata>
                </configuration>
                <executions>
                    <execution>
                        <id>aggregate-metadata</id>
                        <phase>compile</phase>
                        <goals>
                            <goal>aggregate-metadata</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>
解决方案

1. 修正依赖版本匹配问题

你当前使用的Spring Boot 2.7.10、Spring Cloud 2021.0.6(3.1.x)与SCDF 2.10.2,对应的依赖版本需要统一:

  • 移除旧版app-starters-micrometer-common(2.1.x版本与当前环境不兼容)
  • 将prometheus-rsocket-spring升级到1.4.0版本,适配Spring Boot 2.7.x生态

2. 替换为有效依赖配置

保留核心指标相关依赖,更新后的依赖块如下:

<!-- Actuator基础,暴露指标端点 -->
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<!-- Micrometer核心 + Prometheus注册表 -->
<dependency>
    <groupId>io.micrometer</groupId>
    <artifactId>micrometer-registry-prometheus</artifactId>
</dependency>
<!-- RSocket桥接,支持向Prometheus推送指标 -->
<dependency>
    <groupId>io.micrometer.prometheus</groupId>
    <artifactId>prometheus-rsocket-spring</artifactId>
    <version>1.4.0</version>
</dependency>
<!-- 补充RSocket核心依赖,解决类缺失问题 -->
<dependency>
    <groupId>io.rsocket</groupId>
    <artifactId>rsocket-core</artifactId>
    <version>1.1.4</version>
</dependency>
<dependency>
    <groupId>io.rsocket</groupId>
    <artifactId>rsocket-transport-netty</artifactId>
    <version>1.1.4</version>
</dependency>

3. 配置指标暴露

在应用配置文件(如application.yml)中添加以下配置,开启Prometheus端点:

management:
  endpoints:
    web:
      exposure:
        include: prometheus,health
  metrics:
    export:
      prometheus:
        enabled: true

4. 验证配置

启动应用后,访问http://<应用地址>:<端口>/actuator/prometheus,确认能返回Prometheus格式的指标数据。同时确保SCDF的Prometheus采集规则已正确指向该端点。

内容的提问来源于stack exchange,提问作者oldvirus_231

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.23 13:12:00