PowerShell 성능 카운터 바 이 너 리 파일(.blg)기록 읽 기 및 집계 계산

모니터링 및 보고 수요 로 인해 성능 카운터 의 매일 수치 상황 을 통계 하고 데이터베이스 서버 의 운행 상황 을 확인 해 야 한다.계산 기 를 켜 서 작성 하 는 것 이 귀 찮 습 니 다.현재 통계 에 서 는 powershell 로 계수기 의 값 을 읽 습 니 다.
첫 번 째 단계:Powershell 은 계수기 파일 을 읽 고 계수기 의 값 을 통계 합 니 다.

$startDate = (Get-Date).AddDays(-1).Date 
$endDate = (Get-Date).Date 
$perfPath = "D:\DataFiles\PERFMON\MSSQL_PERFMON_08240904.blg" 
 
#            
$counterList = Import-Counter -Path $perfPath 
$countersNameList = $counterList[0].countersamples | % {$_.path} 
 
#              PS 
$counter = $countersNameList -like '*Processor Time*' 
$counterData = Import-Counter -Path $perfPath -Counter $counter | Where-Object -FilterScript {($_.Timestamp -ge $startDate) -and ($_.Timestamp -lt $endDate)}  
 
#             
$counterInfo = $counterData | Foreach-Object {$_.CounterSamples} | Measure-Object -property CookedValue -Average -Maximum 
 
#          
$resultTable=@{} 
$resultTable."CPU    ――  " = $counterInfo.Average 
$resultTable."CPU    ――  " = $counterInfo.Maximum 
 
$resultTable 

두 번 째 단계:파일 에 있 는 모든 계수 기 를 일괄 통계 하여 파일 로 내 보 냅 니 다.

$startDate = (Get-Date).AddDays(-1).Date  
$endDate = (Get-Date).Date  
$perfPath = "D:\360Downloads\*.blg" 
 
#           
$resultTable=@{} 
 
#               
$counterData = Import-Counter -Path $perfPath | Where-Object -FilterScript {($_.Timestamp -ge $startDate) -and ($_.Timestamp -lt $endDate)} 
 
#         
$countersNameList = $counterData[0].countersamples | % {$_.Path} 
 
#       ,             
foreach($counterName in $countersNameList)  
{  
#$counterName = "\\hzc\system\threads" 
$counterDataOne = $counterData | Foreach-Object {$_.CounterSamples} | Where {$_.Path -like $counterName}  
$counterInfo = $counterDataOne | Measure-Object CookedValue -Average -Minimum -Maximum 
$resultTable.$($counterName+" :   ") = $counterInfo.Average 
$resultTable.$($counterName+" :   ") = $counterInfo.Minimum 
$resultTable.$($counterName+" :   ") = $counterInfo.Maximum 
} 
 
#$resultTable.GetEnumerator() | sort Name | Format-Table -Auto 
#          
$resultTable.GetEnumerator() | sort Name | Format-Table -Auto | Out-File "D:\360Downloads\PerfmonCounter.txt" 
$resultTable.GetEnumerator() | sort Name | Export-Csv -Path "D:\360Downloads\PerfmonCounter.txt" -Encoding "unicode" -Force 
$resultTable.GetEnumerator() | sort Name | Format-List | Export-Csv -Path "D:\360Downloads\PerfmonCounter.xlsx" -Encoding "unicode" -Force 

좋은 웹페이지 즐겨찾기