Spring Boot (28) actuator与spring-boot-admin
在上一篇中,通过restful api的方式查看信息过于繁琐,也不直观,效率低下。当服务过多的时候看起来就过于麻烦,每个服务都需要调用不同的接口来查看监控信息。
SBA
SBA全称spring boot admin 是一个管理和监控spring boot 应用程序的开源项目,分为admin-server与admin-client两个组件,admin-server通过采集actuator端点数据,显示在spring -boot-admin-ui上,已知的端点几乎都有进行采集,通过spring-boot-admin可以动态切换日志级别、导出日志、导出heapdump、监控各项指标 等等
spring boot admin在对单一服务监控的同时也提供了集群监控方案,支持通过eureka、consul、zookeeper等注册中心的方式实现多服务监控与管理
导入依赖
在pom.xml中添加对spring-boot-admin的相关依赖
<!-- 服务端:带UI界面 -->
<dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-starter-server</artifactId>
<version>2.0.0</version>
</dependency>
<!-- 客户端包 -->
<dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-starter-client</artifactId>
<version>2.0.0</version>
</dependency>
<!-- 安全认证 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<!-- 端点 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<!-- 在管理界面中与 JMX-beans 进行交互所需要被依赖的 JAR -->
<dependency>
<groupId>org.jolokia</groupId>
<artifactId>jolokia-core</artifactId>
</dependency>
如果想访问info的信息需要如下配置
<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>
属性配置
在application.yml中配置actuator的相关配置,其中info开头的属性,就是访问info端点中显示的相关内容,值得注意的十spring boot2.x中,默认只开放了info、health两个端点,剩余的需要自己通过配置management.endpoints.web.exposure.include属性来加载,这个management.endpoints.web.base-path属性比较重要,因为spring boot2.x后每个端点默认的路径是/actuator/endpointId这样依赖spring boot admin是无法正常采集的
application.yml
spring:
profiles:
active: prod #指定读取哪个文件
boot:
admin:
client:
url: http://localhost:8088
instance:
prefer-ip: true info:
head: head
body: body
management:
endpoints:
web:
exposure:
#加载所有的端点,默认只加载了info、health
include: '*'
#不配置SBA 扫描不到
base-path: /
endpoint:
health:
show-details: always
#可以关闭指定的端点
shutdown:
enabled: false
application-dev.yml 空的
application-prod.yml
server:
port: 8088
servlet:
context-path: / spring:
boot:
admin:
client:
username: david
password: 123456
instance:
metadata:
user:
name: david
password: 123456
security:
user:
name: david
password: 123456
在启动方法中增加@EnableAdminServer注解 代表是Server端
@EnableAdminServer
@SpringBootApplication
public class BootApplication{ public static void main(String[] args) {
SpringApplication.run(BootApplication.class,args);
} @Profile("dev")
@Configuration
public static class SecurityPermitAllConfig extends WebSecurityConfigurerAdapter{
@Override
protected void configure(HttpSecurity http) throws Exception{
http.authorizeRequests().anyRequest().permitAll().and().csrf().disable();
}
} @Profile("prod")
@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{
SavedRequestAwareAuthenticationSuccessHandler successHandler = new SavedRequestAwareAuthenticationSuccessHandler();
successHandler.setTargetUrlParameter("redirectTo"); 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().disable();
}
}
}
测试
启动项目 访问 http://localhost:8088/login

