记录bigdesk中ElasticSearch的性能参数

时间:2022-04-27 06:21:17
定时采集bigdesk中的Elasticsearch性能参数,并保存到数据库或ELK,以便于进行长期监控。
基于python脚本实现,脚本如下:
#coding=gbk

import httplib
import json
import time
import es_savelog
import ConfigHelper
import MQHelper def main(): #变量初始化
#上一次统计数据
dictLastNodeInfo={}
#本次统计当前节点
dictNodeInfo={} print "start..."
while 1==1:
flag=ConfigHelper.GetIntConfig("Flag")
if flag <> 1:
#判断是否满足退出条件
print "终止"+str(flag)
break urlarray = ConfigHelper.GetStringConfig("EsUrl").split('|')
#取出每次执行完成后的休眠时长:秒
sleeptime=ConfigHelper.GetFloatConfig("SleepTime") for urlindex in range(0,len(urlarray)):
url=urlarray[urlindex]
conn = httplib.HTTPConnection(url) #取出ES版本号
conn.request("GET","")
serverinfo=conn.getresponse()
objServerJson=json.loads(serverinfo.read())
esVersion=str(objServerJson["version"]["number"]) #取出集群健康状况
conn.request("GET","/_cluster/health")
healthinfo=conn.getresponse()
objHealthJson=json.loads(healthinfo.read())
health=str(objHealthJson["status"]) #取出各ES节点统计数据
conn.request("GET", "/_nodes/stats?human=true")
nodesread = conn.getresponse()
objNodesJson=json.loads(nodesread.read()) for i in range(0,len(objNodesJson["nodes"].values())):
try:
esNode=objNodesJson["nodes"].values()[i]
nodename=str(esNode["name"])
dictNodeInfo["EsVersion"]=esVersion
dictNodeInfo["Health"]=health #记录ES节点名称
dictNodeInfo["NodeName"]=nodename
dictNodeInfo["Interval"]=sleeptime #记录CPU信息
dictNodeInfo["OSUserCpu"]=esNode["os"]["cpu"]["user"] #记录ThreadpoolCount
dictNodeInfo["ThreadpoolCount"]=esNode["thread_pool"]["search"]["active"] #记录JVM堆内存
dictNodeInfo["HeapMem"]=float(esNode["jvm"]["mem"]["heap_used"].replace("gb","").replace("mb",""))
curGCYoungCount=int(esNode["jvm"]["gc"]["collectors"]["young"]["collection_count"])
curGCOldCount=int(esNode["jvm"]["gc"]["collectors"]["old"]["collection_count"])
curGCYoungTime=int(esNode["jvm"]["gc"]["collectors"]["young"]["collection_time_in_millis"])
curGNCOldTime=int(esNode["jvm"]["gc"]["collectors"]["old"]["collection_time_in_millis"])
lastGCYoungCount=int(dictLastNodeInfo.get(nodename+"_GCYoungCount",-1))
lastGCOldCount=int(dictLastNodeInfo.get(nodename+"_GCOldCount",-1))
lastGCYoungTime=int(dictLastNodeInfo.get(nodename+"_GCYoungTime",-1))
lastGCOldTime=int(dictLastNodeInfo.get(nodename+"_GCOldTime",-1))
if lastGCYoungCount>=0 and lastGCOldCount>=0 and lastGCYoungTime>=0 and lastGCYoungTime>=0:
dictNodeInfo["GCYoungCount"]=curGCYoungCount-lastGCYoungCount
dictNodeInfo["GCOldCount"]=curGCOldCount-lastGCOldCount
dictNodeInfo["GCYoungTime"]=curGCYoungTime-lastGCYoungTime
dictNodeInfo["GCOldTime"]=curGNCOldTime-lastGCOldTime
if lastGCOldCount>0:
dictNodeInfo["GCYOCountRate"]=lastGCYoungCount/lastGCOldCount
dictLastNodeInfo[nodename+"_GCYoungCount"]=curGCYoungCount
dictLastNodeInfo[nodename+"_GCOldCount"]=curGCOldCount
dictLastNodeInfo[nodename+"_GCYoungTime"]=curGCYoungTime
dictLastNodeInfo[nodename+"_GCOldTime"]=curGNCOldTime #记录连接数信息
dictNodeInfo["ChannelTransport"]=esNode["transport"]["server_open"]
dictNodeInfo["ChannelHttp"]=esNode["http"]["current_open"] #记录当前节点Indices-Query信息
objSearch=esNode["indices"]["search"]
curQueryTotal=objSearch["query_total"]
curFetchTotal=objSearch["fetch_total"]
curTimestamp=esNode["timestamp"]
lastQueryTotal=dictLastNodeInfo.get(nodename+"_QueryTotal",-1)
lastFetchTotal=dictLastNodeInfo.get(nodename+"_FetchTotal",-1)
lastTimestamp=dictLastNodeInfo.get(nodename+"_Timestamp",-1) if lastQueryTotal>0 and curQueryTotal>0:
curQueryCount=curQueryTotal-lastQueryTotal
curFetchCount=curFetchTotal-lastFetchTotal
curQueryTime=(curTimestamp-lastTimestamp)/1000
dictNodeInfo["Interval"]=curQueryTime
#print curQueryTotal,lastQueryTotal,curQueryCount,curTimestamp,lastTimestamp,curQueryTime,curQueryCount/curQueryTime
#记录QPS
if curQueryTime>0:
dictNodeInfo["IndicesQueryPS"]=curQueryCount/curQueryTime
dictNodeInfo["IndicesFetchPS"]=curFetchCount/curQueryTime
#print curQueryCount,curQueryTime,curQueryCount/curQueryTime #更新上次节点数据对象
dictLastNodeInfo[nodename+"_QueryTotal"]=curQueryTotal
dictLastNodeInfo[nodename+"_FetchTotal"]=curFetchTotal
dictLastNodeInfo[nodename+"_Timestamp"]=curTimestamp #取出cache信息
dictNodeInfo["FilterCache"] = float(esNode["indices"]["filter_cache"]["memory_size"].replace("mb","").replace("kb",""))
dictNodeInfo["FieldCache"] = float(esNode["indices"]["fielddata"]["memory_size"].replace("mb","").replace("kb","")) #保存数据到数据库
if(dictNodeInfo.get("IndicesQueryPS",-1) < 0 or dictNodeInfo.get("GCYoungCount",-1) < 0):
continue
es_savelog.SaveLog(dictNodeInfo) #推送ELK消息
dictNodeInfo["IndexName"] = "esbigdesk"
dictNodeInfo["LogTime"] = time.strftime("%Y-%m-%d %H:%M:%S.000", time.localtime())
print json.dumps(dictNodeInfo)
MQHelper.SendMessage(json.dumps(dictNodeInfo))
dictNodeInfo.clear()
except Exception,ex:
print Exception,":",ex #休眠
time.sleep(sleeptime) #启动
if __name__=="__main__":
main()
print "over"

