vmware ESX5性能监控

来源:互联网 发布:nginx配置php域名访问 编辑:程序博客网 时间:2024/06/05 14:22
使用pysphere模块
利用vmware提供的web service sdk
参考:http://www.ibm.com/developerworks/cn/cloud/library/1303_jinhui_scevsphere/index.html
代码如下显示

from pysphere import VIServer, MORTypes, VIPropertyfrom pysphere.resources import VimService_services as VIfrom __future__ import divisionHOST="xxx.xxx.xxx.xxx"USER="root"PASSWORD="*****"s = VIServer()s.connect(HOST, USER, PASSWORD)hosts = s.get_hosts()#print hostsfor host in hosts:    p = VIProperty(s, host)    overallCpuUsage=p.summary.quickStats.overallCpuUsage    overallMemoryUsage=p.summary.quickStats.overallMemoryUsage    averagedCpuSpeedPerCore=p.hardware.cpuInfo.hz    numCpuCores=p.hardware.cpuInfo.numCpuCores    totalCpuSpeed=averagedCpuSpeedPerCore*numCpuCores    totalMemorySize=p.hardware.memorySize    try:        CpuUsage=(overallCpuUsage*1024*1024/totalCpuSpeed)*100        MemoryUsage=(overallMemoryUsage*1024*1024/totalMemorySize)*100    except e:        print e        uptime=p.summary.quickStats.uptime    #uptime unit=seconds,so need to convert to centisecond    uptime=uptime*100    print "VMWARE ESXI V5 | CpuUsage=%s MemoryUsage=%s sysUpTime=%s" \            %(str(CpuUsage),str(MemoryUsage),str(uptime))s.disconnect()


******************************************************************************************
相应项目的详细介绍
http://pubs.vmware.com/vsphere-51/index.jsp?topic=%2Fcom.vmware.wssdk.apiref.doc%2Fvim.host.Summary.QuickStats.html
overallCpuUsage*xsd:int Aggregated CPU usage across all cores on the host in MHz. This is only available if the host is connected. overallMemoryUsage*xsd:int   Physical memory usage on the host in MB. This is only available if the host is connected.
http://pubs.vmware.com/vsphere-51/index.jsp?topic=%2Fcom.vmware.wssdk.apiref.doc%2Fvim.host.CpuInfo.html
hzxsd:longCPU speed per core. This might be an averaged value if the speed is not uniform across all cores. The total CPU speed of the box is defined as hz * numCpuCores numCpuCoresxsd:short Number of physical CPU cores on the host.
http://pubs.vmware.com/vsphere-51/index.jsp#com.vmware.wssdk.apiref.doc/vim.host.HardwareInfo.html#field_detail
memorySizexsd:longTotal amount of physical memory on the host in bytes.       
还是需要进行转化
cpu利用率=(overallCpuUsage*1024*1024/hz*numCpuCores)*100
内存利用率=(overallMemoryUsage*1024*1024/memorySize)*100




至于主机内的virtual machine的性能可以参考:
http://pubs.vmware.com/vsphere-51/index.jsp?topic=%2Fcom.vmware.wssdk.apiref.doc%2Fvim.vm.Summary.QuickStats.html

0 0
原创粉丝点击