MONITOR
语法
MONITOR
- 可用版本
- Redis开源版 1.0.0
- 时间复杂度
- ACL 类别
-
@admin,@slow,@dangerous,
MONITOR 是一个调试命令,它会流式返回 Redis 服务器处理的每个命令。这有助于理解数据库正在发生什么。此命令可以通过 redis-cli 和 telnet 使用。
查看服务器处理的所有请求的能力对于在使用 Redis 作为数据库或分布式缓存系统时发现应用程序中的错误非常有用。
$ redis-cli monitor
1339518083.107412 [0 127.0.0.1:60866] "keys" "*"
1339518087.877697 [0 127.0.0.1:60866] "dbsize"
1339518090.420270 [0 127.0.0.1:60866] "set" "x" "6"
1339518096.506257 [0 127.0.0.1:60866] "get" "x"
1339518099.363765 [0 127.0.0.1:60866] "eval" "return redis.call('set','x','7')" "0"
1339518100.363799 [0 lua] "set" "x" "7"
1339518100.544926 [0 127.0.0.1:60866] "del" "x"
通过 redis-cli 运行 MONITOR 流时,使用 SIGINT (Ctrl-C) 停止。
$ telnet localhost 6379
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
MONITOR
+OK
+1339518083.107412 [0 127.0.0.1:60866] "keys" "*"
+1339518087.877697 [0 127.0.0.1:60866] "dbsize"
+1339518090.420270 [0 127.0.0.1:60866] "set" "x" "6"
+1339518096.506257 [0 127.0.0.1:60866] "get" "x"
+1339518099.363765 [0 127.0.0.1:60866] "del" "x"
+1339518100.544926 [0 127.0.0.1:60866] "get" "x"
QUIT
+OK
Connection closed by foreign host.
通过 telnet 运行 MONITOR 流时,手动发出 QUIT 或 RESET 命令停止。
MONITOR 不记录的命令
出于安全考虑,MONITOR 的输出不会记录任何管理命令,并且在命令 AUTH 中敏感数据会被编辑。
此外,命令 QUIT 也不会被记录。
运行 MONITOR 的成本
因为 MONITOR 会流式返回所有命令,所以它的使用是有代价的。以下(完全非科学的)基准测试数字说明了运行 MONITOR 可能产生的成本。
不运行 MONITOR 时的基准测试结果
$ src/redis-benchmark -c 10 -n 100000 -q
PING_INLINE: 101936.80 requests per second
PING_BULK: 102880.66 requests per second
SET: 95419.85 requests per second
GET: 104275.29 requests per second
INCR: 93283.58 requests per second
运行 MONITOR 时的基准测试结果 (redis-cli monitor > /dev/null)
$ src/redis-benchmark -c 10 -n 100000 -q
PING_INLINE: 58479.53 requests per second
PING_BULK: 59136.61 requests per second
SET: 41823.50 requests per second
GET: 45330.91 requests per second
INCR: 41771.09 requests per second
在这种特定情况下,运行单个 MONITOR 客户端可以将吞吐量降低 50% 以上。运行更多 MONITOR 客户端会进一步降低吞吐量。
行为变更历史
>= 6.0.0:AUTH从命令输出中排除。>= 6.2.0: 调用RESET可以退出监听模式。>= 6.2.4:AUTH、HELLO、EVAL、EVAL_RO、EVALSHA和EVALSHA_RO包含在命令输出中。