PowerShell 讀取性能計(jì)數(shù)器二進(jìn)制文件(.blg)記錄并匯總計(jì)算
由于監(jiān)控及報(bào)告需要,要統(tǒng)計(jì)性能計(jì)數(shù)器每天數(shù)值情況,確認(rèn)數(shù)據(jù)庫服務(wù)器的運(yùn)行狀況。若打開計(jì)數(shù)器填寫,比較麻煩,現(xiàn)在統(tǒng)計(jì)用 powershell 來讀取計(jì)數(shù)器的值。
第一階段:Powershell 讀取計(jì)數(shù)器文件并統(tǒng)計(jì)其中一個(gè)計(jì)數(shù)器的值
$startDate = (Get-Date).AddDays(-1).Date $endDate = (Get-Date).Date $perfPath = "D:\DataFiles\PERFMON\MSSQL_PERFMON_08240904.blg" #讀取文件中的計(jì)數(shù)器名稱 $counterList = Import-Counter -Path $perfPath $countersNameList = $counterList[0].countersamples | % {$_.path} #篩選指定計(jì)數(shù)器和時(shí)間重新導(dǎo)入PS $counter = $countersNameList -like '*Processor Time*' $counterData = Import-Counter -Path $perfPath -Counter $counter | Where-Object -FilterScript {($_.Timestamp -ge $startDate) -and ($_.Timestamp -lt $endDate)} #計(jì)算日期范圍內(nèi)的數(shù)值統(tǒng)計(jì) $counterInfo = $counterData | Foreach-Object {$_.CounterSamples} | Measure-Object -property CookedValue -Average -Maximum #哈希表存儲(chǔ)結(jié)果數(shù)據(jù) $resultTable=@{} $resultTable."CPU 利用率——平均" = $counterInfo.Average $resultTable."CPU 利用率——最大" = $counterInfo.Maximum $resultTable
第二階段:批量統(tǒng)計(jì)文件中的所有計(jì)數(shù)器并導(dǎo)出到文件中
$startDate = (Get-Date).AddDays(-1).Date $endDate = (Get-Date).Date $perfPath = "D:\360Downloads\*.blg" #哈希表存儲(chǔ)結(jié)果數(shù)據(jù) $resultTable=@{} #導(dǎo)入指定時(shí)間的所有計(jì)數(shù)器信息 $counterData = Import-Counter -Path $perfPath | Where-Object -FilterScript {($_.Timestamp -ge $startDate) -and ($_.Timestamp -lt $endDate)} #所有的計(jì)數(shù)器名字 $countersNameList = $counterData[0].countersamples | % {$_.Path} #遍歷每個(gè)計(jì)數(shù)器,將計(jì)算結(jié)果存儲(chǔ)到哈希表中 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 #幾種方法導(dǎo)出到文件 $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
相關(guān)文章
Powershell獲取圖片名字、文件夾及拍攝時(shí)間的例子
這篇文章主要介紹了Powershell獲取圖片名字、文件夾及拍攝時(shí)間等信息的例子,需要的朋友可以參考下2014-06-06Powershell使用C#實(shí)現(xiàn)縮寫路徑
這篇文章主要介紹了Powershell使用C#實(shí)現(xiàn)縮寫路徑,縮寫路徑有時(shí)候是非常有用的,比如某些報(bào)表的路徑太長會(huì)很難看,縮寫后就會(huì)好看許多,需要的朋友可以參考下2015-01-01Windows Powershell分析和比較管道結(jié)果
這篇文章主要介紹了Windows Powershell分析和比較管道結(jié)果,需要的朋友可以參考下2014-09-09PowerShell查看本機(jī)文件關(guān)聯(lián)程序和默認(rèn)打開程序的方法
這篇文章主要介紹了PowerShell查看本機(jī)文件關(guān)聯(lián)程序和默認(rèn)打開程序的方法,本文給出了查看方法,同時(shí)給出了一份讀取結(jié)果,需要的朋友可以參考下2015-06-06探索PowerShell (四) PowerShell的對(duì)象、格式與參數(shù)
本節(jié)將要給大家介紹一下PowerShell下的對(duì)象,基本格式以及參數(shù)。依然屬于PowerShell的基礎(chǔ)2012-12-12Powershell訪問SQL Server數(shù)據(jù)庫代碼實(shí)例
這篇文章主要介紹了Powershell訪問SQL Server數(shù)據(jù)庫代碼實(shí)例,本文直接給出代碼,使用時(shí)只需要替換數(shù)據(jù)庫配置參數(shù)即可,需要的朋友可以參考下2014-11-11Windows Powershell排序和分組管道結(jié)果
本文通過實(shí)例,詳細(xì)介紹了Powershell如何對(duì)管道結(jié)果進(jìn)行排序和分組,非常的實(shí)用,有需要的朋友可以參考下2014-09-09