Spring Boot Admin 参考指南 文档

参考文档:http://codecentric.github.io/spring-boot-admin/2.0.3/

Spring Boot管理员参考指南

1.什么是Spring Boot Admin?
codecentric的春季启动Admin是一个社区项目,管理和监控您的春季启动 ®应用。应用程序向我们的Spring Boot Admin Client注册(通过HTTP)或使用SpringCloud®(例如Eureka,Consul)发现。UI只是Spring Boot Actuator端点上的AngularJs应用程序。

2.入门
2.1。设置Spring Boot Admin Server
首先,您需要设置您的服务器。要做到这一点,只需设置一个简单的启动项目(使用start.spring.io)。由于Spring Boot Admin Server能够作为servlet或webflux应用程序运行,因此您需要决定并添加相应的Spring Boot Starter。在这个例子中,我们使用servlet web starter。

将Spring Boot Admin Server启动器添加到您的依赖项:

的pom.xml
<dependency>
    <groupId>de.codecentric</groupId>
    <artifactId>spring-boot-admin-starter-server</artifactId>
    <version>2.0.3</version>
</dependency>
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
</dependency>
通过添加配置来@EnableAdminServer引入Spring Boot Admin Server 配置:

@Configuration
@EnableAutoConfiguration
@EnableAdminServer
public class SpringBootAdminApplication {
    public static void main(String[] args) {
        SpringApplication.run(SpringBootAdminApplication.class, args);
    }
}
如果要通过servlet-container中的war-deployment设置Spring Boot Admin Server,请查看spring-boot-admin-sample-war。
另请参阅spring-boot-admin-sample-servlet项目,该项目还增加了安全性。

2.2。注册客户端应用程序
要在SBA服务器上注册您的应用程序,您可以包含SBA客户端或使用Spring Cloud Discovery(例如Eureka,Consul,...)。在SBA服务器端使用静态配置还有一个简单的选项。

2.2.1。Spring Boot管理客户端
每个要注册的应用程序都必须包含Spring Boot Admin Client。为了保护端点也添加了spring-boot-starter-security。

将spring-boot-admin-starter-client添加到依赖项中:

的pom.xml
<dependency>
    <groupId>de.codecentric</groupId>
    <artifactId>spring-boot-admin-starter-client</artifactId>
    <version>2.0.3</version>
</dependency>
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-security</artifactId>
</dependency>
通过配置Spring Boot Admin Server的URL来启用SBA客户端:

application.yml
spring.boot.admin.client.url: "http://localhost:8080"  
management.endpoints.web.exposure.include: "*"  
要注册的Spring Boot Admin Server的URL。
与Spring Boot 2一样,默认情况下,大多数端点都不会通过http公开,我们会公开所有这些端点。对于生产,您应该仔细选择要公开的端点。
使执行器端点可访问:

@Configuration
public static class SecurityPermitAllConfig extends WebSecurityConfigurerAdapter {
    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http.authorizeRequests().anyRequest().permitAll()  
            .and().csrf().disable();
    }
}
为简洁起见,我们暂时禁用了安全性。查看有关如何处理安全端点的安全性部分。
2.2.2。Spring Cloud Discovery
如果您已经为应用程序使用Spring Cloud Discovery,则不需要SBA客户端。只需将DiscoveryClient添加到Spring Boot Admin Server,其余部分由我们的AutoConfiguration完成。

以下步骤使用Eureka,但也支持其他Spring Cloud Discovery实施。有使用Consul和Zookeeper的例子。

另请参阅Spring Cloud文档。

将spring-cloud-starter-eureka添加到您的依赖项中:

的pom.xml
<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
通过添加@EnableDiscoveryClient到配置来启用发现:

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

    @Configuration
    public static class SecurityPermitAllConfig extends WebSecurityConfigurerAdapter {
        @Override
        protected void configure(HttpSecurity http) throws Exception {
            http.authorizeRequests().anyRequest().permitAll()  
                .and().csrf().disable();
        }
    }
}
为简洁起见,我们暂时禁用了安全性。查看有关如何处理安全端点的安全性部分。
告诉Eureka客户端在哪里找到服务注册表:

application.yml
eureka:   
  instance:
    leaseRenewalIntervalInSeconds: 10
    health-check-url-path: /actuator/health
  client:
    registryFetchIntervalSeconds: 5
    serviceUrl:
      defaultZone: ${EUREKA_SERVICE_URL:http://localhost:8761}/eureka/

management:
  endpoints:
    web:
      exposure:
        include: "*"  
  endpoint:
    health:
      show-details: ALWAYS
Eureka客户端的配置部分
与Spring Boot 2一样,默认情况下,大多数端点都不会通过http公开,我们会公开所有这些端点。对于生产,您应该仔细选择要公开的端点。
另请参阅spring-boot-admin-sample-eureka。

您可以将Spring Boot Admin Server包含在Eureka服务器中。如上所述设置所有内容并设置spring.boot.admin.context-path为不同的内容,"/"以便Spring Boot Admin Server UI不会与Eureka的用户界面冲突。
3.客户申请
3.1。在应用程序列表中显示版本
对于Spring Boot应用程序来说,显示版本的最简单方法是使用生成的build-info目标。另请参阅“ Spring Boot参考指南”。spring-boot-maven-pluginMETA-INF/build-info.properties

对于非Spring Boot应用程序,您可以添加version或build.version注册元数据,版本将显示在应用程序列表中。

的pom.xml
<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <executions>
                <execution>
                    <goals>
                        <goal>build-info</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>
3.2。JMX-bean管理
要在管理UI中与JMX-beans交互,您必须在应用程序中包含Jolokia。由于Jolokia是基于servlet的,因此不支持响应式应用程序。如果你正在使用spring-boot-admin-starter-client它,它会被拉进来,如果没有将Jolokia添加到你的依赖项:

的pom.xml
<dependency>
    <groupId>org.jolokia</groupId>
    <artifactId>jolokia-core</artifactId>
</dependency>
3.3。日志文件查看器
默认情况下,日志文件无法通过执行器端点访问,因此在Spring Boot Admin中不可见。为了启用日志文件执行器端点,您需要配置Spring Boot以编写日志文件,方法是设置 logging.path或logging.file。

Spring Boot Admin将检测看起来像URL的所有内容并将其呈现为超链接。

还支持ANSI颜色转义。您需要设置自定义文件日志模式,因为Spring Boot的默认模式不使用颜色。

application.properties
logging.file =的/ var /数/样品引导application.log 
logging.pattern.file =%clr(%d {yyyy-MM-dd HH:mm:ss.SSS}){faint}%clr(%5p)%clr($ {PID}){magenta}%clr( -  - ){faint}%clr([%15.15t]){faint}%clr(% -  40.40logger {39}){cyan}%clr(:){faint}%m%n%wEx 
写入日志文件的目标。启用日志文件执行器端点。
使用ANSI颜色的文件日志模式。
3.4。每个实例显示标签
Tags是一种在每个实例中添加可视标记的方法,它们将出现在应用程序列表和实例视图中。默认情况下,不会向实例添加任何标记,并且由客户端通过将信息添加到元数据或信息端点来指定所需的标记。

application.properties
#using元数据
spring.boot.admin.client.instance.metadata.tags.environment =测试

#using info端点
info.tags.environment =测试
3.5。Spring Boot管理客户端
Spring Boot Admin Client在管理服务器上注册应用程序。这是通过定期向SBA服务器发送HTTP post请求来提供有关应用程序的信息来完成的。它还将Jolokia添加到您的应用程序中,以便可以通过HTTP访问JMX-beans。

有很多属性可以影响SBA客户端注册应用程序的方式。如果不符合您的需求,您可以提供自己的AppliationFactory实现。
表1. Spring Boot Admin Client配置选项
物业名称    描述    默认值
spring.boot.admin.client.enabled

启用S​​pring Boot Admin Client。

true

spring.boot.admin.client.url

逗号分隔Spring Boot Admin服务器的有序URL列表以进行注册。这会触发自动配置。强制性的。

spring.boot.admin.client.api路径

管理服务器上的注册端点的Http路径。

"instances"

spring.boot.admin.client.username 
spring.boot.admin.client.password

SBA Server api受HTTP基本身份验证保护时的用户名和密码。

spring.boot.admin.client.period

重复注册的间隔(以ms为单位)。

10,000

spring.boot.admin.client.connect超时

连接超时以进行注册(以ms为单位)。

5,000

spring.boot.admin.client.read超时

读取注册超时(以ms为单位)。

5,000

spring.boot.admin.client.auto登记

如果设置为true,则在应用程序准备好后,将自动安排注册应用程序的定期任务。

true

spring.boot.admin.client.auto,注销

切换到上下文关闭时在Spring Boot Admin服务器上启用自动注销。如果未设置该值,则在检测到正在运行的CloudPlatform时该功能处于活动状态。

null

一次spring.boot.admin.client.register

如果设置为true,则客户端将仅针对一个管理服务器注册(按顺序定义spring.boot.admin.instance.url); 如果该管理服务器出现故障,将自动注册下一个管理服务器。如果为false,将注册所有管理服务器。

true

spring.boot.admin.client.instance.health-URL

健康网址注册。如果可访问的URL不同(例如Docker),可以重写。在注册表中必须是唯一的。

基于管理网址和网址猜测endpoints.health.id。

spring.boot.admin.client.instance.management碱基网址

用于计算要注册的management-url的基本URL。路径在运行时推断,并附加到基本URL。

猜测基于management.port,服务网址和server.servlet-path。

spring.boot.admin.client.instance.management-URL

管理 - 网址注册。如果可访问的URL不同(例如Docker),则可以重写。

猜测基于管理基础网址和management.context-path。

spring.boot.admin.client.instance.service碱基网址

用于计算要注册的service-url的基本URL。路径在运行时推断,并附加到基本URL。

猜测基于主机名,server.port。

spring.boot.admin.client.instance.service-URL

要注册的服务网址。如果可访问的URL不同(例如Docker),则可以重写。

猜测基于service-base-url和server.context-path。

spring.boot.admin.client.instance.name

要注册的名称。

${spring.application.name}如果设置,"spring-boot-application"否则。

spring.boot.admin.client.instance.prefer-IP

使用ip-address而不是猜测网址中的主机名。如果server.address/ management.address已设置,则使用它。否则返回的IP地址InetAddress.getLocalHost()被使用。

false

spring.boot.admin.client.instance.metadata。*

与此实例关联的元数据键值对。

spring.boot.admin.client.instance.metadata.tags。*

标记为与此实例关联的键值对。

表2.实例元数据选项
键    值    默认值
user.name 
user.password

用于访问端点的凭据。

4. Spring Boot管理服务器
表3. Spring Boot Admin Server配置选项
物业名称    描述    默认值
spring.boot.admin.context路径

context-path是应该为Admin Server的静态资产和API提供服务的路径的前缀。相对于Dispatcher-Servlet。

spring.boot.admin.monitor.period

以ms为单位的时间间隔,用于更新状态信息过期的应用程序的状态。

spring.boot.admin.monitor.status一生

应用程序状态的生命周期,以ms为单位。在生命周期到期之前,不会查询应用程序/运行状况终结点。

spring.boot.admin.monitor.connect超时

查询应用程序的状态和信息时,以毫秒为单位连接超时。

2000

spring.boot.admin.monitor.read超时

查询应用程序的状态和信息时,以毫秒为单位读取超时。

20000

spring.boot.admin.metadata密钥对的sanitize

匹配这些正则表达式模式的键的元数据值将在所有json输出中清除。

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

spring.boot.admin.probed的端点

对于Spring Boot 1.x客户端应用程序,使用OPTIONS请求对指定端点进行SBA探测。如果路径与id不同,您可以将其指定为id:path(例如health:ping)..

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

spring.boot.admin.instance-proxy.ignored报头

在向客户端发出请求时不会转发标头。

`“Cookie”,“Set-Cookie”,“授权”

spring.boot.admin.ui.brand

品牌将在导航栏中显示。

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

spring.boot.admin.ui.title

页面标题显示。

"Spring Boot Admin"

4.1。Spring Cloud Discovery
Spring Boot管理服务器可以使用Spring Clouds DiscoveryClient来发现应用程序。优点是客户不必包括spring-boot-admin-starter-client。您只需要向DiscoveryClient管理服务器添加一个实现 - 其他一切都由AutoConfiguration完成。

4.1.1。SimpleDiscoveryClient配置
Spring Cloud提供了一个SimpleDiscoveryClient。它允许您通过静态配置指定客户端应用程序:

的pom.xml
<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter</artifactId>
</dependency>
application.yml
spring:
  cloud:
    discovery:
      client:
        simple:
          instances:
            test:
              - uri: http://instance1.intern:8080
                metadata:
                  management.context-path: /actuator
              - uri: http://instance2.intern:8080
                metadata:
                  management.context-path: /actuator
4.1.2。其他DiscoveryClients
Spring Boot Admin支持Spring Cloud的所有其他实现DiscoveryClient(Eureka,Zookeeper,Consul,...)。您需要将其添加到Spring Boot Admin Server并正确配置它。使用Eureka的示例设置如上所示。

4.1.3。转换ServiceInstances
来自服务注册表的信息由ServiceInstanceConverter。Spring Boot Admin附带默认和Eureka转换器实现。AutoConfiguration选择正确的一个。

您可以使用SBA服务器配置选项和实例元数据修改注册表中的信息如何用于注册应用程序。元数据中的值优先于服务器配置。如果有很多选择不符合您的需求,您可以提供自己的选择ServiceInstanceConverter。
使用Eureka时,Eureka healthCheckUrl已知用于健康检查,可以在您的客户端使用eureka.instance.healthCheckUrl。
表4.实例元数据选项
键    值    默认值
user.name 
user.password

用于访问端点的凭据。

management.address

地址在服务URL中被替换,并将用于访问执行器端点。

management.port

端口在服务URL中替换,并将用于访问执行器端点。

management.context路径

该路径附加到服务URL,并将用于访问执行器端点。

${spring.boot.admin.discovery.converter.mangement-context-path}

health.path

该路径将附加到服务URL,并将用于运行状况检查。被忽略了EurekaServiceInstanceConverter。

${spring.boot.admin.discovery.converter.health-endpoint}

表5.发现配置选项
物业名称    描述    默认值
spring.boot.admin.discovery.enabled

为管理服务器启用DiscoveryClient支持。

true

spring.boot.admin.discovery.converter.management上下文路径

当管理URL被转换时,将附加到已发现服务的service-url DefaultServiceInstanceConverter。

/actuator

spring.boot.admin.discovery.converter.health端点路径

当健康网址被转换时,将附加到已发现服务的management-url DefaultServiceInstanceConverter。

"health"

spring.boot.admin.discovery.ignored服务

使用发现而未注册为应用程序时,将忽略此服务。支持简单模式(例如“foo *”,“* bar”,“foo * bar *”)。

spring.boot.admin.discovery.services

使用发现并注册为应用程序时将包含此服务。支持简单模式(例如“foo *”,“* bar”,“foo * bar *”)。

"*"

4.1.4。CloudFoundry
如果要部署的应用程序CloudFoundry然后vcap.application.application_id和vcap.application.instance_index 必须被添加到与春季启动管理服务器应用程序正确注册的元数据。以下是Eureka的示例配置:

application.yml
eureka:
  instance:
    hostname: ${vcap.application.uris[0]}
    nonSecurePort: 80
    metadata-map:
      applicationId: ${vcap.application.application_id}
      instanceId: ${vcap.application.instance_index}
4.2。聚类
Spring Boot Admin Server通过Hazelcast支持群集复制。当存在HazelcastConfig- 或HazelcastInstance-Bean 时,它会自动启用。您还可以将Hazelcast实例配置为持久性,以保持状态重新启动。另请参阅Spring Boot对Hazelcast的支持。

将Hazelcast添加到您的依赖项:

的pom.xml
<dependency>
    <groupId>com.hazelcast</groupId>
    <artifactId>hazelcast</artifactId>
</dependency>
实例化HazelcastConfig:

@Bean
public Config hazelcastConfig() {
    MapConfig mapConfig = new MapConfig("spring-boot-admin-event-store").setInMemoryFormat(InMemoryFormat.OBJECT)
                                                                        .setBackupCount(1)
                                                                        .setEvictionPolicy(EvictionPolicy.NONE);
    return new Config().setProperty("hazelcast.jmx", "true").addMapConfig(mapConfig);
}
表6. Hazelcast配置选项
物业名称    描述    默认值
spring.boot.admin.hazelcast.enabled

启用Hazelcast支持

true

spring.boot.admin.hazelcast.event店

用于存储事件的Hazelcast映射的名称

"spring-boot-admin-event-store"

4.3。通知
4.3.1。提醒通知
该RemindingNotifier向下/离线应用程序发送的提醒,它代表通知到另一个通知的发送。

默认情况下,当注册的应用程序更改为DOWN或时会触发提醒OFFLINE。您可以通过改变此行为setReminderStatuses()。当状态变为非触发状态或相关应用程序被取消注册时,提醒结束。

默认情况下,提醒每10分钟发送一次,以更改此用途setReminderPeriod()。在RemindingNotifier本身不启动后台线程发送提醒,你需要如下图所示给定的例子来照顾这一点;

如何配置提醒
@Configuration
public class NotifierConfiguration {
    @Autowired
    private Notifier notifier;

    @Primary
    @Bean(initMethod = "start", destroyMethod = "stop")
    public RemindingNotifier remindingNotifier() {
        RemindingNotifier notifier = new RemindingNotifier(notifier, repository);
        notifier.setReminderPeriod(Duration.ofMinutes(10)); 
        notifier.setCheckReminderInverval(Duration.ofSeconds(10)); 
        return notifier;
    }
}
提醒将每10分钟发送一次。
安排每10秒发送一次适当的提醒。
4.3.2。过滤通知
将FilteringNotifier允许您过滤基于您可以添加/在运行时删除规则一定通知。它将通知的发送委托给另一个通知程序。

如果FilteringNotifier您ApplicationContext在RESTful接口上添加了一个notifications/filter可用的接口。

如果您不希望在部署应用程序时收到通知,则此通知程序非常有用。在停止应用程序之前,您可以通过POST请求添加(过期)过滤器。

如何配置过滤
@Configuration
public static class NotifierConfig {
    private final InstanceRepository repository;
    private final ObjectProvider<List<Notifier>> otherNotifiers;

    public NotifierConfig(InstanceRepository repository, ObjectProvider<List<Notifier>> otherNotifiers) {
        this.repository = repository;
        this.otherNotifiers = otherNotifiers;
    }

    @Bean
    public FilteringNotifier filteringNotifier() { 
        CompositeNotifier delegate = new CompositeNotifier(otherNotifiers.getIfAvailable(Collections::emptyList));
        return new FilteringNotifier(delegate, repository);
    }

    @Primary
    @Bean(initMethod = "start", destroyMethod = "stop")
    public RemindingNotifier remindingNotifier() { 
        RemindingNotifier notifier = new RemindingNotifier(filteringNotifier(), repository);
        notifier.setReminderPeriod(Duration.ofMinutes(10));
        notifier.setCheckReminderInverval(Duration.ofSeconds(10));
        return notifier;
    }
}
FilteringNotifier使用委托添加bean(例如MailNotifier,配置时)
RemindingNotifier使用FilteringNotifieras委托添加as primary bean 。
此示例组合了提醒和过滤通知程序。这允许您在部署的应用程序在一定时间内未重新启动后(直到过滤器过期)收到通知。
4.3.3。邮件通知
邮件通知将作为使用Thymeleaf模板呈现的HTML电子邮件传递。要启用邮件通知,请配置JavaMailSender使用spring-boot-starter-mail并设置收件人。

邮件通知示例
图1.示例邮件通知
为防止泄露敏感信息,默认邮件模板不显示实例的任何元数据。如果您想显示一些元数据,可以使用自定义模板。
将spring-boot-starter-mail添加到您的依赖项:

的pom.xml
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-mail</artifactId>
</dependency>
配置JavaMailSender

application.properties
spring.mail.host = smtp.example.com
spring.boot.admin.notify.mail.to=admin@example.com
使用以下选项配置邮件

表7.邮件通知配置选项
物业名称    描述    默认值
spring.boot.admin.notify.mail.enabled

启用邮件通知

true

spring.boot.admin.notify.mail.ignore-变化

以逗号分隔的状态更改列表将被忽略。格式:“<from-status>:<to-status>”。允许使用通配符。

"UNKNOWN:UP"

spring.boot.admin.notify.mail.template

用于渲染的Thymelef模板的资源路径。

"classpath:/META-INF/spring-boot-admin-server/mail/status-changed.html"

spring.boot.admin.notify.mail.to

以逗号分隔的邮件收件人列表

"root@localhost"

spring.boot.admin.notify.mail.cc

以逗号分隔的抄送收件人名单

spring.boot.admin.notify.mail.from

邮件发件人

"Spring Boot Admin <noreply@localhost>"

spring.boot.admin.notify.mail.additional的属性

可以从模板访问的其他属性

4.3.4。PagerDuty通知
要启用PagerDuty通知,您只需向PagerDuty帐户添加通用服务,并设置spring.boot.admin.notify.pagerduty.service-key为您收到的服务密钥。

表8. PagerDuty通知配置选项
物业名称    描述    默认值
spring.boot.admin.notify.pagerduty.enabled

启用邮件通知

true

spring.boot.admin.notify.pagerduty.ignore-变化

以逗号分隔的状态更改列表将被忽略。格式:“<from-status>:<to-status>”。允许使用通配符。

"UNKNOWN:UP"

spring.boot.admin.notify.pagerduty.service键

用于PagerDuty的服务密钥

spring.boot.admin.notify.pagerduty.url

Pagerduty-rest-api url

"https://events.pagerduty.com/generic/2010-04-15/create_event.json"

spring.boot.admin.notify.pagerduty.description

在事件中使用的描述。支持SpEL表达式

"#{instance.registration.name}/#{instance.id} is #{instance.statusInfo.status}"

spring.boot.admin.notify.pagerduty.client

要在事件中使用的客户端名称

spring.boot.admin.notify.pagerduty.client-URL

客户端url在事件中使用

4.3.5。OpsGenie通知
要启用OpsGenie通知,您只需将新的JSON Rest API集成添加到您的OpsGenie帐户并设置spring.boot.admin.notify.opsgenie.api-key为您收到的apiKey。

表9. OpsGenie通知配置选项
物业名称    描述    默认值
spring.boot.admin.notify.opsgenie.enabled

启用OpsGenie通知

true

spring.boot.admin.notify.opsgenie.ignore-变化

以逗号分隔的状态更改列表将被忽略。格式:“<from-status>:<to-status>”。允许使用通配符。

"UNKNOWN:UP"

spring.boot.admin.notify.opsgenie.api键

你在创建集成时收到的apiKey

spring.boot.admin.notify.opsgenie.url

OpsGenie Alert API网址

"https://api.opsgenie.com/v2/alerts"

spring.boot.admin.notify.opsgenie.description

在事件中使用的描述。支持SpEL表达式

"#{instance.registration.name}/#{instance.id} is #{instance.statusInfo.status}"

spring.boot.admin.notify.opsgenie.actions

以逗号分隔的可执行操作列表。

spring.boot.admin.notify.opsgenie.source

字段以指定警报源。默认情况下,它将分配给传入请求的IP地址。

spring.boot.admin.notify.opsgenie.tags

逗号分隔附加到警报的标签列表。

spring.boot.admin.notify.opsgenie.entity

警报与之相关的实体。

spring.boot.admin.notify.opsgenie.user

执行的默认所有者。如果未指定用户,则系统将成为执行的所有者。

4.3.6。Hipchat通知
要启用Hipchat通知,您需要在Hipchat帐户上创建API令牌并设置相应的配置属性。

表10. Hipchat通知配置选项
物业名称    描述    默认值
spring.boot.admin.notify.hipchat.enabled

启用Hipchat通知

true

spring.boot.admin.notify.hipchat.ignore-变化

以逗号分隔的状态更改列表将被忽略。格式:“<from-status>:<to-status>”。允许使用通配符。

"UNKNOWN:UP"

spring.boot.admin.notify.hipchat.url

HipChat REST API(V2)URL

spring.boot.admin.notify.hipchat.auth令牌

可以访问通知室的API令牌

spring.boot.admin.notify.hipchat.room-ID

要向其发送通知的房间的ID或网址编码名称

spring.boot.admin.notify.hipchat.notify

消息是否应触发用户通知

false

spring.boot.admin.notify.hipchat.description

在事件中使用的描述。支持SpEL表达式

"<strong>#{instance.registration.name}</strong>/#{instance.id} is <strong>#{event.statusInfo.status}</strong>"

4.3.7。松弛通知
要启用Slack通知,您需要在Slack帐户的自定义集成下添加传入Webhook并进行相应配置。

表11. Slack通知配置选项
物业名称    描述    默认值
spring.boot.admin.notify.slack.enabled

启用S​​lack通知

true

spring.boot.admin.notify.slack.ignore-变化

以逗号分隔的状态更改列表将被忽略。格式:“<from-status>:<to-status>”。允许使用通配符。

"UNKNOWN:UP"

spring.boot.admin.notify.slack.webhook-URL

Slack Webhook URL用于发送通知

spring.boot.admin.notify.slack.channel

可选的频道名称(开头没有#)。如果与Slack Webhooks设置中的通道不同

spring.boot.admin.notify.slack.icon

可选图标名称(不包含冒号)。如果与Slack Webhooks设置中的图标不同

spring.boot.admin.notify.slack.username

如果与Slack Webhooks设置不同,则发送通知的可选用户名

Spring Boot Admin

spring.boot.admin.notify.slack.message

要在事件中使用的消息。支持SpEL表达式和Slack标记

"*#{instance.registration.name}* (#{instance.id}) is *#{event.statusInfo.status}*"

4.3.8。我们聊天通知
要启用Let的聊天通知,您需要添加主机网址并从Let's Chat添加API令牌和用户名

表12.让我们的聊天通知配置选项
物业名称    描述    默认值
spring.boot.admin.notify.letschat.enabled

启用我们的聊天通知

true

spring.boot.admin.notify.letschat.ignore-变化

以逗号分隔的状态更改列表将被忽略。格式:“<from-status>:<to-status>”。允许使用通配符。

"UNKNOWN:UP"

spring.boot.admin.notify.letschat.url

让聊天主机URL发送通知

spring.boot.admin.notify.letschat.room

发送消息的房间

spring.boot.admin.notify.letschat.token

用于访问Let's Chat API的令牌

spring.boot.admin.notify.letschat.username

用于为其创建令牌的用户名

Spring Boot Admin

spring.boot.admin.notify.letschat.message

要在事件中使用的消息。支持SpEL表达式

"*#{instance.registration.name}* (#{instance.id}) is *#{event.statusInfo.status}*"

4.3.9。Microsoft Teams通知
要启用Microsoft Teams通知,您需要设置连接器webhook URL并设置适当的配置属性。

表13. Microsoft Teams通知配置选项
物业名称    描述    默认值
spring.boot.admin.notify.ms-teams.enabled

启用Microsoft Teams通知

true

spring.boot.admin.notify.ms-teams.webhook-URL

Microsoft Teams webhook url将通知发送到。

spring.boot.admin.notify.ms强队。*

有几个选项可以自定义消息标题和颜色

4.3.10。电报通知
要启用电报通知,您需要创建和授权电报机器人并为auth-token和chat-id设置适当的配置属性。

表14. Microsoft Teams通知配置选项
物业名称    描述    默认值
spring.boot.admin.notify.telegram.enabled

启用Microsoft Teams通知

true

spring.boot.admin.notify.telegram.auth令牌

令牌识别和授权您的Telegram机器人(例如123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11)。

spring.boot.admin.notify.telegram.chat-ID

目标聊天的唯一标识符或目标通道的用户名

spring.boot.admin.notify.telegram.disable-通知

如果真实用户将收到没有声音的通知。

false

spring.boot.admin.notify.telegram.parse_mode

已发送消息的解析模式。目前`HTML'并'Markdown'得到支持。

'HTML'

spring.boot.admin.notify.telegram.message

要发送的文字。支持SpEL表达式。

"<strong>#{instance.registration.name}</strong>/#{instance.id} is <strong>#{event.statusInfo.status}</strong>"

5.安全
5.1。保护Spring Boot Admin Server
由于解决分布式Web应用程序中的身份验证和授权有多种方法,因此Spring Boot Admin不提供默认方法。默认情况下,spring-boot-admin-server-ui提供登录页面和注销按钮。

Spring Security配置可能如下所示:

@Configuration
public static class SecuritySecureConfig extends WebSecurityConfigurerAdapter {
    private final String adminContextPath;

    public SecuritySecureConfig(AdminServerProperties adminServerProperties) {
        this.adminContextPath = adminServerProperties.getContextPath();
    }

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        // @formatter:off
        SavedRequestAwareAuthenticationSuccessHandler successHandler = new SavedRequestAwareAuthenticationSuccessHandler();
        successHandler.setTargetUrlParameter("redirectTo");
        successHandler.setDefaultTargetUrl(adminContextPath + "/");

        http.authorizeRequests()
            .antMatchers(adminContextPath + "/assets/**").permitAll() 
            .antMatchers(adminContextPath + "/login").permitAll()
            .anyRequest().authenticated() 
            .and()
        .formLogin().loginPage(adminContextPath + "/login").successHandler(successHandler).and() 
        .logout().logoutUrl(adminContextPath + "/logout").and()
        .httpBasic().and() 
        .csrf()
            .csrfTokenRepository(CookieCsrfTokenRepository.withHttpOnlyFalse())  
            .ignoringAntMatchers(
                adminContextPath + "/instances",   
                adminContextPath + "/actuator/**"  
            );
        // @formatter:on
    }
}
授予对所有静态资产和登录页面的公共访问权限。
必须对每个其他请求进行身份验证。
配置登录和注销。
启用HTTP-Basic支持。这是Spring Boot Admin Client注册所必需的。
使用Cookie启用CSRF保护
禁用CRSF-Protection Spring Boot Admin Client用于注册的端点。
禁用执行器端点的CRSF保护。
有关完整示例,请查看spring-boot-admin-sample-servlet。

