邮件报警
虽然使用AdminServer可以实现监控信息可视化,但是运维工程师不可能24小时盯着屏幕,如果在应用运行时出现问题时能够自动发邮件通知运维工程师,
就会方便很多。对此SpringBoot提供了相应的支持。
修改上一届的Admin工程,添加邮件发送依赖:
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-starter-server</artifactId>
<version>2.4.0</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-mail</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
接下来在application.yml中配置邮件发送基本信息:
spring:
mail:
host: smtp.qq.com
port: 465
username: **@qq.com
password: **
default-encoding: UTF-8
properties:
mail:
smtp:
socketFactory:
class: javax.net.ssl.SSLSocketFactory
debug: true
boot:
admin:
notify:
mail:
from: **@qq.com
to: **@outlook.com
cc:
ignore-changes:
配置完成后,重启AdminServer,然后启动被监控应用,就会收到应用上线或者下线的邮件警报。