我试图将CPU利用率平均提高30分钟。如果它在30分钟内增加了90%,我可以使用任务调度程序和性能监视器以及PowerShell脚本来获取电子邮件警报。
我尝试过每30分钟后获得总CPU利用率。
以下脚本将为您提供超过30分钟的平均处理器时间。如果处理器平均30分钟时间超过90,您可以让脚本发送电子邮件。我对代码进行了评论以便于理解。
Resizable array you can add items to
[System.Collections.ArrayList]$List = @()
#Counter which is increased by 1 after getting each counter
$Counter = 0
#As long as the counter is less than the below value... (1800 = 30 minutes)
While ($Counter -lt 10)
{
#Get 1 counter per second
$CpuTime = $(Get-Counter -Counter "\Processor(_Total)\% Processor Time" -SampleInterval 1 -MaxSamples 1).CounterSamples.CookedValue
#Add the CPU total time to the list
$List.Add($CpuTime)
#Increase the counter by 1. As we are getting one sample per second, this will be increased by one each second
$Counter++
}
#Get the minimum, average and maximum of the values stored in the list
$Measurements = $List | Measure-Object -Minimum -Average -Maximum
#Email bit. To befinished by you
If ($Measurements.Average -gt 90)
{
Send-MailMessage ......
}
希望这可以帮助。