Virtu-Al.Net

Virtually everything is poshable

Quick Stats from VMware for reports

I wrote another quick script today as my powershell skills grow!

The following script can be used to give you a JPG outputted graph of some stats that you can choose, handy for reports.

It can easily be adjusted to perform stats on the ESX servers (vmhost) as well.

Example output (My Test server names have been blurred):

Chart

connect-VIServer yourserver

# Set the following 3 variables for your needs
# Example stats are:
# % CPU Usage – cpu.usage.average
# Mhz CPU Usage – cpu.usageMHZ.average
# % Memory Usage – mem.usage.average
# Kbps Network Usage – net.usage.average
# Kbps Disk Usage – disk.usage.average

$Caption = "CPU Usage"
$Stat = "cpu.usage.average"
$NumToReturn = 20

$categories = @()
$values = @()
$chart = new-object -com OWC11.ChartSpace.11
$chart.Clear()
$c = $chart.charts.Add(0)
$c.Type = 4
$c.HasTitle = "True"
$series = ([array] $chart.charts)[0].SeriesCollection.Add(0)

Get-Stat -Entity (Get-vm) -Stat $stat -MaxSamples 1 -Realtime |Sort-Object Value -Descending | Select-Object Entity, Value -First $NumToReturn | foreach-object {

$categories += $_.Entity.Name
$values += $_.Value * 1
}
$series.Caption = $Caption
$series.SetData(1, -1, $categories)
$series.SetData(2, -1, $values)
$filename = (resolve-path .).Path + "\Chart.jpg"
$chart.ExportPicture($filename, "jpg", 800, 500)
invoke-item $filename

4 Responses to “Quick Stats from VMware for reports”

  • cshanklin says:

    Nice. What’s a good resource to learn more about Office Web Charts? Neither my web searches or actually installing OWC seemed to lead to any obvious documentation.

  • Virtu-Al says:

    The only stuff I could find really was on the MSDN site here…. http://msdn.microsoft.com/en-us/library/aa141474(office.10).aspx plus other examples when google’d which can be adapted to Powershell.

    Thanks for reading the post, glad to see its not just me !

  • Virtu-Al says:

    For anyone else wondering the following site shows you where the reference files are for your version of office….

    http://support.microsoft.com/kb/222101/

  • Brett says:

    Hi,

    You created a very nice script for Datastore capacity graph.
    Do you have an updated version that will run on a Windows 2008 server ?

    The script works on a 2003 server fine but not on 2008.

    fails at the “$series = ([array] $chart.charts)[0].SeriesCollection.Add(0)”

    Cheers

    Brett

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>