prometheus監(jiān)控springboot應(yīng)用簡(jiǎn)單使用介紹詳解
對(duì)于springboot應(yīng)用,需要以下幾個(gè)步驟
springboot應(yīng)用開(kāi)啟endpoint,添加actuator的以來(lái)和promethus的依賴
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency> <dependency> <groupId>io.micrometer</groupId> <artifactId>micrometer-registry-prometheus</artifactId> </dependency>
在yml文件或者properties文件中,加入以下配置:
management:
endpoints:
jmx:
exposure:
include: "*"
web:
exposure:
include: "*"
metrics:
export:
datadog:
application-key: ${spring.application.name}
這里需要注意是,*號(hào)是需要加雙引號(hào)的。
以上兩個(gè)步驟完畢后,剩下的就是要加registry了:
@Bean MeterRegistryCustomizer<MeterRegistry> configurer(
@Value("${spring.application.name}") String applicationName) {
return (registry) -> registry.
config().
commonTags("application", applicationName);
}
對(duì)于springboot的應(yīng)用,到此基本完成了。接下來(lái)是啟動(dòng)promethus。
配置prometheus
首先要下在prometheus":Prometheus - Monitoring system & time series database"
在下載頁(yè)面,選擇何時(shí)的版本下載,推薦下載tar.gz包。下載好后,進(jìn)行解壓。在合適的路徑下即可。
這里介紹下prometheus的目錄和文件:
1、prometheus采用的都是yml文件的配置方式。
2、在根目錄下,有個(gè)prometheus.yml配置文件,文件初始化的內(nèi)容如下:
global: scrape_interval: 15s # 這個(gè)是每次數(shù)據(jù)手機(jī)的頻率 evaluation_interval: 15s # 評(píng)估告警規(guī)則的頻率。 rule_files: # - "first.rules" # - "second.rules" scrape_configs: # 通過(guò)這里的配置控制prometheus監(jiān)控的資源 - job_name: prometheus # prometheus自身默認(rèn)的 static_configs: - targets: ['localhost:9090'] # 默認(rèn)暴露的是9090端口服務(wù)
global是全局配置。具體見(jiàn)上面的注釋說(shuō)明。
3、添加我們的應(yīng)用,對(duì)springboot進(jìn)行監(jiān)控
- job_name: 'spring-sample' metrics_path: 'actuator/prometheus' # 這里我們springboot暴露出來(lái)的endpoint scrape_interval: 5s # 信息收集時(shí)間是間隔5秒 static_configs: - targets: ['localhost:8778'] # 這里是springboot暴露出來(lái)的地址和端口
4、這些配置完成后,可以啟動(dòng)prometheus,./prometheus --config.file=prometheus.yml,服務(wù)即可啟動(dòng)。具體訪問(wèn)產(chǎn)檢官網(wǎng)。
配置grafana
下載grafana,直接啟動(dòng)即可。
1、啟動(dòng)命令參見(jiàn)官網(wǎng):./grafana-server web
2、配置datasource,選擇prometheus。這個(gè)里面有個(gè)很重要的注意點(diǎn),我看網(wǎng)上很多人在轉(zhuǎn)如何用prometheus監(jiān)控springboot應(yīng)用,估計(jì)自己沒(méi)去實(shí)際搭建,在interval這個(gè)時(shí)間上,默認(rèn)是數(shù)字,比如15,代表是15秒。在添加dashboard的時(shí)候,會(huì)發(fā)現(xiàn)監(jiān)控圖標(biāo)左上角是個(gè)紅點(diǎn),報(bào)錯(cuò):Invalid interval string, expecting a number followed by one of "Mwdhmsy" ,這個(gè)錯(cuò)的解決方案就是在這些時(shí)間間隔后面加個(gè)"s"。問(wèn)題解決。
3、選擇dashboard,import的里輸入一個(gè)模板,可以去dashboards去找你對(duì)應(yīng)的模板,我們這里選用jvm的4701模板,然后就能看到你的springboot的監(jiān)控信息了。到此,整個(gè)搭建完成。
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- Prometheus監(jiān)控Springboot程序的實(shí)現(xiàn)方法
- SpringBoot使用prometheus監(jiān)控的示例代碼
- springboot2.X整合prometheus監(jiān)控的實(shí)例講解
- SpringBoot+Prometheus+Grafana實(shí)現(xiàn)應(yīng)用監(jiān)控和報(bào)警的詳細(xì)步驟
- Prometheus 入門教程之SpringBoot 實(shí)現(xiàn)自定義指標(biāo)監(jiān)控
- springboot集成普羅米修斯(Prometheus)的方法
- 使用Prometheus+Grafana的方法監(jiān)控Springboot應(yīng)用教程詳解
- SpringBoot 使用Prometheus采集自定義指標(biāo)數(shù)據(jù)的方案
相關(guān)文章
Spring Boot 集成Mybatis實(shí)現(xiàn)主從(多數(shù)據(jù)源)分離方案示例
本篇文章主要介紹了Spring Boot 集成Mybatis實(shí)現(xiàn)主從(多數(shù)據(jù)源)分離方案實(shí)例,具有一定的參考價(jià)值,有興趣的可以了解一下。2017-03-03
Mybatis-Plus多種批量插入方案對(duì)比小結(jié)
在項(xiàng)目中優(yōu)化Mybatis-Plus批量插入性能是關(guān)鍵,通過(guò)比較不同方案,本文就來(lái)介紹一下Mybatis-Plus多種批量插入方案對(duì)比小結(jié),感興趣都的可以了解一下2024-10-10
Spring Boot自定義配置屬性源(PropertySource)
這篇文章主要介紹了Spring Boot自定義配置屬性源(PropertySource),小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2018-06-06
利用Java多線程技術(shù)導(dǎo)入數(shù)據(jù)到Elasticsearch的方法步驟
這篇文章主要介紹了利用Java多線程技術(shù)導(dǎo)入數(shù)據(jù)到Elasticsearch的方法步驟,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2019-07-07
SpringBoot JWT實(shí)現(xiàn)token登錄刷新功能
JWT本身是無(wú)狀態(tài)的,這點(diǎn)有別于傳統(tǒng)的session,不在服務(wù)端存儲(chǔ)憑證。這種特性使其在分布式場(chǎng)景,更便于擴(kuò)展使用。接下來(lái)通過(guò)本文給大家分享SpringBoot JWT實(shí)現(xiàn)token登錄刷新功能,感興趣的朋友一起看看吧2021-09-09
Java日志框架打印應(yīng)用程序日志代碼的執(zhí)行情況分析
在配置INFO日志級(jí)別時(shí),日志器(logger)中debug級(jí)的日志代碼仍會(huì)被執(zhí)行,只是是否輸出取決于配置的日志級(jí)別,本文基于Java 1.8、SLF4J 1.7.25和Log4j 2.20.0進(jìn)行實(shí)驗(yàn),詳述了日志框架處理日志代碼的機(jī)制,感興趣的朋友一起看看吧2024-10-10

