在spring cloud中使用springboot admin

人盡茶涼 提交于 2019-11-29 00:18:40

##maven

		<!--spring boot admin-->
        <!-- https://mvnrepository.com/artifact/de.codecentric/spring-boot-admin-server -->
        <dependency>
            <groupId>de.codecentric</groupId>
            <artifactId>spring-boot-admin-server</artifactId>
            <version>1.4.6</version>
            <exclusions>
                <exclusion>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-web</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <!--&lt;!&ndash; https://mvnrepository.com/artifact/de.codecentric/spring-boot-admin-server-ui-turbine &ndash;&gt;-->
        <!--<dependency>-->
            <!--<groupId>de.codecentric</groupId>-->
            <!--<artifactId>spring-boot-admin-server-ui-activiti</artifactId>-->
            <!--<version>1.4.6</version>-->
        <!--</dependency>-->
        <dependency>
            <groupId>de.codecentric</groupId>
            <artifactId>spring-boot-admin-server-ui-turbine</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.springframework.boot</groupId>
            <artifactId>spring-boot-configuration-processor</artifactId>
        </dependency>

这里由于spring boot版本不一致,因此eclude了admin server中的start web spring-boot-admin-server-ui-activiti没看出来有什么用,因此注释掉了 由于使用了turbine来聚合hystrix,因此使用了spring-boot-admin-server-ui-turbine

##配置

spring.boot.admin:
#  routes:
#    endpoints: env,metrics,trace,dump,jolokia,info,configprops,trace,logfile,refresh,flyway,liquibase,heapdump,hystrix.stream,turbine.stream,activiti
  turbine:
    clusters: default
    url: http://localhost:8889/turbine.stream

访问 http://localhost:8889/#/turbine 输入图片说明

##动态修改日志级别

需使用logback,并开启jmxConfigurator

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <include resource="org/springframework/boot/logging/logback/base.xml"/>
    <!--<logger name="com.codecraft.graphite" level="DEBUG"/>-->

    <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
        <!-- encoders are  by default assigned the type
             ch.qos.logback.classic.encoder.PatternLayoutEncoder -->
        <encoder>
            <pattern>%d{HH:mm:ss.SSS} %level [%thread] %caller{1} - %msg%n</pattern>
        </encoder>
    </appender>

    <root level="info">
        <appender-ref ref="STDOUT" />
    </root>

    <jmxConfigurator/>
</configuration>

还需要依赖jolokia来将jmx的操作以http的形式暴露出来

<dependency>
   <groupId>org.jolokia</groupId>
   <artifactId>jolokia-core</artifactId>
</dependency>

然后就可以动态修改日志级别了 输入图片说明

##doc

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!