Zabbix3.4通过shell脚本监控redis集群

为了避免单点故障,生产环境中redis升级为集群模式,需要对redis集群进行监控,一旦有节点出现故障便触发报警。Redis有自带的redis-cli客户端,通过cluster info命令能查询到集群的运行情况,我们可以写个shell脚本,通过zabbix来调用这个脚本实现集群的监控。

一、cluster info命令的使用

命令格式:

redis-cli -h [hostname] -p [port] -a [password] cluster info

1、查询集群运行情况(其中一个master节点即可)

/data/redis/bin/redis-cli -h xxx.xxx.xxx.xxx -a ‘password‘ -p 7001 cluster info


2、查询集群运行状态,1为正常,0为故障

/data/redis/bin/redis-cli -h xxx.xxx.xxx.xxx -a ‘password‘ -p 7001 cluster info | grep "cluster_state"

/data/redis/bin/redis-cli -h xxx.xxx.xxx.xxx -a ‘password‘ -p 7001 cluster info | grep -w "cluster_state" | awk -F‘:‘ ‘{print $2}‘|grep -c "ok"


3、查询集群已知节点数量

/data/redis/bin/redis-cli -h xxx.xxx.xxx.xxx -a ‘password‘ -p 7001 cluster info | grep -w "cluster_known_nodes" | awk -F‘:‘ ‘{print $2}‘

二、创建监控脚本

vim /etc/zabbix/zabbix_agentd.d/redis_cluster.sh
#!/bin/bash
REDISCLI="/data/redis/bin/redis-cli"
HOST="xxx.xxx.xxx.xxx"
PORT=7001
PASS="password"

