spring boot admin监控spring cloud应用(在线修改日志级别,应用状态变化邮件告警)

官方地址spring-boot-admin

1、 pom.xml:


    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.5.2.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
        <dependencies>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
             <artifactId>spring-cloud-starter-eureka</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency> 
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-eureka</artifactId>
        </dependency>
        <dependency>
            <groupId>de.codecentric</groupId>
            <artifactId>spring-boot-admin-server</artifactId>
            <version>1.4.6</version>
        </dependency>
        <dependency>
            <groupId>de.codecentric</groupId>
            <artifactId>spring-boot-admin-server-ui</artifactId>
            <version>1.4.6</version>
        </dependency>
        <dependency>
            <groupId>org.jolokia</groupId>
            <artifactId>jolokia-core</artifactId>
        </dependency> 
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-mail</artifactId>
        </dependency>
    </dependencies>
    
        <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>Camden.SR5</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

2、新建Application启动类

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.context.annotation.Configuration;
import de.codecentric.boot.admin.config.EnableAdminServer;

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

3、application.properties

server.port=7088
spring.application.name=service-admin
eureka.client.serviceUrl.defaultZone=http://127.0.0.1:1111/eureka/
management.security.enabled=false
#endpoints.health.sensitive=true
#eureka.instance.leaseRenewalIntervalInSeconds=5
info.version=@project.version@

4、logback.xml

<configuration>
    <include resource="org/springframework/boot/logging/logback/base.xml"/>
    <jmxConfigurator/>
</configuration>

5、启动效果

从监控界面可以看到注册到spring cloud eureka的各个实例

image.png

 

image.png

发送邮件

spring boot admin 可以自动发送邮件
仅需

1、在pom.xml加入

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

2、application.properties加入

spring.mail.host=smtp.qq.com
spring.mail.username=526358233@qq.com
spring.mail.password=#qq邮箱授权码
spring.mail.properties.mail.smtp.auth=true
spring.mail.properties.mail.smtp.ssl.enable=true
spring.boot.admin.notify.mail.from=526358233@qq.com
spring.boot.admin.notify.mail.to=526358233@qq.com
spring.boot.admin.notify.mail.enabled=true
spring.boot.admin.notify.mail.ignore-changes=UNKNOWN:UP,UNKNOWN:OFFLINE,OFFLINE:UP

其中spring.boot.admin.notify.mail.ignore-changes 代表忽略这些状态的扭转,不发送邮件

日志级别在线调整

spring boot admin 有个很实用的功能,可以在线调整各个spring boot实例的日志级别

 

image.png

要利用该功能,还需在被监控项目(如图上的japp-demo-model1项目)中增加如下配置:

  • 1、application.properties增加:
    info.version=@project.version@
  • 2、logback.xml增加:
    <include resource="org/springframework/boot/logging/logback/base.xml"/>
    <jmxConfigurator/>
  • 3、pom.xml增加:
    <dependency>
    <groupId>org.jolokia</groupId>
    <artifactId>jolokia-core</artifactId>
    </dependency>

邮件配置常见问题:

  • 503 Error: need EHLO and AUTH first

解决方法:
application.properties加入如下配置:
spring.mail.username=526358233@qq.com
spring.mail.password=#此处为qq邮箱授权码,如何设置授权码见:http://service.mail.qq.com/cgi-bin/help?subtype=1&&id=28&&no=1001256
spring.mail.properties.mail.smtp.auth=true

  • 530 Error: A secure connection is requiered(such as ssl)

解决方法:
application.properties加入如下配置:
spring.mail.properties.mail.smtp.ssl.enable=true

  • 501 mail from address must be same as authorization user

解决方法:
需要配置发送人
spring.boot.admin.notify.mail.from=526358233@qq.com

参考项目:
https://github.com/Lovnx/micro-service
参考文章:
使用spring boot admin监控spring cloud应用程序
Spring Boot Admin 的使用

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值