prometheus + grafana 对 springboot 项目进行监控
生活随笔
收集整理的這篇文章主要介紹了
prometheus + grafana 对 springboot 项目进行监控
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
1.prometheus接入springboot
prometheus安裝后,在安裝目錄有一個(gè)默認(rèn)的配置文件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"]默認(rèn)配置了一個(gè)job_name,監(jiān)控prometheus本身。需要增加一個(gè)監(jiān)控springboot項(xiàng)目
-?job_name:?"custom_spring_boot"metrics_path:?'/actuator/prometheus'static_configs:-?targets:?["localhost:9595"]metrics_path 默認(rèn)采集metrics的路徑是/metrics;需要改成/actuator/prometheus
scheme 默認(rèn)是http;如果是https需要自定義配置
targets 獲取metrics的地址和端口列表
2.訪問(wèn)prometheus
http://127.0.0.1:9090/出現(xiàn)自定義需要監(jiān)控的springboot端點(diǎn)列表
在首頁(yè),可以查詢各種不同的指標(biāo)
比如查詢custom_http_request_time_seconds_count指標(biāo)
3.grafana接入prometheus
訪問(wèn)
http://127.0.0.1:3000/配置數(shù)據(jù)源
添加一個(gè)數(shù)據(jù)
選擇prometheus
設(shè)置名稱和prometheus服務(wù)地址
4.配置儀表盤
點(diǎn)擊Add a new panel;新建一個(gè)Panel
平均時(shí)間查詢
sum?by(api)?(rate(custom_http_request_time_seconds_count{job="custom_spring_boot",?api="/order"}[5m]))保存,最終顯示
總結(jié)
以上是生活随笔為你收集整理的prometheus + grafana 对 springboot 项目进行监控的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 考研加油站系统的设计与实现
- 下一篇: U-BOOT中mmc命令简介