1.1、编写redis_status.sh脚本
[fieldyang@centos7-135 sbin]$ mkdir -p /usr/lib/zabbix/scripts/
[fieldyang@centos7-135 sbin]$ cd /usr/lib/zabbix/scripts/
[fieldyang@centos7-135 scripts]$ cat >redis_status.sh
#!/bin/bash
#author:Fieldyang
#description:此脚本用于监控redis集群
REDISCLI='/app/redis/bin/redis-cli'
HOST='192.168.28.135'
PORT=7001
PASS='123456'
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_s

本文介绍了如何自定义Zabbix监控Redis6集群的脚本,并通过Python脚本批量创建应用集、监控项和触发器。首先,创建了redis_status.sh脚本并修改了Zabbix agent配置,接着测试验证脚本正常工作。然后,利用Python根据官方文档编写脚本自动化创建监控配置,并在Zabbix Web界面中确认创建成功,最后检查监控数据。
最低0.47元/天 解锁文章
684

被折叠的 条评论
为什么被折叠?



