zabbix 監控ElasticSearch
阿新 • • 發佈:2017-05-10
zabbix elasticsearch
使用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 status UserParameter=estic.timed_out,/bin/sh /scripts/elastic_zabbix.sh timed_out UserParameter=estic.number_of_nodes,/bin/sh /scripts/elastic_zabbix.sh number_of_nodes UserParameter=estic.number_of_data_nodes,/bin/sh /scripts/elastic_zabbix.sh number_of_data_nodes UserParameter=estic.active_primary_shards,/bin/sh /scripts/elastic_zabbix.sh active_primary_shards UserParameter=estic.active_shards,/bin/sh /scripts/elastic_zabbix.sh active_shards UserParameter=estic.relocating_shards,/bin/sh /scripts/elastic_zabbix.sh relocating_shards UserParameter=estic.initializing_shards,/bin/sh /scripts/elastic_zabbix.sh initializing_shards UserParameter=estic.unassigned_shards,/bin/sh /scripts/elastic_zabbix.sh unassigned_shards UserParameter=estic.delayed_unassigned_shards,/bin/sh /scripts/elastic_zabbix.sh delayed_unassigned_shards UserParameter=estic.number_of_pending_tasks,/bin/sh /scripts/elastic_zabbix.sh number_of_pending_tasks UserParameter=estic.number_of_in_flight_fetch,/bin/sh /scripts/elastic_zabbix.sh number_of_in_flight_fetch UserParameter=estic.task_max_waiting_in_queue_millis,/bin/sh /scripts/elastic_zabbix.sh task_max_waiting_in_queue_millis UserParameter=estic.active_shards_percent_as_number,/bin/sh /scripts/elastic_zabbix.sh active_shards_percent_as_number
執行腳本可以放在自定義的目錄中,和上面定義的參數對應:
cat /scripts/elastic_zabbix.sh #!/bin/bash URL="192.168.1.22:9200/_cluster/health" ESstatus="`curl -s -XGET $URL`" #echo $ESstatus status=`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監控模板,可以根據自己的需要進行修改:
<?xml version="1.0" encoding="UTF-8"?> <zabbix_export> <version>3.2</version> <date>2017-05-10T07:40:20Z</date> <groups> <group> <name>Templates</name> </group> </groups> <templates> <template> <template>Template Elastic Search</template> <name>Template Elastic Search</name> <description/> <groups> <group> <name>Templates</name> </group> </groups> <applications> <application> <name>Elasticsearch healthcheck</name> </application> </applications> <items> <item> <name>estic.active_primary_shards</name> <type>0</type> <snmp_community/> <multiplier>1</multiplier> <snmp_oid/> <key>estic.active_primary_shards</key> <delay>300</delay> <history>30</history> <trends>30</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 healthcheck</name> </application> </applications> <valuemap/> <logtimefmt/> </item> <item> <name>estic.active_shards</name> <type>0</type> <snmp_community/> <multiplier>1</multiplier> <snmp_oid/> <key>estic.active_shards</key> <delay>300</delay> <history>30</history> <trends>30</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 healthcheck</name> </application> </applications> <valuemap/> <logtimefmt/> </item> <item> <name>estic.active_shards_percent_as_number</name> <type>0</type> <snmp_community/> <multiplier>1</multiplier> <snmp_oid/> <key>estic.active_shards_percent_as_number</key> <delay>300</delay> <history>30</history> <trends>30</trends> <status>0</status> <value_type>0</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 healthcheck</name> </application> </applications> <valuemap/> <logtimefmt/> </item> <item> <name>estic.delayed_unassigned_shards</name> <type>0</type> <snmp_community/> <multiplier>1</multiplier> <snmp_oid/> <key>estic.delayed_unassigned_shards</key> <delay>300</delay> <history>30</history> <trends>30</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 healthcheck</name> </application> </applications> <valuemap/> <logtimefmt/> </item> <item> <name>estic.initializing_shards</name> <type>0</type> <snmp_community/> <multiplier>1</multiplier> <snmp_oid/> <key>estic.initializing_shards</key> <delay>300</delay> <history>30</history> <trends>30</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 healthcheck</name> </application> </applications> <valuemap/> <logtimefmt/> </item> <item> <name>estic.number_of_data_nodes</name> <type>0</type> <snmp_community/> <multiplier>1</multiplier> <snmp_oid/> <key>estic.number_of_data_nodes</key> <delay>300</delay> <history>30</history> <trends>30</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 healthcheck</name> </application> </applications> <valuemap/> <logtimefmt/> </item> <item> <name>estic.number_of_in_flight_fetch</name> <type>0</type> <snmp_community/> <multiplier>1</multiplier> <snmp_oid/> <key>estic.number_of_in_flight_fetch</key> <delay>300</delay> <history>30</history> <trends>30</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 healthcheck</name> </application> </applications> <valuemap/> <logtimefmt/> </item> <item> <name>estic.number_of_nodes</name> <type>0</type> <snmp_community/> <multiplier>1</multiplier> <snmp_oid/> <key>estic.number_of_nodes</key> <delay>300</delay> <history>30</history> <trends>30</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 healthcheck</name> </application> </applications> <valuemap/> <logtimefmt/> </item> <item> <name>estic.number_of_pending_tasks</name> <type>0</type> <snmp_community/> <multiplier>0</multiplier> <snmp_oid/> <key>estic.number_of_pending_tasks</key> <delay>300</delay> <history>30</history> <trends>30</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 healthcheck</name> </application> </applications> <valuemap/> <logtimefmt/> </item> <item> <name>estic.relocating_shards</name> <type>0</type> <snmp_community/> <multiplier>1</multiplier> <snmp_oid/> <key>estic.relocating_shards</key> <delay>300</delay> <history>30</history> <trends>30</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 healthcheck</name> </application> </applications> <valuemap/> <logtimefmt/> </item> <item> <name>estic.status</name> <type>0</type> <snmp_community/> <multiplier>0</multiplier> <snmp_oid/> <key>estic.status</key> <delay>300</delay> <history>30</history> <trends>0</trends> <status>0</status> <value_type>1</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 healthcheck</name> </application> </applications> <valuemap/> <logtimefmt/> </item> <item> <name>estic.task_max_waiting_in_queue_millis</name> <type>0</type> <snmp_community/> <multiplier>1</multiplier> <snmp_oid/> <key>estic.task_max_waiting_in_queue_millis</key> <delay>300</delay> <history>30</history> <trends>30</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 healthcheck</name> </application> </applications> <valuemap/> <logtimefmt/> </item> <item> <name>estic.timed_out</name> <type>0</type> <snmp_community/> <multiplier>0</multiplier> <snmp_oid/> <key>estic.timed_out</key> <delay>300</delay> <history>30</history> <trends>0</trends> <status>0</status> <value_type>1</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 healthcheck</name> </application> </applications> <valuemap/> <logtimefmt/> </item> <item> <name>estic.unassigned_shards</name> <type>0</type> <snmp_community/> <multiplier>1</multiplier> <snmp_oid/> <key>estic.unassigned_shards</key> <delay>300</delay> <history>30</history> <trends>30</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 healthcheck</name> </application> </applications> <valuemap/> <logtimefmt/> </item> </items> <discovery_rules/> <httptests/> <macros/> <templates/> <screens/> </template> </templates> <triggers> <trigger> <expression>{Template Elastic Search:estic.status.str("\"green\"")}=0</expression> <recovery_mode>0</recovery_mode> <recovery_expression/> <name>elastic is down</name> <correlation_mode>0</correlation_mode> <correlation_tag/> <url/> <status>0</status> <priority>3</priority> <description/> <type>0</type> <manual_close>1</manual_close> <dependencies/> <tags/> </trigger> </triggers> <graphs> <graph> <name>estic.number_of_pending_tasks</name> <width>900</width> <height>200</height> <yaxismin>0.0000</yaxismin> <yaxismax>100.0000</yaxismax> <show_work_period>1</show_work_period> <show_triggers>1</show_triggers> <type>0</type> <show_legend>1</show_legend> <show_3d>0</show_3d> <percent_left>0.0000</percent_left> <percent_right>0.0000</percent_right> <ymin_type_1>0</ymin_type_1> <ymax_type_1>0</ymax_type_1> <ymin_item_1>0</ymin_item_1> <ymax_item_1>0</ymax_item_1> <graph_items> <graph_item> <sortorder>0</sortorder> <drawtype>0</drawtype> <color>1A7C11</color> <yaxisside>0</yaxisside> <calc_fnc>2</calc_fnc> <type>0</type> <item> <host>Template Elastic Search</host> <key>estic.active_primary_shards</key> </item> </graph_item> <graph_item> <sortorder>1</sortorder> <drawtype>0</drawtype> <color>F63100</color> <yaxisside>0</yaxisside> <calc_fnc>2</calc_fnc> <type>0</type> <item> <host>Template Elastic Search</host> <key>estic.active_shards</key> </item> </graph_item> <graph_item> <sortorder>2</sortorder> <drawtype>0</drawtype> <color>2774A4</color> <yaxisside>0</yaxisside> <calc_fnc>2</calc_fnc> <type>0</type> <item> <host>Template Elastic Search</host> <key>estic.number_of_data_nodes</key> </item> </graph_item> <graph_item> <sortorder>3</sortorder> <drawtype>0</drawtype> <color>A54F10</color> <yaxisside>0</yaxisside> <calc_fnc>2</calc_fnc> <type>0</type> <item> <host>Template Elastic Search</host> <key>estic.number_of_nodes</key> </item> </graph_item> </graph_items> </graph> </graphs> </zabbix_export>
本文出自 “Trying” 博客,請務必保留此出處http://tryingstuff.blog.51cto.com/4603492/1924155
zabbix 監控ElasticSearch