监控

Syntax
MONITOR
Available since:
1.0.0
Time complexity:
ACL categories:
@admin, @slow, @dangerous,

MONITOR 是一个调试命令,它会流式返回 Redis 服务器处理的每个命令。 它可以帮助理解数据库中正在发生的情况。 此命令可以通过 redis-clitelnet 使用。

查看服务器处理的所有请求的能力非常有用,无论是在使用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"

使用 SIGINT (Ctrl-C) 来停止通过 redis-cli 运行的 MONITOR 流。

$ 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.

手动发出QUITRESET命令以停止通过telnet运行的MONITOR流。

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客户端将进一步减少吞吐量。

行为变更历史

RESP2/RESP3 回复

Non-standard return value. Dumps the received commands in an infinite flow.
RATE THIS PAGE
Back to top ↑