如果您保护/instances端点,请不要忘记使用spring.boot.admin.client.username和在SBA客户端上配置用户名和密码spring.boot.admin.client.password。
5.2。保护客户端执行器端点
使用HTTP基本身份验证保护执行器端点时,SBA服务器需要凭据才能访问它们。注册应用程序时,您可以在元数据中提交凭据。在BasicAuthHttpHeaderProvider随后使用该元数据添加Authorization标题来访问应用程序的执行端点。您可以提供自己HttpHeadersProvider的更改行为(例如添加一些解密)或添加额外的标头。

使用SBA客户端提交凭据:

application.yml
spring.boot.admin.client:
    url: http://localhost:8080
    instance:
      metadata:
        user.name: ${spring.security.user.name}
        user.password: ${spring.security.user.password}
使用Eureka提交凭据:

application.yml
eureka:
  instance:
    metadata-map:
      user.name: ${spring.security.user.name}
      user.password: ${spring.security.user.password}
SBA服务器屏蔽HTTP接口中的某些元数据,以防止泄漏敏感信息。
在通过元数据提交凭据时,应为SBA服务器或(服务注册表)配置HTTPS。
使用Spring Cloud Discovery时,您必须意识到任何可以查询服务注册表的人都可以获取凭据。
使用此方法时,SBA服务器会决定用户是否可以访问已注册的应用程序。有更复杂的解决方案(使用OAuth2)让客户决定用户是否可以访问端点。为此,请查看joshiste / spring-boot-admin-samples中的示例。
5.2.1。关于执行器端点的CSRF
一些执行器端点(例如/loggers)支持POST请求。使用Spring Security时,您需要忽略CSRF-Protection的执行器端点,因为Spring Boot Admin Server目前缺乏支持。

