使用Prometheus与Grafana追踪SpringBoot程序

本案例使用Prometheus去追踪SpringBoot的Metrics信息,通过Grafana将Prometheus收集到的信息进行可视化展示。

使用的软件版本:

OS:Win10 x64 专业版

JDK1.8_181

Prometheus-2.0

Grafana-6.3.0

1.Prometheus 配置文件 如下所示

# my global config
global:
  scrape_interval:     15s # Set the scrape interval to every 15 seconds. Default is every 1 minute. # 抓取target的时间间隔
  evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute. # 计算rules 的时间间隔
  # 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:
  - job_name: 'jvm-web'
    scrape_interval: 5s
    scrape_timeout: 5s
    metrics_path: '/actuator/prometheus'
    scheme: http
    static_configs:
      - targets:
        - 127.0.0.1:8389  #此处填写 Spring Boot 应用的 IP + 端口号

2.创建一个Spring Boot程序,这里只放pom.xml中主要配置

 
        
        
            org.springframework.boot
            spring-boot-starter-web
            2.1.4.RELEASE
        

        
            org.springframework.boot
            spring-boot-starter-test
            test
            
                
                    org.junit.vintage
                    junit-vintag-engine
                
                
                    junit
                    junit
                
            
        

        
            org.springframework.boot
            spring-boot-starter-actuator
        

        
        
            io.micrometer
            micrometer-registry-prometheus
            1.2.0
        

        
        
            io.github.mweirauch
            micrometer-jvm-extras
            0.1.4
        

    

    
        
            
                org.springframework.boot
                spring-boot-maven-plugin
                
                    
                        
                            build-info
                        
                    
                
            

            
                pl.project13.maven
                git-commit-id-plugin
                2.2.6
                
                    
                        
                            revision
                        
                    
                
                
                    ${project.basedir}/.git
                
            
        
    

3.启动Prometheus

使用Prometheus与Grafana追踪SpringBoot程序_第1张图片

windows版本只需要双击prometheus.exe即可。

验证地址:http://localhost:9090/

4.启动Grafana

验证地址:http://localhost:3000/

使用Prometheus与Grafana追踪SpringBoot程序_第2张图片

5.配置Grafanna数据源

使用Prometheus与Grafana追踪SpringBoot程序_第3张图片

你可能感兴趣的:(数据可视化)