34212131 发表于 2017-1-12 09:07:12

zabbix监控elasticsearch集群


[*]查看es集群健康状态

curl -XGET 'http://localhost:9200/_cluster/health?pretty'
{
"cluster_name" : "hotel-elk-log",
"status" : "green",            #集群状态:green,yellow,red
"timed_out" : false,
"number_of_nodes" : 3,      #集群中node节点数
"number_of_data_nodes" : 2,      #集群中data节点数
"active_primary_shards" : 186,
"active_shards" : 372,
"relocating_shards" : 0,      #迁移分片到新的node
"initializing_shards" : 0,      #初始化分片
"unassigned_shards" : 0,      #
"delayed_unassigned_shards" : 0,
"number_of_pending_tasks" : 0,
"number_of_in_flight_fetch" : 0
}

[*]shell 脚本
#!/bin/bash
case $1 in
      cluster_name)
                curl -s -XGET 'http://localhost:9200/_cluster/health?pretty' |awk -F\" '/cluster_name/ {print $4}' ;;
      status)
                curl -s -XGET 'http://localhost:9200/_cluster/health?pretty' |awk -F\" 'NR==3 {print $4}' ;;
    timed_out)
      curl -s -XGET 'http://localhost:9200/_cluster/health?pretty' |awk -F\, 'NR==4 {print $1}' |awk -F: '{print $2}' ;;
      number_nodes)
      curl -s -XGET 'http://localhost:9200/_cluster/health?pretty' |awk -F\, 'NR==5 {print $1}' |awk -F: '{print $2}' ;;
      data_nodes)
      curl -s -XGET 'http://localhost:9200/_cluster/health?pretty' |awk -F\, 'NR==6 {print $1}' |awk -F: '{print $2}' ;;
      active_primary_shards)
      curl -s -XGET 'http://localhost:9200/_cluster/health?pretty' |awk -F\, 'NR==7 {print $1}' |awk -F: '{print $2}' ;;
      active_shards)
      curl -s -XGET 'http://localhost:9200/_cluster/health?pretty' |awk -F\, 'NR==8 {print $1}' |awk -F: '{print $2}' ;;
    relocating_shards)
      curl -s -XGET 'http://localhost:9200/_cluster/health?pretty' |awk -F\, 'NR==9 {print $1}' |awk -F: '{print $2}' ;;
    initializing_shards)
      curl -s -XGET 'http://localhost:9200/_cluster/health?pretty' |awk -F\, 'NR==10 {print $1}' |awk -F: '{print $2}' ;;
    unassigned_shards)
      curl -s -XGET 'http://localhost:9200/_cluster/health?pretty' |awk -F\, 'NR==11 {print $1}' |awk -F: '{print $2}' ;;
    *)
      echo "Usage: $0 { cluster_name | status | timed_out | number_nodes | data_nodes | active_primary_shards | active_shards | relocating_shards | initializing_shards | unassigned_shards}" ;;
esac

[*]zabbix_agentd.conf
UnsafeUserParameters=1

UserParameter=cluster_name,/usr/local/zabbix/es_status.sh cluster_name
UserParameter=status,/usr/local/zabbix/es_status.sh status
UserParameter=timed_out,/usr/local/zabbix/es_status.sh timed_out
UserParameter=number_nodes,/usr/local/zabbix/es_status.sh number_nodes
UserParameter=data_nodes,/usr/local/zabbix/es_status.sh data_nodes
UserParameter=active_primary_shards,/usr/local/zabbix/es_status.sh active_primary_shards
UserParameter=active_shards,/usr/local/zabbix/es_status.sh active_shards
UserParameter=relocating_shards,/usr/local/zabbix/es_status.sh relocating_shards
UserParameter=initializing_shards,/usr/local/zabbix/es_status.sh initializing_shards
UserParameter=unassigned_shards,/usr/local/zabbix/es_status.sh unassigned_shards

[*]zabbix上添加host,链接到模板



天下123 发表于 2017-1-12 09:10:30

截取脚本真复杂,你可以直接用一条语句,代入传参,就ok了

yy506 发表于 2018-8-6 14:21:39

下载下来的文件怎么是空的

longyu_w 发表于 2022-3-8 16:23:40

文件是空的呀?
页: [1]
查看完整版本: zabbix监控elasticsearch集群