Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
*/
package org.apache.geode.redis.internal;

import java.net.UnknownHostException;

import org.apache.logging.log4j.Logger;

import org.apache.geode.annotations.VisibleForTesting;
Expand All @@ -22,6 +24,7 @@
import org.apache.geode.distributed.internal.InternalDistributedSystem;
import org.apache.geode.internal.cache.InternalCache;
import org.apache.geode.internal.cache.PartitionedRegion;
import org.apache.geode.internal.inet.LocalHostUtil;
import org.apache.geode.internal.statistics.StatisticsClock;
import org.apache.geode.internal.statistics.StatisticsClockFactory;
import org.apache.geode.logging.internal.log4j.api.LogService;
Expand Down Expand Up @@ -74,7 +77,7 @@ public GeodeRedisServer(String bindAddress, int port, InternalCache cache) {

unsupportedCommandsEnabled = Boolean.getBoolean(ENABLE_UNSUPPORTED_COMMANDS_PARAM);

redisStats = createStats(cache);
redisStats = createStats(cache, bindAddress, port);
StripedCoordinator stripedCoordinator = new LockingStripedCoordinator();
RedisMemberInfoRetrievalFunction infoFunction = RedisMemberInfoRetrievalFunction.register();

Expand All @@ -99,17 +102,31 @@ public int getSubscriptionCount() {
return ((PubSubImpl) pubSub).getSubscriptionCount();
}

private static RedisStats createStats(InternalCache cache) {
private static RedisStats createStats(InternalCache cache, String bindAddress, int port) {
InternalDistributedSystem system = cache.getInternalDistributedSystem();
StatisticsClock statisticsClock =
StatisticsClockFactory.clock(true);

return new RedisStats(statisticsClock,
new GeodeRedisStats(system.getStatisticsManager(),
"redisStats",
new GeodeRedisStats(system.getStatisticsManager(), getServerName(bindAddress, port),
statisticsClock));
}

private static String getServerName(String bindAddress, int port) {
String name = "geodeForRedis:";
if (bindAddress != null && !bindAddress.isEmpty()) {
name += bindAddress;
} else {
try {
name += LocalHostUtil.getCanonicalLocalHostName();
} catch (UnknownHostException e) {
name += "*.*.*.*";
}
}
name += ':' + port;
return name;
}

@VisibleForTesting
public RedisStats getStats() {
return redisStats;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,9 @@ public class GeodeRedisStats {
private final Statistics stats;
private final StatisticsClock clock;

public GeodeRedisStats(StatisticsFactory factory, String textId,
StatisticsClock clock) {
public GeodeRedisStats(StatisticsFactory factory, String name, StatisticsClock clock) {
this.clock = clock;
stats = factory == null ? null : factory.createAtomicStatistics(type, textId);
stats = factory == null ? null : factory.createAtomicStatistics(type, name);
}

static {
Expand All @@ -68,15 +67,15 @@ public GeodeRedisStats(StatisticsFactory factory, String textId,
fillListWithCommandDescriptors(statisticsTypeFactory, descriptorList);

StatisticDescriptor[] descriptorArray =
descriptorList.toArray(new StatisticDescriptor[descriptorList.size()]);
descriptorList.toArray(new StatisticDescriptor[0]);

type = statisticsTypeFactory
.createType("statsForServergeodeForRedis",
"Statistics for a Geode server compatible with Redis",
.createType("GeodeForRedisStats",
"Statistics for a geode-for-redis server",
descriptorArray);

fillCompletedIdMap(type);
fillTimeIdMap(type);
fillCompletedIdMap();
fillTimeIdMap();

currentlyConnectedClients = type.nameToId("connectedClients");
passiveExpirationChecksId = type.nameToId("passiveExpirationChecks");
Expand Down Expand Up @@ -182,7 +181,7 @@ private static void fillListWithCompletedCommandDescriptors(StatisticsTypeFactor
}
}

private static void fillCompletedIdMap(StatisticsType type) {
private static void fillCompletedIdMap() {
for (RedisCommandType command : RedisCommandType.values()) {
String name = command.name().toLowerCase();
String statName = name + "Completed";
Expand Down Expand Up @@ -242,7 +241,7 @@ private static void fillListWithCommandDescriptors(StatisticsTypeFactory statist
"nanoseconds"));
}

private static void fillTimeIdMap(StatisticsType type) {
private static void fillTimeIdMap() {
for (RedisCommandType command : RedisCommandType.values()) {
String name = command.name().toLowerCase();
String statName = name + "Time";
Expand Down