prometheus監(jiān)控springboot應(yīng)用簡單使用介紹詳解
對于springboot應(yīng)用,需要以下幾個步驟
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}
這里需要注意是,*號是需要加雙引號的。
以上兩個步驟完畢后,剩下的就是要加registry了:
@Bean MeterRegistryCustomizer<MeterRegistry> configurer( @Value("${spring.application.name}") String applicationName) { return (registry) -> registry. config(). commonTags("application", applicationName); }
對于springboot的應(yīng)用,到此基本完成了。接下來是啟動promethus。
配置prometheus
首先要下在prometheus":Prometheus - Monitoring system & time series database"
在下載頁面,選擇何時的版本下載,推薦下載tar.gz包。下載好后,進(jìn)行解壓。在合適的路徑下即可。
這里介紹下prometheus的目錄和文件:
1、prometheus采用的都是yml文件的配置方式。
2、在根目錄下,有個prometheus.yml配置文件,文件初始化的內(nèi)容如下:
global: scrape_interval: 15s # 這個是每次數(shù)據(jù)手機(jī)的頻率 evaluation_interval: 15s # 評估告警規(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)用,對springboot進(jìn)行監(jiān)控
- job_name: 'spring-sample' metrics_path: 'actuator/prometheus' # 這里我們springboot暴露出來的endpoint scrape_interval: 5s # 信息收集時間是間隔5秒 static_configs: - targets: ['localhost:8778'] # 這里是springboot暴露出來的地址和端口
4、這些配置完成后,可以啟動prometheus,./prometheus --config.file=prometheus.yml,服務(wù)即可啟動。具體訪問產(chǎn)檢官網(wǎng)。
配置grafana
下載grafana,直接啟動即可。
1、啟動命令參見官網(wǎng):./grafana-server web
2、配置datasource,選擇prometheus。這個里面有個很重要的注意點(diǎn),我看網(wǎng)上很多人在轉(zhuǎn)如何用prometheus監(jiān)控springboot應(yīng)用,估計自己沒去實際搭建,在interval這個時間上,默認(rèn)是數(shù)字,比如15,代表是15秒。在添加dashboard的時候,會發(fā)現(xiàn)監(jiān)控圖標(biāo)左上角是個紅點(diǎn),報錯:Invalid interval string, expecting a number followed by one of "Mwdhmsy" ,這個錯的解決方案就是在這些時間間隔后面加個"s"。問題解決。
3、選擇dashboard,import的里輸入一個模板,可以去dashboards去找你對應(yīng)的模板,我們這里選用jvm的4701模板,然后就能看到你的springboot的監(jiān)控信息了。到此,整個搭建完成。
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- Prometheus監(jiān)控Springboot程序的實現(xiàn)方法
- SpringBoot使用prometheus監(jiān)控的示例代碼
- springboot2.X整合prometheus監(jiān)控的實例講解
- SpringBoot+Prometheus+Grafana實現(xiàn)應(yīng)用監(jiān)控和報警的詳細(xì)步驟
- Prometheus 入門教程之SpringBoot 實現(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-09Spring AOP的幾種實現(xiàn)方式總結(jié)
本篇文章主要介紹了Spring AOP的幾種實現(xiàn)方式總結(jié),小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2017-02-02Jasypt的StandardPBEByteEncryptor使用源碼解析
這篇文章主要介紹了Jasypt的StandardPBEByteEncryptor使用源碼解析,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-09-09