Spring Boot Appication 监控记录可视化

SpringBoot 应用监控功能由 Actuator 模块进行采集,通常以 json/txt 文件格式进行显示。可视化方式通常需要配合其他组件进行,如 Prometheus 等。

1.在pom.xml中添加Actuator与Prometheus代码依赖

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>

<!-- Contains aspectj - required by TimedAspect -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-aop</artifactId>
</dependency>

<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-prometheus</artifactId>
<scope>runtime</scope>
</dependency>

2.在application.properties中配置暴露给actuator的接口,这样便可以通过/actuator/prometheus接口访问监控数据了

1
management.endpoints.web.exposure.include=health,info,prometheus

3.Prometheus是独立应用,需要单独启动。SpringBoot配置了Actuator暴露接口后,Prometheus会通过pull方式定期访问监控接口获取数据,可视化呈现给前端。
编辑 /etc/prometheus/prometheus.yml,配置:

1
2
3
4
5
6
7
8
9
10
11
12
13
# Sample Prometheus config
# This assumes that your Prometheus instance can access this application on localhost:8080
global:
scrape_interval: 15s # Set the scrape interval to every 15 seconds. Default is every 1 minute.
evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute.
# scrape_timeout is set to the global default (10s).

scrape_configs:
- job_name: 'spring boot scrape'
metrics_path: '/actuator/prometheus'
scrape_interval: 5s
static_configs:
- targets: ['localhost:8080']

其中localhost:8080为监控应用的IP和端口号

访问 http://localhost:8080/actuator/prometheus 应可以看到文本形式的监控数据。

4.浏览器输入 localhost:9090 进入 promethues 监控界面,点击上方菜单栏 Status > Targets:

Prometheus targets

React从零基础入门 Spring Cloud Gateway实验

评论

You forgot to set the shortname for Disqus. Please set it in _config.yml.
Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×