如何在CPU平均利用率超过90%30分钟时收到电子邮件警报?

问题描述 投票:0回答:1

我试图将CPU利用率平均提高30分钟。如果它在30分钟内增加了90%,我可以使用任务调度程序和性能监视器以及PowerShell脚本来获取电子邮件警报。

我尝试过每30分钟后获得总CPU利用率。

powershell server cpu-usage taskscheduler perfmon
1个回答
0
投票

以下脚本将为您提供超过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 ......
}

希望这可以帮助。

© www.soinside.com 2019 - 2024. All rights reserved.