温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

Spring boot实现监控Actuator-Admin的方法

发布时间:2020-11-02 16:54:33 来源:亿速云 阅读:190 作者:Leah 栏目:开发技术

Spring boot实现监控Actuator-Admin的方法?针对这个问题,这篇文章详细介绍了相对应的分析和解答,希望可以帮助更多想解决这个问题的小伙伴找到更简单易行的方法。

Actuator是监控管理,不过没有可视化,这里就引入了admin-ui来解决Spring Boot Admin 分为Client端和Server端Client端是客户端Server端是spring-boot-admin来监控client的.先来一个Client客户端代码;

<&#63;xml version="1.0" encoding="UTF-8"&#63;>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
 <modelVersion>4.0.0</modelVersion>
 
 <artifactId>spring-boot-demo-admin-client</artifactId>
 <version>1.0.0-SNAPSHOT</version>
 <packaging>jar</packaging>
 
 <name>spring-boot-demo-admin-client</name>
 <description>Demo project for Spring Boot</description>
 
 <parent>
  <groupId>com.xkcoding</groupId>
  <artifactId>spring-boot-demo-admin</artifactId>
  <version>1.0.0-SNAPSHOT</version>
 </parent>
 
 <properties>
  <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
  <java.version>1.8</java.version>
 </properties>
 
 <dependencies>
  <dependency>
   <groupId>org.springframework.boot</groupId>
   <artifactId>spring-boot-starter-web</artifactId>
  </dependency>
 
  <dependency>
   <groupId>de.codecentric</groupId>
   <artifactId>spring-boot-admin-starter-client</artifactId>
  </dependency>
 
  <dependency>
   <groupId>org.springframework.boot</groupId>
   <artifactId>spring-boot-starter-security</artifactId>
  </dependency>
 
  <dependency>
   <groupId>org.springframework.boot</groupId>
   <artifactId>spring-boot-starter-test</artifactId>
   <scope>test</scope>
  </dependency>
 </dependencies>
 
 <build>
  <finalName>spring-boot-demo-admin-client</finalName>
  <plugins>
   <plugin>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-maven-plugin</artifactId>
   </plugin>
  </plugins>
 </build>
 
</project>

application.yml文件,注意这里的url一定跑配置到Server的路径,不然找不到,有点类型erkura的注册中心地址.

server:
 port: 8081
 servlet:
  context-path: /demo
spring:
 application:
  # Spring Boot Admin展示的客户端项目名,不设置,会使用自动生成的随机id
  name: spring-boot-demo-admin-client
 boot:
  admin:
   client:
    # Spring Boot Admin 服务端地址
    url: "http://localhost:8080/"
    instance:
     metadata:
      # 客户端端点信息的安全认证信息
      user.name: ${spring.security.user.name}
      user.password: ${spring.security.user.password}
 security:
  user:
   name: xkcoding
   password: 123456
management:
 endpoint:
  health:
   # 端点健康情况,默认值"never",设置为"always"可以显示硬盘使用情况和线程情况
   show-details: always
 endpoints:
  web:
   exposure:
    # 设置端点暴露的哪些内容,默认["health","info"],设置"*"代表暴露所有可访问的端点
    include: "*"

Java文件就随便暴露个接口就行

package com.xkcoding.admin.client.controller;
 
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
 
/**
 * <p>
 * 首页
 * </p>
 *
 * @package: com.xkcoding.admin.client.controller
 * @description: 首页
 * @author: yangkai.shen
 * @date: Created in 2018/10/8 2:15 PM
 * @copyright: Copyright (c) 2018
 * @version: V1.0
 * @modified: yangkai.shen
 */
@RestController
public class IndexController {
  @GetMapping(value = {"", "/"})
  public String index() {
   return "This is a Spring Boot Admin Client.";
  }
}

接下来是Server服务端,作为监控平台使用pom.xml

<&#63;xml version="1.0" encoding="UTF-8"&#63;>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
 <modelVersion>4.0.0</modelVersion>
 
 <artifactId>spring-boot-demo-admin-server</artifactId>
 <version>1.0.0-SNAPSHOT</version>
 <packaging>jar</packaging>
 
 <name>spring-boot-demo-admin-server</name>
 <description>Demo project for Spring Boot</description>
 
 <parent>
  <groupId>com.xkcoding</groupId>
  <artifactId>spring-boot-demo-admin</artifactId>
  <version>1.0.0-SNAPSHOT</version>
 </parent>
 
 <properties>
  <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
  <java.version>1.8</java.version>
 </properties>
 
 <dependencies>
  <dependency>
   <groupId>org.springframework.boot</groupId>
   <artifactId>spring-boot-starter-web</artifactId>
  </dependency>
 
  <dependency>
   <groupId>de.codecentric</groupId>
   <artifactId>spring-boot-admin-starter-server</artifactId>
  </dependency>
 
  <dependency>
   <groupId>org.springframework.boot</groupId>
   <artifactId>spring-boot-starter-test</artifactId>
   <scope>test</scope>
  </dependency>
 </dependencies>
 
 <build>
  <finalName>spring-boot-demo-admin-server</finalName>
  <plugins>
   <plugin>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-maven-plugin</artifactId>
   </plugin>
  </plugins>
 </build>
 
</project>

application.yml

server:
 port: 8080 

运行服务端地址,发现已经检测到了注册过的客户端

Spring boot实现监控Actuator-Admin的方法

可以看到客户端的信息

Spring boot实现监控Actuator-Admin的方法

http追踪可以看到请求

Spring boot实现监控Actuator-Admin的方法

关于Spring boot实现监控Actuator-Admin的方法问题的解答就分享到这里了,希望以上内容可以对大家有一定的帮助,如果你还有很多疑惑没有解开,可以关注亿速云行业资讯频道了解更多相关知识。

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI