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.

MONITOR is supported in Python, Node.js, Java, and Go clients. C# and PHP support is not yet available.

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.

There are two modes for consuming monitor messages:

  • Callback mode — provide a callback function at creation time; it is invoked for every incoming message.
  • Queue mode — omit the callback; messages are queued internally and retrieved by calling getMonitorMessage / tryGetMonitorMessage.
import asyncio
from glide import GlideClientConfiguration, NodeAddress
from glide.monitor_client import MonitorClient, MonitorMsg
def on_monitor_msg(msg: MonitorMsg) -> None:
print(f"{msg.timestamp:.6f} [{msg.db}] {msg.client_addr} {msg.command} {msg.args}")
async def main():
config = GlideClientConfiguration([NodeAddress("localhost", 6379)])
async with await MonitorClient.create(config, callback=on_monitor_msg) as monitor:
# Run commands on a separate client — the callback will print each one.
await asyncio.sleep(5)
asyncio.run(main())
import asyncio
from glide import GlideClientConfiguration, NodeAddress
from glide.monitor_client import MonitorClient
async def main():
config = GlideClientConfiguration([NodeAddress("localhost", 6379)])
async with await MonitorClient.create(config) as monitor:
msg = await monitor.get_monitor_message()
print(f"{msg.command} {msg.args}")
asyncio.run(main())

Each monitor message contains the following fields:

FieldTypeDescription
timestampfloat/doubleUnix timestamp of when the command was processed
dbintDatabase index the command ran against
clientAddrstringAddress of the client that issued the command
commandstringCommand name
argslist/arrayCommand arguments