码迷,mamicode.com
首页 > 系统相关 > 详细

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

时间:2019-12-06 19:03:46      阅读:91      评论:0      收藏:0      [点我收藏+]

标签:poc   last   图片   rip   templates   url   slots   模式   shell脚本   

为了避免单点故障,生产环境中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文件,将其导入
技术图片

五、给主机添加监控模板

技术图片
技术图片

六、监控效果图

技术图片
技术图片
技术图片

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

标签:poc   last   图片   rip   templates   url   slots   模式   shell脚本   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!