├── es_zabbix_view.png ├── elasticsearch_monitor ├── es_env.sh ├── es_cluster_health.sh ├── es_node_monitor.sh ├── help.md ├── es_index_monitor.sh ├── es_indices_monitor.sh ├── es_nodes_discovery.sh └── es_indices_discovery.sh ├── userparameter_elasticsearch.conf ├── README.md └── zbx_export_templates.xml /es_zabbix_view.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Vastxiao/zabbixMonitorES/HEAD/es_zabbix_view.png -------------------------------------------------------------------------------- /elasticsearch_monitor/es_env.sh: -------------------------------------------------------------------------------- 1 | # es监控环境变量配置文件 2 | # Call to vastxiao.github.io 3 | # Create at 20170411 4 | 5 | # es节点ip和端口 6 | #ESADDR="192.168.13.36:9200, 192.168.13.37:9200" 7 | ESADDR="192.168.13.36:9200, 192.168.13.37:9200, 192.168.13.151:9200" 8 | 9 | -------------------------------------------------------------------------------- /elasticsearch_monitor/es_cluster_health.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # Call to vastxiao.github.io 4 | # Create at 20170411 5 | 6 | PATH=/bin:/sbin:/usr/bin:/usr/sbin 7 | 8 | #echo $0 9 | cd $(dirname $0) 10 | HOMEPATH=$(pwd) 11 | 12 | source es_env.sh 13 | [ $? -ne 0 ] && echo "ERROR: es_env.sh not not found." >&2 && exit 1 14 | 15 | [ X$1 = X ] && echo "ERROR: type empty." >&2 && exit 1 16 | 17 | for addr in $(echo ${ESADDR} |sed -e 's/,/ /g') 18 | do 19 | curl -XGET "http://$addr/_cat/health?h=$1" 2>/dev/null 20 | [ $? -eq 0 ] && break 21 | done 22 | -------------------------------------------------------------------------------- /userparameter_elasticsearch.conf: -------------------------------------------------------------------------------- 1 | UserParameter=es_cluster_health[*],/usr/local/zabbix/scripts/elasticsearch_monitor/es_cluster_health.sh $1 2 | UserParameter=es_nodes_discovery,/usr/local/zabbix/scripts/elasticsearch_monitor/es_nodes_discovery.sh 3 | UserParameter=es_node_monitor[*],/usr/local/zabbix/scripts/elasticsearch_monitor/es_node_monitor.sh $1 $2 4 | UserParameter=es_indices_discovery,/usr/local/zabbix/scripts/elasticsearch_monitor/es_indices_discovery.sh 5 | UserParameter=es_index_monitor[*],/usr/local/zabbix/scripts/elasticsearch_monitor/es_index_monitor.sh $1 $2 6 | -------------------------------------------------------------------------------- /elasticsearch_monitor/es_node_monitor.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # Call to vastxiao.github.io 4 | # Create at 20170411 5 | 6 | PATH=/bin:/sbin:/usr/bin:/usr/sbin 7 | 8 | #echo $0 9 | cd $(dirname $0) 10 | HOMEPATH=$(pwd) 11 | 12 | source es_env.sh 13 | [ $? -ne 0 ] && echo "ERROR: es_env.sh not not found." >&2 && exit 1 14 | 15 | [ X$1 = X ] && echo "ERROR: node name empty." >&2 && exit 1 16 | [ X$2 = X ] && echo "ERROR: type empty." >&2 && exit 1 17 | 18 | for addr in $(echo ${ESADDR} |sed -e 's/,/ /g') 19 | do 20 | curl -XGET "http://$addr/_cat/nodes?bytes=b&size=b&h=name,$2" 2>/dev/null |grep "^$1" |awk '{print $2}' 21 | [ $? -eq 0 ] && break 22 | done 23 | -------------------------------------------------------------------------------- /elasticsearch_monitor/help.md: -------------------------------------------------------------------------------- 1 | # Elasticsearch monitor scripts for zabbix 2 | 3 | **requirments** 4 | - Linux 5 | - zabbix3 6 | - bash 7 | - linux commands: curl, awk, grep, sort, uniq, sed ... 8 | - support es > 5.0 9 | 10 | **install** 11 | 12 | 1. Import zbx\_export\_templates.xml to zabbix. 13 | 2. Copy elasticsearch_monitor directory to your zabbix agentd scripts path. 14 | 3. Copy userparameter_elasticsearch.conf to your zabbix agentd etc path, 15 | and you may change the path to your right agentd scripts path. 16 | 4. Config es\_env.sh and restart zabbix agentd process. 17 | 5. finaly, add the "Elasticsearch Cluster" to the host which should be monitor. 18 | 19 | 20 | # About 21 | 22 | Author: vastxiao.github.io 23 | Date: 2017.04.11 24 | 25 | -------------------------------------------------------------------------------- /elasticsearch_monitor/es_index_monitor.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # Call to vastxiao.github.io 4 | # Create at 20170411 5 | 6 | PATH=/bin:/sbin:/usr/bin:/usr/sbin 7 | 8 | #echo $0 9 | cd $(dirname $0) 10 | HOMEPATH=$(pwd) 11 | 12 | source es_env.sh 13 | [ $? -ne 0 ] && echo "ERROR: es_env.sh not not found." >&2 && exit 1 14 | 15 | # index count 16 | indices_count() { 17 | local indexfilter=$1 18 | for addr in $(echo ${ESADDR} |sed -e 's/,/ /g') 19 | do 20 | curl -XGET "http://$addr/_cat/count/$indexfilter*?h=count" 2>/dev/null 21 | [ $? -eq 0 ] && break 22 | done 23 | } 24 | 25 | 26 | # 检查类型 27 | case $1 in 28 | count) 29 | indices_count $2 30 | ;; 31 | *) 32 | echo "ERROR: monitor type $1 error." >&2 33 | esac 34 | 35 | 36 | -------------------------------------------------------------------------------- /elasticsearch_monitor/es_indices_monitor.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # Call to vastxiao.github.io 4 | # Create at 20170411 5 | 6 | PATH=/bin:/sbin:/usr/bin:/usr/sbin 7 | 8 | #echo $0 9 | cd $(dirname $0) 10 | HOMEPATH=$(pwd) 11 | 12 | source es_env.sh 13 | [ $? -ne 0 ] && echo "ERROR: es_env.sh not not found." >&2 && exit 1 14 | 15 | # index count 16 | indices_count() { 17 | local indexfilter=$1 18 | for addr in $(echo ${ESADDR} |sed -e 's/,/ /g') 19 | do 20 | curl -XGET "http://$addr/_cat/count/$indexfilter*?h=count" 2>/dev/null 21 | [ $? -eq 0 ] && break 22 | done 23 | } 24 | 25 | 26 | # 检查类型 27 | case $1 in 28 | count) 29 | indices_count $2 30 | ;; 31 | *) 32 | echo "ERROR: monitor type $1 error." >&2 33 | esac 34 | 35 | 36 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Elasticsearch monitor scripts for zabbix 2 | 3 | 这是一个关于ES监控的zabbix的脚本. 4 | 5 | **预览** 6 | 7 | ![item show on zabbix web site](es_zabbix_view.png) 8 | 9 | **特性** 10 | 11 | 1. 这个监控脚本是使用bash编写的. 12 | 2. 只需要Linux的基本工具, 无需其他开发语言的依赖. 13 | 3. 只要配置一个节点即可在zabbix上监控整个ES集群,这相当的省事方便, 14 | 就算以后调整了集群节点也不需要再重新配置监控. 15 | 16 | **依赖环境** 17 | 18 | - Linux 19 | - zabbix3 20 | - bash 21 | - linux commands: curl, awk, grep, sort, uniq, sed ... 22 | - support es version 2.x 5.x+ 23 | 24 | **安装指南** 25 | 26 | 1. 将模板文件 zbx\_export\_templates.xml 导入到zabbix. 27 | 2. 复制整个 elasticsearch_monitor 目录到任意一个ES节点的 zabbix agentd scripts 目录中(注意zabbix执行权限问题). 28 | 3. 修改 es\_env.sh 的配置,指定es节点地址, 建议至少加两个以上节点的地址以防单个节点挂掉监控不到数据. 29 | 4. 复制 userparameter_elasticsearch.conf 到 zabbix agentd etc, 注意修改对应的脚本路径. 30 | 5. 在zabbix web中添加 "Elasticsearch Cluster" 模板到配置监控脚本的节点. 31 | 6. 重启监控节点的zabbix agentd 搞定. 32 | 33 | # 关于 34 | 35 | * Author: vastxiao.github.io 36 | * Date: 2017.04.11 37 | * Repo: https://github.com/Vastxiao/zabbixMonitorES 38 | 39 | -------------------------------------------------------------------------------- /elasticsearch_monitor/es_nodes_discovery.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # Call to vastxiao.github.io 4 | # Create at 20170411 5 | 6 | PATH=/bin:/sbin:/usr/bin:/usr/sbin 7 | 8 | #echo $0 9 | cd $(dirname $0) 10 | HOMEPATH=$(pwd) 11 | 12 | source es_env.sh 13 | [ $? -ne 0 ] && echo "ERROR: es_env.sh not not found." >&2 && exit 1 14 | 15 | # 连接es节点,获取索引,自动发现监控项 16 | for addr in $(echo ${ESADDR} |sed -e 's/,/ /g') 17 | do 18 | curl -XGET "http://$addr/" &>/dev/null 19 | [ $? -ne 0 ] && echo "WARN: connect to $addr failed." >&2 && continue 20 | 21 | # 获取索引列表 22 | # 日索引 23 | list=( $(curl -XGET "http://$addr/_cat/nodes?h=name" 2>/dev/null) ) 24 | #echo -e "${list[*]}\n\n" 25 | 26 | #[ x$list = x ] && echo "ERROR: no discovery data list found." >&2 && exit 1 27 | # 将列表list,转换为发送给zabbx的json数据。 28 | length=${#list[@]} 29 | #printf "{\n" 30 | printf '{\"data\":[ ' 31 | for ((i=0;i<$length;i++)) 32 | do 33 | printf "{\"{#NAME}\":\"${list[$i]}\"}" 34 | 35 | if [ $i -lt $[ $length-1 ] ];then 36 | printf ',' 37 | fi 38 | done 39 | #printf "\n\t]\n" 40 | #printf "}\n" 41 | printf " ]}" 42 | 43 | break 44 | done 45 | 46 | -------------------------------------------------------------------------------- /elasticsearch_monitor/es_indices_discovery.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # Call to vastxiao.github.io 4 | # Create at 20170411 5 | 6 | PATH=/bin:/sbin:/usr/bin:/usr/sbin 7 | 8 | #echo $0 9 | cd $(dirname $0) 10 | HOMEPATH=$(pwd) 11 | 12 | source es_env.sh 13 | [ $? -ne 0 ] && echo "ERROR: es_env.sh not not found." >&2 && exit 1 14 | 15 | # 连接es节点,获取索引,自动发现监控项 16 | for addr in $(echo ${ESADDR} |sed -e 's/,/ /g') 17 | do 18 | curl -XGET "http://$addr/" &>/dev/null 19 | [ $? -ne 0 ] && echo "WARN: connect to $addr failed." >&2 && continue 20 | 21 | # 获取索引列表 22 | # 日索引 23 | list=( $(curl -XGET "http://$addr/_cat/indices?h=status,index" 2>/dev/null |grep "^open" |awk '{print $2}' |grep -v '^\.kibana' |grep '\-day-[0-9]\{4\}\.[0-9]\{2\}\.[0-9]\{2\}$' |sed 's/-[0-9]\{4\}\.[0-9]\{2\}\.[0-9]\{2\}$//g' |sort |uniq) ) 24 | # 月索引 25 | list=( $(echo ${list[*]}) $(curl -XGET "http://$addr/_cat/indices?h=status,index" 2>/dev/null |grep "^open" |awk '{print $2}' |grep -v '^\.kibana' |grep '\-mon-[0-9]\{4\}\.[0-9]\{2\}$' |sed 's/-[0-9]\{4\}\.[0-9]\{2\}$//g' |sort |uniq) ) 26 | # 年索引 27 | list=( $(echo ${list[*]}) $(curl -XGET "http://$addr/_cat/indices?h=status,index" 2>/dev/null |grep "^open" |awk '{print $2}' |grep -v '^\.kibana' |grep '\-year-[0-9]\{4\}$' |sed 's/-[0-9]\{4\}$//g' |sort |uniq) ) 28 | #echo -e "${list[*]}\n\n" 29 | 30 | #[ x$list = x ] && echo "ERROR: no discovery data list found." >&2 && exit 1 31 | # 将列表list,转换为发送给zabbx的json数据。 32 | length=${#list[@]} 33 | #printf "{\n" 34 | printf '{\"data\":[ ' 35 | for ((i=0;i<$length;i++)) 36 | do 37 | printf "{\"{#NAME}\":\"${list[$i]}\"}" 38 | 39 | if [ $i -lt $[ $length-1 ] ];then 40 | printf ',' 41 | fi 42 | done 43 | #printf "\n\t]\n" 44 | #printf "}\n" 45 | printf " ]}" 46 | 47 | break 48 | done 49 | 50 | -------------------------------------------------------------------------------- /zbx_export_templates.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 3.4 4 | 2019-06-27T08:04:56Z 5 | 6 | 7 | Templates 8 | 9 | 10 | 11 | 1159 | 1160 | 1161 | 1162 | {Elasticsearch Cluster:es_cluster_health[active_shards_percent].str(100.0%)}=0 1163 | 0 1164 | 1165 | Elasticsearch Cluster active shards percent: {ITEM.LASTVALUE} 1166 | 0 1167 | 1168 | 1169 | 0 1170 | 2 1171 | 1172 | 0 1173 | 0 1174 | 1175 | 1176 | 1177 | 1178 | {Elasticsearch Cluster:es_cluster_health[status].str(red)}=1 1179 | 0 1180 | 1181 | Elasticsearch Cluster health state in [red] 1182 | 0 1183 | 1184 | 1185 | 0 1186 | 5 1187 | 1188 | 0 1189 | 0 1190 | 1191 | 1192 | 1193 | 1194 | {Elasticsearch Cluster:es_cluster_health[status].str(yellow)}=1 1195 | 0 1196 | 1197 | Elasticsearch Cluster health state in [yellow] 1198 | 0 1199 | 1200 | 1201 | 0 1202 | 4 1203 | 1204 | 0 1205 | 0 1206 | 1207 | 1208 | Elasticsearch Cluster health state in [red] 1209 | {Elasticsearch Cluster:es_cluster_health[status].str(red)}=1 1210 | 1211 | 1212 | 1213 | 1214 | 1215 | 1216 | {Elasticsearch Cluster:es_cluster_health[init].last()}<>0 1217 | 0 1218 | 1219 | Elasticsearch Cluster initializing shards: {ITEM.LASTVALUE} 1220 | 0 1221 | 1222 | 1223 | 0 1224 | 1 1225 | 1226 | 0 1227 | 1 1228 | 1229 | 1230 | 1231 | 1232 | {Elasticsearch Cluster:es_cluster_health[pending_tasks].last()}<>0 1233 | 0 1234 | 1235 | Elasticsearch Cluster pending tasks: {ITEM.LASTVALUE} 1236 | 0 1237 | 1238 | 1239 | 0 1240 | 1 1241 | 1242 | 0 1243 | 1 1244 | 1245 | 1246 | 1247 | 1248 | {Elasticsearch Cluster:es_cluster_health[unassign].last()}<>0 1249 | 0 1250 | 1251 | Elasticsearch Cluster unassign shards: {ITEM.LASTVALUE} 1252 | 0 1253 | 1254 | 1255 | 0 1256 | 3 1257 | 1258 | 0 1259 | 1 1260 | 1261 | 1262 | 1263 | 1264 | 1265 | --------------------------------------------------------------------------------