Thursday, June 26, 2008

ASPNet_WP.exe analysis on multiple servers via PowerGadgets


Was recently asked if I could help our development team analyze the ASPNet_WP process on 3 web servers. These 3 servers are load balanced and deliver the same content (FRS). There has been some spikes in the process and they wanted to be able to see this graphically. PowerGadgets to the rescue!

Steps are:
- Grabs an encrypted password (see previous post) as I am going across domains.
- Get WorkingSizeSet of the ASPNet_WP on the servers via WMI
- Store the WorkingSizeSet in a csv file (DB soon!)
- Grab the CSV file an pipe it to Out-Chart (PowerGadgets)
- Create a bat file that calls PowerShell with the appropriate ps1 file
(powershell.exe -nologo -command "& {c:\productionscripts\get-aspnet_wp1.ps1})
- Schedule the bat file
Please forgive the lack of pipes in this post. I am struggling to find a blog that handles code nicely.

###################################################
# Script Name: Get-ASPNet_WP.ps1
# Description: PowerShell Script for ASPNet_WP
# analysis on intapp-p2, webster-vp01
# and webster-vp02
#
# Created By: Wes Stahler
# Date Created: 6/25/2008
# Change Log:
# 6/26/2008 Added PowerGadget chart for
# inclusion on admin web page
###################################################

# Get password from encrypted file
# Once these servers are moved into the correct domain
# we won't have to worry about the creds....
$password = Get-Content c:\cred.txt ConvertTo-SecureString

# Create credentials
$creds = New-Object -typename System.Management.Automation.PSCredential `
-argumentlist "nt3osumc\stah06",$password

# Get WorkingSetSize for the 3 NT3OSUMC servers
$intapp_p2 = Get-WmiObject -Class Win32_Process `
-ComputerName intapp-p2 -Credential $creds `
Where-Object {$_.ProcessName -eq "aspnet_wp.exe"} `
Sort-Object WorkingSetSize -Descending `
Select-Object -First 1

$webster_vp01= Get-WmiObject -Class Win32_Process `
-ComputerName webster-vp01 -Credential $creds `
Where-Object {$_.ProcessName -eq "aspnet_wp.exe"} `
Sort-Object WorkingSetSize -Descending `
Select-Object -First 1

$webster_vp02= Get-WmiObject -Class Win32_Process `
-ComputerName webster-vp02 -Credential $creds `
Where-Object {$_.ProcessName -eq "aspnet_wp.exe"} `
Sort-Object WorkingSetSize -Descending `
Select-Object -First 1

# Being lazy....
$intappp2 = [math]::Round($intapp_p2.workingsetsize/1024/1024,0)
$webstervp01 = [math]::Round($webster_vp01.workingsetsize/1024/1024,0)
$webstervp02 = [math]::Round($webster_vp02.workingsetsize/1024/1024,0)
$dt = Get-Date -Format T

# Format string for to append to the historical file
# Will add to a DB later
$str = "{0},{1},{2},{3}" -f $dt,$intappp2,$webstervp01,$webstervp02

# Append to file
Add-Content -Path "c:\ProductionScripts\ASPNet_WP.csv" -Value $str

# Grab the data (last 7 hours worth) and chart!
$b = Import-Csv "c:\ProductionScripts\ASPNet_WP.csv" select -last 28
$b Out-Chart -Values Intapp-p2, webster-vp01, Webster-vp02 `
-Label Time `
-Title "ASPNet_WP.exe as of $dt" `
-gallery Lines `
-AxisY_Max 1000 `
-Size 800,533 `
-Series_1_AxisY AxesY_0 `
-Series_2_AxisY AxesY_0 `
-Output "file://intapp-p2/e$/Inetpub/Extranet/ProjectManager/Exception/ASPNet_WP.png"
###################################################

No comments: