为了账号安全,请及时绑定邮箱和手机立即绑定

SpringBootAdmin服务端和客户端

2018.10.16 10:23 4735浏览

SpringBootAdmin是一个SpringBoot项目的监控应用

提供如下功能:

它为注册的应用程序提供以下功能。

  • 显示健康状况

  • 显示详细信息,例如

    • JVM和内存指标
    • micrometer.io指标
    • 数据源指标
    • 缓存指标
  • 显示构建信息编号

  • 关注并下载日志文件

  • 查看jvm系统和环境属性

  • 支持Spring Cloud的postable / env- & / refresh-endpoint

  • 轻松的日志级管理

  • 与JMX-beans交互

  • 查看线程转储

  • 查看http跟踪

  • 查看auditevents

  • 查看Http-Endpoints

  • 查看计划任务

  • 查看和删除活动会话(使用spring-session)

  • 查看Flyway / Liquibase数据库迁移

  • 下载heapdump

  • 状态变更通知(通过电子邮件,Slack,Hipchat,…)

  • 状态更改的事件日志(非持久性)

    但是在最新的Spring-Boot-Admin中,不能自动注册Eureka服务的应用。

    所以所有项目需要手动注册

    创建admin-server

    pom.xml添加以下内容

      <parent>
    	<groupId>org.springframework.boot</groupId>
    	<artifactId>spring-boot-starter-parent</artifactId>
    	<version>2.0.4.RELEASE</version>
      </parent>
      <dependencies>
    	<!-- 服务端:带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-actuator</artifactId>
    	</dependency>
    	<dependency>
    	  <groupId>org.springframework.boot</groupId>
    	  <artifactId>spring-boot-starter-web</artifactId>
    	</dependency>
    	<dependency>
    	  <groupId>org.springframework.boot</groupId>
    	  <artifactId>spring-boot-starter-test</artifactId>
    	  <scope>test</scope>
    	</dependency>
    	<!-- 在管理界面中与 JMX-beans 进行交互所需要被依赖的 JAR -->
    	<dependency>
    	  <groupId>org.jolokia</groupId>
    	  <artifactId>jolokia-core</artifactId>
    	</dependency>
      </dependencies>
    
      <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

    server:
      port: 8888
    management:
      endpoint:
    	health:
    	  show-details: always
      endpoints:
    	web:
    	  base-path: /
    	  exposure:
    		include: "*"  # 由于SpringBoot限制,大多数端点不会通过HTTP开放,所以这里选择全部
    spring:
      application:
    	name: admin-server
      boot:
    	admin:
    	  client:
    		instance:
    		  prefer-ip: true  # 使用IP注册
    		url: http://localhost:8888 # 注册服务地址
    logging:
      file: ./admin/log.log
      level:
    	root: info
    

    全部端点如下:“health”, “env”, “metrics”, “httptrace:trace”, “threaddump:dump”, “jolokia”, “info”, “logfile”, “refresh”, “flyway”, “liquibase”, “heapdump”, “loggers”, “auditevents”

    创建AdminApplication.java

    package org.lianglianglee.admin;
    
    import de.codecentric.boot.admin.server.config.EnableAdminServer;
    import org.springframework.boot.SpringApplication;
    import org.springframework.boot.autoconfigure.SpringBootApplication;
    
    /**
     * @ClessName AdminApplication
     * @Desc SpringBootAdmin启动类
     * @Author liangliang
     * @Date 2018/9/10 15:45
     * @Version 1.0
     */
    @SpringBootApplication
    @EnableAdminServer
    public class AdminApplication {
      public static void main(String[] args){
    	 SpringApplication.run(AdminApplication.class,args);
      }
     }
      
    

启动

启动AdminApplication,访问http://localhost:8888

启动

详情

创建客户端admin-client

pom.xml文件添加以下内容

  <properties>
	<maven.compiler.source>1.8</maven.compiler.source>
	<maven.compiler.target>1.8</maven.compiler.target>
  </properties>

  <parent>
	<groupId>org.springframework.boot</groupId>
	<artifactId>spring-boot-starter-parent</artifactId>
	<version>2.0.4.RELEASE</version>
  </parent>
  <dependencies>

	<!-- 客户端包 -->
	<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-actuator</artifactId>
	</dependency>
	<dependency>
	  <groupId>org.springframework.boot</groupId>
	  <artifactId>spring-boot-starter-web</artifactId>
	</dependency>
	<dependency>
	  <groupId>org.springframework.boot</groupId>
	  <artifactId>spring-boot-starter-test</artifactId>
	  <scope>test</scope>
	</dependency>
	<!-- 在管理界面中与 JMX-beans 进行交互所需要被依赖的 JAR -->
	<dependency>
	  <groupId>org.jolokia</groupId>
	  <artifactId>jolokia-core</artifactId>
	</dependency>
  </dependencies>
  <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

server:
  port: 8890
management:
  endpoint:
	health:
	  show-details: always
  endpoints:
	web:
	  base-path: /
	  exposure:
		include: "*"
spring:
  application:
	name: admin-client
  boot:
	admin:
	  client:
		instance:
		  prefer-ip: true
		url: http://localhost:8888
logging:
  file: ./client/log.log
  level:
	root: info

创建ClientApplication.java

package org.lianglianglee.client;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

/**
 * @ClessName ClientApplication
 * @Desc SpringBootAdmin-Client启动类
 * @Author liangliang
 * @Date 2018/9/10 22:29
 * @Version 1.0
 */
@SpringBootApplication
public class ClientApplication {
  public static void main(String[] args){
	SpringApplication.run(ClientApplication.class,args);
  }
}

启动

访问http://localhost:8888

请输入图片描述

点击查看更多内容

本文原创发布于慕课网 ,转载请注明出处,谢谢合作

4人点赞

若觉得本文不错,就分享一下吧!

评论

相关文章推荐

正在加载中
意见反馈 邀请有奖 帮助中心 APP下载
官方微信

举报

0/150
提交
取消