月光必定会冷掉 2025-06-24 20:43 采纳率: 0%
浏览 8
已结题

springboot 2.4.5离线环境下如何集成actuator+Prometheus

springboot 2.4.5离线环境下如何集成actuator+Prometheus
在联网环境下配置好pom后可以通过localhost:port/actuator 查看输出,将本地仓库迁移至离线环境后actuator无法使用,在页面中查看显示404,
在properties中配置endpoint也无法直接自动联想

尝试在离线环境中使用spring-boot-actuator + spring-boot-starter-autoconfigure 可以在页面中访问actuator信息,但是配置文件中无法配置
management.metrics.tags.application 也无法开启Prometheus
想知道具体原因 是缺少依赖还是因为springboot版本过低无法使用

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
            <version>2.4.5</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
            <version>2.4.5</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-websocket</artifactId>
            <version>2.4.5</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-aop</artifactId>
            <version>2.4.5</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
            <version>2.4.5</version>
        </dependency>
        <dependency>
            <groupId>io.micrometer</groupId>
            <artifactId>micrometer-registry-prometheus</artifactId>
            <version>1.6.6</version>
        </dependency>
  • 写回答

5条回答 默认 最新

  • 阿里嘎多学长 2025-06-24 20:43
    关注

    阿里嘎多学长整理AIGC生成,因移动端显示问题导致当前答案未能完全显示,请使用PC端查看更加详细的解答过程

    解决方案

    在Spring Boot 2.4.5离线环境下集成Actuator和Prometheus,可以按照以下步骤进行:

    1. 在pom.xml文件中添加以下依赖项:
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-actuator</artifactId>
    </dependency>
    <dependency>
        <groupId>io.prometheus</groupId>
        <artifactId>simpleclient_spring_boot_starter</artifactId>
    </dependency>
    <dependency>
        <groupId>io.prometheus</groupId>
        <artifactId>simpleclient_hotspot</artifactId>
    </dependency>
    
    1. 在application.properties文件中添加以下配置:
    management.endpoints.web.exposure.include=*
    prometheus.enabled=true
    
    1. 在pom.xml文件中添加以下插件,以便将依赖项复制到离线环境:
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>copy-dependencies</goal>
                        </goals>
                        <configuration>
                            <artifactItems>
                                <artifactItem>
                                    <groupId>org.springframework.boot</groupId>
                                    <artifactId>spring-boot-starter-actuator</artifactId>
                                </artifactItem>
                                <artifactItem>
                                    <groupId>io.prometheus</groupId>
                                    <artifactId>simpleclient_spring_boot_starter</artifactId>
                                </artifactItem>
                                <artifactItem>
                                    <groupId>io.prometheus</groupId>
                                    <artifactId>simpleclient_hotspot</artifactId>
                                </artifactItem>
                            </artifactItems>
                            <outputDirectory>${project.build.directory}/lib</outputDirectory>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
    
    1. 在离线环境中,复制依赖项到lib目录下,然后在pom.xml文件中添加以下插件,以便将依赖项复制到classpath:
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>copy</goal>
                        </goals>
                        <configuration>
                            <artifactItems>
                                <artifactItem>
                                    <groupId>org.springframework.boot</groupId>
                                    <artifactId>spring-boot-starter-actuator</artifactId>
                                </artifactItem>
                                <artifactItem>
                                    <groupId>io.prometheus</groupId>
                                    <artifactId>simpleclient_spring_boot_starter</artifactId>
                                </artifactItem>
                                <artifactItem>
                                    <groupId>io.prometheus</groupId>
                                    <artifactId>simpleclient_hotspot</artifactId>
                                </artifactItem>
                            </artifactItems>
                            <outputDirectory>${project.build.directory}/classes</outputDirectory>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
    
    1. 最后,在application.properties文件中添加以下配置,以便启用Actuator和Prometheus:
    management.endpoints.web.exposure.include=*
    prometheus.enabled=true
    

    这样,在离线环境下,你可以通过localhost:port/actuator访问Actuator的端点,并通过localhost:port/metrics访问Prometheus的指标。

    评论

报告相同问题?

问题事件

  • 已结题 (查看结题原因) 7月4日
  • 创建了问题 6月24日