Automation

 View Only
  • 1.  PowerCLI - Average VM Resource Usage Report

    Posted Aug 05, 2022 05:02 PM

    I'm trying to determine the average VM resource usage for a bunch of VM's. My main goal is determine which VMs can have their cores/memory reduced. I'm trying to run the below script, but I'm getting the same error for each VM "The metric counter "disk.usage.average" doesn't exist for entity".

    Any ideas on how I can correct the error or get average resource usage a different way?

     

    Connect-VIServer <Server Name Redacted>

    $allvms = @()
    $vms = Get-Vm

    $stats = Get-Stat -Entity $vms -start (get-date).AddDays(-7) -Finish (Get-Date)-MaxSamples 10000 -stat "cpu.usage.average","mem.usage.average"
    $stats | Group-Object -Property Entity | %{
    $vmstat = "" | Select VmName, MemMax, MemAvg, MemMin, CPUMax, CPUAvg, CPUMin
    $vmstat.VmName = $_.name

    $cpu = $_.Group | where {$_.MetricId -eq "cpu.usage.average"} | Measure-Object -Property value -Average -Maximum -Minimum
    $mem = $_.Group | where {$_.MetricId -eq "mem.usage.average"} | Measure-Object -Property value -Average -Maximum -Minimum

    $vmstat.CPUMax = [int]$cpu.Maximum
    $vmstat.CPUAvg = [int]$cpu.Average
    $vmstat.CPUMin = [int]$cpu.Minimum
    $vmstat.MemMax = [int]$mem.Maximum
    $vmstat.MemAvg = [int]$mem.Average
    $vmstat.MemMin = [int]$mem.Minimum
    $allvms += $vmstat
    }
    $allvms | Select VmName, MemMax, MemAvg, MemMin, CPUMax, CPUAvg, CPUMin | Export-Csv "c:\VM_Resources\VMs.csv" -noTypeInformation



  • 2.  RE: PowerCLI - Average VM Resource Usage Report
    Best Answer

    Posted Aug 05, 2022 05:55 PM

    There can be a couple of reasons for this message.

    - your VCSA doesn't retain the statistical data long enough

    - the VM might have been powered off at the start of the specified interval

    - the statistical level on your VCSA might not include a specific metric

    Since you state you have the same error for each VM I suspect the 1st bullet might apply.
    Can you make the requested interval shorter (for example 1 day)?
    Does that return data?



  • 3.  RE: PowerCLI - Average VM Resource Usage Report

    Posted Aug 05, 2022 06:17 PM

    The same error is present after changing the interval to 1 day.



  • 4.  RE: PowerCLI - Average VM Resource Usage Report

    Posted Aug 05, 2022 06:54 PM

    Did you check what the retention period for statistical data is?
    Are the statistical data aggregation jobs on the VCSA running correctly?



  • 5.  RE: PowerCLI - Average VM Resource Usage Report

    Posted Aug 05, 2022 09:09 PM
      |   view attached

    I'm not overly familiar with these settings (see attached). From my 5 minute research, it seems like I might need to set a higher statistics level?



  • 6.  RE: PowerCLI - Average VM Resource Usage Report

    Posted Aug 05, 2022 10:28 PM

    These statistics levels look good (they are the defaults), meaning you should be able to get statistical data for the past week.

    Do you see that data in the Web client for 1 of the VMs where the Get-Stat fails?



  • 7.  RE: PowerCLI - Average VM Resource Usage Report

    Posted Aug 08, 2022 04:45 PM

    After looking at it again, changing the interval from 30 to 7 days, it is now able to create the CSV file. The errors are only coming from VM's that are powered off. You have resolved my issue. Thanks for the help!