如何检查应用程序池最后回收

时间:2011-12-14 20:42:57

标签: iis-7 application-pool recycle

是否有可能检查我上次回收应用程序池的时间,我想查看我的应用程序池上次回收的日期,IIS中是否有任何内容我可以获取此信息。

6 个答案:

答案 0 :(得分:49)

您可以使用此PowerShell代码段轻松找到最新的回收时间:

(Get-Process -Id <ProcessId>).StartTime

因此,在任务管理器中查找Web应用程序的进程ID 首先通过工具&gt;添加以下列选择列... :选择 PID 命令行 查找任何w3wp.exe进程并通过检查命令行(应用程序池名称是其中的一部分)找到您的应用程序并记下其PID。
然后运行powershell脚本以查找最新的回收时间:

希望这有帮助

答案 1 :(得分:21)

如果启用了登录回收,您可以在事件查看器(系统日志)中看到此信息。

如果不是,您可以使用PerfMon计数器查看代表您的应用程序池的W3WP.exe上的进程耗​​用时间(这将是自上次回收以来的秒数)

答案 2 :(得分:8)

要使用一个命令获取所有信息,请使用Get-WmiObject而不是get-process。

Get-WmiObject Win32_Process -Filter "name = 'w3wp.exe'" | Select-Object Name, @{"name"="ApplicationPool";expression={(($_).CommandLine).split('"')[1] }},@{"name"="Starttime";expression={$_.ConvertToDateTime($_.CreationDate)}}

答案 3 :(得分:1)

这将为您提供计算机上所有w3wp进程及其开始时间的列表。如果没有启动网站,则ErrorAction可防止命令行进程抛出错误,因此不存在w3wp进程

ps w3wp -ErrorAction SilentlyContinue | select ProcessName, StartTime

使用PowerShell v4.0在Server 2012 R2上测试

答案 4 :(得分:1)

在Powershell中:

(ps -id (Get-IISAppPool -Name <name>).WorkerProcesses.ProcessId).StartTime

如果池已被回收,则出于某种原因,您可能需要重新导入模块以获取新的processId:

$pool = Get-IISAppPool -Name <name>

$pool.recycle()

Import-Module -Force IISAdministration

(ps -id (Get-IISAppPool -Name <name>).WorkerProcesses.ProcessId).StartTime

答案 5 :(得分:0)

获取工作进程的正常运行时间(推荐):

$poolName = <your pool name goes here eg. DefaultPool>
$poolProcess =(gwmi -NS 'root\WebAdministration' -class 'WorkerProcess' | select AppPoolName,ProcessId | Where-Object { $_.AppPoolName -eq $poolName } )

$lastStartTime=(Get-Process -Id $poolProcess.ProcessId).StartTime
write-output $lastStartTime

要使其正常工作,请确保已启用“IIS管理脚本和工具”。

enter image description here

其次,方法是使用事件日志,如果启用

Get-Eventlog -LogName system -Newest 1 -Source "WAS" -Message "*recycle of all worker processes in application pool '$poolName'*")

使用Get-Eventlog,您可以使用-After/-Before参数来进一步限制结果。

要检查应用程序池是否在最后'X'分钟内被回收,可以使用以下powershell代码段:

function isRecycledInLastNMinutes($appPoolName, $lminutes){
    $beforeDate = Get-Date -format 'u'
    $afterDate = $beforeDate.addMinutes(-$lminutes)
    $result = (Get-Eventlog -LogName system -Newest 1 -Source "WAS" -After $afterDate -Before $beforeDate -Message "*recycle of all worker processes in application pool '$appPoolName'*")
    if( $result.length -eq 1){
        return $true
    }else{
        retrun $false
    }
}