當前位置:
首頁 >
前端技术
> javascript
>内容正文
javascript
grafana+prometheus监控Springboot服务
生活随笔
收集整理的這篇文章主要介紹了
grafana+prometheus监控Springboot服务
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
Prometheus(普羅米修斯)是一套開源的監(jiān)控&報警&時間序列數(shù)據(jù)庫的組合,由 SoundCloud 公司開發(fā)。
Prometheus 基本原理是通過 HTTP 協(xié)議周期性抓取被監(jiān)控組件的狀態(tài),這樣做的好處是任意組件只要提供 HTTP 接口就可以接入監(jiān)控系統(tǒng),不需要任何 SDK 或者其他的集成過程。這樣做非常適合虛擬化環(huán)境比如 VM 或者 Docker 。
Prometheus 應該是為數(shù)不多的適合 Docker、Mesos、Kubernetes 環(huán)境的監(jiān)控系統(tǒng)之一。
1.拉取鏡像
docker pull prom/prometheus2.創(chuàng)建prometheus目錄,新增prometheus.yml文件,用于指定設(shè)置docker地址
mkdir -p /home/prometheus3.創(chuàng)建prometheus容器,指定端口、名稱、掛載目錄、設(shè)置時區(qū)
docker run -d -p 9090:9090 -v /home/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml prom/prometheus4.訪問頁面
120.48.54.67:9090
springboot配置
在spring boot工程中引入actuator的起步依賴,以及micrometer-registry-prometheus的依賴。
<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-actuator</artifactId> </dependency> <dependency><groupId>io.micrometer</groupId><artifactId>micrometer-registry-prometheus</artifactId> <version>1.6.4</version> </dependency>application.yml暴露prometheus的接口;暴露metrics.tags,和spring.application.name一致。
server:port: 8087 spring:application:name: swaggerDemo management:endpoints:web:exposure:include: "*"metrics:tags:application: ${spring.application.name}回到prometheus目錄下面修改prometheus.yml:
# my global config global:scrape_interval: 15s # Set the scrape interval to every 15 seconds. Default is every 1 minute.evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute.# scrape_timeout is set to the global default (10s).# Alertmanager configuration alerting:alertmanagers:- static_configs:- targets:# - alertmanager:9093# Load rules once and periodically evaluate them according to the global 'evaluation_interval'. rule_files:# - "first_rules.yml"# - "second_rules.yml"# A scrape configuration containing exactly one endpoint to scrape: # Here it's Prometheus itself. scrape_configs:# The job name is added as a label `job=<job_name>` to any timeseries scraped from this config. ###以下內(nèi)容為SpringBoot應用配置- job_name: 'swaggerDemo'scrape_interval: 5smetrics_path: '/actuator/prometheus'static_configs:- targets: ['120.48.54.67:8087']重啟docker 容器,查看prometheus控制臺:
點擊查看,可以看到服務(wù)信息但是這是prometheus的信息,對于我們來說還是不好理解,這個時候需要結(jié)合Grafana 。
使用 Prometheus + Grafana 實現(xiàn)可視化界面
Add data source(添加數(shù)據(jù)源)
Import(導入模板)
12884是個默認的模板也可以自己去官網(wǎng)選一個模板:
查看儀表盤:
Prometheus+Alertmanager詳細配置郵箱告警
總結(jié)
以上是生活随笔為你收集整理的grafana+prometheus监控Springboot服务的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: centos 8 使用 nmcli 配置
- 下一篇: php 九宫格验证码,PHP+Ajax微