目 录CONTENT

文章目录

Prometheus监控springboot程序

xlong
2024-04-09 / 0 评论 / 0 点赞 / 12 阅读 / 2453 字 / 正在检测是否收录...

Prometheus监控springboot程序

使用prometheus收集springboot的监控指标,使用micrometer-registry-prometheus组件。

第一步:添加pom依赖

        <dependency>
            <groupId>io.micrometer</groupId>
            <artifactId>micrometer-registry-prometheus</artifactId>
            <scope>runtime</scope>
        </dependency>

第二步:修改配置文件添加prometheus相关参数

spring:
  application:
    name: prometheus-demo
management:
  endpoints:
    web:
      exposure:
        include: "*"
  endpoint:
    prometheus:
      enabled: true
    health:
      probes:
        enabled: true
      show-details: always
# kubernetes liveness和readiness探针
      group:
        liveness:
          include: livenessProbe,ping
        readiness:
          include: readinessProbe,ping
  metrics:
    export:
      prometheus:
        enabled: true
server:
  port: 8080
​

第三步:springboot启动入口添加应用服务注册名称,

@SpringBootApplication
public class DemoApplication {
​
    public static void main(String[] args) {
        SpringApplication.run(DemoApplication.class, args);
    }
    //以下为添加内容
    @Bean
    MeterRegistryCustomizer<MeterRegistry> configurer(
            @Value("${spring.application.name]") String applicationName) {
        return (registry) -> registry.config().commonTags("application", applicationName);
    }
    //
}

第四步: 配置prometheus收集指标

第五步:配置grafana配置图表

导入4701的jvm(Micrometer)图表,根据application name选择服务查看指标。

0

评论区