springboot monitor monitoring center construction

To create a monitoring center, you need to have an eureka registration center before that.
EnableAdminServer is represented as the monitoring center
and EnableDiscoveryClient is represented as the monitoring client

@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/

pom configuration

      <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>

After that, create the client, which is basically similar to the monitoring center, but it should be noted that if the servlet path is configured, it needs to be specified in eureka, otherwise there will not be a lot of data monitored.

startup class

@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>

The final effect is as shown in the figure below:
Monitor two applications, one is the admin monitoring itself, and the other is the customer service terminal
click to open the application as shown in the figure below:
insert image description here

Guess you like

Origin blog.csdn.net/wangzhi291/article/details/117229084