Last active
June 6, 2023 09:19
-
-
Save rkttu/81669b7b66eac402a995e426742b6dfc to your computer and use it in GitHub Desktop.
Average Load (1m, 5m, 15m) Display for Windows
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# https://github.com/giampaolo/psutil/blob/master/psutil/arch/windows/wmi.c | |
$LOADAVG_FACTOR_1F = 0.9200444146293232478931553241 | |
$LOADAVG_FACTOR_5F = 0.9834714538216174894737477501 | |
$LOADAVG_FACTOR_15F = 0.9944598480048967508795473394 | |
$SAMPLING_INTERVAL = 5 | |
$load_avg_1m = 0.0; | |
$load_avg_5m = 0.0; | |
$load_avg_15m = 0.0; | |
$myCounter = New-Object -TypeName 'System.Diagnostics.PerformanceCounter' -ArgumentList ('System', 'Processor Queue Length', $null, '.') | |
try { | |
while ($true) { | |
$currentLoad = $myCounter.NextValue() | |
$load_avg_1m = $load_avg_1m * $LOADAVG_FACTOR_1F + $currentLoad * (1.0 - $LOADAVG_FACTOR_1F); | |
$load_avg_5m = $load_avg_5m * $LOADAVG_FACTOR_5F + $currentLoad * (1.0 - $LOADAVG_FACTOR_5F); | |
$load_avg_15m = $load_avg_15m * $LOADAVG_FACTOR_15F + $currentLoad * (1.0 - $LOADAVG_FACTOR_15F); | |
([Math]::Round($load_avg_1m, 2), [Math]::Round($load_avg_5m, 2), [Math]::Round($load_avg_15m, 2)) | ConvertTo-Json -Compress | Write-Output | |
Sleep -Seconds $SAMPLING_INTERVAL | |
} | |
} finally { | |
$myCounter.Dispose() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment