def create_rrd(rrd_file,m_type="None"): if m_type=="host": ret = rrdtool.create( rrd_file, "--step", str(STEP) ,"--start", str(int(time.time())), "DS:cpu:GAUGE:%s:0:U" % str(TIME_DIFF_MS), "DS:ram:GAUGE:%s:0:U" % str(TIME_DIFF_MS), "DS:dr:GAUGE:%s:0:U" % str(TIME_DIFF_MS), "DS:dw:GAUGE:%s:0:U" % str(TIME_DIFF_MS), "DS:tx:GAUGE:%s:0:U" % str(TIME_DIFF_MS), "DS:rx:GAUGE:%s:0:U" % str(TIME_DIFF_MS), "DS:tmp:GAUGE:%s:0:U" % str(TIME_DIFF_MS), "DS:pwr:GAUGE:%s:0:U" % str(TIME_DIFF_MS), "RRA:MIN:0:1:200000", # Data stored for every five minute "RRA:AVERAGE:0.5:12:100", # Average data stored for every hour (300*12) "RRA:AVERAGE:0.5:288:50", # Average data stored for every day (300*288) "RRA:AVERAGE:0.5:8928:24", # Average data stored for every month (300*8928) "RRA:AVERAGE:0.5:107136:10")# Average data stored for every year (300*107136) else: ret = rrdtool.create( rrd_file, "--step", str(STEP) ,"--start", str(int(time.time())), "DS:cpu:GAUGE:%s:0:U" % str(TIME_DIFF_MS), "DS:ram:GAUGE:%s:0:U" % str(TIME_DIFF_MS), "DS:dr:GAUGE:%s:0:U" % str(TIME_DIFF_MS), "DS:dw:GAUGE:%s:0:U" % str(TIME_DIFF_MS), "DS:tx:GAUGE:%s:0:U" % str(TIME_DIFF_MS), "DS:rx:GAUGE:%s:0:U" % str(TIME_DIFF_MS), "RRA:MIN:0:1:200000", # Data stored for every five minute "RRA:AVERAGE:0.5:12:100", # Average data stored for every hour (300*12) "RRA:AVERAGE:0.5:288:50", # Average data stored for every day (300*288) "RRA:AVERAGE:0.5:8928:24", # Average data stored for every month (300*8928) "RRA:AVERAGE:0.5:107136:10")# Average data stored for every year (300*107136) if ret: rrd_logger.warn(rrdtool.error())
def update_host_rrd(host_ip,m_type=None): try: rrd_file = get_rrd_file(host_ip.replace(".","_")) rrd_logger.info(rrd_file) timestamp_now = time.time() rrd_logger.info(timestamp_now) if not (os.path.exists(rrd_file)): rrd_logger.warn("RRD file (%s) does not exists" % (rrd_file)) rrd_logger.warn("Creating new RRD file") if m_type is None: create_rrd(rrd_file,"host") else: create_rrd(rrd_file) else: rrd_logger.info("updating RRD file") if m_type is None: rrd_logger.debug("host_ip is"+ str(host_ip)) host_stats = get_host_resources_usage(host_ip) output=rrdtool.update(rrd_file, "%s:%s:%s:%s:%s:%s:%s:%s:%s" % (timestamp_now, host_stats['cpu'], host_stats['ram'], host_stats['dr'], host_stats['dw'], host_stats['tx'], host_stats['rx'],host_stats['tmp'], host_stats['pwr'])) rrd_logger.debug("update status"+str(output)) else: host_stats = get_host_resources_usage(host_ip,m_type) rrdtool.update(rrd_file, "%s:%s:%s:%s:%s:%s:%s" % (timestamp_now, host_stats['cpu'], host_stats['ram'], host_stats['dr'], host_stats['dw'], host_stats['tx'], host_stats['rx'])) except Exception, e: rrd_logger.debug("Error occured while creating/updating rrd for host: %s" % (host_ip)) rrd_logger.debug(e)
def update_host_rrd(host_ip,m_type=None): """ Updates the RRD file for host with resource utilization data """ try: rrd_file = _get_rrd_file(host_ip.replace(".","_")) rrd_logger.info(rrd_file) timestamp_now = time.time() rrd_logger.info(timestamp_now) if not (os.path.exists(rrd_file)): rrd_logger.warn("RRD file (%s) does not exists" % (rrd_file)) rrd_logger.warn("Creating new RRD file") create_rrd(rrd_file) else: rrd_logger.info("updating RRD file") if m_type is None: host_stats = get_host_resources_usage(host_ip) else: host_stats = get_host_resources_usage(host_ip,m_type) rrdtool.update(rrd_file, "%s:%s:%s:%s:%s:%s:%s" % (timestamp_now, host_stats['cpu'], host_stats['ram'], host_stats['dr'], host_stats['dw'], host_stats['tx'], host_stats['rx'])) except Exception, e: rrd_logger.debug("Error occured while creating/updating rrd for host: %s" % (host_ip)) rrd_logger.debug(e)
def get_dom_mem_usage(dom, host): rrd_logger.info("memory stats for VM:%s is %s" %(dom.name(),dom.memoryStats())) rrd_logger.warn(dom.memoryStats()) try: domain_memUsed=(dom.memoryStats()['available']-dom.memoryStats()['unused']) rrd_logger.info("domain_memUsed is : "+str(domain_memUsed)) except: domain_memUsed=(dom.memoryStats()['rss']) rrd_logger.info("in except and rss value is : "+str(domain_memUsed)) return (domain_memUsed*1024)
def get_current_dom_resource_usage(dom, host_ip): dom_memusage = get_dom_mem_usage(dom.name(), host_ip) dom_nw_usage = get_dom_nw_usage(dom) dom_disk_usage = get_dom_disk_usage(dom) dom_stats = {'rx' : dom_nw_usage[0]} dom_stats.update({'tx' : dom_nw_usage[1]}) dom_stats.update({'diskr' : dom_disk_usage[0]}) dom_stats.update({'diskw' : dom_disk_usage[1]}) dom_stats.update({'memory' : dom_memusage}) dom_stats.update({'cputime' : dom.info()[4]}) dom_stats.update({'cpus' : dom.info()[3]}) rrd_logger.info(dom_stats) rrd_logger.warn("As we get VM mem usage info from rrs size of the process running on host therefore it is observed that the memused is sometimes greater than max mem specified in case when the VM uses memory near to its mam memory") return dom_stats
def update_vm_rrd(dom, active_dom_ids, host_ip): dom_name = dom.name() rrd_file = get_rrd_file(dom.name()) if not (os.path.exists(rrd_file)): rrd_logger.warn("RRD file (%s) does not exists" % (rrd_file)) rrd_logger.warn("Creating new RRD file") create_rrd(rrd_file) else: timestamp_now = time.time() if dom.ID() in active_dom_ids: vm_usage = get_actual_usage(dom, host_ip) rrd_logger.debug("Usage Info for VM %s: %s" % (dom_name, vm_usage)) rrdtool.update(rrd_file, "%s:%s:%s:%s:%s:%s:%s" % (timestamp_now, vm_usage['cpu'], vm_usage['ram'], vm_usage['dr'], vm_usage['dw'], vm_usage['tx'], vm_usage['rx'])) else: rrdtool.update(rrd_file, "%s:0:0:0:0:0:0" % (timestamp_now))
def get_current_dom_resource_usage(dom, host_ip): dom_memusage = get_dom_mem_usage(dom, host_ip) dom_nw_usage = get_dom_nw_usage(dom) dom_disk_usage = get_dom_disk_usage(dom) timestamp_now = time.time() #keerti dom_stats = {'rx' : dom_nw_usage[0]} dom_stats.update({'tx' : dom_nw_usage[1]}) dom_stats.update({'diskr' : dom_disk_usage[0]}) dom_stats.update({'diskw' : dom_disk_usage[1]}) dom_stats.update({'memory' : dom_memusage}) dom_stats.update({'cputime' : dom.info()[4]}) dom_stats.update({'cpus' : dom.info()[3]}) dom_stats.update({'timestamp': timestamp_now}) rrd_logger.info(dom_stats) rrd_logger.warn("As we get VM mem usage info from rrs size of the process running on host therefore it is observed that the memused is sometimes greater than max mem specified in case when the VM uses memory near to its mam memory") return dom_stats
def get_performance_graph(graph_type, vm, graph_period): error = None img = IMG(_src = URL("static" , "images/no_graph.jpg") , _style = "height:100px") try: rrd_file = get_rrd_file(vm) if os.path.exists(rrd_file): if create_graph(vm, graph_type, rrd_file, graph_period): img_pos = "images/vm_graphs/" + vm + "_" + graph_type + ".png" img = IMG(_src = URL("static", img_pos), _style = "height:100%") rrd_logger.info("Graph created successfully") else: rrd_logger.warn("Unable to create graph from rrd file!!!") error = "Unable to create graph from rrd file" else: rrd_logger.warn("VMs RRD File Unavailable!!!") error = "VMs RRD File Unavailable!!!" except: rrd_logger.warn("Error occured while creating graph.") import sys, traceback etype, value, tb = sys.exc_info() error = ''.join(traceback.format_exception(etype, value, tb, 10)) rrd_logger.debug(error) finally: if error != None: return error else: rrd_logger.info("Returning image.") return img
def update_host_rrd(host_ip): try: rrd_file = get_rrd_file(host_ip.replace(".","_")) timestamp_now = time.time() if not (os.path.exists(rrd_file)): rrd_logger.warn("RRD file (%s) does not exists" % (rrd_file)) rrd_logger.warn("Creating new RRD file") create_rrd(rrd_file) else: host_stats = get_host_resources_usage(host_ip) rrdtool.update(rrd_file, "%s:%s:%s:%s:%s:%s:%s" % (timestamp_now, host_stats['cpu'], host_stats['ram'], host_stats['dr'], host_stats['dw'], host_stats['tx'], host_stats['rx'])) except Exception, e: rrd_logger.debug("Error occured while creating/updating rrd for host: %s" % (host_ip)) rrd_logger.debug(e)
def create_rrd(rrd_file): """ Create new Round Robin Database (RRD) file with - step size - start time - data sources - archive (An archive consists of a number of data values or statistics for each of the defined data-sources) """ ret = rrdtool.create( rrd_file, "--step", str(STEP) ,"--start", str(int(time.time())), "DS:cpu:GAUGE:%s:0:U" % str(TIME_DIFF_MS), "DS:ram:GAUGE:%s:0:U" % str(TIME_DIFF_MS), "DS:dr:GAUGE:%s:0:U" % str(TIME_DIFF_MS), "DS:dw:GAUGE:%s:0:U" % str(TIME_DIFF_MS), "DS:tx:GAUGE:%s:0:U" % str(TIME_DIFF_MS), "DS:rx:GAUGE:%s:0:U" % str(TIME_DIFF_MS), "RRA:MIN:0:1:200000", # Data stored for every five minute "RRA:AVERAGE:0.5:12:100", # Average data stored for every hour (300*12) "RRA:AVERAGE:0.5:288:50", # Average data stored for every day (300*288) "RRA:AVERAGE:0.5:8928:24", # Average data stored for every month (300*8928) "RRA:AVERAGE:0.5:107136:10")# Average data stored for every year (300*107136) if ret: rrd_logger.warn(rrdtool.error())