Skip to content

MONITOR Command

The MONITOR command streams every command processed by the Valkey server back to the client in real time. It is intended for debugging and development only.

When you create a MonitorClient, GLIDE opens a dedicated connection and sends the MONITOR command. The server begins streaming command records back over that connection. Each record contains the timestamp, database index, client address, command name, and arguments.

MONITOR is only supported for standalone (non-cluster) connections. Attempting to use it with a cluster configuration will result in an error.

GLIDE clients generally provide two modes for consuming monitor messages:

  • Callback mode: Provide a callback function at creation time that is invoked for every incoming message.
  • Queue mode — Messages are queued internally and retrieved by polling.
import glide.api.MonitorClient;
import glide.api.models.commands.MonitorMsg;
import glide.api.models.configuration.GlideClientConfiguration;
import glide.api.models.configuration.NodeAddress;
GlideClientConfiguration config = GlideClientConfiguration.builder()
.address(NodeAddress.builder().host("localhost").port(6379).build())
.build();
// Callback mode
try (MonitorClient monitor = MonitorClient.create(config, (MonitorMsg msg) ->
System.out.printf("%.6f [%d] %s %s %s%n",
msg.timestamp(), msg.db(), msg.clientAddr(), msg.command(), msg.args()))) {
// Run commands on a separate client — the callback will print each one.
Thread.sleep(5000);
}
// Queue mode
try (MonitorClient monitor = MonitorClient.create(config)) {
MonitorMsg msg = monitor.getMonitorMessage();
System.out.printf("%s %s%n", msg.command(), msg.args());
}

Each monitor message contains the following fields:

FieldTypeDescription
TimestampFloating pointTime when the command was processed
DatabaseIntegerDatabase index the command ran against
Client addressStringAddress of the client that issued the command
CommandStringCommand name
ArgumentsListCommand arguments

The exact names and types vary by client, following each language’s specifications and conventions.