可以用python和/或Powershell获得RAM利用率,而不需要缓存吗?

svdrlsy4  于 4个月前  发布在  Shell
关注(0)|答案(1)|浏览(61)

有没有一种方法可以用powershell/Python获得RAM利用率,而不需要缓存的RAM?我们想要监视我们的系统参数的利用率。目前我在powershell中使用这个,它每30分钟通过任务调度程序调用一次,以及其他参数检查:

...
$counts = 6
$Samples = 145
for($j=0; $j -lt $counts; $j++){
    $temp = 0
    $result = 0
    for ($i=0; $i -lt $Samples; $i++){
        $os = Get-WMIObject Win32_OperatingSystem
        $os | select *memory*
        $pctUsed = [math]::Round(100-($os.FreePhysicalMemory/$os.TotalVisibleMemorySize)*100,2)
        $temp = $pctUsed + $temp
        Start-Sleep -s 2
    }
$result = $temp/$Samples
...

字符串
然后将其发送到我们的监控应用程序。
如何在没有Cache的情况下获得RAM?有办法吗?

ivqmmu1c

ivqmmu1c1#

试试这个,它会在真实的时间内检查RAM的使用情况。

Function Check_RAM{
$time= Get-Date
$usedMemory = Get-CimInstance -Class Win32_OperatingSystem
$totalMemory = $usedMemory.TotalVisibleMemorySize
$freeMemory = $usedMemory.FreePhysicalMemory
$usedMemoryPercentage = ($totalMemory - $freeMemory) / $totalMemory * 100
Write-Host "Used Memory Percentage $usedMemoryPercentage% at $time"
}
do{
Check_RAM
start-sleep -Seconds 10
}until($infinity)

字符串

相关问题