用relog合并perfmon生成的多个blg文件时,若直接relog 1.blg,relog 2.blg -f bin -o result.blg,当blg文件比较多时,有一个无法理解的现象产生,生成的文件只是抓取最近65分钟内的数据,其他数据丢失[经了解,这是因relog合并多个文件,最大数量为32造成],为避免这种情况,现将blg两个两个合成,不一次合成多个,powershell脚本如下:
$logPath = "E:\教程\技术资料\试验厂\powershell\perfmon\211\SqlDiag"
$SavePath = "E:\教程\技术资料\试验厂\powershell\perfmon\211\"
$RunTime = ((Get-Date).ToString("MMddhhmmss"))
$Prefix = "Temp_"
$tmpFileNameBase = $SavePath + $Prefix + ((Get-Date).ToString("MMddhhmmss"))
$FileNameBase = $SavePath + ((Get-Date).ToString("MMddhhmmss"))
$fileList = Get-ChildItem $logPath -recurse *.BLG | %{$_.FullName}
$relog = "relog " + $fileList[0] + " -f bin -o " + $tmpFileNameBase +"[0]" + ".blg"
Invoke-Expression $relog
for( $i = 1; $i –lt $fileList.Length; $i++ ){
$FileName = $tmpFileNameBase +"["+($i-1)+"]" + ".blg" + " " + $fileList[$i]
$relog = "relog " + $FileName + " -f bin -o " + $tmpFileNameBase +"["+($i)+"]" + ".blg"
$relog
Invoke-Expression $relog
}
$relog = "relog " + $tmpFileNameBase +"["+($i-1)+"]" + ".blg" + " -y -f bin -o " + $FileNameBase+ ".blg"
Invoke-Expression $relog
$relog = "relog " + $FileNameBase + ".blg" + " -y -f csv -o " + $FileNameBase+ ".csv"
Invoke-Expression $relog
#删除临时文件
$del = " Remove-Item " + $SavePath + $Prefix + "*.blg"
Invoke-Expression $del
relog /?:
查看记数器 relog sqldiag.blg -q -o counter.txt