五、redis6 集群 zabbix监控【Redis集群监控数据采集】
环境:继 redis6 集群 zabbix监控【zabbix server、zabbix agent 安装】
agent:【192.168.109.139、192.168.109.140】
一、添加redis数据采集脚本【创建redis监控脚本】具体依据需要哪些数据自己家
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#!/bin/bash REDISCLI='/apprun/redis/bin/redis-cli' HOST='192.168.109.139' PORT=7000 PASS='wang!321' if [[ $# == 1 ]];then case $1 in cluster_state) result=`$REDISCLI -c -h $HOST -p $PORT -a $PASS cluster info 2>/dev/null | grep -w "cluster_state" | awk -F':' '{print $2}'| grep -c ok` echo $result ;; cluster_slots_assigned) result=`$REDISCLI -c -h $HOST -p $PORT -a $PASS cluster info 2>/dev/null | grep -w "cluster_slots_assigned" | awk -F':' '{print $2}'` echo $result ;; cluster_slots_ok) result=`$REDISCLI -c -h $HOST -p $PORT -a $PASS cluster info 2>/dev/null | grep -w "cluster_slots_ok" | awk -F':' '{print $2}'` echo $result ;; cluster_slots_pfail) result=`$REDISCLI -c -h $HOST -p $PORT -a $PASS cluster info 2>/dev/null | grep -w "cluster_slots_pfail" | awk -F':' '{print $2}'` echo $result ;; cluster_slots_fail) result=`$REDISCLI -c -h $HOST -p $PORT -a $PASS cluster info 2>/dev/null | grep -w "cluster_slots_fail" | awk -F':' '{print $2}'` echo $result ;; cluster_known_nodes) result=`$REDISCLI -c -h $HOST -p $PORT -a $PASS cluster info 2>/dev/null | grep -w "cluster_known_nodes" | awk -F':' '{print $2}'` echo $result ;; cluster_size) result=`$REDISCLI -c -h $HOST -p $PORT -a $PASS cluster info 2>/dev/null | grep -w "cluster_size" | awk -F':' '{print $2}'` echo $result ;; cluster_current_epoch) result=`$REDISCLI -c -h $HOST -p $PORT -a $PASS cluster info 2>/dev/null | grep -w "cluster_current_epoch" | awk -F':' '{print $2}'` echo $result ;; cluster_my_epoch) result=`$REDISCLI -c -h $HOST -p $PORT -a $PASS cluster info 2>/dev/null | grep -w "cluster_my_epoch" | awk -F':' '{print $2}'` echo $result ;; cluster_stats_messages_ping_sent) result=`$REDISCLI -c -h $HOST -p $PORT -a $PASS cluster info 2>/dev/null | grep -w "cluster_stats_messages_ping_sent" | awk -F':' '{print $2}'` echo $result ;; cluster_stats_messages_pong_sent) result=`$REDISCLI -c -h $HOST -p $PORT -a $PASS cluster info 2>/dev/null | grep -w "cluster_stats_messages_pong_sent" | awk -F':' '{print $2}'` echo $result ;; cluster_stats_messages_sent) result=`$REDISCLI -c -h $HOST -p $PORT -a $PASS cluster info 2>/dev/null | grep -w "cluster_stats_messages_sent" | awk -F':' '{print $2}'` echo $result ;; cluster_stats_messages_ping_received) result=`$REDISCLI -c -h $HOST -p $PORT -a $PASS cluster info 2>/dev/null | grep -w "cluster_stats_messages_ping_received" | awk -F':' '{print $2}'` echo $result ;; cluster_stats_messages_pong_received) result=`$REDISCLI -c -h $HOST -p $PORT -a $PASS cluster info 2>/dev/null | grep -w "cluster_stats_messages_pong_received" | awk -F':' '{print $2}'` echo $result ;; cluster_stats_messages_received) result=`$REDISCLI -c -h $HOST -p $PORT -a $PASS cluster info 2>/dev/null | grep -w "cluster_stats_messages_received" | awk -F':' '{print $2}'` echo $result ;; *) echo -e "\033[33mUsage: $0 {cluster_state|cluster_slots_assigned|cluster_slots_ok|cluster_slots_pfail|cluster_slots_fail|cluster_known_nodes|cluster_size|cluster_current_epoc h|cluster_known_nodes|cluster_size|cluster_current_epoch|cluster_my_epoch|cluster_stats_messages_ping_sent|cluster_stats_messages_pong_sent|cluster_stats_messages_sent|cluster_stats_messages _ping_received|cluster_stats_messages_pong_received|cluster_stats_messages_received}\033[0m" ;; esac fi
chmod +x /etc/zabbix/zabbix_agentd.d/redis_status.sh
二、创建redis监控配置文件
vim /etc/zabbix/zabbix_agentd.d/redis.conf
UserParameter=Redis.status[*],/etc/zabbix/zabbix_agentd.d/redis_status.sh $1
UserParameter=Redisfile,/apprun/redis/bin/redis-cli -h 192.168.109.139 -p 7000 -c -a 'wang!321' cluster nodes 2>/dev/null | awk -F ',' '{print $2}' | grep -c 'fail'
重启zabbix-agent
systemctl restart zabbix-agent.service
在zabbix server端测试【192.168.109.137】
yum install -y zabbix-get
zabbix_get -s 192.168.109.139 -p 10050 -k "Redis.status[cluster_slots_ok]"
三、创建
1.创建模板
2、创建应用集 Applications 随意起个名字
3.创建监控项等等...Items 触发器Triggers 画图Graphs 自动发现规则Discovery 这里就挑脚本中的三个值随意操作一下
绑定模板、配置告警
这里只是针对redis集群监控自己想要监控的数据做配置(prometheus比较适合监控redis集群);其他自己环境想要监控的数据大致也是这么个流程;至于redis常见数据监控可以选择zabbix自带的模板Template DB Redis 当然依据自己的redis环境修改: