脚本文件:

#!/usr/bin/env python
import datetime
import time
import urllib
import json
import urllib2
import os
import sys # ElasticSearch Cluster to Monitor
elasticServer = os.environ.get('ES_METRICS_CLUSTER_URL', 'http://10.80.2.83:9200')
interval = 60 # ElasticSearch Cluster to Send Metrics
elasticIndex = os.environ.get('ES_METRICS_INDEX_NAME', 'elasticsearch_metrics')
elasticMonitoringCluster = os.environ.get('ES_METRICS_MONITORING_CLUSTER_URL', 'http://10.80.2.83:9200') def fetch_clusterhealth():
utc_datetime = datetime.datetime.utcnow()
endpoint = "/_cluster/health"
urlData = elasticServer + endpoint
response = urllib.urlopen(urlData)
jsonData = json.loads(response.read())
clusterName = jsonData['cluster_name']
jsonData['@timestamp'] = str(utc_datetime.strftime('%Y-%m-%dT%H:%M:%S.%f')[:-3])
post_data(jsonData)
return clusterName def fetch_clusterstats():
utc_datetime = datetime.datetime.utcnow()
endpoint = "/_cluster/stats"
urlData = elasticServer + endpoint
response = urllib.urlopen(urlData)
jsonData = json.loads(response.read())
jsonData['@timestamp'] = str(utc_datetime.strftime('%Y-%m-%dT%H:%M:%S.%f')[:-3])
post_data(jsonData) def fetch_nodestats(clusterName):
utc_datetime = datetime.datetime.utcnow()
endpoint = "/_cat/nodes?v&h=n"
urlData = elasticServer + endpoint
response = urllib.urlopen(urlData)
nodes = response.read()[1:-1].strip().split('\n')
for node in nodes:
endpoint = "/_nodes/%s/stats" % node.rstrip()
urlData = elasticServer + endpoint
response = urllib.urlopen(urlData)
jsonData = json.loads(response.read())
nodeID = jsonData['nodes'].keys()
jsonData['nodes'][nodeID[0]]['@timestamp'] = str(utc_datetime.strftime('%Y-%m-%dT%H:%M:%S.%f')[:-3])
jsonData['nodes'][nodeID[0]]['cluster_name'] = clusterName
newJsonData = jsonData['nodes'][nodeID[0]]
post_data(newJsonData) def fetch_indexstats(clusterName):
utc_datetime = datetime.datetime.utcnow()
endpoint = "/_stats"
urlData = elasticServer + endpoint
response = urllib.urlopen(urlData)
jsonData = json.loads(response.read())
jsonData['_all']['@timestamp'] = str(utc_datetime.strftime('%Y-%m-%dT%H:%M:%S.%f')[:-3])
jsonData['_all']['cluster_name'] = clusterName
post_data(jsonData['_all']) def post_data(data):
utc_datetime = datetime.datetime.utcnow()
url_parameters = {
'cluster': elasticMonitoringCluster,
'index': elasticIndex,
'index_period': utc_datetime.strftime("%Y.%m.%d"),
}
url = "%(cluster)s/%(index)s-%(index_period)s/message" % url_parameters
headers = {'content-type': 'application/json'}
try:
req = urllib2.Request(url, headers=headers, data=json.dumps(data))
f = urllib2.urlopen(req)
except Exception as e:
print "Error: {}".format(str(e)) def main():
clusterName = fetch_clusterhealth()
fetch_clusterstats()
fetch_nodestats(clusterName)
fetch_indexstats(clusterName) if __name__ == '__main__':
try:
nextRun = 0
while True:
if time.time() >= nextRun:
nextRun = time.time() + interval
now = time.time()
main()
elapsed = time.time() - now
print "Total Elapsed Time: %s" % elapsed
timeDiff = nextRun - time.time()
time.sleep(timeDiff)
except KeyboardInterrupt:
print 'Interrupted'
try:
sys.exit(0)
except SystemExit:
os._exit(0)

es_monitor.py

grafana面板导出的json文件:

http://files.cnblogs.com/files/xiaoming279/es_monitor.zip

界面如下:

