prometheus監(jiān)控springboot應(yīng)用簡(jiǎn)單使用介紹詳解
對(duì)于springboot應(yīng)用,需要以下幾個(gè)步驟
springboot應(yīng)用開啟endpoint,添加actuator的以來和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)用,到此基本完成了。接下來是啟動(dòng)promethus。
配置prometheus
首先要下在prometheus":Prometheus - Monitoring system & time series database"
在下載頁面,選擇何時(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: # 通過這里的配置控制prometheus監(jiān)控的資源 - job_name: prometheus # prometheus自身默認(rèn)的 static_configs: - targets: ['localhost:9090'] # 默認(rèn)暴露的是9090端口服務(wù)
global是全局配置。具體見上面的注釋說明。
3、添加我們的應(yīng)用,對(duì)springboot進(jìn)行監(jiān)控
- job_name: 'spring-sample' metrics_path: 'actuator/prometheus' # 這里我們springboot暴露出來的endpoint scrape_interval: 5s # 信息收集時(shí)間是間隔5秒 static_configs: - targets: ['localhost:8778'] # 這里是springboot暴露出來的地址和端口
4、這些配置完成后,可以啟動(dòng)prometheus,./prometheus --config.file=prometheus.yml,服務(wù)即可啟動(dòng)。具體訪問產(chǎn)檢官網(wǎng)。
配置grafana
下載grafana,直接啟動(dòng)即可。
1、啟動(dòng)命令參見官網(wǎng):./grafana-server web
2、配置datasource,選擇prometheus。這個(gè)里面有個(gè)很重要的注意點(diǎn),我看網(wǎng)上很多人在轉(zhuǎn)如何用prometheus監(jiān)控springboot應(yīng)用,估計(jì)自己沒去實(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"。問題解決。
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)文章
Java通過導(dǎo)出超大Excel文件解決內(nèi)存溢出問題
導(dǎo)出excel是咱Java開發(fā)的必備技能,下面這篇文章主要給大家介紹了關(guān)于Java通過導(dǎo)出超大Excel文件解決內(nèi)存溢出問題的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),需要的朋友可以參考下2021-09-09Collections.shuffle()方法實(shí)例解析
這篇文章主要介紹了Collections.shuffle()方法實(shí)例解析,分享了相關(guān)代碼示例,小編覺得還是挺不錯(cuò)的,具有一定借鑒價(jià)值,需要的朋友可以參考下2018-01-01Spring AOP的幾種實(shí)現(xiàn)方式總結(jié)
本篇文章主要介紹了Spring AOP的幾種實(shí)現(xiàn)方式總結(jié),小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2017-02-02Jasypt的StandardPBEByteEncryptor使用源碼解析
這篇文章主要介紹了Jasypt的StandardPBEByteEncryptor使用源碼解析,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-09-09普通對(duì)象使用spring容器中的對(duì)象的實(shí)現(xiàn)方法
這篇文章主要介紹了普通對(duì)象使用spring容器中的對(duì)象的實(shí)現(xiàn)方法,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2019-06-06java使用@Transactional時(shí)常犯的N種錯(cuò)誤
@Transactional是我們?cè)谟肧pring時(shí)候幾乎逃不掉的一個(gè)注解,本文主要介紹了使用?@Transactional?時(shí)常犯的N種錯(cuò)誤,文中通過示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-01-01