SpringBoot实现监控Actuator,关闭redis监测
SpringBoot监控Actuator,关闭redis监测
方法
当我们导入了spring-boot-starter-actuator这个依赖后, SpringBoot会默认去监测一些信息。其中就包括redis、 会根据redis的默认初始配置, localhost:6379 尝试连接redis。如果我们没有用到redis, 启动就会报错
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
<version>2.2.1.RELEASE</version>
</dependency>
比如我在使用SpringBootAdmin的时候,其中内置了Actuator的依赖, 启动报错
[WARN ] 2020-05-28 09:28:17.179 [registrationTask1] de.codecentric.boot.admin.client.registration.ApplicationRegistrator - Failed to register application as Application(name=admin-client, managementUrl=http://Gordon-pc:8768/actuator, healthUrl=http://Gordon-pc:8768/actuator/health, serviceUrl=http://Gordon-pc:8768/) at spring-boot-admin ([http://localhost:8769/instances]): I/O error on POST request for "http://localhost:8769/instances": Connection refused: connect; nested exception is java.net.ConnectException: Connection refused: connect. Further attempts are logged on DEBUG level
[WARN ] 2020-05-28 09:28:19.075 [boundedElastic-1] org.springframework.boot.actuate.redis.RedisReactiveHealthIndicator - Redis health check failed
org.springframework.data.redis.RedisConnectionFailureException: Unable to connect to Redis; nested exception is io.lettuce.core.RedisConnectionException: Unable to connect to localhost:6379
at org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory$SharedConnection.getNativeConnection(LettuceConnectionFactory.java:1200)
at org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory$SharedConnection.getConnection(LettuceConnectionFactory.java:1179)
at org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory.getSharedReactiveConnection(LettuceConnectionFactory.java:952)
at org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory.getReactiveConnection(LettuceConnectionFactory.java:429)
at org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory.getReactiveConnection(LettuceConnectionFactory.java:94)
at reactor.core.publisher.MonoSupplier.call(MonoSupplier.java:85)
at reactor.core.publisher.FluxSubscribeOnCallable$CallableSubscribeOnSubscription.run(FluxSubscribeOnCallable.java:225)
at reactor.core.scheduler.SchedulerTask.call(SchedulerTask.java:68)
at reactor.core.scheduler.SchedulerTask.call(SchedulerTask.java:28)
at java.util.concurrent.FutureTask.run$$$capture(FutureTask.java:266)
at java.util.concurrent.FutureTask.run(FutureTask.java)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
Caused by: io.lettuce.core.RedisConnectionException: Unable to connect to localhost:6379
at io.lettuce.core.RedisConnectionException.create(RedisConnectionException.java:78)
at io.lettuce.core.RedisConnectionException.create(RedisConnectionException.java:56)
at io.lettuce.core.AbstractRedisClient.getConnection(AbstractRedisClient.java:234)
at io.lettuce.core.RedisClient.connect(RedisClient.java:207)
at org.springframework.data.redis.connection.lettuce.StandaloneConnectionProvider.lambda$getConnection$1(StandaloneConnectionProvider.java:115)
at java.util.Optional.orElseGet(Optional.java:267)
at org.springframework.data.redis.connection.lettuce.StandaloneConnectionProvider.getConnection(StandaloneConnectionProvider.java:115)
at org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory$SharedConnection.getNativeConnection(LettuceConnectionFactory.java:1198)
... 15 common frames omitted
在网上搜了下解决方法, 发现都是提供的这一种方式:
@Component("redisHealthIndicator")
public class RedisHealthIndicator implements HealthIndicator {
@Override
public Health health() {
return Health.up().build();
}
}
结果我在看配置文件的时候, 发现另一个简单的方式: application.yml中加上
management:
health:
redis:
enabled: false
就可以了~
springboot Actuator
通过Actuator可以深入的了解springboot应用程序的内部, 可以进行监控和度量一些配置信息。
这些特性可以通过rest端点、远程shell和jmx获得。
以下主要探讨rest端点的使用。
查看配置明细
1)/beans 上下文bean的情况
查看spring上下文中bean的情况, /beans会返回一个json文档,描述上下文里每个Bean的情况,类型、依赖注入
2)/autoconfig 自动配置情况
positiveMatches指定的自动配置表示匹配成功的bean
negativeMatches对应的自动配置表示匹配失败的bean
3)/env 查看配置属性
包括:环境变量、JVM属性、命令行参数,以及application.properties或application.yml文件提供的属性
运行时度量
对运行时度量情况作一个快照,以此检查应用程序的健康状况。
1)/metrics 应用程序的度量值
2)/trace 跟踪web请求的所有信息
包括请求方法、路径、时间戳,以及请求和响应的头信息。
3)/health 健康检查器
可以检查应用程序启动状况,以及相关依赖中间件的连接状态。
以上为个人经验,希望能给大家一个参考,也希望大家多多支持。
以上是 SpringBoot实现监控Actuator,关闭redis监测 的全部内容, 来源链接: utcz.com/p/250402.html