spring-boot-admin基础搭建教程

  spring-boot-admin为我们基于spring-boot的基础数据安全端口提供了基础的可视化监控功能。还可以通过spring-boot-admin的server程序对spring-boot程序提供简单的实时管理(例如修改日志输出级别)。

  通过官方的英文指导文档,可以很方便的学习spring-boot-admin的集成。根据个人的学习过程简单整理了一下,希望对想要学习的童鞋有所帮助。

  注意,搭建demo的过程中采用了maven来构建,在父pom中统一配置spring-boot、spring-cloud以及spring-boot-admin相关组件的版本,所以在子模块中,引入依赖时不会显示指明版本。

  以下是父pom中的的主要配置

  org.springframework.boot

  spring-boot-starter-parent

  1.5.8.RELEASE

  1.8

  1.5.4

  org.springframework.cloud

  spring-cloud-dependencies

  Dalston.SR4

  pom

  import

  de.codecentric

  spring-boot-admin-starter-client

  ${admin.version}

  de.codecentric

  spring-boot-admin-server

  ${admin.version}

  de.codecentric

  spring-boot-admin-server-ui

  ${admin.version}

  de.codecentric

  spring-boot-admin-server-ui-hystrix

  ${admin.version}

  de.codecentric

  spring-boot-admin-server-ui-turbine

  ${admin.version}

  de.codecentric

  spring-boot-admin-server-ui-login

  ${admin.version}

  一、spring-boot + spring-boot-admin 集成基础

  1.1、利用spring-boot-starter-actuator创建安全端点

  添加maven依赖

  首先,我们创建一个admin-client作为spring-boot-admin的客户端程序。该程序依赖如下两个依赖

  org.springframework.boot

  spring-boot-starter-web

  org.springframework.boot

  spring-boot-starter-actuator

  application.properties文件配置

  我们设置内嵌tomcat监听端口为8090

  spring.application.name=admin-client

  server.port=8090

  #关闭安全控制

  management.security.enabled=false

  启动类配置

  @SpringBootApplication

  public class AdminClient {

  public static void main(String[] args) {

  SpringApplication.run(AdminClient.class, args);

  }

  }

  测试效果

  直接启动main方法,可以看到日志中有如下几行记录,里面有spring-boot-starter-actuator为我们暴露的信息

  2017-10-22 16:59:22.572 INFO 341860 --- [ main] o.s.b.a.e.mvc.EndpointHandlerMapping : Mapped "{[/loggers/{name:.*}],methods=[GET],produces=[application/vnd.spring-boot.actuator.v1+json || application/json]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.LoggersMvcEndpoint.get(java.lang.String)

  2017-10-22 16:59:22.573 INFO 341860 --- [ main] o.s.b.a.e.mvc.EndpointHandlerMapping : Mapped "{[/loggers/{name:.*}],methods=[POST],consumes=[application/vnd.spring-boot.actuator.v1+json || application/json],produces=[application/vnd.spring-boot.actuator.v1+json || application/json]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.LoggersMvcEndpoint.set(java.lang.String,java.util.Map)

  2017-10-22 16:59:22.573 INFO 341860 --- [ main] o.s.b.a.e.mvc.EndpointHandlerMapping : Mapped "{[/loggers || /loggers.json],methods=[GET],produces=[application/vnd.spring-boot.actuator.v1+json || application/json]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.EndpointMvcAdapter.invoke()

  2017-10-22 16:59:22.579 INFO 341860 --- [ main] o.s.b.a.e.mvc.EndpointHandlerMapping : Mapped "{[/health || /health.json],methods=[GET],produces=[application/vnd.spring-boot.actuator.v1+json || application/json]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.HealthMvcEndpoint.invoke(javax.servlet.http.HttpServletRequest,java.security.Principal)

  2017-10-22 16:59:22.581 INFO 341860 --- [ main] o.s.b.a.e.mvc.EndpointHandlerMapping : Mapped "{[/mappings || /mappings.json],methods=[GET],produces=[application/vnd.spring-boot.actuator.v1+json || application/json]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.EndpointMvcAdapter.invoke()

  2017-10-22 16:59:22.583 INFO 341860 --- [ main] o.s.b.a.e.mvc.EndpointHandlerMapping : Mapped "{[/info || /info.json],methods=[GET],produces=[application/vnd.spring-boot.actuator.v1+json || application/json]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.EndpointMvcAdapter.invoke()

  2017-10-22 16:59:22.584 INFO 341860 --- [ main] o.s.b.a.e.mvc.EndpointHandlerMapping : Mapped "{[/autoconfig || /autoconfig.json],methods=[GET],produces=[application/vnd.spring-boot.actuator.v1+json || application/json]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.EndpointMvcAdapter.invoke()

  2017-10-22 16:59:22.586 INFO 341860 --- [ main] o.s.b.a.e.mvc.EndpointHandlerMapping : Mapped "{[/heapdump || /heapdump.json],methods=[GET],produces=[application/octet-stream]}" onto public void org.springframework.boot.actuate.endpoint.mvc.HeapdumpMvcEndpoint.invoke(boolean,javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse) throws java.io.IOException,javax.servlet.ServletException

  2017-10-22 16:59:22.587 INFO 341860 --- [ main] o.s.b.a.e.mvc.EndpointHandlerMapping : Mapped "{[/configprops || /configprops.json],methods=[GET],produces=[application/vnd.spring-boot.actuator.v1+json || application/json]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.EndpointMvcAdapter.invoke()

  2017-10-22 16:59:22.591 INFO 341860 --- [ main] o.s.b.a.e.mvc.EndpointHandlerMapping : Mapped "{[/beans || /beans.json],methods=[GET],produces=[application/vnd.spring-boot.actuator.v1+json || application/json]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.EndpointMvcAdapter.invoke()

  2017-10-22 16:59:22.598 INFO 341860 --- [ main] o.s.b.a.e.mvc.EndpointHandlerMapping : Mapped "{[/trace || /trace.json],methods=[GET],produces=[application/vnd.spring-boot.actuator.v1+json || application/json]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.EndpointMvcAdapter.invoke()

  2017-10-22 16:59:22.600 INFO 341860 --- [ main] o.s.b.a.e.mvc.EndpointHandlerMapping : Mapped "{[/dump || /dump.json],methods=[GET],produces=[application/vnd.spring-boot.actuator.v1+json || application/json]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.EndpointMvcAdapter.invoke()

  2017-10-22 16:59:22.601 INFO 341860 --- [ main] o.s.b.a.e.mvc.EndpointHandlerMapping : Mapped "{[/metrics/{name:.*}],methods=[GET],produces=[application/vnd.spring-boot.actuator.v1+json || application/json]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.MetricsMvcEndpoint.value(java.lang.String)

  2017-10-22 16:59:22.602 INFO 341860 --- [ main] o.s.b.a.e.mvc.EndpointHandlerMapping : Mapped "{[/metrics || /metrics.json],methods=[GET],produces=[application/vnd.spring-boot.actuator.v1+json || application/json]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.EndpointMvcAdapter.invoke()

  2017-10-22 16:59:22.605 INFO 341860 --- [ main] o.s.b.a.e.mvc.EndpointHandlerMapping : Mapped "{[/auditevents || /auditevents.json],methods=[GET],produces=[application/vnd.spring-boot.actuator.v1+json || application/json]}" onto public org.springframework.http.ResponseEntity org.springframework.boot.actuate.endpoint.mvc.AuditEventsMvcEndpoint.findByPrincipalAndAfterAndType(java.lang.String,java.util.Date,java.lang.String)金牛区人流哪家医院便宜

  2017-10-22 16:59:22.606 INFO 341860 --- [ main] o.s.b.a.e.mvc.EndpointHandlerMapping : Mapped "{[/env/{name:.*}],methods=[GET],produces=[application/vnd.spring-boot.actuator.v1+json || application/json]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.EnvironmentMvcEndpoint.value(java.lang.String)

  2017-10-22 16:59:22.607 INFO 341860 --- [ main] o.s.b.a.e.mvc.EndpointHandlerMapping : Mapped "{[/env || /env.json],methods=[GET],produces=[application/vnd.spring-boot.actuator.v1+json || application/json]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.EndpointMvcAdapter.invoke()

  我们简单访问health端点地址:http://127.0.0.1:8090/health,可以得到如下程序健康信息结果

  {"status":"UP","diskSpace":{"status":"UP","total":104857595904,"free":55882469376,"threshold":10485760}}

  由于端点众多且与其他框架例如spring-cloud集成时还会增加其他端点,非常不方便记忆核操作。同时直接访问的时候返回的数据都是JSON格式的字符串,查看不太直观。所以这就有了spring-boot-admin,它可以为我们提供这些端点比较直观的UI界面效果,方便我们的运营、运维、技术等人员使用。

  1.2、创建spring-boot-admin服务端程序admin-server

  我们创建admin-server作为spring-boot-admin的server端程序,为该程序添加jar包依赖,该依赖包括自动装配依赖和UI依赖郫都区意外怀孕人流费用一般在多少

  de.codecentric

  spring-boot-admin-server

  de.codecentric

  spring-boot-admin-server-ui

  配置监听端口核程序名等

  spring.application.name=admin-server

  server.port=80

  创建核配置启动类

  @SpringBootApplication

  @EnableAdminServer

  public class AdminServer {

  public static void main(String[] args) {

  SpringApplication.run(AdminServer.class,args);

  }锦江区治疗阴道炎费用是多少钱

  }

  @EnableAdminServer注解表示开启spring-boot-admin-server程序。直接启动main方法后,我们访问http://127.0.0.1,可以看到简单的界面效果,由于目前没有客户端程序所以列表中没有记录

你可能感兴趣的:(spring-boot-admin基础搭建教程)