작업 관리자를 보면 "사용 중"메모리를 볼 수 있습니다. Perfmon "사용 중"메모리를 얻는 방법
나는 성능 정보를 PerfMon
에 잡을 수 있다고 알고 있지만 Perfmon의 어떤 카운터가이 값을 검색하는지 알지 못합니다.
지난 날의 평균 메모리 사용량을 확인하는 PowerShell 스크립트를 작성하고 싶습니다. PerfMon이 내가 생각할 수있는 유일한 옵션입니다. PowerShell에서 더 좋은 방법이 있습니까?
작업 관리자를 보면 "사용 중"메모리를 볼 수 있습니다. Perfmon "사용 중"메모리를 얻는 방법
나는 성능 정보를 PerfMon
에 잡을 수 있다고 알고 있지만 Perfmon의 어떤 카운터가이 값을 검색하는지 알지 못합니다.
지난 날의 평균 메모리 사용량을 확인하는 PowerShell 스크립트를 작성하고 싶습니다. PerfMon이 내가 생각할 수있는 유일한 옵션입니다. PowerShell에서 더 좋은 방법이 있습니까?
Get-Counter -Counter
은 PowerShell 2 이상에서 성능 카운터를 얻는 방법입니다. "사용에서"이 Total Memory - Available
의 둥근 값이처럼 보이는 :
[math]::Round(((((Get-Ciminstance Win32_OperatingSystem).TotalVisibleMemorySize * 1kb) - ((Get-Counter -Counter "\Memory\Available Bytes").CounterSamples.CookedValue))/1GB),1)
: $UsedRAM
변수가 당신을 위해 무엇을 찾고 있습니다.
$SystemInfo = Get-WmiObject -Class Win32_OperatingSystem | Select-Object Name, TotalVisibleMemorySize, FreePhysicalMemory
$TotalRAM = $SystemInfo.TotalVisibleMemorySize/1MB
$FreeRAM = $SystemInfo.FreePhysicalMemory/1MB
$UsedRAM = $TotalRAM - $FreeRAM
$RAMPercentFree = ($FreeRAM/$TotalRAM) * 100
$TotalRAM = [Math]::Round($TotalRAM, 2)
$FreeRAM = [Math]::Round($FreeRAM, 2)
$UsedRAM = [Math]::Round($UsedRAM, 2)
$RAMPercentFree = [Math]::Round($RAMPercentFree, 2)
이제 우리는 현재/사용중인 메모리를 얻는 방법을 알고 있지만, 평균을 얻는 데 더 많은 코드가 필요합니다. Get-Counter
을 사용하면 평균의 카운터를 설정할 수는 있지만 테스트 중에 평균을 제공하며 시간이 지나지 않습니다.
평균을 잘 이해하려면 약 1000 건을 계산합니다. 이 또한 메모리를 소비합니다 유의하십시오. 시스템의 언어에 따라 서식이 잘못 될 수 있습니다.
$interval = 1 #seconds
$maxsamples = 1000
$memorycounter = (Get-Counter "\Memory\Available MBytes" -maxsamples $maxsamples -sampleinterval $interval |
select -expand countersamples | measure cookedvalue -average).average
### Memory Average Formatting ###
$freememavg = "{0:N0}" -f $memorycounter
### Get total Physical Memory & Calculate Percentage ###
$physicalmemory = (Get-WMIObject -class Win32_PhysicalMemory | Measure-Object -Property capacity -Sum).Sum/1mb
$physicalmemory - $memorycounter
#$physicalmemory - $freememavg #Depending on the Formatting of your system
이 작업은 CPU와 디스크에서도 수행 할 수 있습니다.
[google yourself] (http://www.google.com/search?q=powershell+perfmon+memory+usage) 및 [this for (예)] (https : //www.simple-talk)를 읽어보십시오. .com/sysadmin/powershell/powershell-day-to-day-admin-tasks-monitoring-performance /) – LotPings