@Override
protected void configure(HttpSecurity http) throws Exception {
    http.csrf()
        .ignoringAntMatchers("/actuator/**");
}
6.定制
6.1。自定义通知程序
您可以通过添加实现Notifier接口的Spring Beans来添加您自己的通知程序,最好通过扩展 AbstractEventNotifier或AbstractStatusChangeNotifier

public class CustomNotifier  extends AbstractEventNotifier {
    private static final Logger LOGGER = LoggerFactory.getLogger(LoggingNotifier.class);

    public CustomNotifier(InstanceRepository repository) {
        super(repository);
    }

    @Override
    protected Mono<Void> doNotify(InstanceEvent event, Instance instance) {
        return Mono.fromRunnable(() -> {
            if (event instanceof InstanceStatusChangedEvent) {
                LOGGER.info("Instance {} ({}) is {}", instance.getRegistration().getName(), event.getInstance(),
                    ((InstanceStatusChangedEvent) event).getStatusInfo().getStatus());
            } else {
                LOGGER.info("Instance {} ({}) {}", instance.getRegistration().getName(), event.getInstance(),
                    event.getType());
            }
        });
    }
}
6.2。注入自定义HTTP标头
如果您需要将自定义HTTP标头注入对受监视应用程序的执行器端点的请求,您可以轻松添加HttpHeadersProvider:

