diff --git a/elasticsearch/README.md b/elasticsearch/README.md new file mode 100644 index 0000000..4fdcc68 --- /dev/null +++ b/elasticsearch/README.md @@ -0,0 +1,13 @@ +# Elasticsearch for Zabbix 3.2 + +## install python3 + + # yum install -y python34 + + + # chmod +x /srv/zabbix/libexec/elasticsearch + + # /srv/zabbix/libexec/elasticsearch indices _all.total.flush.total_time_in_millis + 25557 + + diff --git a/elasticsearch/elasticsearch b/elasticsearch/elasticsearch new file mode 100644 index 0000000..3cf4a57 --- /dev/null +++ b/elasticsearch/elasticsearch @@ -0,0 +1,109 @@ +#!/usr/bin/env python3 +################################################## +# AUTHOR: Neo +# WEBSITE: http://www.netkiller.cn +# Description:zabbix 通过 status 模块监控 nginx +# Note:Zabbix 3.2 +# DateTime: 2016-11-22 +################################################## +try: + import time, json + import os, sys, errno + import logging, logging.handlers + #import configparser + from optparse import OptionParser, OptionGroup + #from urllib import + import urllib.request +except ImportError as err: + print("Error: %s" %(err)) + +class Elasticsearch(): + stats = { + 'cluster': 'http://localhost:9200/_cluster/stats', + 'nodes' : 'http://localhost:9200/_nodes/stats', + 'indices': 'http://localhost:9200/_stats', + 'health' : 'http://localhost:9200/_cluster/health' + } + + def __init__(self): + self.ttl = 60 + pass + + def lock(self,name): + try: + fd = os.open(name, os.O_WRONLY | os.O_CREAT | os.O_EXCL) + os.close(fd) + return True + except OSError as e: + if e.errno == errno.EEXIST: + return False + raise + def expire(self,key, ttl): + if not os.path.exists(key): + return True + elif (time.time() - os.path.getmtime(key)) > ttl: + return True + else: + return False + #return self.lock(key+".lock") + + def open(self, module): + text="" + json_obj = None + cache = '/tmp/elastizabbix-{0}.json'.format(module) + if self.expire(cache, self.ttl): + text = urllib.request.urlopen(self.stats[module]).read().decode("utf-8") + with open(cache, 'w') as f: f.write(text) + json_obj = json.loads(text) + else: + json_obj = json.load(open(cache)) + + return json_obj + + def get(self, module, keyworld): + json_obj = self.open(module); + keys = [] + for i in keyworld.split('.'): + keys.append(i) + key = '.'.join(keys) + if key in json_obj: + json_obj = json_obj.get(key) + keys = [] + return json_obj + + def discover(self,module): + d= {'data': []} + if module == 'nodes': + for k,v in self.get('nodes', 'nodes').items(): + d['data'].append({'{#NAME}': v['name'], '{#NODE}': k}) + + if module == "indices": + for k,v in self.get('indices', 'indices').items(): + d['data'].append({'{#NAME}': k}) + return json.dumps(d) + + + def main(self): + parser = OptionParser(usage='usage: %prog ', version="%prog 1.0.0", description='Elasticsearch for Zabbix') + (options, args) = parser.parse_args() + + if not len(args) == 2: + parser.print_help() + sys.exit(1) + + module = args[0] + keyword = args[1] + + if module in self.stats.keys(): + print(self.get(module, keyword)) + elif module == "discover": + print(self.discover(keyword)) + else: + parser.print_help() + +if __name__ == '__main__': + try: + elastic = Elasticsearch() + elastic.main() + except KeyboardInterrupt: + print ("Crtl+C Pressed. Shutting down.") diff --git a/elasticsearch/userparameter_elasticsearch.conf b/elasticsearch/userparameter_elasticsearch.conf new file mode 100644 index 0000000..2e7e373 --- /dev/null +++ b/elasticsearch/userparameter_elasticsearch.conf @@ -0,0 +1,11 @@ +############################################################ +# Elasticsearch - statistics +# +# Author: Neo Chen +# Website: http://www.netkiller.cn +############################################################ + +# Discovery + +# Return statistics +UserParameter=elasticsearch.status[*],/srv/zabbix/libexec/elasticsearch $1 $2 \ No newline at end of file diff --git a/elasticsearch/zbx_export_templates.xml b/elasticsearch/zbx_export_templates.xml new file mode 100644 index 0000000..c0bc22b --- /dev/null +++ b/elasticsearch/zbx_export_templates.xml @@ -0,0 +1,4184 @@ + + + 3.2 + 2016-11-28T15:20:00Z + + + Templates + + + + + + + + {Template App Elasticsearch:elasticsearch.status[health,status].str(red)}=1 + Elasticsearch Cluster Status is Red + + 0 + 4 + + 0 + + 0 + + 0 + + 0 + + + + {Template App Elasticsearch:elasticsearch.status[health,status].str(yellow)}=1 + Elasticsearch Cluster Status is Yellow + + 0 + 2 + + 0 + + 0 + + 0 + + 0 + + + + {Template App Elasticsearch:elasticsearch.status[health,unassigned_shards].last()}>0 + Unassigned Shards + + 0 + 2 + + 0 + + 0 + + 0 + + 0 + + + + + + Cluster Nodes + 900 + 200 + 0.0000 + 100.0000 + 1 + 1 + 0 + 1 + 0 + 0.0000 + 0.0000 + 1 + 0 + 0 + 0 + + + 0 + 4 + 000000 + 0 + 2 + 0 + + Template App Elasticsearch + elasticsearch.status[cluster,nodes.count.total] + + + + 1 + 1 + 0000DD + 0 + 2 + 0 + + Template App Elasticsearch + elasticsearch.status[cluster,nodes.count.data_only] + + + + + + Doc index rate + 900 + 200 + 0.0000 + 100.0000 + 1 + 1 + 0 + 1 + 0 + 0.0000 + 0.0000 + 0 + 0 + 0 + 0 + + + 0 + 0 + 00C800 + 0 + 2 + 0 + + Template App Elasticsearch + elasticsearch.status[cluster,indices.docs.count] + + + + + + Field data performance + 900 + 200 + 0.0000 + 100.0000 + 1 + 1 + 0 + 1 + 0 + 0.0000 + 0.0000 + 0 + 0 + 0 + 0 + + + 0 + 0 + C80000 + 0 + 2 + 0 + + Template App Elasticsearch + elasticsearch.status[cluster,indices.fielddata.memory_size_in_bytes] + + + + 1 + 0 + 00C800 + 0 + 2 + 0 + + Template App Elasticsearch + elasticsearch.status[cluster,indices.fielddata.evictions] + + + + + + Filter cache performance + 900 + 200 + 0.0000 + 100.0000 + 1 + 1 + 0 + 1 + 0 + 0.0000 + 0.0000 + 0 + 0 + 0 + 0 + + + 0 + 0 + C80000 + 0 + 2 + 0 + + Template App Elasticsearch + elasticsearch.status[cluster,indices.filter_cache.memory_size_in_bytes] + + + + 1 + 0 + 00C800 + 0 + 2 + 0 + + Template App Elasticsearch + elasticsearch.status[cluster,indices.filter_cache.evictions] + + + + + + Index Latency + 900 + 200 + 0.0000 + 100.0000 + 1 + 1 + 0 + 1 + 0 + 0.0000 + 0.0000 + 0 + 0 + 0 + 0 + + + 0 + 0 + 00C800 + 0 + 2 + 0 + + Template App Elasticsearch + elasticsearch.status[indices,_all.total.flush.total_time_in_millis] + + + + 1 + 0 + C80000 + 0 + 2 + 0 + + Template App Elasticsearch + elasticsearch.status[indices,_all.total.get.time_in_millis] + + + + 2 + 0 + 0000C8 + 0 + 2 + 0 + + Template App Elasticsearch + elasticsearch.status[indices,_all.total.indexing.index_time_in_millis] + + + + 3 + 0 + C800C8 + 0 + 2 + 0 + + Template App Elasticsearch + elasticsearch.status[indices,_all.total.merges.total_time_in_millis] + + + + 4 + 0 + 00C8C8 + 0 + 2 + 0 + + Template App Elasticsearch + elasticsearch.status[indices,_all.total.refresh.total_time_in_millis] + + + + 5 + 0 + C8C800 + 0 + 2 + 0 + + Template App Elasticsearch + elasticsearch.status[indices,_all.total.search.query_time_in_millis] + + + + + + Index Operations + 900 + 200 + 0.0000 + 100.0000 + 1 + 1 + 0 + 1 + 0 + 0.0000 + 0.0000 + 0 + 0 + 0 + 0 + + + 0 + 0 + 00C800 + 0 + 2 + 0 + + Template App Elasticsearch + elasticsearch.status[indices,_all.total.flush.total] + + + + 1 + 0 + C80000 + 0 + 2 + 0 + + Template App Elasticsearch + elasticsearch.status[indices,_all.total.get.total] + + + + 2 + 0 + 0000C8 + 0 + 2 + 0 + + Template App Elasticsearch + elasticsearch.status[indices,_all.total.indexing.index_total] + + + + 3 + 0 + C800C8 + 0 + 2 + 0 + + Template App Elasticsearch + elasticsearch.status[indices,_all.total.merges.total] + + + + 4 + 0 + 00C8C8 + 0 + 2 + 0 + + Template App Elasticsearch + elasticsearch.status[indices,_all.total.refresh.total] + + + + 5 + 0 + C8C800 + 0 + 2 + 0 + + Template App Elasticsearch + elasticsearch.status[indices,_all.total.search.query_total] + + + + + + Query Performance + 900 + 200 + 0.0000 + 100.0000 + 1 + 1 + 0 + 1 + 0 + 0.0000 + 0.0000 + 0 + 0 + 0 + 0 + + + 1 + 0 + C80000 + 0 + 2 + 0 + + Template App Elasticsearch + elasticsearch.status[indices,_all.total.search.query_total] + + + + + + Shard Movement + 900 + 200 + 0.0000 + 100.0000 + 1 + 1 + 1 + 1 + 0 + 0.0000 + 0.0000 + 0 + 0 + 0 + 0 + + + 1 + 0 + 00CCCC + 0 + 2 + 0 + + Template App Elasticsearch + elasticsearch.status[health,initializing_shards] + + + + 2 + 0 + 00DD00 + 0 + 2 + 0 + + Template App Elasticsearch + elasticsearch.status[health,relocating_shards] + + + + 0 + 0 + CC00CC + 0 + 2 + 0 + + Template App Elasticsearch + elasticsearch.status[health,unassigned_shards] + + + + + + \ No newline at end of file