Spring-boot-admin

来自ling
跳转至: 导航搜索

https://github.com/codecentric/spring-boot-admin

http://codecentric.github.io/spring-boot-admin/2.0.1/

spring boot admin 2.0结合eureka监控spring boot服务

端点列表

basic-auth,spring-session,oauth2 with spring boot admin

register和cloud admin合并

You can include the Spring Boot Admin Server to your Eureka server. Setup everything as described above and set spring.boot.admin.context-path to something different than "/" so that the Spring Boot Admin Server UI won’t clash with Eureka’s one.

Submitting the credentials using SBA Client:

application.yml

spring.boot.admin.client:
    url: http://localhost:8080
    instance:
      metadata:
        user.name: ${spring.security.user.name}
        user.password: ${spring.security.user.password}

  boot:
    admin:
      client:
        username: "user"       #These two are needed so that the client
        password: "password"   #can register at the protected server api
        instance:
          metadata:
            user.name: "user"         #These two are needed so that the server
            user.password: "password" #can access the protected client endpoints

Submitting the credentials using Eureka:

application.yml

eureka:
  instance:
    metadata-map:
      user.name: ${spring.security.user.name}
      user.password: ${spring.security.user.password}
eureka.instance.metadata-map.user.name: ${spring.security.user.name}
eureka.instance.metadata-map.user.password: ${spring.security.user.password}

server

spring.boot.admin.context-path	The context-path prefixes the path where the Admin Server’s statics assets and API should be served. Relative to the Dispatcher-Servlet.		Admin Server 保留的静态访问和API的前缀(当你在业务应用中使用而不是单独使用时就很有必要了)
spring.boot.admin.monitor.period	Time interval in ms to update the status of applications with expired status-informations.	10.000	更新应用信息的频率,单位毫秒
spring.boot.admin.monitor.status-lifetime	Lifetime of application statuses in ms. The applications /health-endpoint will not be queried until the lifetime has expired.	10.000	被监控的应用信息的过期时间,单位毫秒

client和加密

If you protect the /instances endpoint don’t forget to configure the username and password on your SBA-Client using spring.boot.admin.client.username and spring.boot.admin.instance.password

Spring Cloud 对自动发现的支持

Table 3. Spring Boot Admin Server configuration options

spring.boot.admin.context-path

The context-path prefixes the path where the Admin Server’s statics assets and API should be served. Relative to the Dispatcher-Servlet.

spring.boot.admin.monitor.period

Time interval in ms to update the status of applications with expired status-information.

10,000

spring.boot.admin.monitor.status-lifetime

Lifetime of application statuses in ms. The applications /health-endpoint will not be queried until the lifetime has expired.

10,000

spring.boot.admin.monitor.connect-timeout

Connect timeout in ms when querying the applications' status and info.

2,000

spring.boot.admin.monitor.read-timeout

Read timeout in ms when querying the applications' status and info.

20,000

spring.boot.admin.metadata-keys-to-sanitize

Metadata values for the keys matching these regex patterns will be sanitized in all json output.

".password$", ".*secret$", ".*key$", ".$token$", ".credentials.", ".*vcap_services$"

spring.boot.admin.probed-endpoints

For Spring Boot 1.x client applications SBA probes for the specified endpoints using an OPTIONS request. If the path differs from the id you can specify this as id:path (e.g. health:ping)..

"health", "env", "metrics", "httptrace:trace", "threaddump:dump", "jolokia", "info", "logfile", "refresh", "flyway", "liquibase", "heapdump", "loggers", "auditevents"

spring.boot.admin.instance-proxy.ignored-headers

Headers not to be forwarded when making requests to clients.

