赞
踩
创建监控中心,在这之前需要已经有了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/
pom配置
<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>
之后是创建客户端 ,基本和监控中心差不多,但是需要注意的是如果配置了servlet 路径,需要在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>
最后的效果如下图:
点开应用如下图:
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。