Search code examples
powershellvmwarevspherepowercli

PowerCLI: The metric counter "cpu.usagemhz.maximum" doesn't exist


I am attempting to pull a variety of stats from each of our VMs on particular hosts. Everything works, except for the $maxcpu part.... I'm a PS noob, so I just tried to model it off of the other stats I pulled stylewise, but changed the CPU counter to .maximum rather than .average. With my experimentation, I either get a blank entry in the CSV, or it crashes and gives an error of :

The metric counter "cpu.usagemhz.maximum" doesn't exist for entity "XXXX".

foreach ($vmhost in $hosts) { 
    $vms = Get-VM -Location $vmhost
    $vmHost | echo
    foreach ($vm in $vms) {
        "    " + $vm | echo 
        $avgcpu = @{N="Cpu.UsageMhz.Average";E={[Math]::Round((($_ |Get-Stat -Stat cpu.usagemhz.average -Start (Get-Date).AddDays(-7) | Measure-Object Value -Average).Average),2)}}
        $maxcpu = @{N="Cpu.UsageMhz.Maximum";E={[Math]::Round((($_ |Get-Stat -Stat cpu.usagemhz.maximum -Start (Get-Date).AddDays(-7) | Measure-Object Value -Maximum).Maximum),2)}}
        $avgmem = @{N="Mem.Consumed.Average";E={[Math]::Round((($_ |Get-Stat -Stat mem.consumed.average -Start (Get-Date).AddDays(-7) | Measure-Object Value -Average).Average),2)/1000}}

        $vm | Select Host, Name, NumCpu, $avgcpu, $maxcpu, MemoryMB, $avgmem | Export-Csv -Append "somewhere\csv.csv"
    }
}

Solution

  • This old documentation says cpu.usagemhz.max is available in statistics level 4. @user3290553, if that has changed with 5.5, feel free to explain how you came by that information.

    Just in case it's any help, there's a record of some troubleshooting on a related issue here.

    edit - Here's a 5.5 reference. The (4) in the Level column seems to mean that cpu.usagemhz.max is available in stat level 4. To check your stat levels in the thick/C#/non-web VC client, look under vCenter Server Settings > Statistics.