|
|
@ -1,5 +1,5 @@
|
|
|
|
/*
|
|
|
|
/*
|
|
|
|
* Copyright 2012-2019 the original author or authors.
|
|
|
|
* Copyright 2012-2020 the original author or authors.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
@ -16,8 +16,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
package org.springframework.boot.actuate.redis;
|
|
|
|
package org.springframework.boot.actuate.redis;
|
|
|
|
|
|
|
|
|
|
|
|
import java.util.Properties;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import org.springframework.boot.actuate.health.AbstractHealthIndicator;
|
|
|
|
import org.springframework.boot.actuate.health.AbstractHealthIndicator;
|
|
|
|
import org.springframework.boot.actuate.health.Health;
|
|
|
|
import org.springframework.boot.actuate.health.Health;
|
|
|
|
import org.springframework.boot.actuate.health.HealthIndicator;
|
|
|
|
import org.springframework.boot.actuate.health.HealthIndicator;
|
|
|
@ -39,15 +37,7 @@ import org.springframework.util.Assert;
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public class RedisHealthIndicator extends AbstractHealthIndicator {
|
|
|
|
public class RedisHealthIndicator extends AbstractHealthIndicator {
|
|
|
|
|
|
|
|
|
|
|
|
static final String VERSION = "version";
|
|
|
|
private static final String REDIS_VERSION_PROPERTY = "redis_version";
|
|
|
|
|
|
|
|
|
|
|
|
static final String CLUSTER_SIZE = "cluster_size";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static final String SLOTS_UP = "slots_up";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static final String SLOTS_FAIL = "slots_fail";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static final String REDIS_VERSION = "redis_version";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private final RedisConnectionFactory redisConnectionFactory;
|
|
|
|
private final RedisConnectionFactory redisConnectionFactory;
|
|
|
|
|
|
|
|
|
|
|
@ -61,19 +51,23 @@ public class RedisHealthIndicator extends AbstractHealthIndicator {
|
|
|
|
protected void doHealthCheck(Health.Builder builder) throws Exception {
|
|
|
|
protected void doHealthCheck(Health.Builder builder) throws Exception {
|
|
|
|
RedisConnection connection = RedisConnectionUtils.getConnection(this.redisConnectionFactory);
|
|
|
|
RedisConnection connection = RedisConnectionUtils.getConnection(this.redisConnectionFactory);
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
|
|
|
|
doHealthCheck(builder, connection);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
finally {
|
|
|
|
|
|
|
|
RedisConnectionUtils.releaseConnection(connection, this.redisConnectionFactory, false);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void doHealthCheck(Health.Builder builder, RedisConnection connection) {
|
|
|
|
if (connection instanceof RedisClusterConnection) {
|
|
|
|
if (connection instanceof RedisClusterConnection) {
|
|
|
|
ClusterInfo clusterInfo = ((RedisClusterConnection) connection).clusterGetClusterInfo();
|
|
|
|
ClusterInfo clusterInfo = ((RedisClusterConnection) connection).clusterGetClusterInfo();
|
|
|
|
builder.up().withDetail(CLUSTER_SIZE, clusterInfo.getClusterSize())
|
|
|
|
builder.up().withDetail("cluster_size", clusterInfo.getClusterSize())
|
|
|
|
.withDetail(SLOTS_UP, clusterInfo.getSlotsOk())
|
|
|
|
.withDetail("slots_up", clusterInfo.getSlotsOk())
|
|
|
|
.withDetail(SLOTS_FAIL, clusterInfo.getSlotsFail());
|
|
|
|
.withDetail("slots_fail", clusterInfo.getSlotsFail());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
else {
|
|
|
|
Properties info = connection.info();
|
|
|
|
String version = connection.info().getProperty(REDIS_VERSION_PROPERTY);
|
|
|
|
builder.up().withDetail(VERSION, info.getProperty(REDIS_VERSION));
|
|
|
|
builder.up().withDetail("version", version);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
finally {
|
|
|
|
|
|
|
|
RedisConnectionUtils.releaseConnection(connection, this.redisConnectionFactory, false);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|