• SpringBoot-可视化监控


    一、添加依赖

    <dependency>       
       <groupId>org.springframework.bootgroupId>     
       <artifactId>spring-boot-starter-actuatorartifactId>  
    dependency>  
    
    
    <dependency>          
      <groupId>io.prometheusgroupId>    
      <artifactId>simpleclient_spring_bootartifactId>
      <version>0.0.26version>                         
    dependency>
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11

    二、启动类

    @SpringBootApplication
    @EnablePrometheusEndpoint
    @EnableSpringBootMetricsCollector
    public class Application{
    	public static void main(String[] args){
    		SpringApplication.run(Application.class,args);
    	}
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8

    三、配置文件application.yml

    security:
    	user:
    		name: user
    		paassword: pwd
    		
    
    • 1
    • 2
    • 3
    • 4
    • 5

    应用程序启动后,会看到如下 一系列Mappings
    在这里插入图片描述

    四、利用账号密码访问http://localhost:8080/application/prometheus,可以看到Prometheus格式的指标数据

    在这里插入图片描述

    五、Prometheus采集SpringBoot指标数据

    获取Prometheus的Docker镜像

    docker pull prom/prometheus
    
    • 1

    编写prometheus.yml配置文件

    global:
      scrape_interval: 10s
      scrape_timeout: 10s
      evaluation_interval: 10m
    scrape_configs:
      - job_name: spring-boot
        scrape_interval: 5s
        scrape_timeout: 5s
        metrics_path: /application/prometheus
        scheme: http
        basic_auth:
          username: admin
          password: 123456
        static_configs:
          - targets:
            - 192.168.11.54:8099 #此处填写 Spring Boot 应用的 IP + 端口号
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16

    接着,启动Prometheus

    docker run -d --name prometheus -p 9090:9090
    -v D:\test\actuator\prometheus\prometheus.yml:/etc/prometheus/prometheus.yml prom/prometheus
    
    • 1
    • 2

    请注意,D:\test\actuator\prometheus\prometheus.yml ,是我的配置文件存放地址,我们需要将它放到容器里面去,所以用了-v来做文件映射。/etc/prometheus/prometheus.yml这个是容器启动的时候去取的默认配置,这里我是直接覆盖掉了它。prom/prometheus这是镜像,如果本地没有,就回去你设置好的镜像仓库去取。

    启动后,docker ps查看是否启动成功
    打开浏览器http://localhost:9090/targets,检查 Spring Boot 采集状态是否正常,如果看到下图就是成功了。
    在这里插入图片描述

    六、Grafana可视化监控数据

    # 获取Grafana的Docker镜像
    docker pull grafana/grafanal
    
    # 启动Grafana
    docker run --name grafana -d -p 3000:3000 grafana/grafanal
    
    • 1
    • 2
    • 3
    • 4
    • 5

    接着,访问 http://localhost:3000/ 配置 Prometheus 数据源:
    Grafana 登录账号 admin 密码 admin

    先配置数据源.
    在这里插入图片描述
    配置单个指标的可视化监控面板
    在这里插入图片描述

    在这里插入图片描述
    在这里插入图片描述

    prometh采集的数据
    在这里插入图片描述
    在这里插入图片描述

  • 相关阅读:
    类的加载过程(类的生命周期)详解
    10月12日,每日信息差
    【车】亚洲龙车辆学习使用
    D咖饮品机器人惊艳亮相:智能硬件改变生活习惯
    算法43-欧拉信封问题
    论文解读(BSFDA)《Black-box Source-free Domain Adaptation via Two-stage Knowledge Distillation》
    Android Studio 插件开发5、多语言
    Window PC上安装vmware搭建公网虚拟机遇到的问题
    期末复习【微机原理】
    【记录】打印|用浏览器生成证件照打印PDF,打印在任意尺寸的纸上(简单无损!)
  • 原文地址:https://blog.csdn.net/usa_washington/article/details/132805118