通过externalscripts监控redis server的状态
externalscripts 脚本
#cat es_status.sh #放在externalscripts路径下,zabbix用户可执行
#!/bin/bash
server=$1
check=$2
if [ $check == "nodename" ] || [ $check == "clustername" ] || [ $check == "clusterstatus" ] || [ $check == "nodesnum" ] || [ $check == "datanodesnum" ]
then
case $check in
nodename)
curl http://$server/ 2>&1|grep "\"name\" :"|awk -F'"' '{print $4}' |tac|head -n 1
;;
clustername)
curl http://$server/_cluster/health?pretty 2>&1|grep ^" \"cluster_name\" :"|awk -F'"' '{print $4}'|tac|head -n 1
;;
clusterstatus)
curl http://$server/_cluster/health?pretty 2>&1|grep ^" \"status\" :"|awk -F'"' '{print $4}'|tac|head -n 1
;;
nodesnum)
curl http://$server/_cluster/health?pretty 2>&1|grep ^" \"number_of_nodes\" :"|awk -F" " '{print $3}'|sed 's/,//'|tac|head -n 1
;;
datanodesnum)
curl http://$server/_cluster/health?pretty 2>&1|grep ^" \"number_of_data_nodes\" :"|awk -F" " '{print $3}'|sed 's/,//'|tac|head -n 1
;;
esac
else
echo "not support $3."&&exit 1
fi
监控模板如下
导出模板的xml
<?xml version="1.0" encoding="UTF-8"?>
<zabbix_export>
<version>2.0</version>
<date>2016-04-01T08:20:37Z</date>
<groups>
<group>
<name>Templates</name>
</group>
</groups>
<templates>
<template>
<template>template elasticsearch</template>
<name>template elasticsearch</name>
<description/>
<groups>
<group>
<name>Templates</name>
</group>
</groups>
<applications>
<application>
<name>elasticsearch</name>
</application>
</applications>
<items>
<item>
<name>elasticsearch $1 cluster name</name>
<type>10</type>
<snmp_community/>
<multiplier>0</multiplier>
<snmp_oid/>
<key>es_status.sh[{IPADDRESS}:9200,clustername]</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>elasticsearch</name>
</application>
</applications>
<valuemap/>
<logtimefmt/>
</item>
<item>
<name>elasticsearch $1 cluster status</name>
<type>10</type>
<snmp_community/>
<multiplier>0</multiplier>
<snmp_oid/>
<key>es_status.sh[{IPADDRESS}:9200,clusterstatus]</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>elasticsearch</name>
</application>
</applications>
<valuemap/>
<logtimefmt/>
</item>
<item>
<name>elasticsearch $1 data nodes num</name>
<type>10</type>
<snmp_community/>
<multiplier>0</multiplier>
<snmp_oid/>
<key>es_status.sh[{IPADDRESS}:9200,datanodesnum]</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>elasticsearch</name>
</application>
</applications>
<valuemap/>
<logtimefmt/>
</item>
<item>
<name>elasticsearch $1 node name</name>
<type>10</type>
<snmp_community/>
<multiplier>0</multiplier>
<snmp_oid/>
<key>es_status.sh[{IPADDRESS}:9200,nodename]</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>elasticsearch</name>
</application>
</applications>
<valuemap/>
<logtimefmt/>
</item>
<item>
<name>elasticsearch $1 nodes num</name>
<type>10</type>
<snmp_community/>
<multiplier>0</multiplier>
<snmp_oid/>
<key>es_status.sh[{IPADDRESS}:9200,nodesnum]</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>elasticsearch</name>
</application>
</applications>
<valuemap/>
<logtimefmt/>
</item>
<item>
<name>elasticsearch $2 port 9200 check</name>
<type>3</type>
<snmp_community/>
<multiplier>0</multiplier>
<snmp_oid/>
<key>net.tcp.service[tcp,{IPADDRESS},9200]</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>elasticsearch</name>
</application>
</applications>
<valuemap/>
<logtimefmt/>
</item>
<item>
<name>elasticsearch $2 port 9300 check</name>
<type>3</type>
<snmp_community/>
<multiplier>0</multiplier>
<snmp_oid/>
<key>net.tcp.service[tcp,{IPADDRESS},9300]</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>elasticsearch</name>
</application>
</applications>
<valuemap/>
<logtimefmt/>
</item>
</items>
<discovery_rules/>
<macros/>
<templates/>
<screens/>
</template>
</templates>
<triggers>
<trigger>
<expression>{template elasticsearch:es_status.sh[{IPADDRESS}:9200,nodesnum].diff()}=1 or {template elasticsearch:es_status.sh[{IPADDRESS}:9200,datanodesnum].diff()}=1</expression>
<name>elasticsearch {IPADDRESS} data nodes or nodes number changed.</name>
<url/>
<status>0</status>
<priority>3</priority>
<description/>
<type>0</type>
<dependencies/>
</trigger>
<trigger>
<expression>{template elasticsearch:net.tcp.service[tcp,{IPADDRESS},9200].last()}<>1</expression>
<name>elasticsearch {IPADDRESS} port 9200 check failed.</name>
<url/>
<status>0</status>
<priority>3</priority>
<description/>
<type>0</type>
<dependencies/>
</trigger>
<trigger>
<expression>{template elasticsearch:net.tcp.service[tcp,{IPADDRESS},9300].last()}<>1</expression>
<name>elasticsearch {IPADDRESS} port 9300 check failed.</name>
<url/>
<status>0</status>
<priority>3</priority>
<description/>
<type>0</type>
<dependencies/>
</trigger>
<trigger>
<expression>{template elasticsearch:es_status.sh[{IPADDRESS}:9200,clusterstatus].str(green,#1)}<>1</expression>
<name>elasticsearch {IPADDRESS} status error</name>
<url/>
<status>0</status>
<priority>3</priority>
<description/>
<type>0</type>
<dependencies/>
</trigger>
</triggers>
</zabbix_export>