Prometheus + Grafana 監控SpringBoot應用


 
1、用到的工具
 
2、安裝和運行Prometheus
  1. 官網下載prometheus-2.9.1.linux-amd64.tar.gz並解壓
       2. 配置(修改Prometheus目錄下的prometheus.yml文件)
 
       3. 啓動(nohup ./prometheus --config.file=prometheus.yml &)
 
       4. 訪問(localhost:9090)
 
 
3、安裝和運行Granfana
 
        yum localinstall grafana-6.2.5-1.x86_64.rpm  
 
     2. 啓動(service grafana-server start)
 
     3. 訪問(http://localhost:3000/,admin/admin)
 
     4. 添加Prometheus數據源   
 
     4. 添加Dashboard(4701)
 
 
4、建立SpringBoot應用
 
1. 添加以下依賴
<!--監控 begin-->
<dependency>
   <groupId>org.springframework.boot</groupId>
   <artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<!--Micrometer-->
<dependency>
   <groupId>io.micrometer</groupId>
   <artifactId>micrometer-registry-prometheus</artifactId>
</dependency>
<!--監控 end-->

 

2. 配置監控html

spring.application.name=bounter-monitor

## 暴露全部的actuator endpoints
management.endpoints.web.exposure.include=*

## Grafana上的應用名字
management.metrics.tags.application=${spring.application.name}

 

3. 打包並在服務器上運行
    nohup java -jar bounter-monitor &
 
4. 配置Prometheus endpoint
  # SpringBoot Application
  - job_name: 'bounter-monitor'
    scrape_interval: 5s
    metrics_path: '/actuator/prometheus'
    static_configs:
      - targets: ['localhost:8080']
 
在作好以上步驟後,重啓Prometheus就能夠在Grafana看到jvm 監控數據了,以下圖:
 
 
是否是以爲挺簡單哉!那就趕快本身動手試試吧!
 
參考資料:
相關文章
相關標籤/搜索