`"Cookie", "Set-Cookie", "Authorization"

spring.boot.admin.ui.brand

Brand to be shown in then navbar.

"<img src="assets/img/icon-spring-boot-admin.svg"><span>Spring Boot Admin</span>"

spring.boot.admin.ui.title

Page-Title to be shown.

"Spring Boot Admin"

logging

logfile 参考logback

Returns the contents of the logfile (if logging.file or logging.path properties have been set). Supports the use of the HTTP Range header to retrieve part of the log file’s content.

To make the logging section work you need to make the /jolokia-endpoint accessible. Include the jolokia-core.jar in your spring-boot-application:

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

Please note that the logging section currently only works with Logback. To make the section work with Logback please activate the JMXConfigurator in your logback.xml:

下面的<file>${log.path}/spring.log</file>中spring.log和<jmxConfigurator/>是关键

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

logback-spring.xml

<?xml version="1.0" encoding="UTF-8"?>
<!--
  ~    Copyright (c) 2018-2025, lengleng All rights reserved.
  ~
  ~ Redistribution and use in source and binary forms, with or without
  ~ modification, are permitted provided that the following conditions are met:
  ~
  ~ Redistributions of source code must retain the above copyright notice,
  ~ this list of conditions and the following disclaimer.
  ~ Redistributions in binary form must reproduce the above copyright
  ~ notice, this list of conditions and the following disclaimer in the
  ~ documentation and/or other materials provided with the distribution.
  ~ Neither the name of the pig4cloud.com developer nor the names of its
  ~ contributors may be used to endorse or promote products derived from
  ~ this software without specific prior written permission.
  ~ Author: lengleng (wangiegie@gmail.com)
  -->

<configuration debug="false" scan="false">
	<springProperty scope="context" name="log.path" source="logging.path"
					defaultValue="logs/${spring.application.name}"/>
	<springProperty scope="context" name="logging.level" source="logging.level" defaultValue="INFO"/>
	<springProperty scope="context" name="serverName" source="spring.application.name"/>
	<springProperty scop="context" name="spring.application.name" source="spring.application.name"
					defaultValue="ling.cloud"/>

	<!-- Console log output -->
	<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
		<encoder>
			<pattern>%d{MM-dd HH:mm:ss.SSS} %-5level [%logger{50}] - %msg%n</pattern>
		</encoder>
	</appender>

	<!-- Log file debug output -->
	<appender name="debug" class="ch.qos.logback.core.rolling.RollingFileAppender">
		<file>${log.path}/spring.log</file>
		<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
			<fileNamePattern>${log.path}/%d{yyyy-MM}/debug.%d{yyyy-MM-dd}.%i.log.gz</fileNamePattern>
			<maxFileSize>50MB</maxFileSize>
			<maxHistory>30</maxHistory>
		</rollingPolicy>
		<encoder>
			<pattern>%date [%thread] %-5level [%logger{50}] %file:%line - %msg%n</pattern>
		</encoder>
	</appender>

	<!-- Log file error output -->
	<appender name="error" class="ch.qos.logback.core.rolling.RollingFileAppender">
		<file>${log.path}/error.log</file>
		<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
			<fileNamePattern>${log.path}/%d{yyyy-MM}/error.%d{yyyy-MM-dd}.%i.log.gz</fileNamePattern>
			<maxFileSize>50MB</maxFileSize>
			<maxHistory>30</maxHistory>
		</rollingPolicy>
		<encoder>
			<pattern>%date [%thread] %-5level [%logger{50}] %file:%line - %msg%n</pattern>
		</encoder>
		<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
			<level>ERROR</level>
		</filter>
	</appender>

	<!-- Level: FATAL 0  ERROR 3  WARN 4  INFO 6  DEBUG 7 -->
	<root level="${logging.level}">
		<appender-ref ref="console"/>
		<appender-ref ref="debug"/>
		<appender-ref ref="error"/>
	</root>
	<!--<include resource="org/springframework/boot/logging/logback/base.xml"/>-->
	<jmxConfigurator/>
</configuration>

问题解决

你的主机中的软件中止了一个已建立的连接 Servlet.service() for servlet [dispatcherServlet] threw exception。