SpringBoot集成Prometheus 01

一、Prometheus集成

1、再pom文件中添加如下配置


    org.springframework.boot
    spring-boot-starter-web



    org.springframework.boot
    spring-boot-starter-actuator



    io.micrometer
    micrometer-registry-prometheus

2、添加yum配置文件

management:
  server:
    port: 11001
  endpoints:
    web:
      exposure:
        include: prometheus,health

3、在启动类中添加入下代码,用于注册统一tag名,便于查询

     方案1:添加配置文件 (低版本没tags属性:譬如 2.0.9.RELEASE)

  SpringBoot集成Prometheus 01_第1张图片

    方案2:注册代码

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

4、启动项目访问:http://127.0.0.1:11001/actuator/prometheus

SpringBoot集成Prometheus 01_第2张图片

二、Prometheus监控

1、下载Prometheus

      官网:https://prometheus.io/download/

      地址:https://prometheus.io/download/prometheus-2.21.0.linux-amd64.tar.gz

2、 解压并修改配置

    修改 prometheus.yml

    scrape_configs:
      - job_name: 'prometheus-job1'

        metrics_path: '/actuator/prometheus'
        static_configs:
        - targets: ['127.0.0.1:11001']

3、启动Prometheus

     ./prometheus --config.file="prometheus.yml" &

4、访问  http://192.168.158.200:9090/targets

SpringBoot集成Prometheus 01_第3张图片

SpringBoot集成Prometheus 01_第4张图片

三、配置Grafana 监控

1、  下载Grafana

      官网:https://grafana.com/grafana/download?platform=linux

      地址:https://dl.grafana.com/oss/release/grafana-7.1.5.linux-amd64.tar.gz

2、解压启动grafana

     bin/grafana-server &

3、访问 http://192.168.158.200:3000/

  1)、添加Prometheus数据源

SpringBoot集成Prometheus 01_第5张图片

2、添加监控DashBoard

  1)添加监控 JVM 的 Dashboard ,导入模板编号为 4701

SpringBoot集成Prometheus 01_第6张图片

SpringBoot集成Prometheus 01_第7张图片

 1)添加自定panel,点击右上角添加新panel

 

SpringBoot集成Prometheus 01_第8张图片

SpringBoot集成Prometheus 01_第9张图片

SpringBoot集成Prometheus 01_第10张图片

以上!!!

PS:自定义dashboar的查询条件需要在settings->Variables添加变量,

eg:

SpringBoot集成Prometheus 01_第11张图片

你可能感兴趣的:(工具)