@Bean
public HttpHeadersProvider customHttpHeadersProvider() {
    return  instance -> {
        HttpHeaders httpHeaders = new HttpHeaders();
        httpHeaders.add("X-CUSTOM", "My Custom Value");
        return httpHeaders;
    };
}
6.3。拦截请求和响应
您可以通过实现InstanceExchangeFilterFunction接口来拦截和修改对受监视应用程序的执行器端点的请求和响应。这对于审核或添加一些额外的安全检查非常有用。

@Bean
public InstanceExchangeFilterFunction auditLog() {
    return (instance, request, next) -> {
        if (HttpMethod.DELETE.equals(request.method()) || HttpMethod.POST.equals(request.method())) {
            log.info("{} for {} on {}", request.method(), instance.getId(), request.url());
        }
        return next.exchange(request);
    };
}
6.4。自定义视图
可以向ui添加自定义视图。视图必须实现为Vue.js组件。

必须将Javascript-Bundle和Css-Stlysheet放在类路径上,/META-INF/spring-boot-admin-server-ui/extensions/{name}/以便服务器可以接收它们。该弹簧引导管理样本定制的UI模块包含有必要的行家设置建立这样一个模块的样品。

自定义扩展通过调用自身注册SBA.use()并需要公开一个install()函数,该函数在设置路由时由ui调用。该install()函数接收引用viewRegistry和applicationStore的参数对象,以便注册视图和/或回调。

