Free application or script to monitor App pool memory usage
If you don't have IIS 7 and the provider, you can use WMI. The attached script works for most of your requirements, except CPU usage. Save the below script as get-webserverapppoolstats.ps1 (or whatever you want).
You can run the script then with:
./Get-WebServerAppPoolStats.ps1 'Server1', 'Server2', 'Server3' -IntegratedAuthentication OR Get-Content servers.txt | ./Get-WebServerAppPoolStats.ps1 -IntegratedAuthentication
param (
$webserver = $null,
$username,
$password,
[switch]$IntegratedAuthentication)
BEGIN
{
$path = $MyInvocation.MyCommand.Path
if ($webserver -ne $null)
{
if ($IntegratedAuthentication)
{
$webserver | &$path -IntegratedAuthentication
}
else
{
$webserver | &$path -username $username -password $password
}
}
$OFS = ', '
$Fields = 'CommandLine', 'Name', 'CreationDate', 'ProcessID', 'WorkingSetSize', 'ThreadCount', 'PageFileUsage', 'PageFaults'
$query = @"
Select $fields
From Win32_Process
Where name = 'w3wp.exe'
"@
$AppPool = @{Name='Application Pool';Expression={($_.commandline).split(' ')[-1]}}
$Process = @{Name='Process';Expression={$_.name}}
$RunningSince = @{Name='Running since';Expression={[System.Management.ManagementDateTimeconverter]::ToDateTime($_.creationdate)}}
$Memory = @{Name='Memory Used';Expression={'{0:#,#}' -f $_.WorkingSetSize}}
$Threads = @{Name='Thread Count';Expression={$_.threadcount}}
$PageFile = @{Name='Page File Size';Expression={'{0:#,#}' -f $_.pagefileusage}}
$PageFaults = @{Name='Page Faults';Expression={'{0:#,#}' -f $_.pagefaults}}
}
PROCESS
{
$server = $_
if ($server -ne $null)
{
if ($IntegratedAuthentication)
{
$result = Get-WmiObject -Query $query -ComputerName $server
}
else
{
$securepassword = ConvertTo-SecureString $password -AsPlainText -Force
$cred = New-Object System.Management.Automation.PSCredential -ArgumentList $username, $securepassword
$result = Get-WmiObject -Query $query -ComputerName $server -Credential $cred
}
$Server = @{Name='Server';Expression={$server}}
$result | Select-Object $Server, $AppPool, $Process, $RunningSince, $Memory, $Threads, $PageFile, $pageFaults
}
}
Yes powershell can do this with the new powershell provider for IIS it's easy. Here are some of the examples from the run time data walkthru's provided:
AppPool State
PS IIS:\> cd AppPools
PS IIS:\AppPools> Get-WebItemState DemoAppPool
Started
PS IIS:\AppPools> Stop-WebItem DemoAppPool
PS IIS:\AppPools> Get-WebItemState DemoAppPool
Stopped
Worker Processes and Requests The get-process cmdlet doesn't help you figuring out which Application Pool a particular worker process is serving. This can be easily done however:
PS IIS:\AppPools> dir DefaultAppPool\WorkerProcesses
processId Handles state StartTime
--------- -------
6612 326 1 3/28/2008 12:20:27 PM
note that once you have the PID regular
get-process -id pid
will tell you the memory usage