配置自定义告警邮件通知

2021-10-07 SpringBoot

如果线上服务突然崩溃了怎么办,如果崩溃了可以及时通知到我,而不是等用户投诉再去看监控,岂不是更好。

这里使用邮件通知的方式

<!-- java mail 邮件依赖 -->
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-mail</artifactId>
</dependency>

核心配置

spring:
  mail:
    host: smtp.163.com
    username: 账号
    password: 授权码
    default-encoding: UTF-8
  boot:
    admin:
      notify:
        mail:
          from: ${spring.mail.username}
          to: 1919301983@qq.com
          cc: 1919301983@qq.com

配置如下

server:
  port: 13006
  servlet:
    context-path: /blog-admin

spring:
  application:
    name: xk857-admin # 应用名
  security:
    user:
      name: admin
      password: admin
  cloud:
    nacos:
      discovery:
        server-addr: 121.5.111.26:8848
        metadata:
          management:
            context-path: ${server.servlet.context-path}/actuator
          user.name: admin
          user.password: admin
  thymeleaf:
    check-template: false
    check-template-location: false
  # 被监控的应用状态变更为 DOWN、OFFLINE、UNKNOWN 时, 会自动发出告警: 实例的状态、原因、实例地址等信息
  # 需要在 pom.xml 文件中添加 spring-boot-starter-mail 依赖
  # 配置发送告警的邮箱服务器,但是, 这个要能连接上, 否则会报错
  mail:
    host: smtp.163.com
    username: 账号
    password: 授权码
    default-encoding: UTF-8
  boot:
    admin:
      notify:
        mail:
          from: ${spring.mail.username}
          to: 1919301983@qq.com
          cc: 1919301983@qq.com


# 暴露端点
management:
  endpoints:
    web:
      exposure:
        include: '*'  # 需要开放的端点。默认值只打开 health 和 info 两个端点。通过设置 *, 可以开放所有端点
  endpoint:
    health:
      show-details: always
上次更新: 2 年前