Prometheus + Grafana 监控SpringBoot应用


 
一、用到的工具
  • Prometheus
  • Grafana
  • Micrometer
  • Grafana Dashboard (4701)
 
二、安装和运行Prometheus
  1. 官网下载prometheus-2.9.1.linux-amd64.tar.gz并解压
       2. 配置(修改Prometheus目录下的prometheus.yml文件)
 
       3. 启动(nohup ./prometheus --config.file=prometheus.yml &)
 
       4. 访问(localhost:9090)
 
 
三、安装和运行Granfana
 
     1. wget  https://dl.grafana.com/oss/release/grafana-6.2.5-1.x86_64.rpm
        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)
 
 
四、创建SpringBoot应用
 
1. 添加如下依赖

<dependency>
   <groupId>org.springframework.bootgroupId>
   <artifactId>spring-boot-starter-actuatorartifactId>
dependency>

<dependency>
   <groupId>io.micrometergroupId>
   <artifactId>micrometer-registry-prometheusartifactId>
dependency>

 

2. 配置监控

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 监控数据了,如下图:
 
Prometheus + Grafana 监控SpringBoot应用_第1张图片
 
是不是觉得挺简单哉!那就赶快自己动手试试吧!
 
参考资料:
  • https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#production-ready-metrics
  • https://prometheus.io/docs/prometheus/latest/getting_started/
  • https://micrometer.io/docs
  • https://grafana.com/docs/installation/rpm/

转载于:https://www.cnblogs.com/gdufs/p/11098402.html

你可能感兴趣的:(java)