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

搭建spring boot admin项目

官方地址spring-boot-admin

1、 pom.xml:


    
        org.springframework.boot
        spring-boot-starter-parent
        1.5.2.RELEASE
         
    
        
        
            org.springframework.cloud
             spring-cloud-starter-eureka
        
        
            org.springframework.boot
            spring-boot-starter-actuator
         
        
            org.springframework.cloud
            spring-cloud-starter-eureka
        
        
            de.codecentric
            spring-boot-admin-server
            1.4.6
        
        
            de.codecentric
            spring-boot-admin-server-ui
            1.4.6
        
        
            org.jolokia
            jolokia-core
         
        
            org.springframework.boot
            spring-boot-starter-mail
        
    
    
        
        
            
                org.springframework.cloud
                spring-cloud-dependencies
                Camden.SR5
                pom
                import
            
        
    

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
[email protected]@

4、logback.xml


    
    

5、启动效果

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

spring boot admin监控spring cloud应用(在线修改日志级别,应用状态变化邮件告警)_第1张图片
image.png

spring boot admin监控spring cloud应用(在线修改日志级别,应用状态变化邮件告警)_第2张图片
image.png

发送邮件

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

1、在pom.xml加入
        
            org.springframework.boot
            spring-boot-starter-mail
        
2、application.properties加入
spring.mail.host=smtp.qq.com
[email protected]
spring.mail.password=#qq邮箱授权码
spring.mail.properties.mail.smtp.auth=true
spring.mail.properties.mail.smtp.ssl.enable=true
[email protected]
[email protected]
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实例的日志级别


spring boot admin监控spring cloud应用(在线修改日志级别,应用状态变化邮件告警)_第3张图片
image.png

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

  • 1、application.properties增加:
    [email protected]@
  • 2、logback.xml增加:

  • 3、pom.xml增加:

    org.jolokia
    jolokia-core

邮件配置常见问题:

  • 503 Error: need EHLO and AUTH first

解决方法:
application.properties加入如下配置:
[email protected]
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

解决方法:
需要配置发送人
[email protected]

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

你可能感兴趣的:(spring boot admin监控spring cloud应用(在线修改日志级别,应用状态变化邮件告警))