Redis监控
Posted 天宇轩-王
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Redis监控相关的知识,希望对你有一定的参考价值。
redis-benchmark
1.1 简介
第一个就介绍一下,Redis自带的性能检测工具redis-benchmark, 该工具可以模拟 N 个客户端同时发出 Y 个请求。 可以使用 redis-benchmark -h 来查看基准参数。
1.2 命令格式:
redis-benchmark [-h ] [-p ] [-c ] [-n <requests]> [-k ]
1.3 参数介绍:
序号 | 选项 | 描述 | 默认值 |
---|---|---|---|
1 | -h | 指定服务器主机名 | 127.0.0.1 |
2 | -p | 指定服务器端口 | 6379 |
3 | -s | 指定服务器 socket | |
4 | -c | 指定并发连接数 | 50 |
5 | -n | 指定请求数 | 10000 |
6 | -d | 以字节的形式指定 SET/GET 值的数据大小 | 2 |
7 | -k | 1=keep alive 0=reconnect | 1 |
8 | -r | SET/GET/INCR 使用随机 key, SADD 使用随机值 | |
9 | -P | 通过管道传输 <numreq> 请求 | 1 |
10 | -q | 强制退出 redis。仅显示 query/sec 值 | |
11 | --csv | 以 CSV 格式输出 | |
12 | -l | 生成循环,永久执行测试 | |
13 | -t | 仅运行以逗号分隔的测试命令列表。 | |
14 | -I | Idle 模式。仅打开 N 个 idle 连接并等待。 |
1.4 实例:
1.4.1 同时执行1000个请求来检测性能:
[root@iZbp143t3oxhfc3ar7jey0Z data]# redis-benchmark -n 1000 -q PING_INLINE: 62500.00 requests per second PING_BULK: 66666.67 requests per second SET: 62500.00 requests per second GET: 76923.08 requests per second INCR: 76923.08 requests per second LPUSH: 62500.00 requests per second RPUSH: 62500.00 requests per second LPOP: 76923.08 requests per second RPOP: 76923.08 requests per second SADD: 66666.67 requests per second HSET: 83333.34 requests per second SPOP: 76923.08 requests per second LPUSH (needed to benchmark LRANGE): 76923.08 requests per second LRANGE_100 (first 100 elements): 71428.57 requests per second LRANGE_300 (first 300 elements): 66666.67 requests per second LRANGE_500 (first 450 elements): 76923.08 requests per second LRANGE_600 (first 600 elements): 71428.57 requests per second MSET (10 keys): 58823.53 requests per second [root@iZbp143t3oxhfc3ar7jey0Z data]#
1.4.2 50个并发请求,10000个请求,检测Redis性能:
[root@iZbp143t3oxhfc3ar7jey0Z data]# redis-benchmark -p 6379 -c 50 -n 10000 ====== PING_INLINE ====== 10000 requests completed in 0.15 seconds 50 parallel clients 3 bytes payload keep alive: 1 96.22% <= 1 milliseconds 99.99% <= 2 milliseconds 100.00% <= 2 milliseconds 65789.48 requests per second ====== PING_BULK ====== 10000 requests completed in 0.14 seconds 50 parallel clients 3 bytes payload keep alive: 1 99.24% <= 1 milliseconds 100.00% <= 1 milliseconds 68965.52 requests per second ====== SET ====== 10000 requests completed in 0.14 seconds 50 parallel clients 3 bytes payload keep alive: 1 99.19% <= 1 milliseconds 100.00% <= 1 milliseconds 70422.53 requests per second ====== GET ====== 10000 requests completed in 0.14 seconds 50 parallel clients 3 bytes payload keep alive: 1 98.93% <= 1 milliseconds 100.00% <= 1 milliseconds 68965.52 requests per second ====== INCR ====== 10000 requests completed in 0.14 seconds 50 parallel clients 3 bytes payload keep alive: 1 98.73% <= 1 milliseconds 100.00% <= 1 milliseconds 69444.45 requests per second ====== LPUSH ====== 10000 requests completed in 0.14 seconds 50 parallel clients 3 bytes payload keep alive: 1 99.05% <= 1 milliseconds 100.00% <= 1 milliseconds 71942.45 requests per second ====== RPUSH ====== 10000 requests completed in 0.16 seconds 50 parallel clients 3 bytes payload keep alive: 1 97.35% <= 1 milliseconds 100.00% <= 2 milliseconds 63291.14 requests per second ====== LPOP ====== 10000 requests completed in 0.15 seconds 50 parallel clients 3 bytes payload keep alive: 1 99.32% <= 1 milliseconds 100.00% <= 1 milliseconds 66666.66 requests per second ====== RPOP ====== 10000 requests completed in 0.15 seconds 50 parallel clients 3 bytes payload keep alive: 1 97.83% <= 1 milliseconds 100.00% <= 1 milliseconds 68027.21 requests per second ====== SADD ====== 10000 requests completed in 0.14 seconds 50 parallel clients 3 bytes payload keep alive: 1 98.96% <= 1 milliseconds 100.00% <= 1 milliseconds 72992.70 requests per second ====== HSET ====== 10000 requests completed in 0.14 seconds 50 parallel clients 3 bytes payload keep alive: 1 98.20% <= 1 milliseconds 100.00% <= 1 milliseconds 71942.45 requests per second ====== SPOP ====== 10000 requests completed in 0.14 seconds 50 parallel clients 3 bytes payload keep alive: 1 98.86% <= 1 milliseconds 100.00% <= 1 milliseconds 71942.45 requests per second ====== LPUSH (needed to benchmark LRANGE) ====== 10000 requests completed in 0.14 seconds 50 parallel clients 3 bytes payload keep alive: 1 99.14% <= 1 milliseconds 100.00% <= 1 milliseconds 68965.52 requests per second ====== LRANGE_100 (first 100 elements) ====== 10000 requests completed in 0.16 seconds 50 parallel clients 3 bytes payload keep alive: 1 98.85% <= 1 milliseconds 100.00% <= 1 milliseconds 61349.69 requests per second ====== LRANGE_300 (first 300 elements) ====== 10000 requests completed in 0.15 seconds 50 parallel clients 3 bytes payload keep alive: 1 98.57% <= 1 milliseconds 100.00% <= 1 milliseconds 65789.48 requests per second ====== LRANGE_500 (first 450 elements) ====== 10000 requests completed in 0.15 seconds 50 parallel clients 3 bytes payload keep alive: 1 98.52% <= 1 milliseconds 100.00% <= 1 milliseconds 67567.57 requests per second ====== LRANGE_600 (first 600 elements) ====== 10000 requests completed in 0.15 seconds 50 parallel clients 3 bytes payload keep alive: 1 98.18% <= 1 milliseconds 100.00% <= 1 milliseconds 67567.57 requests per second ====== MSET (10 keys) ====== 10000 requests completed in 0.18 seconds 50 parallel clients 3 bytes payload keep alive: 1 90.30% <= 1 milliseconds 99.99% <= 2 milliseconds 100.00% <= 2 milliseconds 56818.18 requests per second [root@iZbp143t3oxhfc3ar7jey0Z data]#
monitor
2.1 简介
查看redis的连接及读写操作
2.2 命令格式
monitor
2.3 实例:
由于我现在的环境是集群,哨兵的情况下,看的更细一点,我这边就直接把视频里面的图占出来。
showlog
3.1 简介
redis的slowlog是redis用于记录记录慢查询执行时间的日志系统。由于slowlog只保存在内存中,因此slowlog的效率很高,完全不用担心会影响到redis的性能。Slowlog是Redis从2.2.12版本引入的一条命令。
3.2 命令格式
命令
- get :获取慢查询日志
- len :获取慢查询日志条目数
- reset :重置慢查询日志
在redis-cli中有关于slowlog的设置:
CONFIG SET slowlog-log-slower-than 6000 #设置慢查询的时间下线,单位:微妙
CONFIG SET slowlog-max-len 25 #设置慢查询命令对应的日志显示长度,单位:命令数
现在流行的是Prometheus+Grafana搭建监控系统,页面炫酷,也可以监控redis
Redis的监控指标
以上是关于Redis监控的主要内容,如果未能解决你的问题,请参考以下文章