if [[ $# == 1 ]];then
    case $1 in
        cluster_state)
            result=`$REDISCLI -h $HOST -a $PASS -p $PORT cluster info 2>/dev/null | grep -w "cluster_state" | awk -F‘:‘ ‘{print $2}‘ | grep -c "ok"`
            echo $result
        ;;
        cluster_slots_assigned)
            result=`$REDISCLI -h $HOST -a $PASS -p $PORT cluster info 2>/dev/null | grep -w "cluster_slots_assigned" | awk -F‘:‘ ‘{print $2}‘`
            echo $result
        ;;
        cluster_slots_ok)
            result=`$REDISCLI -h $HOST -a $PASS -p $PORT cluster info 2>/dev/null | grep -w "cluster_slots_ok" | awk -F‘:‘ ‘{print $2}‘`
            echo $result
        ;;
        cluster_slots_pfail)
            result=`$REDISCLI -h $HOST -a $PASS -p $PORT cluster info 2>/dev/null | grep -w "cluster_slots_pfail" | awk -F‘:‘ ‘{print $2}‘`
            echo $result
        ;;
        cluster_slots_fail)
            result=`$REDISCLI -h $HOST -a $PASS -p $PORT cluster info 2>/dev/null | grep -w "cluster_slots_fail" | awk -F‘:‘ ‘{print $2}‘`
            echo $result
        ;;
        cluster_known_nodes)
            result=`$REDISCLI -h $HOST -a $PASS -p $PORT cluster info 2>/dev/null | grep -w "cluster_known_nodes" | awk -F‘:‘ ‘{print $2}‘`
            echo $result
        ;;
        cluster_size)
            result=`$REDISCLI -h $HOST -a $PASS -p $PORT cluster info 2>/dev/null | grep -w "cluster_size" | awk -F‘:‘ ‘{print $2}‘`
            echo $result
        ;;
        cluster_current_epoch)
            result=`$REDISCLI -h $HOST -a $PASS -p $PORT cluster info 2>/dev/null | grep -w "cluster_current_epoch" | awk -F‘:‘ ‘{print $2}‘`
            echo $result
        ;;
        cluster_my_epoch)
            result=`$REDISCLI -h $HOST -a $PASS -p $PORT cluster info 2>/dev/null | grep -w "cluster_my_epoch" | awk -F‘:‘ ‘{print $2}‘`
            echo $result
        ;;
        cluster_stats_messages_ping_sent)
            result=`$REDISCLI -h $HOST -a $PASS -p $PORT 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 -h $HOST -a $PASS -p $PORT cluster info 2>/dev/null | grep -w "cluster_stats_messages_pong_sent" | awk -F‘:‘ ‘{print $2}‘`
            echo $result
        ;;
        cluster_stats_messages_sent)
            result=`$REDISCLI -h $HOST -a $PASS -p $PORT cluster info 2>/dev/null | grep -w "cluster_stats_messages_sent" | awk -F‘:‘ ‘{print $2}‘`
            echo $result
        ;;
        cluster_stats_messages_ping_received)
            result=`$REDISCLI -h $HOST -a $PASS -p $PORT 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 -h $HOST -a $PASS -p $PORT cluster info 2>/dev/null | grep -w "cluster_stats_messages_pong_received" | awk -F‘:‘ ‘{print $2}‘`
            echo $result
        ;;
        cluster_stats_messages_meet_received)
            result=`$REDISCLI -h $HOST -a $PASS -p $PORT cluster info 2>/dev/null | grep -w "cluster_stats_messages_meet_received" | awk -F‘:‘ ‘{print $2}‘`
            echo $result
        ;;
        cluster_stats_messages_received)
            result=`$REDISCLI -h $HOST -a $PASS -p $PORT 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 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_meet_received|cluster_stats_messages_received}\033[0m"
        ;;
    esac
fi

2、赋予脚本可执行权限

chmod +x /etc/zabbix/zabbix_agentd.d/redis_cluster.sh

3、脚本测试
查看redis集群节点数量

/etc/zabbix/zabbix_agentd.d/redis_cluster.sh cluster_known_nodes

三、创建redis集群监控配置文件

1、编写redis监控配置文件

vim /etc/zabbix/zabbix_agentd.d/redis.conf
UserParameter=Redis.Cluster[*],/etc/zabbix/zabbix_agentd.d/redis_cluster.sh $1

2、重启zabbix-agent

systemctl restart zabbix-agent

3、在zabbix server端测试

zabbix_get -s xxx.xxx.xxx.xxx -p 10050 -k "Redis.Cluster[cluster_slots_ok]"

四、创建并导入监控模板

1、创建监控模板文件
注:此模板报警阀值设置为cluster current epoch < 6、cluster known nodes < 6和clusterstate不是ok
redis_cluster_templates.xml文件内容如下

<?xml version="1.0" encoding="UTF-8"?>
<zabbix_export>
    <version>3.4</version>
    <date>2019-12-06T05:43:56Z</date>
    <groups>
        <group>
            <name>Templates</name>
        </group>
    </groups>
    <templates>
        <template>
            <template>Template Redis Cluster</template>
            <name>Template Redis Cluster</name>
            <description>redis集群监控模板</description>
            <groups>
                <group>
                    <name>Templates</name>
                </group>
            </groups>
            <applications>
                <application>
                    <name>Redis cluster node</name>
                </application>
                <application>
                    <name>Redis cluster slots</name>
                </application>
                <application>
                    <name>Redis cluster stats messages</name>
                </application>
            </applications>
            <items>
                <item>
                    <name>cluster_current_epoch</name>
                    <type>0</type>
                    <snmp_community/>
                    <snmp_oid/>
                    <key>Redis.Cluster[cluster_current_epoch]</key>
                    <delay>30s</delay>
                    <history>90d</history>
                    <trends>365d</trends>
                    <status>0</status>
                    <value_type>3</value_type>
                    <allowed_hosts/>
                    <units/>
                    <snmpv3_contextname/>
                    <snmpv3_securityname/>
                    <snmpv3_securitylevel>0</snmpv3_securitylevel>
                    <snmpv3_authprotocol>0</snmpv3_authprotocol>
                    <snmpv3_authpassphrase/>
                    <snmpv3_privprotocol>0</snmpv3_privprotocol>
                    <snmpv3_privpassphrase/>
                    <params/>
                    <ipmi_sensor/>
                    <authtype>0</authtype>
                    <username/>
                    <password/>
                    <publickey/>
                    <privatekey/>
                    <port/>
                    <description/>
                    <inventory_link>0</inventory_link>
                    <applications>
                        <application>
                            <name>Redis cluster node</name>
                        </application>
                    </applications>
                    <valuemap/>
                    <logtimefmt/>
                    <preprocessing/>
                    <jmx_endpoint/>
                    <master_item/>
                </item>
                <item>
                    <name>cluster_known_nodes</name>
                    <type>0</type>
                    <snmp_community/>
                    <snmp_oid/>
                    <key>Redis.Cluster[cluster_known_nodes]</key>
                    <delay>30s</delay>
                    <history>90d</history>
                    <trends>365d</trends>
                    <status>0</status>
                    <value_type>3</value_type>
                    <allowed_hosts/>
                    <units/>
                    <snmpv3_contextname/>
                    <snmpv3_securityname/>
                    <snmpv3_securitylevel>0</snmpv3_securitylevel>
                    <snmpv3_authprotocol>0</snmpv3_authprotocol>
                    <snmpv3_authpassphrase/>
                    <snmpv3_privprotocol>0</snmpv3_privprotocol>
                    <snmpv3_privpassphrase/>
                    <params/>
                    <ipmi_sensor/>
                    <authtype>0</authtype>
                    <username/>
                    <password/>
                    <publickey/>
                    <privatekey/>
                    <port/>
                    <description/>
                    <inventory_link>0</inventory_link>
                    <applications>
                        <application>
                            <name>Redis cluster node</name>
                        </application>
                    </applications>
                    <valuemap/>
                    <logtimefmt/>
                    <preprocessing/>
                    <jmx_endpoint/>
                    <master_item/>
                </item>
                <item>
                    <name>cluster_my_epoch</name>
                    <type>0</type>
                    <snmp_community/>
                    <snmp_oid/>
                    <key>Redis.Cluster[cluster_my_epoch]</key>
                    <delay>30s</delay>
                    <history>90d</history>
                    <trends>365d</trends>
                    <status>0</status>
                    <value_type>3</value_type>
                    <allowed_hosts/>
                    <units/>
                    <snmpv3_contextname/>
                    <snmpv3_securityname/>
                    <snmpv3_securitylevel>0</snmpv3_securitylevel>
                    <snmpv3_authprotocol>0</snmpv3_authprotocol>
                    <snmpv3_authpassphrase/>
                    <snmpv3_privprotocol>0</snmpv3_privprotocol>
                    <snmpv3_privpassphrase/>
                    <params/>
                    <ipmi_sensor/>
                    <authtype>0</authtype>
                    <username/>
                    <password/>
                    <publickey/>
                    <privatekey/>
                    <port/>
                    <description/>
                    <inventory_link>0</inventory_link>
                    <applications>
                        <application>
                            <name>Redis cluster node</name>
                        </application>
                    </applications>
                    <valuemap/>
                    <logtimefmt/>
                    <preprocessing/>
                    <jmx_endpoint/>
                    <master_item/>
                </item>
                <item>
                    <name>cluster_size</name>
                    <type>0</type>
                    <snmp_community/>
                    <snmp_oid/>
                    <key>Redis.Cluster[cluster_size]</key>
                    <delay>30s</delay>
                    <history>90d</history>
                    <trends>365d</trends>
                    <status>0</status>
                    <value_type>3</value_type>
                    <allowed_hosts/>
                    <units/>
                    <snmpv3_contextname/>
                    <snmpv3_securityname/>
                    <snmpv3_securitylevel>0</snmpv3_securitylevel>
                    <snmpv3_authprotocol>0</snmpv3_authprotocol>
                    <snmpv3_authpassphrase/>
                    <snmpv3_privprotocol>0</snmpv3_privprotocol>
                    <snmpv3_privpassphrase/>
                    <params/>
                    <ipmi_sensor/>
                    <authtype>0</authtype>
                    <username/>
                    <password/>
                    <publickey/>
                    <privatekey/>
                    <port/>
                    <description/>
                    <inventory_link>0</inventory_link>
                    <applications>
                        <application>
                            <name>Redis cluster node</name>
                        </application>
                    </applications>
                    <valuemap/>
                    <logtimefmt/>
                    <preprocessing/>
                    <jmx_endpoint/>
                    <master_item/>
                </item>
                <item>
                    <name>cluster_slots_assigned</name>
                    <type>0</type>
                    <snmp_community/>
                    <snmp_oid/>
                    <key>Redis.Cluster[cluster_slots_assigned]</key>
                    <delay>30s</delay>
                    <history>90d</history>
                    <trends>365d</trends>
                    <status>0</status>
                    <value_type>3</value_type>
                    <allowed_hosts/>
                    <units/>
                    <snmpv3_contextname/>
                    <snmpv3_securityname/>
                    <snmpv3_securitylevel>0</snmpv3_securitylevel>
                    <snmpv3_authprotocol>0</snmpv3_authprotocol>
                    <snmpv3_authpassphrase/>
                    <snmpv3_privprotocol>0</snmpv3_privprotocol>
                    <snmpv3_privpassphrase/>
                    <params/>
                    <ipmi_sensor/>
                    <authtype>0</authtype>
                    <username/>
                    <password/>
                    <publickey/>
                    <privatekey/>
                    <port/>
                    <description/>
                    <inventory_link>0</inventory_link>
                    <applications>
                        <application>
                            <name>Redis cluster slots</name>
                        </application>
                    </applications>
                    <valuemap/>
                    <logtimefmt/>
                    <preprocessing/>
                    <jmx_endpoint/>
                    <master_item/>
                </item>
                <item>
                    <name>cluster_slots_fail</name>
                    <type>0</type>
                    <snmp_community/>
                    <snmp_oid/>
                    <key>Redis.Cluster[cluster_slots_fail]</key>
                    <delay>30s</delay>
                    <history>90d</history>
                    <trends>365d</trends>
                    <status>0</status>
                    <value_type>3</value_type>
                    <allowed_hosts/>
                    <units/>
                    <snmpv3_contextname/>
                    <snmpv3_securityname/>
                    <snmpv3_securitylevel>0</snmpv3_securitylevel>
                    <snmpv3_authprotocol>0</snmpv3_authprotocol>
                    <snmpv3_authpassphrase/>
                    <snmpv3_privprotocol>0</snmpv3_privprotocol>
                    <snmpv3_privpassphrase/>
                    <params/>
                    <ipmi_sensor/>
                    <authtype>0</authtype>
                    <username/>
                    <password/>
                    <publickey/>
                    <privatekey/>
                    <port/>
                    <description/>
                    <inventory_link>0</inventory_link>
                    <applications>
                        <application>
                            <name>Redis cluster slots</name>
                        </application>
                    </applications>
                    <valuemap/>
                    <logtimefmt/>
                    <preprocessing/>
                    <jmx_endpoint/>
                    <master_item/>
                </item>
                <item>
                    <name>cluster_slots_ok</name>
                    <type>0</type>
                    <snmp_community/>
                    <snmp_oid/>
                    <key>Redis.Cluster[cluster_slots_ok]</key>
                    <delay>30s</delay>
                    <history>90d</history>
                    <trends>365d</trends>
                    <status>0</status>
                    <value_type>3</value_type>
                    <allowed_hosts/>
                    <units/>
                    <snmpv3_contextname/>
                    <snmpv3_securityname/>
                    <snmpv3_securitylevel>0</snmpv3_securitylevel>
                    <snmpv3_authprotocol>0</snmpv3_authprotocol>
                    <snmpv3_authpassphrase/>
                    <snmpv3_privprotocol>0</snmpv3_privprotocol>
                    <snmpv3_privpassphrase/>
                    <params/>
                    <ipmi_sensor/>
                    <authtype>0</authtype>
                    <username/>
                    <password/>
                    <publickey/>
                    <privatekey/>
                    <port/>
                    <description/>
                    <inventory_link>0</inventory_link>
                    <applications>
                        <application>
                            <name>Redis cluster slots</name>
                        </application>
                    </applications>
                    <valuemap/>
                    <logtimefmt/>
                    <preprocessing/>
                    <jmx_endpoint/>
                    <master_item/>
                </item>
                <item>
                    <name>cluster_slots_pfail</name>
                    <type>0</type>
                    <snmp_community/>
                    <snmp_oid/>
                    <key>Redis.Cluster[cluster_slots_pfail]</key>
                    <delay>30s</delay>
                    <history>90d</history>
                    <trends>365d</trends>
                    <status>0</status>
                    <value_type>3</value_type>
                    <allowed_hosts/>
                    <units/>
                    <snmpv3_contextname/>
                    <snmpv3_securityname/>
                    <snmpv3_securitylevel>0</snmpv3_securitylevel>
                    <snmpv3_authprotocol>0</snmpv3_authprotocol>
                    <snmpv3_authpassphrase/>
                    <snmpv3_privprotocol>0</snmpv3_privprotocol>
                    <snmpv3_privpassphrase/>
                    <params/>
                    <ipmi_sensor/>
                    <authtype>0</authtype>
                    <username/>
                    <password/>
                    <publickey/>
                    <privatekey/>
                    <port/>
                    <description/>
                    <inventory_link>0</inventory_link>
                    <applications>
                        <application>
                            <name>Redis cluster slots</name>
                        </application>
                    </applications>
                    <valuemap/>
                    <logtimefmt/>
                    <preprocessing/>
                    <jmx_endpoint/>
                    <master_item/>
                </item>
                <item>
                    <name>cluster_state</name>
                    <type>0</type>
                    <snmp_community/>
                    <snmp_oid/>
                    <key>Redis.Cluster[cluster_state]</key>
                    <delay>30s</delay>
                    <history>90d</history>
                    <trends>365d</trends>
                    <status>0</status>
                    <value_type>3</value_type>
                    <allowed_hosts/>
                    <units/>
                    <snmpv3_contextname/>
                    <snmpv3_securityname/>
                    <snmpv3_securitylevel>0</snmpv3_securitylevel>
                    <snmpv3_authprotocol>0</snmpv3_authprotocol>
                    <snmpv3_authpassphrase/>
                    <snmpv3_privprotocol>0</snmpv3_privprotocol>
                    <snmpv3_privpassphrase/>
                    <params/>
                    <ipmi_sensor/>
                    <authtype>0</authtype>
                    <username/>
                    <password/>
                    <publickey/>
                    <privatekey/>
                    <port/>
                    <description/>
                    <inventory_link>0</inventory_link>
                    <applications/>
                    <valuemap/>
                    <logtimefmt/>
                    <preprocessing/>
                    <jmx_endpoint/>
                    <master_item/>
                </item>
                <item>
                    <name>cluster_stats_messages_meet_received</name>
                    <type>0</type>
                    <snmp_community/>
                    <snmp_oid/>
                    <key>Redis.Cluster[cluster_stats_messages_meet_received]</key>
                    <delay>30s</delay>
                    <history>90d</history>
                    <trends>365d</trends>
                    <status>0</status>
                    <value_type>3</value_type>
                    <allowed_hosts/>
                    <units/>
                    <snmpv3_contextname/>
                    <snmpv3_securityname/>
                    <snmpv3_securitylevel>0</snmpv3_securitylevel>
                    <snmpv3_authprotocol>0</snmpv3_authprotocol>
                    <snmpv3_authpassphrase/>
                    <snmpv3_privprotocol>0</snmpv3_privprotocol>
                    <snmpv3_privpassphrase/>
                    <params/>
                    <ipmi_sensor/>
                    <authtype>0</authtype>
                    <username/>
                    <password/>
                    <publickey/>
                    <privatekey/>
                    <port/>
                    <description/>
                    <inventory_link>0</inventory_link>
                    <applications>
                        <application>
                            <name>Redis cluster stats messages</name>
                        </application>
                    </applications>
                    <valuemap/>
                    <logtimefmt/>
                    <preprocessing/>
                    <jmx_endpoint/>
                    <master_item/>
                </item>
                <item>
                    <name>cluster_stats_messages_ping_received</name>
                    <type>0</type>
                    <snmp_community/>
                    <snmp_oid/>
                    <key>Redis.Cluster[cluster_stats_messages_ping_received]</key>
                    <delay>30s</delay>
                    <history>90d</history>
                    <trends>365d</trends>
                    <status>0</status>
                    <value_type>3</value_type>
                    <allowed_hosts/>
                    <units/>
                    <snmpv3_contextname/>
                    <snmpv3_securityname/>
                    <snmpv3_securitylevel>0</snmpv3_securitylevel>
                    <snmpv3_authprotocol>0</snmpv3_authprotocol>
                    <snmpv3_authpassphrase/>
                    <snmpv3_privprotocol>0</snmpv3_privprotocol>
                    <snmpv3_privpassphrase/>
                    <params/>
                    <ipmi_sensor/>
                    <authtype>0</authtype>
                    <username/>
                    <password/>
                    <publickey/>
                    <privatekey/>
                    <port/>
                    <description/>
                    <inventory_link>0</inventory_link>
                    <applications>
                        <application>
                            <name>Redis cluster stats messages</name>
                        </application>
                    </applications>
                    <valuemap/>
                    <logtimefmt/>
                    <preprocessing/>
                    <jmx_endpoint/>
                    <master_item/>
                </item>
                <item>
                    <name>cluster_stats_messages_ping_sent</name>
                    <type>0</type>
                    <snmp_community/>
                    <snmp_oid/>
                    <key>Redis.Cluster[cluster_stats_messages_ping_sent]</key>
                    <delay>30s</delay>
                    <history>90d</history>
                    <trends>365d</trends>
                    <status>0</status>
                    <value_type>3</value_type>
                    <allowed_hosts/>
                    <units/>
                    <snmpv3_contextname/>
                    <snmpv3_securityname/>
                    <snmpv3_securitylevel>0</snmpv3_securitylevel>
                    <snmpv3_authprotocol>0</snmpv3_authprotocol>
                    <snmpv3_authpassphrase/>
                    <snmpv3_privprotocol>0</snmpv3_privprotocol>
                    <snmpv3_privpassphrase/>
                    <params/>
                    <ipmi_sensor/>
                    <authtype>0</authtype>
                    <username/>
                    <password/>
                    <publickey/>
                    <privatekey/>
                    <port/>
                    <description/>
                    <inventory_link>0</inventory_link>
                    <applications>
                        <application>
                            <name>Redis cluster stats messages</name>
                        </application>
                    </applications>
                    <valuemap/>
                    <logtimefmt/>
                    <preprocessing/>
                    <jmx_endpoint/>
                    <master_item/>
                </item>
                <item>
                    <name>cluster_stats_messages_pong_received</name>
                    <type>0</type>
                    <snmp_community/>
                    <snmp_oid/>
                    <key>Redis.Cluster[cluster_stats_messages_pong_received]</key>
                    <delay>30s</delay>
                    <history>90d</history>
                    <trends>365d</trends>
                    <status>0</status>
                    <value_type>3</value_type>
                    <allowed_hosts/>
                    <units/>
                    <snmpv3_contextname/>
                    <snmpv3_securityname/>
                    <snmpv3_securitylevel>0</snmpv3_securitylevel>
                    <snmpv3_authprotocol>0</snmpv3_authprotocol>
                    <snmpv3_authpassphrase/>
                    <snmpv3_privprotocol>0</snmpv3_privprotocol>
                    <snmpv3_privpassphrase/>
                    <params/>
                    <ipmi_sensor/>
                    <authtype>0</authtype>
                    <username/>
                    <password/>
                    <publickey/>
                    <privatekey/>
                    <port/>
                    <description/>
                    <inventory_link>0</inventory_link>
                    <applications>
                        <application>
                            <name>Redis cluster stats messages</name>
                        </application>
                    </applications>
                    <valuemap/>
                    <logtimefmt/>
                    <preprocessing/>
                    <jmx_endpoint/>
                    <master_item/>
                </item>
                <item>
                    <name>cluster_stats_messages_pong_sent</name>
                    <type>0</type>
                    <snmp_community/>
                    <snmp_oid/>
                    <key>Redis.Cluster[cluster_stats_messages_pong_sent]</key>
                    <delay>30s</delay>
                    <history>90d</history>
                    <trends>365d</trends>
                    <status>0</status>
                    <value_type>3</value_type>
                    <allowed_hosts/>
                    <units/>
                    <snmpv3_contextname/>
                    <snmpv3_securityname/>
                    <snmpv3_securitylevel>0</snmpv3_securitylevel>
                    <snmpv3_authprotocol>0</snmpv3_authprotocol>
                    <snmpv3_authpassphrase/>
                    <snmpv3_privprotocol>0</snmpv3_privprotocol>
                    <snmpv3_privpassphrase/>
                    <params/>
                    <ipmi_sensor/>
                    <authtype>0</authtype>
                    <username/>
                    <password/>
                    <publickey/>
                    <privatekey/>
                    <port/>
                    <description/>
                    <inventory_link>0</inventory_link>
                    <applications>
                        <application>
                            <name>Redis cluster stats messages</name>
                        </application>
                    </applications>
                    <valuemap/>
                    <logtimefmt/>
                    <preprocessing/>
                    <jmx_endpoint/>
                    <master_item/>
                </item>
                <item>
                    <name>cluster_stats_messages_received</name>
                    <type>0</type>
                    <snmp_community/>
                    <snmp_oid/>
                    <key>Redis.Cluster[cluster_stats_messages_received]</key>
                    <delay>30s</delay>
                    <history>90d</history>
                    <trends>365d</trends>
                    <status>0</status>
                    <value_type>3</value_type>
                    <allowed_hosts/>
                    <units/>
                    <snmpv3_contextname/>
                    <snmpv3_securityname/>
                    <snmpv3_securitylevel>0</snmpv3_securitylevel>
                    <snmpv3_authprotocol>0</snmpv3_authprotocol>
                    <snmpv3_authpassphrase/>
                    <snmpv3_privprotocol>0</snmpv3_privprotocol>
                    <snmpv3_privpassphrase/>
                    <params/>
                    <ipmi_sensor/>
                    <authtype>0</authtype>
                    <username/>
                    <password/>
                    <publickey/>
                    <privatekey/>
                    <port/>
                    <description/>
                    <inventory_link>0</inventory_link>
                    <applications>
                        <application>
                            <name>Redis cluster stats messages</name>
                        </application>
                    </applications>
                    <valuemap/>
                    <logtimefmt/>
                    <preprocessing/>
                    <jmx_endpoint/>
                    <master_item/>
                </item>
                <item>
                    <name>cluster_stats_messages_sent</name>
                    <type>0</type>
                    <snmp_community/>
                    <snmp_oid/>
                    <key>Redis.Cluster[cluster_stats_messages_sent]</key>
                    <delay>30s</delay>
                    <history>90d</history>
                    <trends>365d</trends>
                    <status>0</status>
                    <value_type>3</value_type>
                    <allowed_hosts/>
                    <units/>
                    <snmpv3_contextname/>
                    <snmpv3_securityname/>
                    <snmpv3_securitylevel>0</snmpv3_securitylevel>
                    <snmpv3_authprotocol>0</snmpv3_authprotocol>
                    <snmpv3_authpassphrase/>
                    <snmpv3_privprotocol>0</snmpv3_privprotocol>
                    <snmpv3_privpassphrase/>
                    <params/>
                    <ipmi_sensor/>
                    <authtype>0</authtype>
                    <username/>
                    <password/>
                    <publickey/>
                    <privatekey/>
                    <port/>
                    <description/>
                    <inventory_link>0</inventory_link>
                    <applications>
                        <application>
                            <name>Redis cluster stats messages</name>
                        </application>
                    </applications>
                    <valuemap/>
                    <logtimefmt/>
                    <preprocessing/>
                    <jmx_endpoint/>
                    <master_item/>
                </item>
            </items>
            <discovery_rules/>
            <httptests/>
            <macros/>
            <templates/>
            <screens/>
        </template>
    </templates>
    <triggers>
        <trigger>
            <expression>{Template Redis Cluster:Redis.Cluster[cluster_current_epoch].last()}&lt;6</expression>
            <recovery_mode>0</recovery_mode>
            <recovery_expression/>
            <name>cluster current epoch &lt; 6</name>
            <correlation_mode>0</correlation_mode>
            <correlation_tag/>
            <url/>
            <status>0</status>
            <priority>3</priority>
            <description/>
            <type>0</type>
            <manual_close>1</manual_close>
            <dependencies/>
            <tags/>
        </trigger>
        <trigger>
            <expression>{Template Redis Cluster:Redis.Cluster[cluster_known_nodes].last()}&lt;6</expression>
            <recovery_mode>0</recovery_mode>
            <recovery_expression/>
            <name>cluster known nodes &lt; 6</name>
            <correlation_mode>0</correlation_mode>
            <correlation_tag/>
            <url/>
            <status>0</status>
            <priority>3</priority>
            <description/>
            <type>0</type>
            <manual_close>1</manual_close>
            <dependencies/>
            <tags/>
        </trigger>
        <trigger>
            <expression>{Template Redis Cluster:Redis.Cluster[cluster_state].last()}=0</expression>
            <recovery_mode>0</recovery_mode>
            <recovery_expression/>
            <name>Redis Cluster is down</name>
            <correlation_mode>0</correlation_mode>
            <correlation_tag/>
            <url/>
            <status>0</status>
            <priority>4</priority>
            <description/>
            <type>0</type>
            <manual_close>1</manual_close>
            <dependencies/>
            <tags/>
        </trigger>
    </triggers>
    <graphs>
        <graph>
            <name>Redis cluster node</name>
            <width>900</width>
            <height>200</height>
            <yaxismin>0.0000</yaxismin>
            <yaxismax>100.0000</yaxismax>
            <show_work_period>1</show_work_period>
            <show_triggers>1</show_triggers>
            <type>0</type>
            <show_legend>1</show_legend>
            <show_3d>0</show_3d>
            <percent_left>0.0000</percent_left>
            <percent_right>0.0000</percent_right>
            <ymin_type_1>0</ymin_type_1>
            <ymax_type_1>0</ymax_type_1>
            <ymin_item_1>0</ymin_item_1>
            <ymax_item_1>0</ymax_item_1>
            <graph_items>
                <graph_item>
                    <sortorder>0</sortorder>
                    <drawtype>0</drawtype>
                    <color>1A7C11</color>
                    <yaxisside>0</yaxisside>
                    <calc_fnc>7</calc_fnc>
                    <type>0</type>
                    <item>
                        <host>Template Redis Cluster</host>
                        <key>Redis.Cluster[cluster_current_epoch]</key>
                    </item>
                </graph_item>
                <graph_item>
                    <sortorder>1</sortorder>
                    <drawtype>0</drawtype>
                    <color>F63100</color>
                    <yaxisside>0</yaxisside>
                    <calc_fnc>7</calc_fnc>
                    <type>0</type>
                    <item>
                        <host>Template Redis Cluster</host>
                        <key>Redis.Cluster[cluster_known_nodes]</key>
                    </item>
                </graph_item>
                <graph_item>
                    <sortorder>2</sortorder>
                    <drawtype>0</drawtype>
                    <color>2774A4</color>
                    <yaxisside>0</yaxisside>
                    <calc_fnc>7</calc_fnc>
                    <type>0</type>
                    <item>
                        <host>Template Redis Cluster</host>
                        <key>Redis.Cluster[cluster_my_epoch]</key>
                    </item>
                </graph_item>
                <graph_item>
                    <sortorder>3</sortorder>
                    <drawtype>0</drawtype>
                    <color>A54F10</color>
                    <yaxisside>0</yaxisside>
                    <calc_fnc>7</calc_fnc>
                    <type>0</type>
                    <item>
                        <host>Template Redis Cluster</host>
                        <key>Redis.Cluster[cluster_size]</key>
                    </item>
                </graph_item>
            </graph_items>
        </graph>
        <graph>
            <name>Redis cluster slots</name>
            <width>900</width>
            <height>200</height>
            <yaxismin>0.0000</yaxismin>
            <yaxismax>100.0000</yaxismax>
            <show_work_period>1</show_work_period>
            <show_triggers>1</show_triggers>
            <type>0</type>
            <show_legend>1</show_legend>
            <show_3d>0</show_3d>
            <percent_left>0.0000</percent_left>
            <percent_right>0.0000</percent_right>
            <ymin_type_1>0</ymin_type_1>
            <ymax_type_1>0</ymax_type_1>
            <ymin_item_1>0</ymin_item_1>
            <ymax_item_1>0</ymax_item_1>
            <graph_items>
                <graph_item>
                    <sortorder>0</sortorder>
                    <drawtype>0</drawtype>
                    <color>1A7C11</color>
                    <yaxisside>0</yaxisside>
                    <calc_fnc>7</calc_fnc>
                    <type>0</type>
                    <item>
                        <host>Template Redis Cluster</host>
                        <key>Redis.Cluster[cluster_slots_assigned]</key>
                    </item>
                </graph_item>
                <graph_item>
                    <sortorder>1</sortorder>
                    <drawtype>0</drawtype>
                    <color>F63100</color>
                    <yaxisside>0</yaxisside>
                    <calc_fnc>7</calc_fnc>
                    <type>0</type>
                    <item>
                        <host>Template Redis Cluster</host>
                        <key>Redis.Cluster[cluster_slots_fail]</key>
                    </item>
                </graph_item>
                <graph_item>
                    <sortorder>2</sortorder>
                    <drawtype>0</drawtype>
                    <color>2774A4</color>
                    <yaxisside>0</yaxisside>
                    <calc_fnc>7</calc_fnc>
                    <type>0</type>
                    <item>
                        <host>Template Redis Cluster</host>
                        <key>Redis.Cluster[cluster_slots_ok]</key>
                    </item>
                </graph_item>
                <graph_item>
                    <sortorder>3</sortorder>
                    <drawtype>0</drawtype>
                    <color>A54F10</color>
                    <yaxisside>0</yaxisside>
                    <calc_fnc>7</calc_fnc>
                    <type>0</type>
                    <item>
                        <host>Template Redis Cluster</host>
                        <key>Redis.Cluster[cluster_slots_pfail]</key>
                    </item>
                </graph_item>
            </graph_items>
        </graph>
        <graph>
            <name>Redis cluster stats messages</name>
            <width>900</width>
            <height>200</height>
            <yaxismin>0.0000</yaxismin>
            <yaxismax>100.0000</yaxismax>
            <show_work_period>1</show_work_period>
            <show_triggers>1</show_triggers>
            <type>0</type>
            <show_legend>1</show_legend>
            <show_3d>0</show_3d>
            <percent_left>0.0000</percent_left>
            <percent_right>0.0000</percent_right>
            <ymin_type_1>0</ymin_type_1>
            <ymax_type_1>0</ymax_type_1>
            <ymin_item_1>0</ymin_item_1>
            <ymax_item_1>0</ymax_item_1>
            <graph_items>
                <graph_item>
                    <sortorder>0</sortorder>
                    <drawtype>0</drawtype>
                    <color>1A7C11</color>
                    <yaxisside>0</yaxisside>
                    <calc_fnc>7</calc_fnc>
                    <type>0</type>
                    <item>
                        <host>Template Redis Cluster</host>
                        <key>Redis.Cluster[cluster_stats_messages_meet_received]</key>
                    </item>
                </graph_item>
                <graph_item>
                    <sortorder>1</sortorder>
                    <drawtype>0</drawtype>
                    <color>F63100</color>
                    <yaxisside>0</yaxisside>
                    <calc_fnc>7</calc_fnc>
                    <type>0</type>
                    <item>
                        <host>Template Redis Cluster</host>
                        <key>Redis.Cluster[cluster_stats_messages_ping_received]</key>
                    </item>
                </graph_item>
                <graph_item>
                    <sortorder>2</sortorder>
                    <drawtype>0</drawtype>
                    <color>2774A4</color>
                    <yaxisside>0</yaxisside>
                    <calc_fnc>7</calc_fnc>
                    <type>0</type>
                    <item>
                        <host>Template Redis Cluster</host>
                        <key>Redis.Cluster[cluster_stats_messages_ping_sent]</key>
                    </item>
                </graph_item>
                <graph_item>
                    <sortorder>3</sortorder>
                    <drawtype>0</drawtype>
                    <color>A54F10</color>
                    <yaxisside>0</yaxisside>
                    <calc_fnc>7</calc_fnc>
                    <type>0</type>
                    <item>
                        <host>Template Redis Cluster</host>
                        <key>Redis.Cluster[cluster_stats_messages_pong_received]</key>
                    </item>
                </graph_item>
                <graph_item>
                    <sortorder>4</sortorder>
                    <drawtype>0</drawtype>
                    <color>FC6EA3</color>
                    <yaxisside>0</yaxisside>
                    <calc_fnc>7</calc_fnc>
                    <type>0</type>
                    <item>
                        <host>Template Redis Cluster</host>
                        <key>Redis.Cluster[cluster_stats_messages_pong_sent]</key>
                    </item>
                </graph_item>
                <graph_item>
                    <sortorder>5</sortorder>
                    <drawtype>0</drawtype>
                    <color>6C59DC</color>
                    <yaxisside>0</yaxisside>
                    <calc_fnc>7</calc_fnc>
                    <type>0</type>
                    <item>
                        <host>Template Redis Cluster</host>
                        <key>Redis.Cluster[cluster_stats_messages_received]</key>
                    </item>
                </graph_item>
                <graph_item>
                    <sortorder>6</sortorder>
                    <drawtype>0</drawtype>
                    <color>AC8C14</color>
                    <yaxisside>0</yaxisside>
                    <calc_fnc>7</calc_fnc>
                    <type>0</type>
                    <item>
                        <host>Template Redis Cluster</host>
                        <key>Redis.Cluster[cluster_stats_messages_sent]</key>
                    </item>
                </graph_item>
            </graph_items>
        </graph>
    </graphs>
</zabbix_export>

2、导入监控模板
配置—模板—导入

点击“选择文件”,找到redis_cluster_templates.xml文件,将其导入

五、给主机添加监控模板


六、监控效果图



原文地址:https://blog.51cto.com/andyxu/2456638

时间: 2024-11-16 14:39:47

Zabbix3.4通过shell脚本监控redis集群的相关文章

Prometheus 监控 Redis 集群

Prometheus 监控 Redis cluster,其实套路都是一样的,使用 exporter. exporter 负责采集指标,通过 http 暴露给 Prometheus 拉取.granafa 则通过这些指标绘图展示数据.Prometheus 收集的数据还会根据你设置的告警规则判断是否要发送给 Alertmanager, Alertmanager 则要判断是否要发出告警. Alertmanager 告警分为三个阶段 Inactive 触发告警的规则会被发送到这来. Pending 你设置

zabbix监控redis集群

1.agent端新建自动发现redis集群端口 脚本如下 #!/bin/bash #redis_sport_scan.sh redis() { port=($(sudo netstat -tpln | awk -F "[ :]+" '/redis/ && /0.0.0.0/ {print $5}')) printf '{\n' printf '\t"data":[\n' for key in ${!port[@]} do if [[ "${

Shell 脚本 更换tomcat集群war包

运行之前将服务器弄成免ssh登陆. 配置文件没有太大的改动 可以覆盖之前的配置 profile 配置文件 bak=/home/wsm/bak webapps=/home/wsm/webapps/WSMMeasure arry=192.168.68.29 192.168.10.147 newwar=1.war deplypath=/home/wsm/deploy scp.sh 拷贝相关war和脚本到远程服务上 scp.sh #!/bin/bash #拷贝war|deploy.sh|profile

Redis-Sentinel(Redis集群监控管理)

Redis的高可用方案的实现:主从切换以及虚拟IP或客户端 从Redis 2.8开始加入对Sentinel机制从而实现了服务器端的主从切换,但目前尚未发现实现虚拟IP或客户端切换方案 Redis-Sentinel是Redis官方推荐的高可用性(HA)解决方案 当用Redis做Master-slave的高可用方案时,假如master宕机了,Redis本身(包括它的很多客户端)都没有实现自动进行主备切换, 而Redis-sentinel本身也是一个独立运行的进程,它能监控多个master-slave

Redis集群监控RedisClusterManager

RedisClusterManager监控Redis集群 环境要求:Java8+ jdk配置这里略过 RedisClusterManager 下载地址:  附件:systemMonitor-release.tar.gz 收集系统状态包  附件: RedisManager-Web-1.0.0-SNAPSHOT-beta.tar.gz redis集群管理包      1.安装systemMonitor    # tar -zxvf systemMonitor-release.tar.gz   # v

Redis集群redis主从自动切换Sentinel(哨兵模式)

Redis SentinelSentinel(哨兵)是用于监控redis集群中Master状态的工具,其已经被集成在redis2.4+的版本中 一.Sentinel作用:1):Master状态检测 2):如果Master异常,则会进行Master-Slave切换,将其中一个Slave作为Master,将之前的Master作为Slave3):Master-Slave切换后,master_redis.conf.slave_redis.conf和sentinel.conf的内容都会发生改变,即mast

redis 集群热备自动切换sentinel配置实战

Redis SentinelSentinel(哨兵)是用于监控redis集群中Master状态的工具,其已经被集成在redis2.4+的版本中 一.Sentinel作用:1):Master状态检测 2):如果Master异常,则会进行Master-Slave切换,将其中一个Slave作为Master,将之前的Master作为Slave3):Master-Slave切换后,master_redis.conf.slave_redis.conf和sentinel.conf的内容都会发生改变,即mast

redis集群方案总结

一,公司现在正在使用的集群方案(redis+sentinel) 通过多个Sentinel一起监控redis集群,检测到master不可用时,通过投票来决定master是否需要切换. Sentinel 之间互相检测(通过在共同检测的master中写入信息来进行),Sentinel 只需要配置master节点,自动通过master来获取已经连接的slave列表.当其中的某一个Sentinel 检测到master宕机之后,标示master为SDOWN,向其他的Sentinel 发送SENTINEL i

Redis集群知识解析

redis集群在启动的时候就自动在多个节点间分好片.同时提供了分片之间的可用性:当一部分redis节点故障或网络中断,集群也能继续工作.但是,当大面积的节点故障或网络中断(比如大部分的主节点都不可用了),集群就不能使用. 所以,从实用性的角度,Redis集群提供以下功能: 自动把数据切分到多个redis节点中 当一部分节点挂了或不可达,集群依然能继续工作 Redis集群的TCP端口 redis集群中的每个节点都需要建立2个tcp连接,监听这2个端口:一个端口称之为“客户端端口”,用于接受客户端指