Jump to content
Software FX Community

DrillDown Part 2. Master-Detail using PowerGadgets


Recommended Posts

To show how DrillDown_script allows you to interactively analyze your data and link multiple PowerShell scripts we will build a series of scripts used to monitor multiple IIS web servers. We will start with a chart showing Current Connections for all of our servers.


$servers = "webserver1", "webserver2", "webserver3"
Get-WmiObject Win32_PerfFormattedData_W3SVC_WebService -computername $servers -filter "Name='_Total'" -property __SERVER, CurrentConnections | select __Server,CurrentConnections

I tried to speed this script by both filtering and specifying the output properties at the get-wmiobject call, trying to minimize network traffic and hopefully wmi execution but it still feels a little sluggish. If you know how to improve the performance of this remote wmi command please add a comment to this post.

IISServers | out-chart -drilldown_script IISServer -drilldown_parameter {$_.__Server} -refresh 0:0:30 -legendbox_visible false

Posted Image

Now we need to make sure our IISServer.ps1 script handles a parameter which will have one of the server names, on this script we will list information on a per-site basis, please be aware that when you double click on a bar you will get detailed information for the specific server but on a busy server this new detailed information might be different than the "Total"  showed on the previous chart as it will be fresh data.


$computer = $args[0]
$title = "Current Connections for " + $computer
Get-WmiObject Win32_PerfFormattedData_W3SVC_WebService -computername $computer -property __SERVER, Name, CurrentConnections | select Name, CurrentConnections, __SERVER | where {$_.Name -ne "_Total"} | out-chart -title $title -drilldown_script IISSite -drilldown_parameter {$_.__Server},{$_.Name} -refresh 0:0:30 -gallery pie

Posted Image

Note that in this script we are actually getting the data and immediately sending it to the chart, normally we recommend you try to keep your "data/business-layer" scripts separated from the presentation scripts but this make this sample a little easier. You could split it into 2 scripts if desired. Also note we are again piping the server name to the out-chart cmdlet, we do this in order to be able to pass this parameter to our third script when double clicking.

Finally IISSite.ps1 will show the real-time trend information for a specific site on a server, in this case because the script will return one "record" of information, out-chart will automatically add points every time the refresh timer ticks.


$computer = $args[0]
$site = $args[1]
$title = "Site " + $site + " on " + $computer
$filter = "Name = '"+$site+"'"
Get-WmiObject Win32_PerfFormattedData_W3SVC_WebService -computername $computer -filter $filter -property Name, CurrentConnections, BytesTotalPersec | select Name, CurrentConnections, BytesTotalPersec | out-chart -values CurrentConnections,BytesTotalPersec -refresh 0:0:30 -disableauto AxisY -series_1_axisy AxisY2 -gallery Lines -title $title -legendbox_dock bottom -axisy_TextColor DarkBlue -axisy2_TextColor DarkRed

Some notes about this chart

  • We are using -disableAuto and -series1_axisy in the out-chart cmdlet, normally PowerGadgets will analyze your data to see if multiple Y axes are required, this analysis is not repeated when adding points to avoid an axis suddenly appearing/disappearing. We want to make sure we force the use of 2 Y axes in case the data for CurrentConnections and BytesTotalPerSec on the first point collected are both small as later they will most likely differ.
  • The legend window will be placed at the bottom using -legendbox_dock to improve space usage.
  • We are changing the color used to paint the axis labels to make more clear the relation between each line and its axis, if you hover one of the lines or the legend box we will also highlight the appropriate element while dimming non-related items.
  • When PowerGadgets detects a realtime chart that adds points is not using X axis labels it will automatically set the label to the time the data was collected.

Posted Image

Posted Image

DrillDown to a console window

Sometimes listing text is actually the best choice, if you want to drilldown to a script that just outputs data to the console you can do so by adding the -drilldown_console flag, e.g. if double clicking on a server in IISServer.ps1 should just list all web sites including the number of connections for each site you would remove the out-chart call in IISServer.ps1 so that it just returns the request data and then add -drilldown_console to the out-chart that gets data from IISServers.ps1. If you forget to add -drilldown_console we will still run IISServer.ps1 but you will not see its output.

I try to make most of the sample code in my posts not to require any attachments (databases, etc.) as I feel this gives you a chance of quickly experimenting with it, obviously if you are using invoke-sql to connect gadgets to databases you can easily apply the concepts in this post to add drill down interactivity to your gadgets.


Link to comment
Share on other sites

  • 2 weeks later...
  • Create New...