记录bigdesk中ElasticSearch的性能参数

定时采集bigdesk中的Elasticsearch性能参数,并保存到数据库或ELK,以便于进行长期监控。

基于python脚本实现,脚本如下:

#coding=gbk

import httplibimport jsonimport timeimport es_savelogimport ConfigHelperimport 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"
时间: 2024-07-30 22:38:22

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

ElasticSearch中的JVM性能调优

ElasticSearch中的JVM性能调优 前一段时间被人问了个问题:在使用ES的过程中有没有做过什么JVM调优措施? 在我搭建ES集群过程中,参照important-settings官方文档来的,并没有对JVM参数做过多的调整.其实谈JVM配置参数,少不了操作系统层面上的一些配置参数,比如 page cache.同时ES进程需要打开大量文件,文件描述符的个数(/etc/security/limits.conf)也要配置得大一些.这里简要介绍一下关于ES JVM参数的配置: 将 xms 和 x

认识loadrunner及相关性能参数

认识loadrunner及相关性能参数 LoadRunner,是一种预测系统行为和性能的负载测试工具.通过以模拟上千万用户实施并发负载及实时性能监测的方式来确认和查找问题,LoadRunner能够对整个企业架构进行测试.通过使用 LoadRunner,企业能最大限度地缩短测试时间,优化性能和加速应用系统的发布周期. LoadRunner是一种适用于各种体系架构的自动负载测试工具,它能预测系统行为并优化系统性能. 对象 LoadRunner的测试对象是整个企业的系统,它通过模拟实际用户的操作行为和

数据仓库中的 SQL 性能优化(Hive篇)

一个Hive查询生成多个map reduce job,一个map reduce job又有map,reduce,spill,shuffle,sort等多个阶段,所以针对hive查询的优化可以大致分为针对MR中单个步骤的优化(其中又会有细分),针对MR全局的优化,和针对整个查询(多MR job)的优化,下文会分别阐述. 在开始之前,先把MR的流程图帖出来(摘自Hadoop权威指南),方便后面对照.另外要说明的是,这个优化只是针对Hive 0.9版本,而不是后来Hortonwork发起Stinger

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

转自:http://blog.csdn.net/zhongwen7710/article/details/39213377 第一部分:相关的概念 数据类型 Java虚拟机中,数据类型可以分为两类:基本类型和引用类型.基本类型的变量保存原始值,即:他代表的值就是数值本身:而引用类型的变量保存引用值.“引用值”代表了某个对象的引用,而不是对象本身,对象本身存放在这个引用值所表示的地址的位置. 基本类型包括:byte,short,int,long,char,float,double,Boolean,r

如何获得服务器的常见性能参数 mysql性能 jetty性能

mysql存储服务器S:i5,8G,ssd; centos 7 x64; 安装图形化监控工具(监控工具自身也要消耗资源) jetty应用服务器A:i5,8G,ssd; centos 7 x64; 安装图形化监控工具(监控工具自身也要消耗资源) 局域网内测试机T:i5,8G,ssd 如何获得S和A的极限性能参数,以及S和A配合后的极限性能参数 确保局域网带宽不是瓶颈. S服务测试方法: 在T上编写python脚本,确保python脚本的执行不是瓶颈.  或用mysql测试工具. 1.只打开mysq

mysql数据库性能参数配置(转)

max_connections MySql的最大连接数,如果服务器的并发连接请求量比较大,建议调高此值,以增加并行连接数量,当然这建立在机器能支撑的情况下,因为如果连接数越多,MySql会为每个连接提供连接缓冲区,就会开销越多的内存,连接数太大,服务器消耗的内存越多,以至于影响服务器性能,所以要根据服务器的配置适当调整该值,不能盲目提高设值.可以过'conn%'通配符查看当前状态的连接数量,以定夺该值的大小. show variables like 'max_connections' 最大连接数

性能视图和性能参数

在oracle中,和用户有关的表有三种:用户自己创建的表,数据字典视图,动态性能视图.在后2种视图中,用户可以查询自己关心的信息.数据字典是一种系统表,它在数据库被创建时自动产生,由数据库服务器进行维护和更新.有三类主要的数据字典视图,这些视图名称分别以以下标识符开始: user_ : 存储当前用户所拥有的某类对象信息 all_ : 存储当前用户有权访问的某类对象信息 dba_ : 存储数据库中所有的某类对象信息,仅管理员可以访问. user_objects 当前用户所拥有的所有对象的信息. u

[转帖]Java虚拟机(JVM)体系结构概述及各种性能参数优化总结

Java虚拟机(JVM)体系结构概述及各种性能参数优化总结 2014年09月11日 23:05:27 zhongwen7710 阅读数 1437 标签: JVM调优jvm 更多 个人分类: Java知识点总结技术架构原理 https://blog.csdn.net/zhongwen7710/article/details/39213377 写的很好.. 堆栈分不清楚的我 愧对计算机系毕业.. 第一部分:相关的概念 数据类型 Java虚拟机中,数据类型可以分为两类:基本类型和引用类型.基本类型的变

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

Java生鲜电商平台-SpringCloud微服务架构中网络请求性能优化与源码解析 说明:Java生鲜电商平台中,由于服务进行了拆分,很多的业务服务导致了请求的网络延迟与性能消耗,对应的这些问题,我们应该如何进行网络请求的优化与处理呢? 到底有没有一些好的建议与方案呢? 下面这个文章将揭晓上面的问题,让你对SpringCloud微服务网络请求性能有一个全新的认识. 目录简介 01.网络请求异常分类 02.开发中注意问题 03.原始的处理方式 04.如何减少代码耦合性 05.异常统一处理步骤 06