Zabbix自定义redis6集群监控项并用python脚本自动创建应用集、监控项、触发器

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

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值