PowerShell 读取性能计数器二进制文件(.blg)记录并汇总计算(读出计数器上的数)干货满满

随心笔谈11个月前发布 admin
89 0


$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

© 版权声明

相关文章