当 CPU 平均利用率超过 90% 持续 30 分钟时,如何获得电子邮件提醒?

How to get Email alerts when CPU average utilization is grater than 90 percent for 30 min?

我正在尝试获取 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 ......
}

希望对您有所帮助。