6.4.1。添加顶级视图
这是一个简单的顶级视图,列出了所有已注册的应用程序:

<template>
  <pre v-text="stringify(applications, null, 4)"/>
</template>

<script>
export default {
  props: {
    applications: { 
      type: Array,
      required: true
    }
  },
  methods: {
    stringify: JSON.stringify
  }
};
</script>
如果您定义一个applicationsprop,该组件将接收所有已注册的应用程序。
应用程序和实例对象有一些有用的方法可用。看看application.js和instance.js
这就是您注册顶级视图的方式。

SBA.use({
  install({viewRegistry}) {
    viewRegistry.addView({
      name: 'custom',  
      path: '/custom', 
      component: custom, 
      label: 'Custom', 
      order: 1000, 
    });
  }
});
视图名称和视图路径
可以访问视图的路径
导入的自定义组件,将在路径上呈现。
自定义视图的标签将显示在顶部导航栏中。
订购视图。顶部导航栏中的视图按升序排序。
6.4.2。可视化自定义端点
以下是显示自定义端点的视图:

<template>
  <div class="custom">
    Instance: <span v-text="instance.id"/>
    Output: <span v-text="text"/>
  </div>
</template>

<script>
export default {
  props: {
    instance: { 
      type: Object,
      required: true
    }
  },
  data: () => ({
    text: ''
  }),
  async created() {
    const response = await this.instance.axios.get('actuator/custom'); 
    this.text = response.data;
  }
};
</script>

<style>
  .custom {
    font-size: 20px;
    width: 80%;
  }
</style>
如果定义一个instanceprop,组件将接收应该为其呈现视图的实例。
每个实例都有一个预先配置的axios实例,可以使用正确的路径和标头访问端点。
注册实例视图与顶级视图一样,具有一些其他属性:

SBA.use({
  install({viewRegistry}) {
    viewRegistry.addView({
      name: 'instances/custom',
      parent: 'instances', 
      path: 'custom',
      component: customEndpoint,
      label: 'Custom',
      order: 1000,
      isEnabled: ({instance}) => instance.hasEndpoint('custom') 
    });
  }
});
父级必须是“实例”才能为单个实例呈现新的自定义视图。
如果添加isEnabled回调,则可以动态计算出是否应显示特定实例的视图。
6.5。自定义标题徽标和标题
您可以使用以下配置属性在标题中设置自定义信息(即显示登台信息或公司名称):

spring.boot.admin.ui.brand:此HTML代码段在导航标题中呈现,默认为<img src="assets/img/icon-spring-boot-admin.svg"><span>Spring Boot Admin</span>。默认情况下,它会显示SBA徽标,后跟其名称。如果要显示自定义徽标,可以设置:spring.boot.admin.ui.brand=<img src="custom/custom-icon.png">。您可以将图像添加到jar文件中/META-INF/spring-boot-admin-server-ui/(ResourceHandler默认情况下,SBA会为此位置注册),或者您必须确保自己正确地提供图像(例如,通过注册您自己的图像ResourceHandler)

