跳到主要内容

可观测系统

SpringBoot+Prometheus 监控

官网:https://prometheus.io/

中文官网:https://prometheus.ac.cn/

基本介绍

Prometheus将其指标收集并存储为时间序列数据,即指标信息与记录它的时间戳一起存储,以及称为标签的可选键值对。

Spring Boot Actuator 是 Spring Boot 提供的一系列用于监控和管理 Spring Boot 应用的工具。它提供了许多端点(endpoints),例如 /health、/info、/metrics 等,这些端点可以公开应用的内部信息,如健康状态、配置信息和度量指标。

项目部署

Docker部署prometheus:

version: '3.8'
services:
prometheus:
image: prom/prometheus:latest
container_name: prometheus
restart: always
ports:
- "10002:9090"
volumes:
- ./prometheus.yml:/etc/prometheus/prometheus.yml

Docker部署grafana:

version: '3.8'
services:
grafana:
image: grafana/grafana:latest
container_name: grafana
restart: always
ports:
- "10003:3000"
volumes:
- ./grafana:/var/lib/grafana

SpringBoot中使用

导入依赖:

        <dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-prometheus</artifactId>
<scope>runtime</scope>
</dependency>

暴露指标:

management:
endpoints:
enabled-by-default: true #暴露所有端点信息
web:
exposure:
include: '*' #以web方式暴露

配置Prometheus,在prometheus.yml中进行配置:

参考资料

https://blog.csdn.net/yyuggjggg/article/details/122864519