一、場景
今年的實際業務中,出現了一次redis bigkeys導致的生產事故,導致業務1個小時收不到指令。
二、關於bigkeys查詢方法
1、使用redis-cli加--bigkeys引數
$ redis-cli -h 192.168.3.74 -p 6379 --bigkeys
$ redis-cli -h 192.168.3.74 -p 6379 --bigkeys # Scanning the entire keyspace to find biggest keys as well as # average sizes per key type. You can use -i 0.1 to sleep 0.1 sec # per 100 SCAN commands (not usually needed). [00.00%] Biggest string found so far '"command-work-device-info:IGV807"' with 37 bytes [00.00%] Biggest string found so far '"factor:vms_crane:CR40"' with 124 bytes [00.00%] Biggest string found so far '"factor:crane:CR16"' with 375 bytes [00.00%] Biggest string found so far '"factor:vehicle_instr:IGV820"' with 470 bytes [05.18%] Biggest hash found so far '"remote-gantry-info"' with 173 fields [05.18%] Biggest string found so far '"factor:vehicle_instr_queue:IGV819"' with 6795 bytes [06.91%] Biggest set found so far '"online-truck-no-set"' with 1 members [12.09%] Biggest string found so far '"pscp_route_info_T811"' with 89885 bytes [42.31%] Biggest set found so far '"truck-white-list:Node1-1"' with 197 members [44.21%] Biggest list found so far '"factor:command_parse_result:IGV841"' with 2 items [45.94%] Biggest hash found so far '"truck-info"' with 187 fields [45.94%] Biggest list found so far '"run-event-alarms"' with 12 items -------- summary ------- Sampled 579 keys in the keyspace! Total key length in bytes is 13082 (avg len 22.59) Biggest list found '"run-event-alarms"' has 12 items Biggest hash found '"truck-info"' has 187 fields Biggest string found '"pscp_route_info_T811"' has 89885 bytes Biggest set found '"truck-white-list:Node1-1"' has 197 members 2 lists with 14 items (00.35% of keys, avg size 7.00) 8 hashs with 784 fields (01.38% of keys, avg size 98.00) 565 strings with 388320 bytes (97.58% of keys, avg size 687.29) 0 streams with 0 entries (00.00% of keys, avg size 0.00) 4 sets with 200 members (00.69% of keys, avg size 50.00) 0 zsets with 0 members (00.00% of keys, avg size 0.00) $ redis-cli -h 192.168.3.74 -p 6379 --bigkeys # Scanning the entire keyspace to find biggest keys as well as # average sizes per key type. You can use -i 0.1 to sleep 0.1 sec # per 100 SCAN commands (not usually needed). [00.00%] Biggest string found so far '"command-work-device-info:IGV807"' with 37 bytes [00.00%] Biggest string found so far '"factor:vms_crane:CR40"' with 124 bytes [00.00%] Biggest string found so far '"factor:crane:CR16"' with 375 bytes [00.00%] Biggest string found so far '"factor:vehicle_instr:IGV820"' with 470 bytes [05.18%] Biggest hash found so far '"remote-gantry-info"' with 173 fields [05.18%] Biggest string found so far '"factor:vehicle_instr_queue:IGV819"' with 6795 bytes [06.91%] Biggest set found so far '"online-truck-no-set"' with 1 members [12.09%] Biggest string found so far '"pscp_route_info_T811"' with 89885 bytes [42.31%] Biggest set found so far '"truck-white-list:Node1-1"' with 197 members [44.21%] Biggest list found so far '"factor:command_parse_result:IGV841"' with 2 items [45.94%] Biggest hash found so far '"truck-info"' with 187 fields [45.94%] Biggest list found so far '"run-event-alarms"' with 12 items -------- summary ------- Sampled 579 keys in the keyspace! Total key length in bytes is 13082 (avg len 22.59) Biggest list found '"run-event-alarms"' has 12 items Biggest hash found '"truck-info"' has 187 fields Biggest string found '"pscp_route_info_T811"' has 89885 bytes Biggest set found '"truck-white-list:Node1-1"' has 197 members 2 lists with 14 items (00.35% of keys, avg size 7.00) 8 hashs with 784 fields (01.38% of keys, avg size 98.00) 565 strings with 388320 bytes (97.58% of keys, avg size 687.29) 0 streams with 0 entries (00.00% of keys, avg size 0.00) 4 sets with 200 members (00.69% of keys, avg size 50.00) 0 zsets with 0 members (00.00% of keys, avg size 0.00)
2、使用redis-cli中的scan和memory usage
https://openatomworkshop.csdn.net/67441ed53a01316874d7ab20.html
3、使用開源工具redis-rdb-tools
可以看官方文件
https://github.com/sripathikrishnan/redis-rdb-tools
4、使用開源工具rdb_bigkeys
看官方文件
https://github.com/weiyanwei412/rdb_bigkeys.git
5、使用雲服務提供商配套的工具
此項為可選項
三、關於預警的方案
採用promethus+grafana+alert-manager+exporter-node實現redis的監控和告警
參考連結:
每個方法有所差異,可以根據需求進行使用,比如key的長度,大小等的統計。
https://blog.csdn.net/jc0803kevin/article/details/141031065
https://openatomworkshop.csdn.net/674403a23a01316874d787c4.html