Redis慢日志查询系统slowlog

Redis慢日志查询系统slowlog

一、什么是SlowLog

SlowLog是Redis用来记录慢查询执行时间的日志系统。由于SlowLog只保存在内存中,所以SlowLog的效率非常高,

所以你不用担心会影响到你Redis的性能问题。SlowLog是Redis 2.2.12版本之后才引入的一条命令。

二、SlowLog设置

SlowLog两种设置方式如下:

1、redis.conf配置文件设置

在配置文件redis.conf中设置:

slowlog-log-slower-than 10000

slowlog-max-len 128

其中slowlog-log-slower-than表示slowlog的划定界限,只有query执行时间大于slowlog-log-slower-than的才会定义成慢查询,才会被slowlog进行记录。slowlog-log-slower-than设置的单位是微秒,默认是10000微秒,也就是10毫秒。

slowlog-max-len表示慢查询最大的条数,当slowlog超过设定的最大值后,会将最早的slowlog删除,是个FIFO队列。

2、使用config方式动态设置slowlog

如下,可以通过config方式动态设置slowlog:

- 查看当前slowlog-log-slower-than设置

127.0.0.1:6379> CONFIG GET slowlog-log-slower-than

1) "slowlog-log-slower-than"

2) "10000"

- 设置slowlog-log-slower-than为100ms

127.0.0.1:6379> CONFIG SET slowlog-log-slower-than 100000

OK

- 设置slowlog-max-len为1000

127.0.0.1:6379> CONFIG SET slowlog-max-len 1000

OK

参考http://redisdoc.com/server/slowlog.html

三、SlowLog 查看

1、查看slowlog总条数

127.0.0.1:6379> SLOWLOG LEN

(integer) 4

2、查看slowlog

127.0.0.1:6379> SLOWLOG GET

1) 1) (integer) 25

2) (integer) 1440057769

3) (integer) 6

4) 1) "SLOWLOG"

2) "LEN"

2) 1) (integer) 24

2) (integer) 1440057756

3) (integer) 36

4) 1) "CONFIG"

2) "GET"

3) "slowlog-log-slower-than"

3) 1) (integer) 23

2) (integer) 1440057752

3) (integer) 11

4) 1) "CONFIG"

2) "SET"

3) "slowlog-log-slower-than"

4) "1"

4) 1) (integer) 22

2) (integer) 1440057493

3) (integer) 27

4) 1) "CONFIG"

2) "GET"

3) "slowlog-log-slower-than"

5) 1) (integer) 21

2) (integer) 1440057133

3) (integer) 7

4) 1) "monitor"

如果要获取指定的条数可以使用SLOWLOG GET N命令

127.0.0.1:6379> SLOWLOG GET 1

1) 1) (integer) 26            // slowlog唯一编号id

2) (integer) 1440057815    // 查询的时间戳

3) (integer) 47            // 查询的耗时(微秒),如表示本条命令查询耗时47微秒

4) 1) "SLOWLOG"            // 查询命令,完整命令为 SLOWLOG GET,slowlog最多保存前面的31个key和128字符

2) "GET"

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容