Springboot添加jvm監(jiān)控實(shí)現(xiàn)數(shù)據(jù)可視化
1.簡(jiǎn)介
最近越發(fā)覺得,任何一個(gè)系統(tǒng)上線,運(yùn)維監(jiān)控都太重要了。本文介紹Prometheus + Grafana的方法監(jiān)控Springboot 2.X,實(shí)現(xiàn)美觀漂亮的數(shù)據(jù)可視化。
2.添加監(jiān)控
Spring-boot-actuator module 可幫助您在將應(yīng)用程序投入生產(chǎn)時(shí)監(jiān)視和管理應(yīng)用程序。您可以選擇使用 HTTP 端點(diǎn)或 JMX 來管理和監(jiān)控您的應(yīng)用程序。Auditing, health, and metrics gathering 也可以自動(dòng)應(yīng)用于您的應(yīng)用程序。引入依賴如下:
<!--監(jiān)控報(bào)警--><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-actuator</artifactId></dependency><dependency><groupId>io.micrometer</groupId><artifactId>micrometer-registry-prometheus</artifactId></dependency>
對(duì)于Springboot,要開啟Actuator,并打開對(duì)應(yīng)的Endpoint:
#prometheus配置info:alen:alenmanagement:endpoints:web:base-path:/actuatorexposure:include:'*'
啟動(dòng)Springboot后,可以通過下面URL看能不能正確獲取到監(jiān)控?cái)?shù)據(jù):localhost/actuator/prometheus 獲取數(shù)據(jù)成功,說明Springboot能正常提供監(jiān)控?cái)?shù)據(jù)。
主要的端點(diǎn)
3.配置Prometheus
Prometheus 是 Cloud Native Computing Foundation 項(xiàng)目之一,是一個(gè)系統(tǒng)和服務(wù)監(jiān)控系統(tǒng)。它按給定的時(shí)間間隔從配置的目標(biāo)收集指標(biāo),評(píng)估規(guī)則表達(dá)式,顯示結(jié)果,并且如果觀察到某些條件為真,則可觸發(fā)警報(bào)。
特性
• 多維度 數(shù)據(jù)模型(由度量名稱和鍵/值維度集定義的時(shí)間序列)• 靈活的查詢語言 來利用這種維度• 不依賴分布式存儲(chǔ);單個(gè)服務(wù)器節(jié)點(diǎn)是自治的 • 時(shí)間序列采集通過HTTP上的 pull model 發(fā)生• 推送時(shí)間序列 通過中間網(wǎng)關(guān)得到支持• 通過 服務(wù)發(fā)現(xiàn) 或 靜態(tài)配置 來發(fā)現(xiàn)目標(biāo)• 多種模式的 圖形和儀表盤支持• 支持分級(jí)和水平 federation
通過 Prometheus 來抓取數(shù)據(jù) Prometheus 會(huì)按照配置的時(shí)間周期去 pull 暴露的端點(diǎn)(/actuator/prometheus)中的指標(biāo)數(shù)據(jù) prometheus.yml 配置
- job_name: ’actuator-ruoyi’ # metrics_path defaults to ’/metrics’ # scheme defaults to ’http’. metrics_path: ’/actuator/prometheus’ static_configs: - targets: [’10.42.95.4’]
重然后再啟動(dòng)prometheus,訪問prometheus網(wǎng)址,查看targets啟動(dòng)是否正常如下圖
4.Grafana添加監(jiān)控模版
默認(rèn)啟動(dòng)后Grafana地址為:http://localhost:3000/,登錄用戶名和密碼是admin/admin,import配置grafana id = 4701
最終的效果是這樣子的,如下圖
5.備注
問題:添加上訪問不了Endpoint?解決方案:原因是項(xiàng)目用的shiro,需要添加過濾
filterChainDefinitionMap.put('/actuator/**','anon');
問題二:
/O exception (java.io.IOException) caught when processing request to {}->unix://localhost:80: Broken pipe
解決方法:導(dǎo)致這個(gè)錯(cuò)誤的原因是 project.artifactId 可能包含了大寫。改成小寫就行
到此這篇關(guān)于Springboot添加jvm監(jiān)控實(shí)現(xiàn)數(shù)據(jù)可視化的文章就介紹到這了,更多相關(guān)Springboot jvm監(jiān)控?cái)?shù)據(jù)可視化內(nèi)容請(qǐng)搜索好吧啦網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持好吧啦網(wǎng)!
相關(guān)文章:
1. Python sorted排序方法如何實(shí)現(xiàn)2. Python基于requests實(shí)現(xiàn)模擬上傳文件3. ASP.NET MVC實(shí)現(xiàn)橫向展示購(gòu)物車4. windows服務(wù)器使用IIS時(shí)thinkphp搜索中文無效問題5. python利用opencv實(shí)現(xiàn)顏色檢測(cè)6. Python文本文件的合并操作方法代碼實(shí)例7. Python 中如何使用 virtualenv 管理虛擬環(huán)境8. 通過CSS數(shù)學(xué)函數(shù)實(shí)現(xiàn)動(dòng)畫特效9. asp讀取xml文件和記數(shù)10. Python獲取B站粉絲數(shù)的示例代碼
