Elasticsearch集群状态脚本及grafana监控面板导出的json文件
脚本文件:
#!/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文件的更多相关文章
- grafana日志分析界面及导出的json文件
日志分析面板导出的json文件,效果图如下: 下载地址:http://files.cnblogs.com/files/xiaoming279/%E9%9D%A2%E6%9D%BF.zip 主机面板 主 ...
- zabbix通过简单命令监控elasticsearch集群状态
简单命令监控elasticsearch集群状态 原理: 使用curl命令模拟访问任意一个es节点可以反馈的集群状态,集群的状态需要为green curl -sXGET http://serverip: ...
- zabbix通过简单shell命令监控elasticsearch集群状态
简单命令监控elasticsearch集群状态 原理: 使用curl命令模拟访问任意一个es节点可以反馈的集群状态,集群的状态需要为green curl -sXGET http://serverip: ...
- 如何监控 Elasticsearch 集群状态?
Marvel 让你可以很简单的通过 Kibana 监控 Elasticsearch.你可以实时查看你 的集群健康状态和性能,也可以分析过去的集群.索引和节点指标.
- 050.集群管理-Prometheus+Grafana监控方案
一 Prometheus概述 1.1 Prometheus简介 Prometheus是由SoundCloud公司开发的开源监控系统,是继Kubernetes之后CNCF第2个毕业的项目,在容器和微服务 ...
- Elasticsearch集群状态健康值处于red状态问题分析与解决(图文详解)
问题详情 我的es集群,开启后,都好久了,一直报red状态??? 问题分析 有两个分片数据好像丢了. 不知道你这数据怎么丢的. 确认下本地到底还有没有,本地要是确认没了,那数据就丢了,删除索引 ...
- 处理存在UNASSIGNED的主分片导致Elasticsearch集群状态为Red的问题
我们默认是开启了自动分配的,但仍然会因为服务器软硬件的原因导致分配分配失败,从而出现UNASSIGNED的分片,如果存在该状态的主分片则会导致集群为Red状态.此时我们可以通过reroute API进 ...
- ElasticSearch集群状态查看命令大全
Elasticsearch中信息很多,同时ES也有很多信息查看命令,可以帮助开发者快速查询Elasticsearch的相关信息. _cat $ curl localhost:9200/_cat =^. ...
- ElasticSearch集群状态查看命令大全(转)
原文地址: https://blog.csdn.net/pilihaotian/article/details/52460747 Elasticsearch中信息很多,同时ES也有很多信息查看命令,可 ...
随机推荐
- javax.net.ssl.SSLHandshakeException(Cas导入证书)
一.报错: javax.net.ssl.SSLHandshakeException二.原因分析:CAS部署时,常常要涉及到HTTPS的证书发布问题.由于在实验环境中,CAS和应用服务常常是共用一台PC ...
- WinForm登陆:窗体间的数据传递
1. 登陆逻辑 FrmMain 为主窗体(启动窗体) FrmLogin 为登陆窗体 在“主窗体”中使用ShowDialog()方法显示“登陆窗体”,并通过“登陆窗体”的DialogResult告知“主 ...
- jni调试3(线程调试env变量问题)
jni层调试线程死机原因 一,导致死机原因: jni层中 线程函数中 只要添加调用env 的函数 ,,就会死机 二,解决方法 第一我们应该理解: ①(独立性) JNIEnv 是一个与线 ...
- linux 搜索相关命令(2)
文件搜索相关命令 1:locate命令 需要 yum install mlocate locate 文件名 在后台数据库中按文件名搜索,搜索速度更快 /var/lib/mlocate #locate命 ...
- [Django]下拉表单与模型查询
前言:本文主要针对自定义下拉表单制作,下拉表单的内容是取至于数据库,即动态实现下拉表单 正文: 动态实现下拉表单有两种方法: 一.自己手动写 html 模板中的 <form ...> &l ...
- 360:且用且珍惜!解决虚拟机linux启动缓慢以及ssh端卡顿的问题!
优化软件以及杀毒软件想必大家都是用过的,小编自用的第一台电脑自带安装的是金山毒霸,随着时间的偏移渐渐用过小红伞,卡巴斯基,优化大师,鲁大师到后来的360优化杀毒套装,优化软件给大家带来了方便,尤其是上 ...
- python 类属性与方法
Python 类属性与方法 标签(空格分隔): Python Python的访问限制 Python支持面向对象,其对属性的权限控制通过属性名来实现,如果一个属性有双下划线开头(__),该属性就无法被外 ...
- Android 高清加载巨图方案 拒绝压缩图片
Android 高清加载巨图方案 拒绝压缩图片 转载请标明出处: http://blog.csdn.net/lmj623565791/article/details/49300989: 本文出自:[张 ...
- echo print() print_r() var_dump()的区别
常用调试方法 echo()可以一次输出多个值,多个值之间用逗号分隔.echo是语言结构(language construct),而并不是真正的函数,因此不能作为表达式的一部分使用. print()函数 ...
- C/C++实践笔记 004
转义字符 #define _CRT_SECURE_NO_WARNINGS#include<stdio.h>#include<stdlib.h> void main1() { c ...