Spring Boot 应用可视化监控

企业动态
以下是Spring Boot 应用可视化监控,希望对大家学习有所帮助。

 [[247132]]

图文简介

 

快速开始

1、Spring Boot 应用暴露监控指标【版本 1.5.7.RELEASE】

首先,添加依赖如下依赖:

  1. <dependency> 
  2.            <groupId>org.springframework.boot</groupId> 
  3.            <artifactId>spring-boot-starter-actuator</artifactId> 
  4.        </dependency> 
  5.        <dependency> 
  6.            <groupId>io.prometheus</groupId> 
  7.            <artifactId>simpleclient_spring_boot</artifactId> 
  8.            <version>0.0.26</version> 
  9.        </dependency> 

然后,在启动类 Application.java 添加如下注解:

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

***,配置默认的登录账号和密码,在 application.yml 中:

  1. security: 
  2.  user
  3.    nameuser 
  4.    password: pwd 

提示:不建议配置 management.security.enabled:false启动应用程序后,会看到如下一系列的 Mappings

 

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

 

2、Prometheus 采集 Spring Boot 指标数据

首先,获取 Prometheus 的 Docker 镜像:

  1. $ docker pull prom/prometheus 

然后,编写配置文件 prometheus.yml :

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

接着,启动 Prometheus :

  1. $ docker run -d \ 
  2. --name prometheus \ 
  3. -p 9090:9090 \ 
  4. -m 500M \ 
  5. -v "$(pwd)/prometheus.yml":/prometheus.yml \ 
  6. -v "$(pwd)/data":/data \ 
  7. prom/prometheus \ 
  8. -config.file=/prometheus.yml \ 
  9. -log.level=info 

***,访问 http://localhost:9090/targets , 检查 Spring Boot 采集状态是否正常。

 

3、Grafana 可视化监控数据

首先,获取 Grafana 的 Docker 镜像:

  1. $ docker pull grafana/grafana 

然后,启动 Grafana:

  1. $ docker run --name grafana -d -p 3000:3000 grafana/grafana 

接着,访问 http://localhost:3000/ 配置 Prometheus 数据源:

Grafana 登录账号 admin 密码 admin

 

***,配置单个指标的可视化监控面板:

 

提示,此处不能任意填写,只能填已有的指标点,具体的可以在 Prometheus 的首页看到,即 http://localhost:9090/graph

 

多配置几个指标之后,即可有如下效果:

 

参考文档

  • prometheus 官方文档
  • Grafana Docker 安装
  • Spring Boot 官方文档

【本文为51CTO专栏作者“李强强”的原创稿件,转载请通过51CTO联系作者获取授权】

 

戳这里,看该作者更多好文

责任编辑:武晓燕 来源: 51CTO专栏
相关推荐

2009-04-21 14:26:41

可视化监控IT管理摩卡

2023-02-07 07:03:39

2020-03-11 14:39:26

数据可视化地图可视化地理信息

2020-03-01 14:01:22

Echarts数据可视化图表

2022-02-09 20:39:52

Actuator应用监控

2021-09-26 16:20:04

Sentry Dashboards 数据可视化

2009-08-31 13:32:12

2022-08-26 09:15:58

Python可视化plotly

2017-10-14 13:54:26

数据可视化数据信息可视化

2023-12-27 18:05:13

2020-11-10 09:19:23

Spring BootJava开发

2021-02-03 12:47:09

Spring Boot应用监控

2010-06-17 17:56:57

世博IT监控Rfid

2009-12-29 18:17:32

Silverlight

2021-01-21 05:32:26

云端视频监控

2023-04-14 08:21:55

2015-08-20 10:06:36

可视化

2022-04-15 11:32:20

IDE工具鸿蒙操作系统

2018-08-10 14:45:52

Python网络爬虫mongodb

2023-09-19 21:09:40

可视化监控Skywalking
点赞
收藏

51CTO技术栈公众号