監控 redis 執行命令


監控 redis 執行命令

Intro

最近在用 redis 的時候想看看執行了哪些命令,於是發現了 redis-cli 提供的 Monitor 命令,直接使用這個就可以監控執行的大部分 redis 命令,之所以說是大部分,是因為有一些命令如:config 出於安全原因是不會記錄的。

Monitor 是調試用的命令

Redis-cli

使用redis-cli連接到redis服務器

redis-cli -h [redis server ip/host] -p [redis server port] [-a accessKey]

之后執行 monitor 命令

$ 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] "del" "x"
1339518100.544926 [0 127.0.0.1:60866] "get" "x"

使用 Ctrl+C 退出 monitor

Telnet

使用 telnet 連接 redis服務器,而后執行 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.

使用 Quit 命令來退出 monitor

性能消耗

由於 MONITOR 命令返回 服務器處理的所有的 命令, 所以在性能上會有一些消耗.

在不運行 MONITOR 命令的情況下,benchmark的測試結果:

$ 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 命令的情況下,benchmark 的測試結果:

$ 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 這個命令,僅供開發過程中的調試。

Reference


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM