最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

spring boot metrics監(jiān)控指標使用教程

 更新時間:2022年02月22日 08:33:31   作者:kl  
這篇文章主要為大家介紹了針對應用監(jiān)控指標暴露spring boot metrics監(jiān)控指標的使用教程,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步

spring boot metrics是什么?

針對應用監(jiān)控指標暴露,spring boot有一套完整的解決方案,并且內(nèi)置了好很多的指標收集器,如tomcat、jvm、cpu、kafka、DataSource、spring mvc(缺少直方圖的數(shù)據(jù))等?;趍icrometer技術,幾乎支持所有主流的監(jiān)控服務的指標數(shù)據(jù)收集,這其中就包含了我們線上使用的Prometheus,這份指南旨在最快速接入boot的metrics功能,暴露prometheus的數(shù)據(jù)監(jiān)控指標服務。

micrometer地址:https://micrometer.io/

一、引入依賴

implementation ('org.springframework.boot:spring-boot-starter-actuator')
implementation ('io.micrometer:micrometer-registry-prometheus:1.6.1')
implementation ('io.micrometer:micrometer-core:1.6.1')

actuator是spring boot中負責運維功能的包,這里主要是通過它來暴露和管理metrics接口的。其他兩個依賴是為了包兼容引入的,在sprinr boot2.x中,actuator中默認引入的prometheus支持包存在兼容性問題,如果你的環(huán)境不存在兼容性問題,可以不用引入下面兩個依賴。

二、配置啟用

通過如下的配置,來開啟prometheus的端點接口服務

management.endpoints.web.exposure.include=prometheus

開啟服務后,會暴露/actuator/prometheus 端點接口服務。

在瀏覽器中,輸入http://localhost:8080/actuator/prometheus ??梢钥吹絻?nèi)置的指標收集器收集到的監(jiān)控指標

三、獨立的web服務

默認情況下,/actuator/prometheus端點服務跟隨應用的web容器一起發(fā)布,但是當我們的web服務面向公網(wǎng)需要授權認證時,可以使用如下配置啟用獨立的容器暴露服務

management.server.port=8081

四、全局標簽設置

在metrics監(jiān)控系統(tǒng)設計中,tag用來標記區(qū)分一組指標集。比如我們在監(jiān)控grpc時,servicename就是是監(jiān)控指標的其中一個tag。有的時候為了區(qū)分環(huán)境和應用,我們會設置一些全局的tag:

management.metrics.tags.application = ${spring.application.name}
management.metrics.tags.region = bj

如上配置,我們添加了一個應用的名字和一個區(qū)域的tag。這種配置是全局的。雖然grpc的組件可能只記錄了servicename,但是最終數(shù)據(jù)呈現(xiàn)時,也會帶上全局配置的tag

五、自定義指標收集

spring boot所有的指標最終都是通過MeterRegistry來注冊的,這個實例被spring托管,所以你可以在spring的上下文中注入這個實例,結合micrometer指標定義,自定義自己的監(jiān)控指標

六、推送or拉取指標

目前,我們線上是通過k8s的monitoring.coreos.com/v1 api定義指定prometheus主動拉取應用pod的監(jiān)控指標信息,主要是因為之前的metrics系統(tǒng)是基于prometheus client模式暴露的。在基于spring boot的metrics系統(tǒng)中,主動推送數(shù)據(jù)的模式非常容易實現(xiàn),這里需要prometheus-gateway支持

引入依賴

implementation("io.prometheus:simpleclient_pushgateway")

啟用push模式

#開啟prometheus的數(shù)據(jù)推送模式
management.metrics.export.prometheus.pushgateway.enabled=true
#prometheus服務端地址
management.metrics.export.prometheus.pushgateway.base-url=localhost:9091
#推送數(shù)據(jù)的頻率,默認1m(單位分鐘)
management.metrics.export.prometheus.pushgateway.push-rate=1m
#在jvm關閉之前將數(shù)據(jù)推送出去
management.metrics.export.prometheus.pushgateway.shutdown-operation=push

以上就是spring boot metrics監(jiān)控指標使用教程的詳細內(nèi)容,更多關于spring boot metrics監(jiān)控指標教程的資料請關注腳本之家其它相關文章!

相關文章

最新評論

雷州市| 东乡县| 乐安县| 大方县| 宜州市| 离岛区| 平舆县| 留坝县| 辉县市| 辰溪县| 江口县| 耿马| 峡江县| 田阳县| 双牌县| 涟源市| 蒲江县| 平阴县| 潮安县| 郑州市| 汤阴县| 泰来县| 旬阳县| 英德市| 馆陶县| 黎平县| 清水县| 金寨县| 晋城| 临夏市| 巴林左旗| 宜黄县| 道真| 定安县| 漳州市| 衡阳市| 嘉祥县| 突泉县| 北流市| 灌阳县| 闵行区|