• SpringBoot 版本
    • 2.3.1.RELEASE
  • micrometer-registry-prometheus 版本
    • 1.6.6

      SpringBoot 项目配置

      1. <!-- https://mvnrepository.com/artifact/io.micrometer/micrometer-registry-prometheus -->
      2. <dependency>
      3. <groupId>io.micrometer</groupId>
      4. <artifactId>micrometer-registry-prometheus</artifactId>
      5. <version>1.6.6</version>
      6. </dependency>
      SpringBoot配置文件里面添加
      1. # prometheus metric
      2. management:
      3. endpoints:
      4. web:
      5. exposure:
      6. include: "prometheus"
      7. metrics:
      8. export:
      9. datadog:
      10. host-tag: "springboot-application"
      重新启动 SpringBoot 项目。

Prometheus 配置

vim prometheus.yml 新增如下配置, ip 和 port 填写自己的web服务地址和端口

  1. - job_name: "springboot-application"
  2. # 采集数据时间间隔
  3. scrape_interval: 15s
  4. # 采集超时时间
  5. scrape_timeout: 10s
  6. # 采集路径
  7. metrics_path: '/actuator/prometheus'
  8. # 采集服务地址
  9. static_configs:
  10. - targets: ['ip:port']

Grafana 配置

Grafana 配置文件 https://grafana.com/grafana/dashboards/4701

参考

https://blog.csdn.net/Goodbye_Youth/article/details/105575954

https://blog.csdn.net/weixin_48182198/article/details/114491254