SCOM 2012 R2 - IIS Application Pool Performance with Powershell Grid Widget

When you want to create a dashboard on Operations Manager you can find alot of widgets. One of them is “Powershell Grid Widget” . using this widged you can create what ever grid dashboard you want.

In this article, I will explain how to create a dashboard that shows the amount of CPU and Ram used by application pools on the IIS, using powershell grid widget.

Before Starting the configuration, we will create the necessary dashboard template on SCOM.

To create this, we have to choose Dashboard View Section as below.

Continue choosing Grid Layouts as in the exhibit.

Name the dashboard and continue.

Determine dashboard cell count and structure on wizards layout page.

After creating the dashboard, we can add the related widgets to the cells. There are alot of widgets on SCOM. We will select “Powershell Grid Widget”.

Name the widged and continue. I will name it “IIS Servers” as in this section IIS servers will be listed.

In teh next part we will write the script. I will explain the script below.

#We will assign IIS Server class to a variable.

$class = Get-SCOMClass -Name Microsoft.Windows.InternetInformationServices.ServerRole

#Using this class, we will get IIS Servers.

 $computers = Get-SCOMClassInstance -Class $class

#To assign a number value to grid elements,we will create a variable.

$i=1

#We will add each computer object to grid with ID,HealthState and DisplayName columns. We will map the value of those columns with object attributes.

foreach ($computer in $computers)

{

$dataObject = $ScriptContext.CreateFromObject($computer, "Id=Id,HealthState=HealthState,DisplayName=Path", $null)

#we will define custom column for each object on the grid. (like order number)

$dataObject["CustomColumn"]=$i

$ScriptContext.ReturnCollection.Add($dataObject)

$i++

}

After saving the script, IIS Servers will be listed like below.

Lets move on with configuring the second cell. The process in this section is depending on the first cell. We will see the application pool information that is on the selected the server in the first cell, in the second cell.

We will select “Powershell Grid Widget” for second cell and continue.

Name the selected widgets and continue.

Add the powershell script below and continue. The explanation scripts are below.

#we will get the server info selected on the other cell as parameter.

Param($globalSelectedItems)

#we will perform the processes below for each item.

foreach ($globalSelectedItem in $globalSelectedItems)

{

#Assign IIS Server name to the variable.

$ServerName=$globalSelectedItem["DisplayName"]

#Assign “W3WP” process to a variable on the server

$proclist = Get-Process -ComputerName $ServerName -name "W3WP"

# To assign a number value to grid elements,we will create a variable.

$i=1

#Perform processes below for all w3wp process.

foreach ($p in $proclist)

 {

#Create new attribute for process.

 $p | Add-Member -type NoteProperty -name UserID -value ((Get-WmiObject -ComputerName $ServerName -class win32_process | where{$_.ProcessID -eq $p.id}).getowner()).user

#Create new CPU percent usege attribute for process.

$p | Add-Member -type NoteProperty -name PercentCPU -value (get-wmiobject -ComputerName $ServerName -Class Win32_PerfFormattedData_PerfProc_Process | where{$_.IDProcess -eq $p.id}).PercentProcessorTime

#Specify grid columns and that values.

$dataObject = $ScriptContext.CreateInstance("xsd://foo!bar/baz")

$dataObject["Id"] = $i.ToString()

$dataObject["PoolName"] = $p.UserID

$dataObject["PID"] = $p.Id.ToString()

$dataObject["CPU"] = "%"+" "+$p.PercentCPU.ToString()

$dataObject["Memory (MB)"] = "{0:N0}" -f ($p.WS/1MB)+" "+"MB"

$dataObject["NPM"] = "{0:N0}" -f ($p.NPM/1KB)+" "+"KB"

$dataObject["Private Bytes (MB)"] =  "{0:N0}" -f ($p.PM / 1MB)+" "+"MB"

$dataObject["Virtual Memory Size"] = "{0:N0}" -f ($p.VM / 1MB)+" "+"MB"

$ScriptContext.ReturnCollection.Add($dataObject)

$i++

 }

}

Copy scripts and complete the wizard.

After the configuration , for each IIS server that you have selected from Iıs Servers section, application pools and the amount of CPU/RAM they consme will be listed as below.

See you in the next article

FIRAT