记录bigdesk中ElasticSearch的性能参数的更多相关文章

  1. ElasticSearch中的JVM性能调优

    ElasticSearch中的JVM性能调优 前一段时间被人问了个问题:在使用ES的过程中有没有做过什么JVM调优措施? 在我搭建ES集群过程中,参照important-settings官方文档来的, ...

  2. elasticsearch 基础 —— Mapping参数boost、coerce、copy&lowbar;to、doc&lowbar;values、dynamic、

    boost 在查询时,各个字段可以自动提升 - 更多地依赖于相关性得分,boost参数如下: PUT my_index { "mappings": { "_doc&quo ...

  3. Java虚拟机(JVM)体系结构概述及各种性能参数优化总结

    转自:http://blog.csdn.net/zhongwen7710/article/details/39213377 第一部分:相关的概念 数据类型 Java虚拟机中,数据类型可以分为两类:基本 ...

  4. 认识loadrunner及相关性能参数

    认识loadrunner及相关性能参数 LoadRunner,是一种预测系统行为和性能的负载测试工具.通过以模拟上千万用户实施并发负载及实时性能监测的方式来确认和查找问题,LoadRunner能够对整 ...

  5. Java生鲜电商平台-SpringCloud微服务架构中网络请求性能优化与源码解析

    Java生鲜电商平台-SpringCloud微服务架构中网络请求性能优化与源码解析 说明:Java生鲜电商平台中,由于服务进行了拆分,很多的业务服务导致了请求的网络延迟与性能消耗,对应的这些问题,我们 ...

  6. &lbrack;转帖&rsqb;Java虚拟机(JVM)体系结构概述及各种性能参数优化总结

    Java虚拟机(JVM)体系结构概述及各种性能参数优化总结 2014年09月11日 23:05:27 zhongwen7710 阅读数 1437 标签: JVM调优jvm 更多 个人分类: Java知 ...

  7. PolarDB阿里初赛问题记录 PolarDB 阿里 中间件 比赛 性能 工程手册

    Contents 这篇纯碎是碎碎念记录. 每个value都是4KB,总共最多会写6400W个value,算下来就是64 * 1000 * 1000 * 4 * 1024 Bytes ≈ 256G. 每 ...

  8. 浅谈JavaScript中的变量、参数、作用域和作用域链

    基本类型和引用类型 在JavaScript中有两种数据类型值.基本类型值和引用类型值.基本类型值指的是简单的数据段,而引用类型值指的是可能由多个值构成的对象.在JavaScript中有5种基本数据类型 ...

  9. Extjs中给同一个GridPanel中的事件添加参数的方法

    Extjs中给同一个GridPanel中的事件添加参数的方法: this.isUse = new Ext.Action({            text:'启用',            scope ...

随机推荐

  1. python面试2

    Python语言特性 1 Python的函数参数传递 看两个例子:     1 2 3 4 5 a = 1 def fun(a):     a = 2 fun(a) print a  # 1 1 2 ...

  2. mysql之预处理语句prepare、execute、deallocate

    预制语句的SQL语法基于三个SQL语句: PREPARE stmt_name FROM preparable_stmt; EXECUTE stmt_name [USING @var_name [, @ ...

  3. 如何修改ubuntu系统的电脑名(主机名)

    在按照ubuntu系统时,会提示你给电脑填写一个名字,可能当时你没有想好,就随便填写了一个,可是以后就又有新的想法,想重新更换一个名字,该怎么办呢? 其实很简单.按照下面的步骤即可. 进去后,修改完, ...

  4. ZOJ 2182 Cable TV Network(无向图点割-最大流)

    题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=2182 题意:给出一个无向图,问最少删掉多少个顶点之后图变得不连通 ...

  5. CSS控制a标签链接的四种状态

    /*CSS链接的四种状态 *a:link 普通的.未被访问的链接样式 *a:visited 用户已访问的链接样式 *a:hover 鼠标指针位于链接上方样式 *a:active 链接被点击的时刻样式 ...

  6. Linux企业级项目实践之网络爬虫(24)——定制规则扩展为垂直爬虫

    在垂直搜索的索引建立之前,我们需要到垂直网站上抓取资源并做一定的处理.垂直搜索与通用搜索不同之处在于,通用搜索不需要理会网站哪些资源是需要的,哪些是不需要的,一并抓取并将其文本部分做索引.而垂直搜索里 ...

  7. viewpager处理(一):让viewpager不能滑动

    1.实现原理: 自定义viewpager,重写onTouchEvent方法,什么触摸事件都不响应即可让viewpager不能滑动. 2.代码如下 public class NoScrollViewPa ...

  8. golang 中 string 转换 &lbrack;&rsqb;byte 的一道笔试题

    背景 去面试的时候遇到一道和 string 相关的题目,记录一下用到的知识点.题目如下: s:="123" ps:=&s b:=[]byte(s) pb:=&b s ...

  9. golang 使用pprof进行性能调优

    package main import "fmt" func lengthOfNonRepeatingSubStr(s string) int { lastOccurred := ...

  10. pandas中Dataframe的查询方法(&lbrack;&rsqb;&comma; loc&comma; iloc&comma; at&comma; iat&comma; ix)

    数据介绍 先随机生成一组数据: import pandas as pd import numpy as np state = ['Ohio', 'Ohio', 'Ohio', 'Nevada', 'N ...