java我爱编程

spring boot admin监控spring cloud应

2017-11-17  本文已影响186人  staconfree

搭建spring boot admin项目

官方地址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项目)中增加如下配置:

邮件配置常见问题:

解决方法:
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

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

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

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

上一篇 下一篇

猜你喜欢

热点阅读