springboot可视化监控之prometheus

2020-07-07  本文已影响0人  炒面Z

涉及组件介绍

1. springboot项目增加组件 micrometer-registry-prometheus 和 actuator

       <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
      </dependency>
      <!-- Micrometer Prometheus registry  -->
        <dependency>
            <groupId>io.micrometer</groupId>
            <artifactId>micrometer-registry-prometheus</artifactId>
        </dependency>
@Configuration
public class MetricsConfig {

    @Bean
    MeterRegistryCustomizer<MeterRegistry> configurer(
            @Value("${spring.application.name}") String applicationName) {
        return (registry) -> registry.
                config().
                commonTags("application", applicationName);
    }
}
management:
  endpoints:
    jmx:
      exposure:
        include: "*"
    web:
      exposure:
        include: health,prometheus
  endpoint:
    health:
      show-details: always   
  metrics:
    export:
      datadog:
        application-key: ${spring.application.name}

2.在 prometheus 配置任务定时抓取springboot指标数据

  - job_name: 'content-cloud-webapi-test' #任务名
    metrics_path: 'actuator/prometheus'    # endpoint
    scrape_interval: 15s                    # 信息收集间隔10秒
    static_configs:
    - targets: ['IP:PORT']          # springboot项目暴露的地址+端口

3.在grafana中配置模板ID展示dashborad,此处使用报表模板ID=4701

image.png

grafana和prometheus在docker下的安装和使用可参考: https://www.jianshu.com/p/87e1ca5b84c9

上一篇 下一篇

猜你喜欢

热点阅读