使用powershell计算性能计数器的均值
function SaveToDisk([string]$filename,[string]$counterPath)
{
$total=0
$singleCounterArrayList=import-counter $filename -counter $counterPath
foreach ($singleCounter in $singleCounterArrayList)
{
$total=$total+$singleCounter.CounterSamples[0].CookedValue
}
$averageValue=$total/($singleCounterArrayList.count)
Write-Host $counterPath.replace("\\db-web-read-15\\","") " is $averageValue"
}
SaveToDisk "C:\2.blg" "\\db-web-read-15\\physicalDisk(_total)\Avg. Disk sec/Write"
{
$total=0
$singleCounterArrayList=import-counter $filename -counter $counterPath
foreach ($singleCounter in $singleCounterArrayList)
{
$total=$total+$singleCounter.CounterSamples[0].CookedValue
}
$averageValue=$total/($singleCounterArrayList.count)
Write-Host $counterPath.replace("\\db-web-read-15\\","") " is $averageValue"
}
SaveToDisk "C:\2.blg" "\\db-web-read-15\\physicalDisk(_total)\Avg. Disk sec/Write"
不知道哪里出了错误, Avg.Disk sec/Write这个计数器的值和打开blg文件得到的平均值严重不符...
貌似不是代码的问题,将blg到处成csv格式,计算均值,也和双击打开的值不符...
其它的性能技术器都还比较准确,只有 Avg.Disk sec/Write不对