Zabbix 和 Grafana 监控Elasticsearch集群相关指标

1.需求:需要监控elasticsearch集群的需求,以便告警使用。

2.说明:zabbix 采用shell脚本监控相关指标,Grafana使用模板监控集群状态看板。

3.zabbix监控指标及脚本

cluster_name
status
timed_out
number_nodes
data_nodes
active_primary_shards
active_shards
relocating_shards
initializing_shards
unassigned_shards
其他指标请查看官方文档........

其中status为green yellow /red / time_out 的值为false /true ,其他参数为数字

shell脚本:

#!/bin/bash
case $1 in
        cluster_name)
                curl -s -XGET 'http://192.168.0.179:9200/_cluster/health?pretty' |awk -F\" '/cluster_name/ {print $4}' ;;
        status)
                curl -s -XGET 'http://192.168.0.179:9200/_cluster/health?pretty' |awk -F\" 'NR==3 {print $4}' ;;
    timed_out)
        curl -s -XGET 'http://192.168.0.179:9200/_cluster/health?pretty' |awk -F\, 'NR==4 {print $1}' |awk -F: '{print $2}' ;;
        number_nodes)
        curl -s -XGET 'http://192.168.0.179:9200/_cluster/health?pretty' |awk -F\, 'NR==5 {print $1}' |awk -F: '{print $2}' ;;
        data_nodes)
        curl -s -XGET 'http://192.168.0.179:9200/_cluster/health?pretty' |awk -F\, 'NR==6 {print $1}' |awk -F: '{print $2}' ;;
        active_primary_shards)
        curl -s -XGET 'http://192.168.0.179:9200/_cluster/health?pretty' |awk -F\, 'NR==7 {print $1}' |awk -F: '{print $2}' ;;
        active_shards)
        curl -s -XGET 'http://192.168.0.179:9200/_cluster/health?pretty' |awk -F\, 'NR==8 {print $1}' |awk -F: '{print $2}' ;;
    relocating_shards)
        curl -s -XGET 'http://192.168.0.179:9200/_cluster/health?pretty' |awk -F\, 'NR==9 {print $1}' |awk -F: '{print $2}' ;;
    initializing_shards)
        curl -s -XGET 'http://192.168.0.179:9200/_cluster/health?pretty' |awk -F\, 'NR==10 {print $1}' |awk -F: '{print $2}' ;;
    unassigned_shards)
        curl -s -XGET 'http://192.168.0.179: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 和 Grafana 监控Elasticsearch集群相关指标_第1张图片
Zabbix 和 Grafana 监控Elasticsearch集群相关指标_第2张图片

Zabbix 和 Grafana 监控Elasticsearch集群相关指标_第3张图片

Zabbix 和 Grafana 监控Elasticsearch集群相关指标_第4张图片

4.Grafana监控看板

1).部署elasticsearch_exporter
	wget https://github.com/justwatchcom/elasticsearch_exporter/releases/download/v1.1.0/elasticsearch_exporter-1.1.0.linux-amd64.tar.gz
#启动exporter
nohup ./elasticsearch_exporter --es.all --es.indices --es.cluster_settings --es.indices_settings --es.shards --es.snapshots --es.timeout=30s --web.listen-address=":9114" --web.telemetry-path="/metrics" --es.uri http://192.168.0.179:9200 >/tmp/elasticsearch_exporter.log &

2):添加elasticsearch_exporter到promethus
   - job_name: 'elasticsearch'
    static_configs:
     - targets : ['192.168.0.179:9114','192.168.0.180:9114','192.168.0.152:9114','192.168.1.191:9114','192.168.1.48:9114','192.168.1.155:9114']

3):下载grafana 的elasticsearch模板并导入
	https://grafana.com/grafana/dashboards/6483

Zabbix 和 Grafana 监控Elasticsearch集群相关指标_第5张图片

4):效果图

Zabbix 和 Grafana 监控Elasticsearch集群相关指标_第6张图片
注意:很多模板数据可能无法显示,多尝试几个模板,我用的模板id是6483

你可能感兴趣的:(监控系统及应用)