VMware Cloud Community
VJ2019
Contributor
Contributor
Jump to solution

Get CPU MHz of a VM

Hi All.

I found some hints to get CPU MHz Infos. All of them (until now) based on the VM host values. They are wrong from guest point of view. The host values are more less statistic values, if I follow those example:

          Get-VM "<guest name>" | Select-Object -Property Name,@{Name='MaxHostCpuMhz';Expression={$_.NumCpu * $_.VMHost.CpuTotalMhz / $_.VMHost.NumCpu}}

          ProcessorType: Intel(R) Xeon(R) Gold 6146 CPU @ 3.20GHz

If I have a look on the guest side with dmiodecode --type processor, I have complete different values:

          Manufacturer: GenuineIntel

          Version:        Intel(R) Xeon(R) CPU E7- 4807  @ 1.87GHz

How can I get the real / current guest values with the Power CLI and there options?

Thanks for a short example, I guess with Invoke-Script... A link to more detailed tutorial using Invoke-Script on guest systems would perhaps help also.

Volker

Tags (3)
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

I don't understand why you would be getting 0 if the individual values are what you show here.

There are 2 types of objects in PowerCLI.

  1. The .Net objects, which are returned by PowerCLI cmdlets, and which are documented in the Types online help.
  2. The vSphere objects, reachable from the .Net objects via the ExtensionData property (or via the Get-View cmdlet). They are documented in the vSphere API Reference.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

0 Kudos
10 Replies
T180985
Expert
Expert
Jump to solution

Not sure if im understanding exactly what youre wanting but if youre looking for current utilization values then you could use get-stat e.g.

Get-stat -entity $_ -Stat cpu.usage.average -Realtime -MaxSamples 1

Please mark helpful or correct if my answer resolved your issue. How to post effectively on VMTN https://communities.vmware.com/people/daphnissov/blog/2018/12/05/how-to-ask-for-help-on-tech-forums
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Do you get different values when you run this?

Get-VM <MyVM> |

Select-Object -Property Name,

    @{N='vCPUMhz';E={$_.ExtensionData.Runtime.MaxCpuUsage/$_.NumCpu}},

    @{Name='HostCpuMhz';Expression={$_.VMHost.CpuTotalMhz / $_.VMHost.NumCpu}}

I get (on an Ubuntu box with 2 vCPU)

cpuFreq.png

And this corresponds with what dmidecode tells me.

dmidecode.png


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
VJ2019
Contributor
Contributor
Jump to solution

Hi LucD

I get vCPUMhz = 0 and HostCpuMhz is empty (or null)

0 Kudos
LucD
Leadership
Leadership
Jump to solution

What is this returning?

Get-VM MyVM |

Select-Object -Property Name,NumCpu,CoresPerSocket,

    @{N='MaxCPUMhz';E={$_.ExtensionData.Runtime.MaxCpuUsage}},

    @{N='VMHostNumCpu';E={$_.VMHost.NumCpu}},

    @{N='HostCpuMhz';E={$_.VMHost.CpuTotalMhz}}


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
VJ2019
Contributor
Contributor
Jump to solution

Hi T180985.

I want no monitoring values about a VM. I want only get the CPU values (MHz / Type) from VM point of view. To calculate values based on the host  data is perhaps not the real view.

0 Kudos
VJ2019
Contributor
Contributor
Jump to solution

Name       : my vm name
NumCpu     : 2

CoresPerSocket : 1

MaxCPUMhz  : 6384

VMHostNumCpu   : 16

HostCpuMhz : 51072
0 Kudos
VJ2019
Contributor
Contributor
Jump to solution

Hi LucD.

Exist somewhere a link to a full description abount the data model useable by PowerCLI? I think, (no, I know Smiley Wink) if I a have look at this, I know than what is possible and what not?

0 Kudos
LucD
Leadership
Leadership
Jump to solution

I don't understand why you would be getting 0 if the individual values are what you show here.

There are 2 types of objects in PowerCLI.

  1. The .Net objects, which are returned by PowerCLI cmdlets, and which are documented in the Types online help.
  2. The vSphere objects, reachable from the .Net objects via the ExtensionData property (or via the Get-View cmdlet). They are documented in the vSphere API Reference.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
VJ2019
Contributor
Contributor
Jump to solution

I "solved" for now with the values from:

$cpuType   = $vm.VMHost.ProcessorType
$cpuMaxMhz = [String] ([convert]::ToInt32($vm.ExtensionData.Runtime.MaxCpuUsage) / [convert]::ToInt32($vm.NumCpu))

inside my script.

It's ok for now, but in fact I would prefer the values from a dmidecode. I guess, I need to do it anyway with Invoke-Script, because I also need the guests BIOS values...

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Yes, that would be the way to go.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos