VMware {code} Community
sajuptpm
Contributor
Contributor

howto calculate cpu and memory utilization percentage

I got cpu and memory usage of ESXi host from following code

cpu_usage = host.summary.quickStats.overallCpuUsage
memory_usage =host.summary.quickStats.overallMemoryUsage

ie,

cpu_usage = 200

memory_usage = 4699

Howto calculate percentage of utlilization from values ??

Have any other way to find cpu and memory utilization percentage ??

0 Kudos
7 Replies
sajuptpm
Contributor
Contributor

Hi,

Can i calculate percentage of cpu and memory utilization like ???

cpu utilization

===========

overallCpuUsage = host.summary.quickStats.overallCpuUsage

numCpuCores = host.summary.hardware.numCpuCores

numCpuPkgs = host.summary.hardware.numCpuPkgs

cpuMhz = host.summary.hardware.cpuMhz


cpu_usage_percentage = ( overallCpuUsage / ( numCpuPkgs * numCpuCores * cpuMhz ) ) * 100   <=== ??

I got this equation from link bellow

http://pubs.vmware.com/vsphere-4-esx-vcenter/index.jsp?topic=/com.vmware.vsphere.dcadmin.doc_41/vsp_...

Memory utilization

================

overallCpuUsage = host.summary.quickStats.overallCpuUsage

memorySize = host.summary.hardware.memorySize

memory_usage_percentage = (overallCpuUsage / memorySize) * 100  <=== ??


0 Kudos
stumpr
Virtuoso
Virtuoso

I believe numCores is the total across all CPU sockets, but I would validate it.

(numCores * cpuMhz) = cpuTotalMhz

(memorySize /1048576) = memTotalMB

Then use the quickStats values to calculate a % usage.

Reuben Stump | http://www.virtuin.com | @ReubenStump
0 Kudos
stumpr
Virtuoso
Virtuoso

Yeah, that's just 1024 * 1024 to convert B to MB.

Reuben Stump | http://www.virtuin.com | @ReubenStump
0 Kudos
sajuptpm
Contributor
Contributor

Hi stumpr,

thanks for this info

Could you please confirm this

cpu_usage_percent = ( (numCores*cpuMhz) / cpu_usage ) * 100

mem_usage_percent = ( (memorySize*1048576) / mem_usage ) * 100

thanks

0 Kudos
stumpr
Virtuoso
Virtuoso

That should be it.  as long as cpu_usage is Mhz and mem_usage is MB from the quickStats properties.

Reuben Stump | http://www.virtuin.com | @ReubenStump
0 Kudos
sajuptpm
Contributor
Contributor

Hi,

This example should be helpful for others

QuickStats
overallCpuUsage = 191
overallMemoryUsage = 4708

cpu_mhz = 2933
numCores = 2
memorySize = 5298638848

cpu_usage_perc = ( overallCpuUsage / ( numCores * cpu_mhz ) ) * 100
cpu_usage_perc = 3.2
mem_usage_perc = ( overallMemoryUsage / ( memorySize / (1024*1024) ) ) * 100
mem_usage_perc = 93.1

0 Kudos
sajuptpm
Contributor
Contributor

I have following data from Virtual machine and I want to calculate percentage of cpu and memory utilization.

Note : I could not find cpuMhz of Virtual machine.

config.hardware

============

memoryMB = 8192

numCPU = 2

numCoresPerSocket = 1

summary.quickStats

===============

overallCpuUsage    = 116

guestMemoryUsage = 409

hostMemoryUsage = 3609

* I think percentage of memory utilization can be calculate like  ????

mem_usage_perc = ( guestMemoryUsage / memoryMB ) * 100

mem_usage_perc = 4.9

* How calculate percentage of cpu utilization ???

0 Kudos