Oct 182010
 

I have been investigating using Microsoft Chart Controls for Microsoft .NET Framework 3.5 to create some nice looking images in my Powershell reporting script. I am in the early stage but here is an initial snip-it of how powerful this can be.

Once I finish my report script I will post it for everyone to enjoy.

# -----------------------------------------------------------------------------------------------------------
###
### Script Name - charting for vcenter object demo
###
### Author - David Owen
###
### Description - this script gathers the VM objects and displays them in graph format.
###
 
# connect to you VC or ESX server
Connect-VIServer -Server "your server"
 
# gather statistics to be used in the graph
$vms = Get-VM -Name *io*
$vms1 = Get-VM -Name *4
 
# create chart object
$Chart = New-object System.Windows.Forms.DataVisualization.Charting.Chart
$Chart.Width = 350
$Chart.Height = 250
$Chart.Left = 25
$Chart.Top = 15
 
# create a chart area to draw on and add to chart
$ChartArea = New-Object System.Windows.Forms.DataVisualization.Charting.ChartArea
$Chart.ChartAreas.Add($ChartArea)
 
# add data to chart
$conts = @{"Total of vms with io in the name" = $vms.count; "number of VMs with 4 in the name" = $vms1.count}
[void]$Chart.Series.Add("Data")
$Chart.Series["Data"].Points.DataBindXY($conts.Keys, $conts.Values)
 
# set chart type
$Chart.Series["Data"].ChartType = [System.Windows.Forms.DataVisualization.Charting.SeriesChartType]::Pie
 
# set chart options
$Chart.Series["Data"]["PieLabelStyle"] = "Outside"
$Chart.Series["Data"]["PieLineColor"] = "Black"
$Chart.Series["Data"]["PieDrawingStyle"] = "Concave"
($Chart.Series["Data"].Points.FindMaxByValue())["Exploded"] = $true
 
$Chart.SaveImage("$pwd\myChart1.gif",[System.Windows.Forms.DataVisualization.Charting.ChartImageFormat]::Gif)
 
invoke-item "$pwd\myChart1.gif"
 
Disconnect-VIServer -Force -WarningAction SilentlyContinue

Here are some example charts.

I produced the pie chard just using get-vm as the data source.

As you can see you can do some real cool treading stats with this .net extension. I’m not a .net developer and all the examples are in .net so its a slow process but the basic charts I am producing are relay cool and will fit nicely into reports.

Things like up-time statistics and resource processes easy accessible through the VMware APIs that normally you can only get from the viclient are now totally customizable into you own format etc to fit your needs.

Post to Twitter

  3 Responses to “Using Microsoft Chart Controls to Report on vCenter Statistics”

  1. There are certainly a lot of possibilities for PowerCLI and Chart Controls. I’ve only played with the Histograms so far. Nice to see how simple the pie charts can be too.

  2. yeah im looking forward to doing some trend analysis and put it all into a nice web gui or somthing. Windows forms are great if you run it localy but if you want to share to the managment or somthing you need to output the charts to HTML of somthing.

  3. […] experimenting with Chart Controls also. We compared notes over a few beers after IP Expo yesterday. His article is a good read and efficiently produces a nice pie chart from his script. I’m looking forward […]

 Leave a Reply

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=""> <s> <strike> <strong>

(required)

(required)

Twitter links powered by Tweet This v1.8.3, a WordPress plugin for Twitter.