Spring boot 모니터링 Actuator-Admin 실현 과정 상세 설명

Actuator 는 모니터링 관리 이지 만 시각 화 되 지 않 았 습 니 다.여 기 는 admin-ui 를 도입 하여 Spring Boot Admin 을 클 라 이언 트 엔 드 와 서버 엔 드 클 라 이언 트 엔 드 는 클 라 이언 트 서버 엔 드 가 spring-boot-admin 으로 나 누 어 클 라 이언 트 를 감시 합 니 다.먼저 클 라 이언 트 클 라 이언 트 코드 를 사용 합 니 다.

<?xml version="1.0" encoding="UTF-8"?>
<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 은 서버 에 설 정 된 경 로 를 찾 을 수 없습니다.그렇지 않 으 면 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: "*"
자바 파일 은 인 터 페 이 스 를 마음대로 노출 시 키 면 됩 니 다.

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.";
  }
}
다음은 서버 서버 서버 입 니 다.모니터링 플랫폼 으로 pom.xml 을 사용 합 니 다.

<?xml version="1.0" encoding="UTF-8"?>
<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 
서버 주 소 를 실행 하면 등 록 된 클 라 이언 트 가 감지 되 었 습 니 다.

클 라 이언 트 의 정 보 를 볼 수 있 습 니 다.

http 추적 요청 볼 수 있 습 니 다.

이상 이 바로 본 고의 모든 내용 입 니 다.여러분 의 학습 에 도움 이 되 고 저 희 를 많이 응원 해 주 셨 으 면 좋 겠 습 니 다.

좋은 웹페이지 즐겨찾기