Home > ESX, VMware, vSphere > Get the trend of VM CPU Usage over a 1 year period

Get the trend of VM CPU Usage over a 1 year period

Ever wondered what the trend is of all your VM’s CPU Usage?  You might see surprising things 🙂

 

The following script calculates the following things:

Perf1yAgo The average VM CPU usage over a 10 days timespan exactly 1 year ago
PerfNow The average VM CPU usage over the last 10 days
Trend 0 % = No change in CPU usage
100 % = CPU Usage doubled in a 1 year timespan
-50 % = CPU Usage is half of what it used to be 1 year ago

VM’s with no statistics available from 1 year ago are skipped.  PoweredOff VM’s are skipped as well.

 

Instructions

Fire up PowerCLI and connect to one or more vCenter servers with Connect-VIServer.

Run the following script: (copy-paste it and save with .ps1 extension)

Foreach ($lobjVM in $(Get-VM | Where-Object {$_.PowerState -eq "PoweredOn"}))

{

    [Double] $ldblPerf1yAgo = (Get-Stat -Entity $lobjVM -Stat cpu.usage.average -Start $((Get-Date).AddDays(-365)) `

        -Finish $((Get-Date).AddDays(-355)) -ErrorAction Continue | Measure-Object -Average Value).Average

    If ($ldblPerf1yAgo -eq 0) {Continue}    

    [Double] $lblPerfNow = (Get-Stat -Entity $lobjVM -Stat cpu.usage.average -Start $((Get-Date).AddDays(-10)) -ErrorAction Continue `

        | Measure-Object -Average Value).Average

    [Int] $lintTrend = (($lblPerfNow - $ldblPerf1yAgo) / $ldblPerf1yAgo) * 100

    $objOutput = "" | Select-Object VMName, Perf1yAgo, PerfNow, Trend

    $objOutput.VMName = $lobjVM.Name

    $objOutput.Perf1yAgo = "{0:f2} %" -f $ldblPerf1yAgo

    $objOutput.PerfNow = "{0:f2} %" -f $lblPerfNow

    $objOutput.Trend = "{0} %" -f $lintTrend

    $objOutput

}

It will give you a nice output with the Trend of each VM.

image

Have fun!

Advertisements
Categories: ESX, VMware, vSphere
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: