For something that seems so easy, I'm having a hard time figuring this out.
All I want to do is get the current CPU and memory usage of a running VM, but I can't seem to get the information. I have a simple script that does the following:
var maxCpu = vm.runtime.maxCpuUsage;
var maxMem = vm.runtime.maxMemoryUsage;
var curCpu = vm.summary.quickStats.overallCpuUsage;
var curMem = vm.summary.quickStats.guestMemoryUsage;
System.log("max cpu = "+maxCpu);
System.log("max mem = "+maxMem);
System.log("cur cpu = "+curCpu);
System.log("cur mem = "+curMem);
var cpuUsage = (curCpu * 100.0) / maxCpu;
var memUsage = (curMem * 100.0) / maxMem;
System.log("cpu usg = "+cpuUsage);
System.log("mem usg = "+memUsage);
The "vm" is the VcVirtualMachine object which is an input variable. VMtools is running on the VM. When I run the script and select a VM, the cpuUsage shows "0" while the memUsage shows "10" for a particular VM. I then log into the VM and run "stress" to stress the CPU and/or memory. I then run the orchestrator script again and the values for cpuUsage and memUsage remain unchanged. Even if I let the VM stress for several minutes and try running the orchestrator script above, the values still remain unchanged. I can see the CPU and memory being stressed in the vSphere client so I know the "stress" program is running correctly. In fact vSphere shows a CPU and memory alarm for the VM after a while, but still I get the same values when I run the script above.
Anyone know what is happening and can give me a solution so I can get the actual runtime values for the CPU and memory usage of a VM in orchestrator? Much appreciated.