首页 > 其他分享 >prometheus监控springboot项目配置

prometheus监控springboot项目配置

时间:2024-08-13 13:51:08浏览次数:10  
标签:springboot 项目 spring application prometheus 监控 增加

项目运行状况,如果想要了解,那么项目需要增加如下配置,才能被prometheus发现。

1、pom.xml增加maven依赖

我这项目是maven项目,所以增加的是maven依赖。我这做了统一的版本管理,所以依赖信息中的version去掉了。

        <!--监控prometheus -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>
        <dependency>
          <groupId>io.micrometer</groupId>
          <artifactId>micrometer-registry-prometheus</artifactId>
        </dependency>

 

2、yml配置文件中,增加监控发现配置。

#监控
# Actuator
management:
  endpoints.web.exposure.include: "*"
# Prometheus
  metrics.tags.application: ${spring.application.name}

 

3、增加注入bean。这里直接在启动类中增加,当然也可以在config文件中增加。

这里定义的"application",是为了后续的监控名称所使用。

    @Bean
    public MeterRegistryCustomizer<MeterRegistry> configurer(@Value("${spring.application.name}") String applicationName) {
        return registry -> registry.config().commonTags("application", applicationName);
    }

这里会用到

 

4、在prometheus.yml中增加项目访问信息。

 5、重启prometheus,访问target列表

如果正确配置,那么就会展示在列表上。

 

 

 

至此项目发现配置完成。

 

标签:springboot,项目,spring,application,prometheus,监控,增加
From: https://www.cnblogs.com/a393060727/p/18356712

相关文章