使用elasticsearch的健康检查命令来监控其集群状态:

 curl -s -XGET 192.168.1.22:9200/_cluster/health?pretty{  "cluster_name" : "elastic",  "status" : "green",  "timed_out" : false,  "number_of_nodes" : 3,  "number_of_data_nodes" : 3,  "active_primary_shards" : 5,  "active_shards" : 10,  "relocating_shards" : 0,  "initializing_shards" : 0,  "unassigned_shards" : 0,  "delayed_unassigned_shards" : 0,  "number_of_pending_tasks" : 0,  "number_of_in_flight_fetch" : 0,  "task_max_waiting_in_queue_millis" : 0,  "active_shards_percent_as_number" : 100.0}

配置键值参数

在zabbix存放自定义参数模板路径下创建如下文件:

cat /etc/zabbix/zabbix_agentd.d/userparameter_elastic.conf UserParameter=estic.status,/bin/sh /scripts/elastic_zabbix.sh statusUserParameter=estic.timed_out,/bin/sh /scripts/elastic_zabbix.sh timed_outUserParameter=estic.number_of_nodes,/bin/sh /scripts/elastic_zabbix.sh number_of_nodesUserParameter=estic.number_of_data_nodes,/bin/sh /scripts/elastic_zabbix.sh number_of_data_nodesUserParameter=estic.active_primary_shards,/bin/sh /scripts/elastic_zabbix.sh active_primary_shardsUserParameter=estic.active_shards,/bin/sh /scripts/elastic_zabbix.sh active_shardsUserParameter=estic.relocating_shards,/bin/sh /scripts/elastic_zabbix.sh relocating_shardsUserParameter=estic.initializing_shards,/bin/sh /scripts/elastic_zabbix.sh initializing_shardsUserParameter=estic.unassigned_shards,/bin/sh /scripts/elastic_zabbix.sh unassigned_shardsUserParameter=estic.delayed_unassigned_shards,/bin/sh /scripts/elastic_zabbix.sh delayed_unassigned_shardsUserParameter=estic.number_of_pending_tasks,/bin/sh /scripts/elastic_zabbix.sh number_of_pending_tasksUserParameter=estic.number_of_in_flight_fetch,/bin/sh /scripts/elastic_zabbix.sh number_of_in_flight_fetchUserParameter=estic.task_max_waiting_in_queue_millis,/bin/sh /scripts/elastic_zabbix.sh task_max_waiting_in_queue_millisUserParameter=estic.active_shards_percent_as_number,/bin/sh /scripts/elastic_zabbix.sh active_shards_percent_as_number

执行脚本可以放在自定义的目录中,和上面定义的参数对应:

cat /scripts/elastic_zabbix.sh #!/bin/bashURL="192.168.1.22:9200/_cluster/health"ESstatus="`curl -s -XGET $URL`"#echo $ESstatusstatus=`echo $ESstatus|awk -F '[:,}]' '{print $4}'`timed_out=`echo $ESstatus|awk -F '[:,}]' '{print $6}'`number_of_nodes=`echo $ESstatus|awk -F '[:,}]' '{print $8}'`number_of_data_nodes=`echo $ESstatus|awk -F '[:,}]' '{print $10}'`active_primary_shards=`echo $ESstatus|awk -F '[:,}]' '{print $12}'`active_shards=`echo $ESstatus|awk -F '[:,}]' '{print $14}'`relocating_shards=`echo $ESstatus|awk -F '[:,}]' '{print $16}'`initializing_shards=`echo $ESstatus|awk -F '[:,}]' '{print $18}'`unassigned_shards=`echo $ESstatus|awk -F '[:,}]' '{print $20}'`delayed_unassigned_shards=`echo $ESstatus|awk -F '[:,}]' '{print $22}'`number_of_pending_tasks=`echo $ESstatus|awk -F '[:,}]' '{print $24}'`number_of_in_flight_fetch=`echo $ESstatus|awk -F '[:,}]' '{print $26}'`task_max_waiting_in_queue_millis=`echo $ESstatus|awk -F '[:,}]' '{print $28}'`active_shards_percent_as_number=`echo $ESstatus|awk -F '[:,}]' '{print $30}'`get_values(){case $1 in  status) echo $status  ;;  timed_out) echo $timed_out  ;;  number_of_nodes) echo $number_of_nodes  ;;  number_of_data_nodes) echo $number_of_data_nodes  ;;  active_primary_shards) echo $active_primary_shards  ;;  active_shards) echo $active_shards  ;;  relocating_shards) echo $relocating_shards  ;;  initializing_shards) echo $initializing_shards  ;;  unassigned_shards) echo $unassigned_shards  ;;  delayed_unassigned_shards) echo $delayed_unassigned_shards  ;;  number_of_pending_tasks) echo $number_of_pending_tasks  ;;  number_of_in_flight_fetch) echo $number_of_in_flight_fetch  ;;  task_max_waiting_in_queue_millis) echo $task_max_waiting_in_queue_millis  ;;  active_shards_percent_as_number) echo $active_shards_percent_as_number  ;;   *)     echo error  esac}main (){get_values $1}main $1

这里是三个节点的Elastic组成的集群,在每个节点上配置以上的参数和脚本。

导入配置模板

附件是对应自定义的zabbix监控模板,可以根据自己的需要进行修改:

    
3.2
    
2017-05-10T07:40:20Z
    
        
            
Templates
        
    
    
        
    
    
        
            
{Template Elastic Search:estic.status.str("\"green\"")}=0
            
0
            
            
elastic is down
            
0
            
            
            
0
            
3
            
            
0
            
1
            
            
        
    
    
        
            
estic.number_of_pending_tasks
            
900
            
200
            
0.0000
            
100.0000
            
1
            
1
            
0
            
1
            
0
            
0.0000
            
0.0000
            
0
            
0
            
0
            
0
            
                
                    
0
                    
0
                    
1A7C11
                    
0
                    
2
                    
0
                    
                        
Template Elastic Search
                        
estic.active_primary_shards
                    
                
                
                    
1
                    
0
                    
F63100
                    
0
                    
2
                    
0
                    
                        
Template Elastic Search
                        
estic.active_shards
                    
                
                
                    
2
                    
0
                    
2774A4
                    
0
                    
2
                    
0
                    
                        
Template Elastic Search
                        
estic.number_of_data_nodes
                    
                
                
                    
3
                    
0
                    
A54F10
                    
0
                    
2
                    
0
                    
                        
Template Elastic Search
                        
estic.number_of_nodes