Debian系统下Redis监控方法
Redis提供了内置命令行工具,无需额外安装软件,适合快速查看实例状态:
redis-cli info查看所有类别(如memory内存使用、stats统计信息、replication主从复制等),或指定类别(如redis-cli info memory仅看内存)。redis-cli monitor查看所有命令,redis-cli monitor | grep SET过滤特定命令。sudo apt-get install prometheus;sudo apt-get install grafana;/etc/prometheus/prometheus.yml,添加Redis监控目标(如scrape_configs: - job_name: 'redis' static_configs: - targets: ['localhost:6379']);sudo systemctl start prometheus、sudo systemctl start grafana-server;gem install redis-stat安装(需提前安装Ruby),运行redis-stat即可查看实时监控指标(如QPS、内存使用、连接数等),支持自定义刷新间隔。sudo apt-get install redisinsight安装,运行redisinsight启动,添加Redis实例(redis://localhost:6379)即可使用。sudo apt install zabbix-agent;/etc/zabbix/zabbix_agentd.conf,设置Server=<Zabbix_Server_IP>、Hostname=<Redis_Server_Hostname>;sudo systemctl restart zabbix-agent;slowlog-log-slower-than设置慢查询阈值(单位:微秒,如1000表示1毫秒),slowlog-max-len设置慢查询日志长度(如100表示保留100条日志),例如sudo vim /etc/redis/redis.conf修改后重启Redis生效。redis-cli slowlog get查看慢查询日志,分析执行慢的命令(如KEYS *这类全表扫描命令),优化查询逻辑。