スプリングブーツモニター監視センター建設

監視センターを作成するには、その前に eureka 登録センターが必要です。
EnableAdminServer はモニタリング センターとして表され
、EnableDiscoveryClient はモニタリング クライアントとして表されます。

@EnableAdminServer
@EnableDiscoveryClient
@SpringBootApplication
public class SpringbootMonitorApplication
{
    
    
    public static void main(String[] args)
    {
    
    
        SpringApplication.run(SpringbootMonitorApplication.class, args);
    }
}

```java
server:
  port: 28762
spring:
  security:
    user:
      name: admin
      password: admin
  application:
    name: springboot-monitor
management:
  endpoints:
    web:
      exposure:
        include: "*"
  endpoint:
    health:
      show-details: always

eureka:
  instance:
    lease-expiration-duration-in-seconds: 30 # 心跳,租约续约频率,单位:秒
    lease-renewal-interval-in-seconds: 10 #  eureka server多久没有收到心跳,则表示对应的实例过期,单位:秒。
    health-check-url-path: /actuator/health
    statusPageUrlPath: /actuator/health
    prefer-ip-address: true #以IP地址注册到服务中心,相互注册使用IP地址
    # ip-address: 127.0.0.1 #强制指定IP地址,默认会获取本机的IP地址
    instance-id: ${
    
    spring.application.name}:${
    
    spring.cloud.client.ip-address}:${
    
    server.port}
  client:
    fetch-registry: true #通过设置fetch-registry与register-with-eureka 表明自己是一个eureka服务
    register-with-eureka: true #服务注册中心也会将自己作为客户端来尝试注册自己,true(默认)时自动生效
    service-url:
      defaultZone: http://localhost:28761/eureka/

ポン設定

      <dependency>
            <groupId>de.codecentric</groupId>
            <artifactId>spring-boot-admin-starter-server</artifactId>
            <version>2.4.1</version>
        </dependency>

        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
        </dependency>

その後、クライアントを作成します。これは基本的に監視センターに似ていますが、サーブレット パスが構成されている場合は eureka で指定する必要があることに注意してください。そうしないと、多くのデータが監視されません。

起動クラス

@EnableTransactionManagement
@MapperScan("com.aaa.aaa.aaa.mapper")
@EnableCircuitBreaker
**@EnableEurekaClient**
@EnableFeignClients(basePackages ={
    
    "com.aaa.*"})
@ComponentScan(basePackages = {
    
    "com.aaa.aaa.*"})
@SpringBootApplication
public class DeviceApplication {
    
    

    public static void main(String[] args) {
    
    
        SpringApplication.run(DeviceApplication.class, args);
    }
spring:
  application:
    name: baop-device

server:
  port: 8888
  servlet:
    context-path: /device #注意这个对监控的影响

management:
  endpoints:
    web:
      exposure:
        include: "*"
  endpoint:
    health:
      show-details: ALWAYS
#上面两段配置就是支持admin监控的配置
eureka:
  instance:
    lease-expiration-duration-in-seconds: 30 # 心跳,租约续约频率,单位:秒
    lease-renewal-interval-in-seconds: 10 #  eureka server多久没有收到心跳,则表示对应的实例过期,单位:秒。
    health-check-url-path: /actuator/health
    statusPageUrlPath: /actuator/health
    prefer-ip-address: true #以IP地址注册到服务中心,相互注册使用IP地址
    instance-id: ${
    
    spring.application.name}:${
    
    spring.cloud.client.ip-address}:${
    
    server.port}
    metadata-map:
      management:
        context-path: ${
    
    server.servlet.context-path}/actuator#注意这个配置 如果没有就不用配置 其他都是常见的eureka配置
  client:
    fetch-registry: true #通过设置fetch-registry与register-with-eureka 表明自己是一个eureka服务
    register-with-eureka: true #服务注册中心也会将自己作为客户端来尝试注册自己,true(默认)时自动生效
    service-url:
      defaultZone: http://localhost:28761/eureka/
 <dependency>
                <groupId>de.codecentric</groupId>
                <artifactId>spring-boot-admin-starter-client</artifactId>
                <version>2.4.1</version>
            </dependency>
			<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-actuator</artifactId>
		</dependency>

最終的な効果は、下の図に示すとおりです。
2 つのアプリケーションを監視します。1 つは管理者の監視そのもので、もう 1 つはカスタマー サービス ターミナルです。
下の図に示すように、クリックしてアプリケーションを開きます。
ここに画像の説明を挿入

おすすめ

転載: blog.csdn.net/wangzhi291/article/details/117229084