Spring Boot Admin
发博词
spring boot admin为spring boot应用提供了整合的视图,应用的详情视图提供了应用本身及运行时环境(OS和JVM)运维比较关心的数据,应用的运行时信息,log输出,metrics统计,environment和logging level实时调整,thread线程运行时状态,trace,audit和Hystrix。
同时提供了turbine扩展插件,用于整合展示整个集群的熔断器信息。
在Journal模块,可以提供整个集群所有节点的状态变化历程。
使用要点
架构原理
spring boot admin+discovery server架构的原理是,spring boot admin通过内置的zuul连接discovery server,通过zuul与具体的节点通信。
健康检查
首页展示每个Instance的基本信息,最重要的状态信息是通过spring boot admin 内置的zuul调用各个Instance的健康检查接口实时更新的。
这里配置时需要注意,我们的Instance在使用actuator的时候,生产环境中是需要给其设置一个context-path的,那么如何让spring boot admin知道这个配置呢,
查看ServiceInstanceConverter的默认实现DefaultServiceInstanceConverter的子类EurekaServiceInstanceConverter#getHealthUrl方法的具体实现可知:
@Override
protected URI getHealthUrl(ServiceInstance instance) {
Assert.isInstanceOf(EurekaServiceInstance.class, instance,
"serviceInstance must be of type EurekaServiceInstance");
InstanceInfo instanceInfo = ((EurekaServiceInstance) instance).getInstanceInfo();
String healthUrl = instanceInfo.getSecureHealthCheckUrl();
if (StringUtils.isEmpty(healthUrl)) {
healthUrl = instanceInfo.getHealthCheckUrl();
}
return URI.create(healthUrl);
}
我们只需要给要被观察的Instance设置eureka.instance.secure-health-check-url或者eureka.instance.health-check-url即可
eureka:
instance:
hostname: localhost
server-hostname: localhost
metadata-map:
cluster: MAIN
management.context-path: ${management.context-path}
secure-health-check-url: http://localhost:8080/actuator/health
health-check-url: http://localhost:8080/actuator/health
应用信息
前面提到,应用的运行时信息,也就是actuator开放出来那些接口提供的信息,spring boot admin是通过zuul去调用的,与health接口调用时情况类似,如果被观察的Instance设置了management.context-path,那么如何让spring boot admin知道呢,答案是通过eureka.instance.metadata-map传递此信息。
eureka:
instance:
hostname: localhost
server-hostname: localhost
metadata-map:
cluster: MAIN
management.context-path: ${management.context-path}
注意:
如果只设置这个地方,health那个接口是没法起作用的,具体参看EurekaServiceInstanceConverter#getHealthUrl方法的实现。
应用信息#日志
这里的日志读取的实际上是这个应用的logfile指定的文件,所以被观察的应用必须要指定logging.file的值。
其余的信息也是类似的。
Turbine
在使用turbine时,spring boot admin默认在集群中找serviceid为turbine的Instance,如果找不到就会报错,通过spring.boot.admin.turbine.location可以修改这个配置。
如果我们的turbine server注册到discovery server的时候serviceid不是turbine,那么久可以通过这个配置调整。
spring.boot.admin.turbine.clusters可以配置turbine的cluster的标识。
Journal
Basic认证
Instance通过metadata-map将自己的用户名和密码传递给spring boot admin。在BasicAuthHttpHeaderProvider中可以查看具体的实现细节。
配置如下:
eureka:
instance:
metadata-map:
user.name: ${security.user.name}
user.password: ${security.user.password}