spring.boot.admin.ui.title:使用此选项可自定义浏览器窗口标题。

7.监控Spring Boot 1.5.x
可以使用Spring Boot Admin 2.x监视Spring Boot 1.5.x应用程序。旧的Spring Boot Admin Client可以在较新的服务器上注册。由于API略有变化,您需要在旧客户端上设置以下属性:

重新配置Spring Boot Admin Client 1.5.x的api路径:

application.yml
spring.boot.admin.api-path: instances
由于一些执行器端点随Spring Boot 2发布而改变,因此并非所有选项都可用(例如/metrics端点); 对于某些端点,我们提供传统转换器。

8. 2.x的变化
为所有jar添加了稳定的自动模块名称

8.1。UI
用vue.js重写ui

将ui-login模块集成到主ui模块中

删除了ui-activiti模块,因为它很少使用

删除了Hystrix-Dashboard集成(可能会有变化)

添加了对会话端点的支持

添加了(已清理的)元数据的显示

添加了重置日志级别的选项

添加了墙板视图

8.2。后端
将所有类移动到spring.boot.admin.server包中

使用事件采购原则重新设计后端

添加了应用程序的概念(包含1到n个实例)

通过查询/actuator-index或通过OPTIONS请求进行探测,将端点检测移至后端

使用WebClient将Zuul替换为自定义代理

删除了对spring-cloud-starter的依赖

新增CompositeHttpHeadersProvider支持多个HttpHeadersProviders同时

添加了`InstanceExchangeFilterFunction`,它允许拦截/修改对受监控实例的请求

为CloudFoundry添加了开箱即用的支持

使用添加了对Spring Boot 1.5.x执行器端点的支持 LegacyEndpointConverters

更新OpsGenieNotifier到api v2

重写MailNotifier使用Thymeleaf模板

8.3。客户
将所有属性移至和spring.boot.admin.client.spring.boot.admin.client.instance.

将所有类移动到spring.boot.admin.client包中

添加了支持webflux应用程序

为CloudFoundry添加了开箱即用的支持

9.常见问题
我可以在我的业务应用程序中包含spring-boot-admin吗?
tl; dr你可以,但你不应该。
您可以设置spring.boot.admin.context-path更改提供UI和REST-API的路径,但根据应用程序的复杂程度,您可能会遇到麻烦。另一方面,在我看来,应用程序监控自身是没有意义的。如果您的应用程序出现故障,您的监控工具也会出现故

版本2.0.3

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值