Spring Boot (28) actuator与spring-boot-admin的更多相关文章
- Spring Boot,Spring Cloud,Eureka,Actuator,Spring Boot Admin,Stream,Hystrix
Spring Boot,Spring Cloud,Eureka,Actuator,Spring Boot Admin,Stream,Hystrix 一.Spring Cloud 之 Eureka. 1 ...
- spring boot 2.0.3+spring cloud (Finchley)8、微服务监控Spring Boot Admin
参考:Spring Boot Admin 2.0 上手 Spring Boot Admin 用于管理和监控一个或多个Spring Boot程序,在 Spring Boot Actuator 的基础上提 ...
- Spring Cloud第十三篇 | Spring Boot Admin服务监控
本文是Spring Cloud专栏的第十三篇文章,了解前十二篇文章内容有助于更好的理解本文: Spring Cloud第一篇 | Spring Cloud前言及其常用组件介绍概览 Spring Clo ...
- Spring Boot (27) actuator服务监控与管理
actuaotr是spring boot项目中非常强大的一个功能,有助于对应用程序进行监控和管理,通过restful api请求来监管.审计.收集应用的运行情况,针对微服务而言它是必不可少的一个环节. ...
- 第11章 Spring Boot使用Actuator
在生产环境中,需要实时或定期监控服务的可用性,spring-Boot的Actuator 功能提供了很多监控所需的接口. Actuator是Spring Boot提供的对应用系统的自省和监控的集成功能, ...
- Spring Boot整合actuator实现监控管理
Spring Boot使用actuator监控管理 1.在pom文件中导入相关的依赖 <dependency> <groupId>org.springframework.boo ...
- 【Spring】关于Boot应用中集成Spring Security你必须了解的那些事
Spring Security Spring Security是Spring社区的一个顶级项目,也是Spring Boot官方推荐使用的Security框架.除了常规的Authentication和A ...
- spring Boot 入门--为什么用spring boot
为什么用spring boot 回答这个问题不得不说下spring 假设你受命用Spring开发一个简单的Hello World Web应用程序.你该做什么? 我能想到一些 基本的需要. 一个项目 ...
- Spring Boot(十四):spring boot整合shiro-登录认证和权限管理
Spring Boot(十四):spring boot整合shiro-登录认证和权限管理 使用Spring Boot集成Apache Shiro.安全应该是互联网公司的一道生命线,几乎任何的公司都会涉 ...
随机推荐
- SQL Server转sqlite数据库
下载地址:http://files.cnblogs.com/jason-davis/SQL_Server_To_SQLite_DB_Converter_bin.zip 下载地址:http://file ...
- json数组显示格式
{“colorAndImg”:[{"颜色":“红色”,"地址":“www.sohu.com”}, {“颜色”:“绿色,“地址”:“www.sohu.com”}] ...
- 条款九: 避免隐藏标准形式的new
因为内部范围声明的名称会隐藏掉外部范围的相同的名称,所以对于分别在类的内部和全局声明的两个相同名字的函数f来说,类的成员函数会隐藏掉全局函数 class x { public: void f(); / ...
- 踩坑录-mysql不允许远程连接(错误码:1130) Host'xxx.xxx.xxx.xxx' is not allowed to connect to this MySQL server“
每次搭建mysql环境都会遇见同样的问题,在此分享一下踩坑笔录. 一.问题描述 安装成功后,本地直接链接远程mysql,默认为不允许远程访问,则客户端提示1130 - Host'xxx.xxx.xxx ...
- android:“新版飞机大战”源码开源啦!
今天10.24,为了纪念程序猿的节日,把之前写过的一个"飞机大战"的一个源码开源了. 源码地址:https://github.com/nuptboyzhb/newplanegame ...
- 【Akka】Actor模型探索
Akka是什么 Akka就是为了改变编写高容错性和强可扩展性的并发程序而生的.通过使用Actor模型我们提升了抽象级别,为构建正确的可扩展并发应用提供了一个更好的平台.在容错性方面我们採取了" ...
- 基于Office 365 无代码工作流分析-数据源的建立!
标准操作步骤 下面整个步骤我们是以嘉昊信息的招聘过程的整个流程为一个场景,整个的流程场景的步骤例如以下: 整个的过程,我们通过Infopath 进行对应的表单流转,然后利用Sharepoint ...
- android不是内部或外部命令,也不是可执行的程序或批处理文件
问题: 原因:没有配置好android sdk环境变量 解决方法: (1)切换到android sdk下的tools文件夹,再执行android命令就可以启动Android SDK管理器,我的andr ...
- SSH-struts2的异常处理
在学习j2se的时候学习过利用java的exception类去处理异常.在struts2框架中也提供了对于异常的处理.简单说就是当Action发生异常时.能够在struts2.xml文件里进行配置,将 ...
- ZOJ 3684 Destroy 树的中心
中心节点就是树的中心,2遍dfs求到树的直径.而中心一定在直径上,顺着直径找到中心就够了. 然后能够一遍树形DP找到最小值或者二分+推断是否訪问到叶子节点. #include <iostream ...