OpsMgr: Sample Speedometer Gauge Widget Template

This blog post features a sample management pack that consist of a widget template that allows the user to create custom Speedometer Gauge widgets from the output of PowerShell scripts via a UI within a dashboard layout in the OpsMgr 2012 Operations Console. 

This sample management pack library can now be downloaded from the TechNet Gallery

image

This Speedometer Gauge Widget template is defined in a management pack with a display name of Sample Speedometer Gauge Widget Component Library and importing the management pack into a OpsMgr 2012 R2 environment will allow the widget template to appear under the "All Templates/WeiOutThere Speedometer Gauge" folder in the "New Dashboard and Widget Wizard" page:

image
    

To create an instance of this custom Speedometer Gauge widget, first create a dashboard layout (with n-cells), Click to add widget on a cell, then select the Sample Speedometer Gauge Widget template, go through the UI pages of the template and enter the required information.

  1. On the “General Properties” page, enter a name for the widget.

    image

  2. On the "PowerShell Script" page, the page is already pre-filled with a sample script that consist of all the key properties that utilizes the ScriptContext helper object ( $dataObject = $ScriptContext.CreateFromObject ... ), to control the display on the Speedometer Gauge widget.

    image

    The following picture shows the mapping between the key properties in the script and the corresponding part on the Speedometer Gauge widget that they control:

    image

  3. On the “Refresh Interval” page, enter a numerical value for the refresh interval of the widget (in seconds).
    Note that the default refresh interval for the Speedometer Gauge widget is set at 300 seconds (i.e. refreshes every 5 minutes).

    image

  4. On the “Additional Information” page, enter an additional note for the Speedometer Gauge widget if applicable, or leave it blank.

    image

  5. Click the Finish button to create the custom Speedometer Gauge widget.

    image

Alternatively, the $globalSelectedItems variable can also be used to pass context to a Speedometer Gauge Widget.

Here is an example of a custom Speedometer Gauge Widget utilizing the $globalSelectedItems variable to pass context from objects listed in a State Widget, with the sample script as follows:

############################################################################################################

Param( $globalSelectedItems)

#Create data object
$dataObject = $ScriptContext.CreateInstance("xsd://Speedo!val/stat")
$dataObject["Id"] = "ObjectID"

foreach ($globalSelectedItem in $globalSelectedItems) {

#Get The Name of the selected object
$selectedObjectId = $globalSelectedItem["Id"]
}

$selectedobject = get-scomclassinstance -Id $selectedObjectId

$class = get-scomclass -Name Microsoft.Windows.Server.OperatingSystem

#Look for OS instance of server
$selectedserverOS = Get-SCOMClassInstance -class $class | where Path -eq $selectedobject."[Microsoft.Windows.Computer].PrincipalName"

#Last 3 hours UTC
$aggregationInterval = 3
$dt = New-TimeSpan -hour $aggregationInterval
$nowlocal = Get-Date
#Convert local time to UTC time
$now = $nowlocal.ToUniversalTime()
$from = $now.Subtract($dt)

$perfRules = $selectedserverOS.GetMonitoringPerformanceData()

foreach ($perfRule in $perfRules)
{
#Get % Memory Used Stat
if($perfRule.CounterName -eq "PercentMemoryUsed") {
$data = $perfRule.GetValues($from, $now) | % { $_.SampleValue } | Measure-Object –Average  

     $MemState = [math]::round($data.Average,2)

#Assign % Memory Used Stat to the Value field of the Speedometer Gauge
$dataObject["Value"] = $MemState
}
}

$dataObject["Minimum"] = "0"
$dataObject["Maximum"] = "100"
$dataObject["FormatString"] = "P"

#Threshold and Target/Goal
$dataObject["Goal"] = "50"
$dataObject["ThresholdEndPointTarget"] = "50"

#Red Color Code
$dataObject["ThresholdColorTarget"] = "#9BBC24"
$dataObject["ThresholdEndPointFull"] = "100"

#Green Color Code
$dataObject["ThresholdColorFull"] = "#BC4524"

#Return the data object collection to the Speedometer Gauge
$ScriptContext.ReturnCollection.Add($dataObject)

############################################################################################################

Selecting the first object on the state widget:

image

Selecting another object on the state widget:  
        
image

Additional Reference:

PSG - Introducing $globalSelectedItems:
https://gallery.technet.microsoft.com/PowerShell-Grid-Introducing-90e620dd

ScriptContextObject:
https://social.technet.microsoft.com/wiki/contents/articles/21625.scriptcontextobject.aspx

Thank you for your support and Happy New Year !

      
                 

Disclaimer:
All information on this blog is provided on an as-is basis with no warranties and for informational purposes only. Use at your own risk. The opinions and views expressed in this blog are those of the author and do not necessarily state or reflect those of my employer.