Spring?Boot?Admin?監(jiān)控指標(biāo)接入Grafana可視化的實(shí)例詳解
Spring Boot Admin2 自帶有部分監(jiān)控圖表,如圖,有線程、內(nèi)存Heap和內(nèi)存Non Heap,但也就只有這幾個(gè)監(jiān)控圖表,數(shù)量很少,并且它只能看到當(dāng)時(shí)的監(jiān)控?cái)?shù)據(jù),并不能查看歷史數(shù)據(jù),為了改變這種情況,我們需要將指標(biāo)進(jìn)行持久化,并使用更強(qiáng)大的可視化工具,這個(gè)工具就是Grafana。
在前面我們知道SBA2具備的監(jiān)控指標(biāo)還是挺多的,訪問/actuator
即可知道,如下圖
現(xiàn)在在這篇文章,我們要做的就是將這些指標(biāo)進(jìn)行持久化,并在Grafana展示更多的圖標(biāo),讓我們開始。
首先我們需要再Spring Boot中集成持久化數(shù)據(jù)庫(kù),我這里使用了Prometheus,也可以使用InfluxDB。
引入Maven依賴
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency> <!--橋接prometheus--> <dependency> <groupId>io.micrometer</groupId> <artifactId>micrometer-registry-prometheus</artifactId> </dependency>
application.properties 配置
由于之前我們已經(jīng)接入過SBA2,所以我們已經(jīng)配置過需要暴露的端點(diǎn),無需再次配置。
management.endpoints.web.exposure.include=* management.endpoint.health.show-details=always
生產(chǎn)環(huán)境,需要配置Spring Security,我這里并未配置。
接入Prometheus
安裝prometheus,為了能夠快速體驗(yàn),這邊使用Docker安裝,并將本地配置文件映射到Docker中
docker run -p 9090:9090 -v D:\sdk\prometheus\prometheus.yml:/etc/prometheus/prometheus.yml -v D:\sdk\prometheus\alert_rules.yml:/etc/prometheus/alert_rules.yml prom/prometheus
alert_rules.yml 是 Prometheus 告警規(guī)則的配置,這個(gè)后面其他文章再講
配置prometheus.yml
scrape_configs: # The job name is added as a label `job=<job_name>` to any timeseries scraped from this config. - job_name: 'prometheus' # Override the global default and scrape targets from this job every 5 seconds. scrape_interval: 5s static_configs: - targets: ['localhost:9090'] #- job_name: 'prometheus-demo' # scrape_interval: 5s # static_configs: # - targets: ['192.168.0.115:8088'] - job_name: 'provider' metrics_path: '/actuator/prometheus' scrape_interval: 5s static_configs: - targets: ['192.168.0.115:8000']
metrics_path:指標(biāo)地址,原有的Spring Boot 指標(biāo)將自動(dòng)轉(zhuǎn)換為prometheus指標(biāo)
scrape_interval:指標(biāo)拉取間隔,這里配置5s
192.168.0.115:8000: 為本地服務(wù)的地址+端口
配置完畢,重啟Prometheus,訪問地址,可見兩個(gè)服務(wù)都已經(jīng)是UP狀態(tài)
訪問http://192.168.0.115:8000/actuator/prometheus
地址,就是我們剛配置的服務(wù)指標(biāo)
接入Grafana
同樣的,為了快速體驗(yàn),我們使用Docker來安裝Grafana
docker run -p 3000:3000 grafana/grafana
安裝完畢,訪問http://localhost:3000
進(jìn)入主界面,默認(rèn)賬號(hào)密碼:admin/admin
接入第一步,配置數(shù)據(jù)源
選擇Prometheus,URL選擇Prometheus端口地址,我這邊已經(jīng)將端口暴露出來,其他默認(rèn)
設(shè)置完畢,下一步創(chuàng)建一個(gè)大屏,這里以創(chuàng)建JVM監(jiān)控大屏為例。
由于Grafana會(huì)提供一些大屏指標(biāo)模板,我們只需要導(dǎo)入即可,或者進(jìn)行適當(dāng)?shù)男薷模?code>https://grafana.com/grafana/dashboards
搜索結(jié)果第一個(gè)即為我們需要的模板,進(jìn)入詳情頁,copy模板ID,到Grafana進(jìn)行導(dǎo)入
選擇剛配置的Prometheus數(shù)據(jù)源,設(shè)置名稱和文件夾,導(dǎo)入后即可生成JVM大屏
最終的JVM大屏效果如圖,這里截圖頭部部分指標(biāo)
包含的所有指標(biāo)
每個(gè)指標(biāo)的具體含義,可以自行去了解,本篇文章我們以JVM為例,將Spring Boot2 的JVM 指標(biāo)接入到Grafana進(jìn)行可視化,在前面我們通過actuator端點(diǎn)實(shí)際暴露是有很多端點(diǎn)的,后面將介紹如何自定義大屏接入上述指標(biāo)。
到此這篇關(guān)于Spring Boot Admin 監(jiān)控指標(biāo)接入Grafana可視化的文章就介紹到這了,更多相關(guān)Spring Boot Admin監(jiān)控內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
- 使用SpringBoot+Prometheus+Grafana實(shí)現(xiàn)可視化監(jiān)控
- vue+flv.js+SpringBoot+websocket實(shí)現(xiàn)視頻監(jiān)控與回放功能
- SpringBoot Admin 如何實(shí)現(xiàn)Actuator端點(diǎn)可視化監(jiān)控
- springboot Actuator的指標(biāo)監(jiān)控可視化功能詳解
- SpringBoot可視化監(jiān)控的具體應(yīng)用
- Springboot添加jvm監(jiān)控實(shí)現(xiàn)數(shù)據(jù)可視化
- SpringBoot監(jiān)視器的具體使用
相關(guān)文章
使用Spring @DependsOn控制bean加載順序的實(shí)例
這篇文章主要介紹了使用Spring @DependsOn控制bean加載順序的實(shí)例講解,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2021-07-07Spring Boot文件上傳原理與實(shí)現(xiàn)詳解
這篇文章主要介紹了Spring Boot 文件上傳原理與實(shí)現(xiàn)詳解,前端文件上傳是面向多用戶的,多用戶之間可能存在上傳同一個(gè)名稱、類型的文件;為了避免文件沖突導(dǎo)致的覆蓋問題這些應(yīng)該在后臺(tái)進(jìn)行解決,需要的朋友可以參考下2024-01-01使用Sentinel滑動(dòng)窗口實(shí)現(xiàn)限流和降級(jí)
Sentinel 是一個(gè)開源的高可用性、高擴(kuò)展性的實(shí)時(shí)流量控制框架,它可以用于保護(hù)服務(wù)穩(wěn)定性,防止系統(tǒng)因?yàn)榱髁窟^大而崩潰,這篇文章我們所介紹的是滑動(dòng)窗口,它是 Sentinel 實(shí)現(xiàn)限流和降級(jí)的重要組件之一,感興趣的同學(xué)跟著小編來看看吧2023-09-09詳解springboot 使用c3p0數(shù)據(jù)庫(kù)連接池的方法
本篇文章主要介紹了springboot 使用c3p0數(shù)據(jù)庫(kù)連接池的方法,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-09-09