예제 #1
0
 def getPerformanceStats(bridgeName):
     try:
         rxBytesPath = join("/sys/class/net/", bridgeName, "statistics/rx_bytes")
         txBytesPath = join("/sys/class/net/", bridgeName, "statistics/tx_bytes")
         if not exists(rxBytesPath):
             raise Exception("Cannot find %s" % rxBytesPath)
         if not exists(txBytesPath):
             raise Exception("Cannot find %s" % txBytesPath)
         rxBytes = long(doCmd(["cat", rxBytesPath])) / 1000
         txBytes = long(doCmd(["cat", txBytesPath])) / 1000
         sysPerf = successToMap(sys_perf_info())
         cpuUtil = float(100 - float(sysPerf["cpu_idle"]) * 100)
         freeMemory = MtoBytes(long(sysPerf["mem_free"]))
         xmInfo = successToMap(xen_get_xm_info())
         totalMemory = MtoBytes(long(xmInfo["total_memory"]))
         rs = toGson(
             {
                 "cpuUtil": cpuUtil,
                 "totalMemory": totalMemory,
                 "freeMemory": freeMemory,
                 "rxBytes": rxBytes,
                 "txBytes": txBytes,
             }
         )
         logger.info(OvmHost.getPerformanceStats, rs)
         return rs
     except Exception, e:
         errmsg = fmt_err_msg(e)
         logger.error(OvmHost.getPerformanceStats, errmsg)
         raise XmlRpcFault(toErrCode(OvmHost, OvmHost.getPerformanceStats), errmsg)
예제 #2
0
 def getDetails():
     try:
         obj = OvmHost()
         masterIp = successToMap(get_master_ip())
         safeSetAttr(obj, 'masterIp', masterIp['ip'])
         xmInfo = successToMap(xen_get_xm_info())
         totalMemory = MtoBytes(long(xmInfo['total_memory']))
         safeSetAttr(obj, 'totalMemory', totalMemory)
         freeMemory = MtoBytes(long(xmInfo['free_memory']))
         safeSetAttr(obj, 'freeMemory', freeMemory)
         dom0Memory = totalMemory - freeMemory
         safeSetAttr(obj, 'dom0Memory', dom0Memory)
         cpuNum = int(xmInfo['nr_cpus'])
         safeSetAttr(obj, 'cpuNum', cpuNum)
         cpuSpeed = int(xmInfo['cpu_mhz'])
         safeSetAttr(obj, 'cpuSpeed', cpuSpeed)
         name = xmInfo['host']
         safeSetAttr(obj, 'name', name)
         dom0KernelVersion = xmInfo['release']
         safeSetAttr(obj, 'dom0KernelVersion', dom0KernelVersion)
         hypervisorVersion = xmInfo['xen_major'] + '.' + xmInfo['xen_minor'] + xmInfo['xen_extra']
         safeSetAttr(obj, 'hypervisorVersion', hypervisorVersion)
         agtVersion = successToMap(get_agent_version())
         safeSetAttr(obj, 'agentVersion', agtVersion['agent_version'])
         res = fromOvmHost(obj)
         logger.debug(OvmHost.getDetails, res)
         return res
     except Exception, e:
         errmsg = fmt_err_msg(e)
         logger.error(OvmHost.getDetails, errmsg)
         raise XmlRpcFault(toErrCode(OvmHost, OvmHost.getDetails), errmsg)
예제 #3
0
 def getDetails():
     try:
         obj = OvmHost()
         masterIp = successToMap(get_master_ip())
         safeSetAttr(obj, "masterIp", masterIp["ip"])
         xmInfo = successToMap(xen_get_xm_info())
         totalMemory = MtoBytes(long(xmInfo["total_memory"]))
         safeSetAttr(obj, "totalMemory", totalMemory)
         freeMemory = MtoBytes(long(xmInfo["free_memory"]))
         safeSetAttr(obj, "freeMemory", freeMemory)
         dom0Memory = totalMemory - freeMemory
         safeSetAttr(obj, "dom0Memory", dom0Memory)
         cpuNum = int(xmInfo["nr_cpus"])
         safeSetAttr(obj, "cpuNum", cpuNum)
         cpuSpeed = int(xmInfo["cpu_mhz"])
         safeSetAttr(obj, "cpuSpeed", cpuSpeed)
         name = xmInfo["host"]
         safeSetAttr(obj, "name", name)
         dom0KernelVersion = xmInfo["release"]
         safeSetAttr(obj, "dom0KernelVersion", dom0KernelVersion)
         hypervisorVersion = xmInfo["xen_major"] + "." + xmInfo["xen_minor"] + xmInfo["xen_extra"]
         safeSetAttr(obj, "hypervisorVersion", hypervisorVersion)
         agtVersion = successToMap(get_agent_version())
         safeSetAttr(obj, "agentVersion", agtVersion["agent_version"])
         res = fromOvmHost(obj)
         logger.debug(OvmHost.getDetails, res)
         return res
     except Exception, e:
         errmsg = fmt_err_msg(e)
         logger.error(OvmHost.getDetails, errmsg)
         raise XmlRpcFault(toErrCode(OvmHost, OvmHost.getDetails), errmsg)
 def getDetails():
     try:
         obj = OvmHost()
         masterIp = successToMap(get_master_ip())
         safeSetAttr(obj, 'masterIp', masterIp['ip'])
         xmInfo = successToMap(xen_get_xm_info())
         totalMemory = MtoBytes(long(xmInfo['total_memory']))
         safeSetAttr(obj, 'totalMemory', totalMemory)
         freeMemory = MtoBytes(long(xmInfo['free_memory']))
         safeSetAttr(obj, 'freeMemory', freeMemory)
         dom0Memory = totalMemory - freeMemory
         safeSetAttr(obj, 'dom0Memory', dom0Memory)
         cpuNum = int(xmInfo['nr_cpus'])
         safeSetAttr(obj, 'cpuNum', cpuNum)
         cpuSpeed = int(xmInfo['cpu_mhz'])
         safeSetAttr(obj, 'cpuSpeed', cpuSpeed)
         name = xmInfo['host']
         safeSetAttr(obj, 'name', name)
         dom0KernelVersion = xmInfo['release']
         safeSetAttr(obj, 'dom0KernelVersion', dom0KernelVersion)
         hypervisorVersion = xmInfo['xen_major'] + '.' + xmInfo['xen_minor'] + xmInfo['xen_extra']
         safeSetAttr(obj, 'hypervisorVersion', hypervisorVersion)
         agtVersion = successToMap(get_agent_version())
         safeSetAttr(obj, 'agentVersion', agtVersion['agent_version'])
         res = fromOvmHost(obj)
         logger.debug(OvmHost.getDetails, res)
         return res
     except Exception, e:
         errmsg = fmt_err_msg(e)
         logger.error(OvmHost.getDetails, errmsg)
         raise XmlRpcFault(toErrCode(OvmHost, OvmHost.getDetails), errmsg)
        def getVcpuNumAndUtils():
            try:
                session = session_login()
                refs = session.xenapi.VM.get_by_name_label(vmName)
                if len(refs) == 0:
                    raise Exception(
                        "No ref for %s found in xenapi VM objects" % vmName)
                vm = XenAPIObject('VM', session, refs[0])
                VM_metrics = XenAPIObject("VM_metrics", session,
                                          vm.get_metrics())
                items = VM_metrics.get_VCPUs_utilisation().items()
                nvCpus = len(items)
                if nvCpus == 0:
                    raise Exception("vm %s has 0 vcpus !!!" % vmName)

                xmInfo = successToMap(xen_get_xm_info())
                nCpus = int(xmInfo['nr_cpus'])
                totalUtils = 0.0
                # CPU utlization of VM = (total cpu utilization of each vcpu) / number of physical cpu
                for num, util in items:
                    totalUtils += float(util)
                avgUtils = float(totalUtils / nCpus) * 100
                return (nvCpus, avgUtils)
            finally:
                session_logout()
예제 #6
0
 def getPerformanceStats(bridgeName):
     try:
         rxBytesPath = join("/sys/class/net/", bridgeName,
                            "statistics/rx_bytes")
         txBytesPath = join("/sys/class/net/", bridgeName,
                            "statistics/tx_bytes")
         if not exists(rxBytesPath):
             raise Exception("Cannot find %s" % rxBytesPath)
         if not exists(txBytesPath):
             raise Exception("Cannot find %s" % txBytesPath)
         rxBytes = long(doCmd(['cat', rxBytesPath])) / 1000
         txBytes = long(doCmd(['cat', txBytesPath])) / 1000
         sysPerf = successToMap(sys_perf_info())
         cpuUtil = float(100 - float(sysPerf['cpu_idle']) * 100)
         freeMemory = MtoBytes(long(sysPerf['mem_free']))
         xmInfo = successToMap(xen_get_xm_info())
         totalMemory = MtoBytes(long(xmInfo['total_memory']))
         rs = toGson({
             "cpuUtil": cpuUtil,
             "totalMemory": totalMemory,
             "freeMemory": freeMemory,
             "rxBytes": rxBytes,
             "txBytes": txBytes
         })
         logger.info(OvmHost.getPerformanceStats, rs)
         return rs
     except Exception, e:
         errmsg = fmt_err_msg(e)
         logger.error(OvmHost.getPerformanceStats, errmsg)
         raise XmlRpcFault(toErrCode(OvmHost, OvmHost.getPerformanceStats),
                           errmsg)
예제 #7
0
 def getVcpuNumAndUtils():
     try:
         session = session_login()
         refs = session.xenapi.VM.get_by_name_label(vmName)
         if len(refs) == 0:
             raise Exception("No ref for %s found in xenapi VM objects"%vmName)
         vm = XenAPIObject('VM', session, refs[0])
         VM_metrics = XenAPIObject("VM_metrics", session, vm.get_metrics())
         items = VM_metrics.get_VCPUs_utilisation().items()
         nvCpus = len(items)
         if nvCpus == 0:
             raise Exception("vm %s has 0 vcpus !!!"%vmName)
         
         xmInfo = successToMap(xen_get_xm_info())
         nCpus = int(xmInfo['nr_cpus'])
         totalUtils = 0.0
         # CPU utlization of VM = (total cpu utilization of each vcpu) / number of physical cpu
         for num, util in items:
             totalUtils += float(util)
         avgUtils = float(totalUtils/nCpus) * 100
         return (nvCpus, avgUtils)
     finally:
         session_logout()