当前位置:   article > 正文

Springboot JVM监控 通过Promethus

Springboot JVM监控 通过Promethus

Springboot内置了对Prometheus得支持,可以监测得点有:

  • JVM各指标参数(GC,堆,非堆等)
  • 接口调用次数,延时
  • 系统内存,IO,CPU使用率

部署Prometheus和Grafana

准备一台2核4G或以上配置得linux系统(centos7.9、ubuntu18.04或更高版本),按下面得方式部署Prometheus和Grafana

  1. #下载镜像
  2. docker pull prom/prometheus
  3. docker pull grafana/grafana
  4. #将docker里的配置拷出来
  5. docker run --name=grafana -d -p 3000:3000 -itd grafana/grafana
  6. mkdir -p /docker/prometheus/grafana/data
  7. mkdir -p /docker/prometheus/grafana
  8. docker cp grafana:/etc/grafana/grafana.ini /docker/prometheus/grafana/
  9. #写Prometheus配置文件
  10. vim prometheus.yml
  11. global:
  12. scrape_interval: 15s
  13. evaluation_interval: 15s
  14. scrape_configs:
  15. - job_name: 'prometheus'
  16. static_configs:
  17. - targets: ['localhost:9090']
  18. - job_name: "ProvideAPIServices"
  19. scrape_interval: 5s
  20. metrics_path: "/actuator/prometheus"
  21. static_configs:
  22. - targets: ["172.16.0.88:8789","172.16.0.69:8789"]
  23. #启动Prometheus
  24. docker run -d --name prometheus -p 9090:9090 -v /root/prometheus.yml:/etc/prometheus/prometheus.yml prom/prometheus
  25. #启动grafana
  26. docker run -d -p 3000:3000 --name grafana --restart=always -v /docker/prometheus/grafana/grafana.ini:/etc/grafana/grafana.ini -v /docker/prometheus/grafana/data:/var/lib/grafana -e "GF_SECURITY_ADMIN_PASSWORD=admin" grafana/grafana

注意两个地方 

metrics_path: "/actuator/prometheus"   #这里填java服务得请求路径+/actuator/prometheus,如果加了前缀,如 context-path: /abc,则为/abc/actuator/prometheus

["172.16.0.88:8789","172.16.0.69:8789"]  #172.16.0.88:8789 为java服务ip+断开

修改pom.xml

加入下面依赖

jdk<=11

  1. <dependency>
  2. <groupId>io.micrometer</groupId>
  3. <artifactId>micrometer-registry-prometheus</artifactId>
  4. <scope>runtime</scope>
  5. </dependency>

jdk>=17

  1. <dependency>
  2. <groupId>io.prometheus</groupId>
  3. <artifactId>simpleclient_pushgateway</artifactId>
  4. </dependency>

修改application.xml

  1. management:
  2. endpoints:
  3. web:
  4. exposure:
  5. include: "*"
  6. endpoint:
  7. prometheus:
  8. enabled: true #激活prometheus
  9. health:
  10. show-details: always
  11. metrics:
  12. export:
  13. prometheus:
  14. enabled: true

 

Grafana dashboards | Grafana Labs

在grafna导入模板,建议 12464  14430 

 

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小蓝xlanll/article/detail/684358
推荐阅读
相关标签
  

闽ICP备14008679号