經過externalscripts監控redis sentinel的狀態,可是隻支持監控一個redis集羣的sentinel,由於只監控master0,要支持多集羣的sentinel的話本身寫個返回各個master0-xxx的json格式的腳本,配合自動探索去作吧。redis
#cat check_sentinel.sh #放在externalscripts路徑下,zabbix用戶可執行express
#!/bin/bash ip=$1 port=$2 check=$3 #(echo -en "INFO\r\n";sleep 1)|nc $ip $port if [ $check == "uptime" ] || [ $check == "redisclustername" ] || [ $check == "redisclusterstatus" ] || [ $check == "slavenum" ] || [ $check == "sentinelnum" ] || [ $check == "redismaster" ] then case $check in uptime) (echo -en "INFO\r\n";sleep 1)|nc $ip $port |grep ^uptime_in_seconds:|awk -F: '{print $2}' ;; redisclustername) (echo -en "INFO\r\n";sleep 1)|nc $ip $port |grep ^master0:name|sed 's/^.*:name=//'|sed 's/,status=.*$//' ;; redisclusterstatus) (echo -en "INFO\r\n";sleep 1)|nc $ip $port |grep ^master0:name|sed 's/^.*,status=//'|sed 's/,address=.*$//' ;; slavenum) (echo -en "INFO\r\n";sleep 1)|nc $ip $port |grep ^master0:name|sed 's/^.*slaves=//'|sed 's/,sentinels=.*$//' ;; sentinelnum) (echo -en "INFO\r\n";sleep 1)|nc $ip $port |grep ^master0:name|sed 's/^.*sentinels=//' ;; redismaster) (echo -en "INFO\r\n";sleep 1)|nc $ip $port |grep ^master0:name|sed 's/^.*,address=//'|sed 's/,slaves.*$//' ;; esac else echo "not support $3."&&exit 1 fi
導出的zabbix模板json
<?xml version="1.0" encoding="UTF-8"?> <zabbix_export> <version>2.0</version> <date>2016-04-01T07:17:19Z</date> <groups> <group> <name>Templates</name> </group> </groups> <templates> <template> <template>template redis sentinel</template> <name>template redis sentinel</name> <description/> <groups> <group> <name>Templates</name> </group> </groups> <applications> <application> <name>sentinel</name> </application> </applications> <items> <item> <name>check redis sentinel $2 port 26379</name> <type>3</type> <snmp_community/> <multiplier>0</multiplier> <snmp_oid/> <key>net.tcp.service[tcp,{IPADDRESS},26379]</key> <delay>60</delay> <history>90</history> <trends>365</trends> <status>0</status> <value_type>3</value_type> <allowed_hosts/> <units/> <delta>0</delta> <snmpv3_contextname/> <snmpv3_securityname/> <snmpv3_securitylevel>0</snmpv3_securitylevel> <snmpv3_authprotocol>0</snmpv3_authprotocol> <snmpv3_authpassphrase/> <snmpv3_privprotocol>0</snmpv3_privprotocol> <snmpv3_privpassphrase/> <formula>1</formula> <delay_flex/> <params/> <ipmi_sensor/> <data_type>0</data_type> <authtype>0</authtype> <username/> <password/> <publickey/> <privatekey/> <port/> <description/> <inventory_link>0</inventory_link> <applications> <application> <name>sentinel</name> </application> </applications> <valuemap/> <logtimefmt/> </item> <item> <name>redis sentinel $1 redis cluster name</name> <type>10</type> <snmp_community/> <multiplier>0</multiplier> <snmp_oid/> <key>check_sentinel.sh[{IPADDRESS},26379,redisclustername]</key> <delay>60</delay> <history>90</history> <trends>365</trends> <status>0</status> <value_type>4</value_type> <allowed_hosts/> <units/> <delta>0</delta> <snmpv3_contextname/> <snmpv3_securityname/> <snmpv3_securitylevel>0</snmpv3_securitylevel> <snmpv3_authprotocol>0</snmpv3_authprotocol> <snmpv3_authpassphrase/> <snmpv3_privprotocol>0</snmpv3_privprotocol> <snmpv3_privpassphrase/> <formula>1</formula> <delay_flex/> <params/> <ipmi_sensor/> <data_type>0</data_type> <authtype>0</authtype> <username/> <password/> <publickey/> <privatekey/> <port/> <description/> <inventory_link>0</inventory_link> <applications> <application> <name>sentinel</name> </application> </applications> <valuemap/> <logtimefmt/> </item> <item> <name>redis sentinel $1 redis cluster status</name> <type>10</type> <snmp_community/> <multiplier>0</multiplier> <snmp_oid/> <key>check_sentinel.sh[{IPADDRESS},26379,redisclusterstatus]</key> <delay>60</delay> <history>90</history> <trends>365</trends> <status>0</status> <value_type>4</value_type> <allowed_hosts/> <units/> <delta>0</delta> <snmpv3_contextname/> <snmpv3_securityname/> <snmpv3_securitylevel>0</snmpv3_securitylevel> <snmpv3_authprotocol>0</snmpv3_authprotocol> <snmpv3_authpassphrase/> <snmpv3_privprotocol>0</snmpv3_privprotocol> <snmpv3_privpassphrase/> <formula>1</formula> <delay_flex/> <params/> <ipmi_sensor/> <data_type>0</data_type> <authtype>0</authtype> <username/> <password/> <publickey/> <privatekey/> <port/> <description/> <inventory_link>0</inventory_link> <applications> <application> <name>sentinel</name> </application> </applications> <valuemap/> <logtimefmt/> </item> <item> <name>redis sentinel $1 redis master</name> <type>10</type> <snmp_community/> <multiplier>0</multiplier> <snmp_oid/> <key>check_sentinel.sh[{IPADDRESS},26379,redismaster]</key> <delay>60</delay> <history>90</history> <trends>365</trends> <status>0</status> <value_type>4</value_type> <allowed_hosts/> <units/> <delta>0</delta> <snmpv3_contextname/> <snmpv3_securityname/> <snmpv3_securitylevel>0</snmpv3_securitylevel> <snmpv3_authprotocol>0</snmpv3_authprotocol> <snmpv3_authpassphrase/> <snmpv3_privprotocol>0</snmpv3_privprotocol> <snmpv3_privpassphrase/> <formula>1</formula> <delay_flex/> <params/> <ipmi_sensor/> <data_type>0</data_type> <authtype>0</authtype> <username/> <password/> <publickey/> <privatekey/> <port/> <description/> <inventory_link>0</inventory_link> <applications> <application> <name>sentinel</name> </application> </applications> <valuemap/> <logtimefmt/> </item> <item> <name>redis sentinel $1 sentinel num</name> <type>10</type> <snmp_community/> <multiplier>0</multiplier> <snmp_oid/> <key>check_sentinel.sh[{IPADDRESS},26379,sentinelnum]</key> <delay>60</delay> <history>90</history> <trends>365</trends> <status>0</status> <value_type>3</value_type> <allowed_hosts/> <units>s</units> <delta>0</delta> <snmpv3_contextname/> <snmpv3_securityname/> <snmpv3_securitylevel>0</snmpv3_securitylevel> <snmpv3_authprotocol>0</snmpv3_authprotocol> <snmpv3_authpassphrase/> <snmpv3_privprotocol>0</snmpv3_privprotocol> <snmpv3_privpassphrase/> <formula>1</formula> <delay_flex/> <params/> <ipmi_sensor/> <data_type>0</data_type> <authtype>0</authtype> <username/> <password/> <publickey/> <privatekey/> <port/> <description/> <inventory_link>0</inventory_link> <applications> <application> <name>sentinel</name> </application> </applications> <valuemap/> <logtimefmt/> </item> <item> <name>redis sentinel $1 slave num</name> <type>10</type> <snmp_community/> <multiplier>0</multiplier> <snmp_oid/> <key>check_sentinel.sh[{IPADDRESS},26379,slavenum]</key> <delay>60</delay> <history>90</history> <trends>365</trends> <status>0</status> <value_type>3</value_type> <allowed_hosts/> <units/> <delta>0</delta> <snmpv3_contextname/> <snmpv3_securityname/> <snmpv3_securitylevel>0</snmpv3_securitylevel> <snmpv3_authprotocol>0</snmpv3_authprotocol> <snmpv3_authpassphrase/> <snmpv3_privprotocol>0</snmpv3_privprotocol> <snmpv3_privpassphrase/> <formula>1</formula> <delay_flex/> <params/> <ipmi_sensor/> <data_type>0</data_type> <authtype>0</authtype> <username/> <password/> <publickey/> <privatekey/> <port/> <description/> <inventory_link>0</inventory_link> <applications> <application> <name>sentinel</name> </application> </applications> <valuemap/> <logtimefmt/> </item> <item> <name>redis sentinel $1 uptime</name> <type>10</type> <snmp_community/> <multiplier>0</multiplier> <snmp_oid/> <key>check_sentinel.sh[{IPADDRESS},26379,uptime]</key> <delay>60</delay> <history>90</history> <trends>365</trends> <status>0</status> <value_type>3</value_type> <allowed_hosts/> <units>s</units> <delta>0</delta> <snmpv3_contextname/> <snmpv3_securityname/> <snmpv3_securitylevel>0</snmpv3_securitylevel> <snmpv3_authprotocol>0</snmpv3_authprotocol> <snmpv3_authpassphrase/> <snmpv3_privprotocol>0</snmpv3_privprotocol> <snmpv3_privpassphrase/> <formula>1</formula> <delay_flex/> <params/> <ipmi_sensor/> <data_type>0</data_type> <authtype>0</authtype> <username/> <password/> <publickey/> <privatekey/> <port/> <description/> <inventory_link>0</inventory_link> <applications> <application> <name>sentinel</name> </application> </applications> <valuemap/> <logtimefmt/> </item> </items> <discovery_rules/> <macros/> <templates/> <screens/> </template> </templates> <triggers> <trigger> <expression>{template redis sentinel:check_sentinel.sh[{IPADDRESS},26379,redisclusterstatus].str(ok,#2)}=0</expression> <name>check redis cluster monited by sentinel {IPADDRESS} not ok</name> <url/> <status>0</status> <priority>4</priority> <description/> <type>0</type> <dependencies/> </trigger> <trigger> <expression>{template redis sentinel:net.tcp.service[tcp,{IPADDRESS},26379].last(#1)}<>1</expression> <name>check sentinel {IPADDRESS} port 26379 failed.</name> <url/> <status>0</status> <priority>4</priority> <description/> <type>0</type> <dependencies/> </trigger> </triggers> </zabbix_export>