集成 Prometheus
-
prometheus 是一款第三方的監控組件,提供了更直觀和方便的監控需求,原理是,定時對應用的 /actuator/metrics 發起信息採集,進行展示和分析;
-
首先需要引入 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
- /targets 顯示當前監控應用的狀態,/graph 顯示指定 mertics 的數值,如,這裏顯示 tomcat 最大線程數,jvm 最大內存;
集成 Grafana
-
在 prometheus 的基礎上,提供了更多的查詢,監控,告警的功能,數據採集源有多渠道,如 DB,prometheus;
-
首先 grafana 也需要單獨部署和啓動,部署完成後,訪問 http://192.168.99.100:3000/,然後添加數據源,URL 是prometheus 的訪問 URL(http://192.168.99.100:9090),添加 dashboard,點擊 graph,選擇 panel,進行 edit,並選擇監控的 metrics,enable query 後即可看到對 mertics 的監控;
-
更詳細操作參考:https://editor.csdn.net/md/?articleId=103539144;