redis慢查詢日誌
運維需要記錄一下主redis中那些“慢操作”的命令,然後找到相關的業務方,不然的話,阻塞
就不好玩了。然後就直接在redis手冊中就找到了相關的命令。
SLOWLOG subcommand [argument] 什麼是 SLOWLOG Slow log 是 Redis 用來記錄查詢執行時間的日誌系統。 查詢執行時間指的是不包括像客戶端響應(talking)、發送回覆等 IO 操作,而單單是執行一個查詢命令所耗費的時間。 另外,slow log 保存在內存裏面,讀寫速度非常快,因此你可以放心地使用它,不必擔心因爲開啓 slow log 而損害 Redis 的速度。 設置 SLOWLOG Slow log 的行爲由兩個配置參數(configuration parameter)指定,可以通過改寫 redis.conf 文件或者用 CONFIG GET 和 CONFIG SET 命令對它們動態地進行修改。 第一個選項是 slowlog-log-slower-than ,它決定要對執行時間大於多少微秒(microsecond,1秒 = 1,000,000 微秒)的查詢進行記錄。 比如執行以下命令將讓 slow log 記錄所有查詢時間大於等於 100 微秒的查詢: CONFIG SET slowlog-log-slower-than 100 而以下命令記錄所有查詢時間大於 1000 微秒的查詢: CONFIG SET slowlog-log-slower-than 1000 另一個選項是 slowlog-max-len ,它決定 slow log 最多能保存多少條日誌, slow log 本身是一個 FIFO 隊列,當隊列大小超過 slowlog-max-len 時,最舊的一條日誌將被刪除,而最新的一條日誌加入到 slow log ,以此類推。 以下命令讓 slow log 最多保存 1000 條日誌: CONFIG SET slowlog-max-len 1000
從上面這段話中,大概看出了兩個屬性: slowlog-log-slower-than 和 slowlog-max-len,爲了測試方便,我就不config set了,直接改掉
redis.conf文件即可。。。
# The following time is expressed in microseconds, so 1000000 is equivalent # to one second. Note that a negative number disables the slow log, while # a value of zero forces the logging of every command. slowlog-log-slower-than 0 # There is no limit to this length. Just be aware that it will consume memory. # You can reclaim memory used by the slow log with SLOWLOG RESET. slowlog-max-len 10
然後我簡單測試一下,所有command都會被記錄到slowlog裏面去了,下圖中的紅色框框就是comand的執行時間。
有了這個,我現在是不是可以找到所有生產線上哪些慢的command命令呢???這樣大家就不會扯皮了。。。