prometheus + grafana 对 springboot 项目进行监控
生活随笔
收集整理的這篇文章主要介紹了
prometheus + grafana 对 springboot 项目进行监控
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
1.prometheus接入springboot
prometheus安裝后,在安裝目錄有一個默認的配置文件prometheus.yml
#?my?global?config global:scrape_interval:?15s?#?Set?the?scrape?interval?to?every?15?seconds.?Default?is?every?1?minute.evaluation_interval:?15s?#?Evaluate?rules?every?15?seconds.?The?default?is?every?1?minute.#?scrape_timeout?is?set?to?the?global?default?(10s).#?Alertmanager?configuration alerting:alertmanagers:-?static_configs:-?targets:#?-?alertmanager:9093#?Load?rules?once?and?periodically?evaluate?them?according?to?the?global?'evaluation_interval'. rule_files:#?-?"first_rules.yml"#?-?"second_rules.yml"#?A?scrape?configuration?containing?exactly?one?endpoint?to?scrape: #?Here?it's?Prometheus?itself. scrape_configs:#?The?job?name?is?added?as?a?label?`job=<job_name>`?to?any?timeseries?scraped?from?this?config.-?job_name:?"prometheus"#?metrics_path?defaults?to?'/metrics'#?scheme?defaults?to?'http'.static_configs:-?targets:?["localhost:9090"]默認配置了一個job_name,監控prometheus本身。需要增加一個監控springboot項目
-?job_name:?"custom_spring_boot"metrics_path:?'/actuator/prometheus'static_configs:-?targets:?["localhost:9595"]metrics_path 默認采集metrics的路徑是/metrics;需要改成/actuator/prometheus
scheme 默認是http;如果是https需要自定義配置
targets 獲取metrics的地址和端口列表
2.訪問prometheus
http://127.0.0.1:9090/出現自定義需要監控的springboot端點列表
在首頁,可以查詢各種不同的指標
比如查詢custom_http_request_time_seconds_count指標
3.grafana接入prometheus
訪問
http://127.0.0.1:3000/配置數據源
添加一個數據
選擇prometheus
設置名稱和prometheus服務地址
4.配置儀表盤
點擊Add a new panel;新建一個Panel
平均時間查詢
sum?by(api)?(rate(custom_http_request_time_seconds_count{job="custom_spring_boot",?api="/order"}[5m]))保存,最終顯示
總結
以上是生活随笔為你收集整理的prometheus + grafana 对 springboot 项目进行监控的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 考研加油站系统的设计与实现
- 下一篇: U-BOOT中mmc命令简介