博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
zabbix 监控 ElasticSearch
阅读量:2228 次
发布时间:2019-05-09

本文共 2235 字,大约阅读时间需要 7 分钟。

ElasticSearch  可以直接使用zabbix官方的模板

模板地址:

 

通过zabbix server 直接监控

1、下载模板文件导入模板

2、把模板关联到zabbix server

3、添加自定义KEY

 

vim /etc/zabbix/scripts/elastizabbix.py#!/usr/bin/pythonimport osimport sysimport jsonimport urllib2import timeimport errnottl = 60stats = {'cluster': 'http://elasticsearch.xxx.cn:19200/_cluster/stats','nodes' : 'http://elasticsearch.xxx.cn:19200/_nodes/stats','indices': 'http://elasticsearch.xxx.cn:19200/_stats','health' : 'http://elasticsearch.xxx.cn:19200/_cluster/health'}def created_file(name):try:fd = os.open(name, os.O_WRONLY | os.O_CREAT | os.O_EXCL)os.close(fd)return Trueexcept OSError, e:if e.errno == errno.EEXIST:return Falseraisedef is_older_then(name, ttl):age = time.time() - os.path.getmtime(name)return age > ttldef get_cache(api):cache = '/tmp/elastizabbix-{0}.json'.format(api)lock = '/tmp/elastizabbix-{0}.lock'.format(api)should_update = (not os.path.exists(cache)) or is_older_then(cache, ttl)if should_update and created_file(lock):try:d = urllib2.urlopen(stats[api]).read()with open(cache, 'w') as f: f.write(d)except Exception as e:passif os.path.exists(lock):os.remove(lock)if os.path.exists(lock) and is_older_then(lock, 300):os.remove(lock)ret_data = {}try:with open(cache) as data_file:ret_data = json.load(data_file)except Exception as e:ret_data = json.loads(urllib2.urlopen(stats[api]).read())return ret_datadef get_stat(api, stat):d = get_cache(api)keys = []for i in stat.split('.'):keys.append(i)key = '.'.join(keys)if key in d:d = d.get(key)keys = []return ddef discover_nodes():d = {
'data': []}for k,v in get_stat('nodes', 'nodes').iteritems():d['data'].append({
'{#NAME}': v['name'], '{#NODE}': k})return json.dumps(d)def discover_indices():d = {
'data': []}for k,v in get_stat('indices', 'indices').iteritems():d['data'].append({
'{#NAME}': k})return json.dumps(d)if __name__ == '__main__':api = sys.argv[1]stat = sys.argv[2]if api == 'discover':if stat == 'nodes':print discover_nodes()if stat == 'indices':print discover_indices()else:stat = get_stat(api, stat)if isinstance(stat, dict):print ''else:print stat

 

vim /etc/zabbix/zabbix_agentd.d/es.confUserParameter=elastizabbix[*],/etc/zabbix/scripts/elastizabbix.py $1 $2

  

 

转载于:https://www.cnblogs.com/37yan/p/7095853.html

你可能感兴趣的文章
【数据结构】栈的简单理解以及对栈的基本操作
查看>>
【数据结构】简单不带环迷宫的实现(用栈实现)
查看>>
【C语言】简单的了解递归(求斐波那契,n的阶乘,字符串长度,把一个整型(无符号),转化为字符型并打印出来)
查看>>
【数据结构】动态栈的实现
查看>>
【数据结构】简单的迷宫(用递归实现)
查看>>
【数据结构】队列的基本认识和队列的基本操作
查看>>
【数据结构】循环队列的认识和基本操作
查看>>
【LeetCode】无重复字符的最长子串
查看>>
时间复杂度
查看>>
【C++】动态内存管理 new和delete的理解
查看>>
【Linux】了解根目录下每个文件的作用
查看>>
【Linux】进程的理解(一)
查看>>
【Linux】进程的理解(二)
查看>>
【C语言】深度理解函数的调用(栈帧)
查看>>
【Linux】进程的理解(三)
查看>>
【C++】带头节点的双向线链表的实现
查看>>
【C++】STL -- Vector容器的用法
查看>>
【Linux】Linux中的0644 和 0755的权限
查看>>
【数据结构】有关二叉树的面试题
查看>>
【Linux】内核态和用户态
查看>>