From 019ffdaf1262752b9cc5725b80370f989c401bf7 Mon Sep 17 00:00:00 2001 From: Jon Chambers Date: Fri, 16 Oct 2020 14:48:52 -0400 Subject: [PATCH] Add a command for dumping Redis command stats. --- .../textsecuregcm/WhisperServerService.java | 2 ++ .../workers/GetRedisCommandStatsCommand.java | 35 +++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 service/src/main/java/org/whispersystems/textsecuregcm/workers/GetRedisCommandStatsCommand.java diff --git a/service/src/main/java/org/whispersystems/textsecuregcm/WhisperServerService.java b/service/src/main/java/org/whispersystems/textsecuregcm/WhisperServerService.java index aeb44d866..0fedf8db0 100644 --- a/service/src/main/java/org/whispersystems/textsecuregcm/WhisperServerService.java +++ b/service/src/main/java/org/whispersystems/textsecuregcm/WhisperServerService.java @@ -155,6 +155,7 @@ import org.whispersystems.textsecuregcm.websocket.ProvisioningConnectListener; import org.whispersystems.textsecuregcm.websocket.WebSocketAccountAuthenticator; import org.whispersystems.textsecuregcm.workers.CertificateCommand; import org.whispersystems.textsecuregcm.workers.DeleteUserCommand; +import org.whispersystems.textsecuregcm.workers.GetRedisCommandStatsCommand; import org.whispersystems.textsecuregcm.workers.GetRedisSlowlogCommand; import org.whispersystems.textsecuregcm.workers.VacuumCommand; import org.whispersystems.textsecuregcm.workers.ZkParamsCommand; @@ -191,6 +192,7 @@ public class WhisperServerService extends Application("accountdb", "accountsdb.xml") { @Override diff --git a/service/src/main/java/org/whispersystems/textsecuregcm/workers/GetRedisCommandStatsCommand.java b/service/src/main/java/org/whispersystems/textsecuregcm/workers/GetRedisCommandStatsCommand.java new file mode 100644 index 000000000..c4d913d42 --- /dev/null +++ b/service/src/main/java/org/whispersystems/textsecuregcm/workers/GetRedisCommandStatsCommand.java @@ -0,0 +1,35 @@ +package org.whispersystems.textsecuregcm.workers; + +import io.dropwizard.cli.ConfiguredCommand; +import io.dropwizard.setup.Bootstrap; +import net.sourceforge.argparse4j.inf.Namespace; +import org.whispersystems.textsecuregcm.WhisperServerConfiguration; +import org.whispersystems.textsecuregcm.redis.FaultTolerantRedisCluster; + +import java.util.List; + +public class GetRedisCommandStatsCommand extends ConfiguredCommand { + + public GetRedisCommandStatsCommand() { + super("rediscommandstats", "Dump Redis command stats"); + } + + @Override + protected void run(final Bootstrap bootstrap, final Namespace namespace, final WhisperServerConfiguration config) throws Exception { + final FaultTolerantRedisCluster cacheCluster = new FaultTolerantRedisCluster("main_cache_cluster", config.getCacheClusterConfiguration()); + final FaultTolerantRedisCluster messagesCacheCluster = new FaultTolerantRedisCluster("messages_cluster", config.getMessageCacheConfiguration().getRedisClusterConfiguration()); + final FaultTolerantRedisCluster metricsCluster = new FaultTolerantRedisCluster("metrics_cluster", config.getMetricsClusterConfiguration()); + + for (final FaultTolerantRedisCluster cluster : List.of(cacheCluster, messagesCacheCluster, metricsCluster)) { + cluster.useCluster(connection -> connection.sync() + .masters() + .commands() + .info("commandstats") + .asMap() + .forEach((node, commandStats) -> { + System.out.format("# %s - %s\n\n", cluster.getName(), node.getUri()); + System.out.println(commandStats); + })); + } + } +}