Elasticsearch集群状态脚本及grafana监控面板导出的json文件的更多相关文章

  1. grafana日志分析界面及导出的json文件

    日志分析面板导出的json文件,效果图如下: 下载地址:http://files.cnblogs.com/files/xiaoming279/%E9%9D%A2%E6%9D%BF.zip 主机面板 主 ...

  2. zabbix通过简单命令监控elasticsearch集群状态

    简单命令监控elasticsearch集群状态 原理: 使用curl命令模拟访问任意一个es节点可以反馈的集群状态,集群的状态需要为green curl -sXGET http://serverip: ...

  3. zabbix通过简单shell命令监控elasticsearch集群状态

    简单命令监控elasticsearch集群状态 原理: 使用curl命令模拟访问任意一个es节点可以反馈的集群状态,集群的状态需要为green curl -sXGET http://serverip: ...

  4. 如何监控 Elasticsearch 集群状态?

    Marvel 让你可以很简单的通过 Kibana 监控 Elasticsearch.你可以实时查看你 的集群健康状态和性能,也可以分析过去的集群.索引和节点指标.

  5. 050.集群管理-Prometheus+Grafana监控方案

    一 Prometheus概述 1.1 Prometheus简介 Prometheus是由SoundCloud公司开发的开源监控系统,是继Kubernetes之后CNCF第2个毕业的项目,在容器和微服务 ...

  6. Elasticsearch集群状态健康值处于red状态问题分析与解决(图文详解)

      问题详情 我的es集群,开启后,都好久了,一直报red状态??? 问题分析 有两个分片数据好像丢了.   不知道你这数据怎么丢的. 确认下本地到底还有没有,本地要是确认没了,那数据就丢了,删除索引 ...

  7. 处理存在UNASSIGNED的主分片导致Elasticsearch集群状态为Red的问题

    我们默认是开启了自动分配的,但仍然会因为服务器软硬件的原因导致分配分配失败,从而出现UNASSIGNED的分片,如果存在该状态的主分片则会导致集群为Red状态.此时我们可以通过reroute API进 ...

  8. ElasticSearch集群状态查看命令大全

    Elasticsearch中信息很多,同时ES也有很多信息查看命令,可以帮助开发者快速查询Elasticsearch的相关信息. _cat $ curl localhost:9200/_cat =^. ...

  9. ElasticSearch集群状态查看命令大全(转)

    原文地址: https://blog.csdn.net/pilihaotian/article/details/52460747 Elasticsearch中信息很多,同时ES也有很多信息查看命令,可 ...

随机推荐

  1. SQL SERVER 2000 迁移后SQL SERVER代理服务启动错误分析

    公司有一个老系统,这个系统所用的数据库是SQL SERVER 2000,它所在的Dell服务器已经运行超过10年了,早已经过了保修服务期,最近几乎每周会出现一次故障,加之5月份另外一台服务器坏了两个硬 ...

  2. C++ 重载、重写、重定义

    出自:http://blog.163.com/clevertanglei900@126/blog/ 1 成员函数重载特征: a 相同的范围(在同一个类中) b 函数名字相同 c 参数不同 d virt ...

  3. ELF Format 笔记(十)—— 重定位(relocation)

    ilocker:关注 Android 安全(新手) QQ: 2597294287 重定位就是把符号引用与符号定义链接起来的过程,这也是 android linker 的主要工作之一. 当程序中调用一个 ...

  4. 【转】iframe和父页,window.open打开页面之间的引用

    [转]iframe和父页,window.open打开页面之间的引用 iframe和父页,window.open打开页面和被打开页面之间的关系可以通过下面的对象获取到 1)通过iframe加载的,在if ...

  5. 【转】能否用讲个故事的方式,由浅入深,通俗易懂地解释一下什么是天使投资,VC,PE.

    能否用讲个故事的方式,由浅入深,通俗易懂地解释一下什么是天使投资,VC,PE 今天在知乎上看到一篇文章,觉得值得一转的,Here. 我给楼主讲个完整点的故事吧.长文慎点,前方高能,自备避雷针.18岁以 ...

  6. 如何捕捉并分析SIGSEGV的现场

    linux下程序对SIGSEGV信号的默认处理方式是产生coredump并终止程序,可以参考man 7 signal Signal Value Action Comment ───────────── ...

  7. Excel自文本导入内容时如何做到单元格内换行

    前言:今天在处理数据的时候,在数据库中用到了\n换行符号,目的是在同表格内做到数据多行显示,比如  字段名1  字段名2  字段名3  1 数据一行 数据二行 数据三行 例子是在sql查询后的结果  ...

  8. Java Generics and Collections-8.1

    8.1 Take Care when Calling Legacy Code 通常,泛型都是在编译时检查的,而不是运行时.便意识检查可以提早通知错误,而不至于到运行时才出问题. 但有时后编译时检查不一 ...

  9. AWS S3 CLI的权限bug

    使用AWS CLI在S3上创建了一个bucket,上传文件的时候报以下错误: A client error (AccessDenied) occurred when calling the Creat ...

  10. 让那些为Webkit优化的网站也能适配IE10

    特别声明:此篇文章由David根据Charles Morris的英文文章原名<Adapting your WebKit-optimized site for Internet Explorer ...