zabbix監控elasticsearch集羣

  1. 監控腳本如下:zabbix_monitor_elasticsearch.py . 這裏需要指定elasticsearch的主機IP

#!/usr/bin/env python
# Rewrite by Wilson Luiz Prosdocimo
# Based on https://github.com/serialsito/Elasticsearch-zabbix
from elasticsearch import *
import sys
# Define the fail message
def zbx_fail():
    print "ZBX_NOTSUPPORTED"
    sys.exit(2)
# Define groups of keys
searchkeys = ['query_total', 'fetch_time_in_millis', 'fetch_total', 'fetch_time', 'query_current', 'fetch_current', 'query_time_in_millis']
getkeys = ['missing_total', 'exists_total', 'current', 'time_in_millis', 'missing_time_in_millis', 'exists_time_in_millis', 'total']
docskeys = ['count', 'deleted']
indexingkeys = ['delete_time_in_millis', 'index_total', 'index_current', 'delete_total', 'index_time_in_millis', 'delete_current']
storekeys = ['size_in_bytes', 'throttle_time_in_millis']
cachekeys = ['filter_size_in_bytes', 'field_size_in_bytes', 'field_evictions']
jvmkeys = ['heap_used_percent']
clusterkeys = searchkeys + getkeys + docskeys + indexingkeys + storekeys
returnval = None
# __main__
# We need to have two command-line args:
# sys.argv[1]: The node name or "cluster"
# sys.argv[2]: The "key" (status, filter_size_in_bytes, etc)
if len(sys.argv) < 3:
    zbx_fail()
# Try to establish a connection to elasticsearch
try:
    conn = Elasticsearch(request_timeout=25)
    conn = Elasticsearch([{'host':'192.168.0.138','port':'9200','request_timeout':'25'}])
except Exception, e:
    zbx_fail()
if sys.argv[1] == 'cluster':
    if sys.argv[2] in clusterkeys:
        nodestats = conn.nodes.stats()
        subtotal = 0
        for nodename in nodestats[u'nodes']:
            if sys.argv[2] in indexingkeys:
                indexstats = nodestats[u'nodes'][nodename][u'indices'][u'indexing']
            elif sys.argv[2] in storekeys:
                indexstats = nodestats[u'nodes'][nodename][u'indices'][u'store']
            elif sys.argv[2] in getkeys:
                indexstats = nodestats[u'nodes'][nodename][u'indices'][u'get']
            elif sys.argv[2] in docskeys:
                indexstats = nodestats[u'nodes'][nodename][u'indices'][u'docs']
            elif sys.argv[2] in searchkeys:
                indexstats = nodestats[u'nodes'][nodename][u'indices'][u'search']
            try:
                subtotal += indexstats[sys.argv[2]]
            except Exception, e:
                pass
        returnval = subtotal
    else:
        # Try to get a value to match the key provided
        try:
            returnval = conn.cluster.health()[unicode(sys.argv[2])]
        except Exception, e:
            zbx_fail()
        # If the key is "status" then we need to map that to an integer
        if sys.argv[2] == 'status':
            if returnval == 'green':
                returnval = 1
            elif returnval == 'yellow':
                returnval = 2
            elif returnval == 'red':
                returnval = 3
            else:
                zbx_fail()
# Mod to check if ES service is up
elif sys.argv[1] == 'service':
    if sys.argv[2] == 'status':
        try:
            conn.ping()
            returnval = 1
        except Exception, e:
            returnval = 0
else: # Not clusterwide, check the next arg
    nodestats = conn.nodes.stats()
    for nodename in nodestats[u'nodes']:
        if sys.argv[1] in nodestats[u'nodes'][nodename][u'name']:
            if sys.argv[2] in indexingkeys:
                stats = nodestats[u'nodes'][nodename][u'indices'][u'indexing']
            elif sys.argv[2] in storekeys:
                stats = nodestats[u'nodes'][nodename][u'indices'][u'store']
            elif sys.argv[2] in getkeys:
                stats = nodestats[u'nodes'][nodename][u'indices'][u'get']
            elif sys.argv[2] in docskeys:
                stats = nodestats[u'nodes'][nodename][u'indices'][u'docs']
            elif sys.argv[2] in searchkeys:
                stats = nodestats[u'nodes'][nodename][u'indices'][u'search']
            elif sys.argv[2] in jvmkeys:
                stats = nodestats[u'nodes'][nodename][u'jvm'][u'mem']
            try:
                returnval = stats[unicode(sys.argv[2])]
            except Exception, e:
                pass
# If we somehow did not get a value here, that's a problem.  Send back the standard
# ZBX_NOTSUPPORTED
if returnval is None:
    zbx_fail()
else:
    print returnval

2.編寫zabbix_agentd.conf

UserParameter=ESzabbix[*],/usr/local/zabbix/etc/scripts/ESzabbix.py $1 $2

3.編寫item

wKioL1c5Pm_hX2AmAASIiM4Rbns781.jpg

wKioL1c5PnKQEaF6AAMGFzqeXz4082.jpg

wKiom1c5PY-wtaetAASbSY1Mtlw225.jpg

wKioL1c5Pn6SZ1VSAArymzA7lYQ306.jpg

4.或者上傳附件的3個模板

5.創建全局mapping對應關係

Administration---General----Value Mapping

wKioL1c5P_bTT-4MAABhOilN8q0128.jpg

6.創建每個主機的局部宏變量

Configureation----》Host---》Macro

wKioL1c5QOyjW63PAAIHIJqHBEk636.jpg


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章