Springboot基礎課五:集成 Prometheus 和 Grafana

集成 Prometheus

  1. prometheus 是一款第三方的監控組件,提供了更直觀和方便的監控需求,原理是,定時對應用的 /actuator/metrics 發起信息採集,進行展示和分析;

  2. 首先需要引入 micrometer-registry-prometheus 的 jar 包,資源配置文件中,添加對 premetheus 的 endpoint 的 web 暴露,然後單獨部署和啓動 Prometheus,並配置對應用的監控任務,最後訪問 prometheus 頁面;

	# 應用的promethenus的endpoint
	http://localhost:12301/actuator/prometheus
	
	# prometheus的配置文件(部分)
	job_name: explore-spring-boot
    metrics_path: '/actuator/prometheus'
    static_configs:
      - targets: ['192.168.8.129:12301']
        labels:
          instance: explore-spring-boot
	
	# prometheus的頁面訪問
	http://192.168.99.100:9090/targets   
  1. /targets 顯示當前監控應用的狀態,/graph 顯示指定 mertics 的數值,如,這裏顯示 tomcat 最大線程數,jvm 最大內存;
    在這裏插入圖片描述
    在這裏插入圖片描述
    在這裏插入圖片描述

集成 Grafana

  1. 在 prometheus 的基礎上,提供了更多的查詢,監控,告警的功能,數據採集源有多渠道,如 DB,prometheus;

  2. 首先 grafana 也需要單獨部署和啓動,部署完成後,訪問 http://192.168.99.100:3000/,然後添加數據源,URL 是prometheus 的訪問 URL(http://192.168.99.100:9090),添加 dashboard,點擊 graph,選擇 panel,進行 edit,並選擇監控的 metrics,enable query 後即可看到對 mertics 的監控;
    在這裏插入圖片描述
    在這裏插入圖片描述在這裏插入圖片描述

  3. 更詳細操作參考:https://editor.csdn.net/md/?articleId=103539144;

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章