Spring Cloud Admin实现微信监控及邮件提醒

一、创建Spring Cloud Admin项目

1.pom文件


<parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.0.6.RELEASE</version>
        <relativePath />
    </parent>
    
    <groupId>slan-shop</groupId>
    <artifactId>server-admin</artifactId>
    <version>0.0.1-SNAPSHOT</version>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
        </dependency>
        <dependency>
            <groupId>de.codecentric</groupId>
            <artifactId>spring-boot-admin-starter-server</artifactId>
            <version>2.0.6</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-thymeleaf</artifactId>
        </dependency>
    </dependencies>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>Finchley.RELEASE</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

2.配置文件


server.port=8005
spring.application.name=server-admin
eureka.client.serviceUrl.defaultZone=http://localhost:8000/eureka/

3.启动类


import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;

import de.codecentric.boot.admin.server.config.EnableAdminServer;

@EnableAutoConfiguration
@EnableAdminServer
public class SpringBootAdminApplication {
    public static void main(String[] args) {
        SpringApplication.run(SpringBootAdminApplication.class, args);
    }
}

4.在需要监控的项目添加配置

4.1.配置文件


spring.boot.admin.client.url=http://localhost:8005
management.endpoints.web.exposure.include=*
management.endpoint.health.show-details=ALWAYS

4.2 在需要监控的项目里添加pom依赖


       <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-thymeleaf</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>

二、测试

访问地址http://localhost:8005/,端口是自己配置文件里配置的
在这里插入图片描述

通过上图可以看到注册上来的服务,我配置了4个项目,所以这里就有4个服务。选择一个服务可以看到服务内的详细信息,如下图:
在这里插入图片描述

三、添加邮件提醒

1.添加pom依赖:


      <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-mail</artifactId>
        </dependency>

2.添加配置:


spring.mail.host=smtp.qq.com
spring.mail.username=303138741@qq.com
#注意这里的password不是邮箱密码,而是邮箱授权码
spring.mail.password=wsytydsenaipbjdg
spring.mail.properties.mail.smtp.auth=true
spring.mail.properties.mail.smtp.starttls.enable=true
spring.mail.properties.mail.smtp.starttls.required=true
# 发件邮箱
spring.boot.admin.notify.mail.from=303138741@qq.com

# 收件邮箱
spring.boot.admin.notify.mail.to=2389166591@qq.com

3.测试:

1.停掉一个服务或新服务上线都会发邮件,如下图是一个服务下线后发送的一封邮件提醒:
在这里插入图片描述

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值