一、Prometheus和AlertManager服务器部署
此处有很多博客有详细部署文档,本文省略。
二、SpringBoot添加Prometheus相关依赖和配置
1.pom依赖
<!-- SpringBoot Actuator -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-core</artifactId>
</dependency>
<!-- prometheus 收集数据功能包-->
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-prometheus</artifactId>
</dependency>
2.yml文件配置
bootstrap.yml(没有的话在application.yml文件)中添加如下配置
#Prometheus配置
management:
endpoints:
web:
exposure:
include: '*'
base-path: /actuator
metrics:
tags:
application: ${spring.application.name}
export:
prometheus:
enabled: true
endpoint:
metrics:
enabled: true
prometheus:
enabled: true
3.启动类Application中添加注册到micrometer的Bean
/**
* 项目启动时讲服务名注册到micrometer 中的 application,用于prometheu