この集計作業を自動化したいので、VBSで組んでもらえないでしょうか。概要は、別エクセルを作成し、日単位、時間単位、分単位のシートを作成し、それぞれのシートに結果を書いてください。よろしくお願いします。
「Log Parser」を利用するというのはいかがでしょう?
「Log Parser」は、Microsoft が提供している強力な多目的ツールです。
これを利用すると、様々な形式のログファイルを SQL 構文を利用して集計、抽出などの加工を行うことが可能です。
EXE 版(単体実行可能なバージョン)と、DLL 版(COM コンポーネントとして利用可能なバージョン)があります。
「パフォーマンスモニタ」のログファイルにも対応しています。
(詳しい使用方法はインストール先のフォルダの LogParser.chm をご覧ください。)
■ スクリプト センター : Log Parser
http://www.microsoft.com/japan/technet/scriptcenter/tools/logpar...
■ ダウンロードの詳細 : Log Parser 2.2 日本語版
http://www.microsoft.com/downloads/details.aspx?FamilyID=890cd06...
以下、サンプルコードです(動作確認:Windows 2000 SP4 + Log Parser 2.2)
' File Name : MakeSummaryReport.csv ' Usage : CScript MakeSummaryReport.csv //Nologo Option Explicit Const g_strDir = "C:\PerfLogs" ' 作業フォルダ(ログファイルのある場所) Const g_strPerfLog = "CPU_000001.csv" ' ログファイル名(パフォーマンスモニタ) Const g_strExcelFile = "CPU_Report.xls" ' 集計ファイル Call Main() Sub Main() Call MakeSummaryCsv() ' 日、時間、分ごとに集計結果を CSV 出力 Call ConvertCsvToXls() ' CSV ファイルを Excel ファイルに統合 End Sub ' Log Parser の集計機能を利用して集計結果を CSV ファイルに出力する Sub MakeSummaryCsv() Dim oCSVInputFormat Set oCSVInputFormat = CreateObject("MSUtil.LogQuery.CSVInputFormat") oCSVInputFormat.iTsFormat = "MM/dd/yyyy hh:mm:ss.ll" ' パフォーマンスモニタの時間書式 oCSVInputFormat.nSkipLines = 1 ' ヘッダ行は読み飛ばす(ユーザー環境に依存するため。マシン名など) oCSVInputFormat.headerRow = False Dim oCSVOutputFormat Set oCSVOutputFormat = CreateObject("MSUtil.LogQuery.CSVOutputFormat") oCSVOutputFormat.oTsFormat = "yyyy/MM/dd hh:mm:ss" Dim oLogQuery Set oLogQuery = CreateObject("MSUtil.LogQuery") oLogQuery.ExecuteBatch GetSummaryQuery( "Day", 86400, "Day.csv" ), oCSVInputFormat, oCSVOutputFormat oLogQuery.ExecuteBatch GetSummaryQuery( "Hour", 3600, "Hour.csv" ), oCSVInputFormat, oCSVOutputFormat oLogQuery.ExecuteBatch GetSummaryQuery( "Minute", 60, "Minute.csv" ), oCSVInputFormat, oCSVOutputFormat Set oLogQuery = Nothing Set oCSVOutputFormat = Nothing Set oCSVInputFormat = Nothing End Sub Function GetSummaryQuery( ByVal strFieldName, ByVal nSec, ByVal strTableName ) Dim strResult strResult = "SELECT" & _ " QUANTIZE(Field1, " & CLng(nSec) & " ) AS " & strFieldName & "," & _ " AVG(Field2) AS CPU(Average) " & _ " INTO " & strTableName & _ " FROM " & g_strPerfLog & _ " GROUP BY " & strFieldName WScript.Echo strResult GetSummaryQuery = strResult End Function ' ADO を使用して CSV ファイルを Excel ファイルのシートに書き込む Sub ConvertCsvToXls() Dim cn Set cn = CreateObject("ADODB.Connection") Dim strCon strCon = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & g_strExcelFile & ";Extended Properties=Excel 8.0" cn.Open strCon cn.Execute GetConvertQuery( "[Day]", "Day.csv" ) cn.Execute GetConvertQuery( "[Hour]", "Hour.csv" ) cn.Execute GetConvertQuery( "[Minute]", "Minute.csv" ) cn.Close Set cn = Nothing End Sub Function GetConvertQuery( ByVal strNewTableName, ByVal strOldTableName ) Dim strResult strResult = "SELECT * INTO " & strNewTableName & _ " FROM [Text;DATABASE=" & g_strDir & ";HDR=YES;]." & strOldTableName WScript.Echo strResult GetConvertQuery = strResult End Function
以下は「Log Parser」関連情報です。
<関連情報>
■ Tales from the Script: 2005 年 1 月 - ログこそすべて (Log Parser について)
http://www.microsoft.com/japan/technet/community/columns/scripts...
■ Professor Windows ‐ 2005 年 5 月 ‐ Log Parser 2.2 の動作方法
http://www.microsoft.com/japan/technet/community/columns/profwin...
■ Log Parser 2.2 日本語版の半分はコミュニティへの熱意でできています。
http://www.exconn.net/Blogs/team00/archive/2005/05/13/428.aspx
コメント(1件)
を使ったほうが色々応用できそうなので使わせてもらいます。ありがとうございました。
Dim fld
Dim rec
Dim i
Dim cnt
Dim col0_pre
Dim col0_cur
Dim col1
Dim col2
Dim col3
Dim flg
Dim flg_sum
Dim fso
Dim objInText
Dim objOutText_t
Dim objOutText_m
Dim strval
Dim args1, args2
Dim str1, str2
str1 = InputBox("入力するファイル名をパスを含めて入力 例c:\log\aaa.csv")
str2 = InputBox("出力するパスを入力。分単位と時単位の2つ作成 例c:\log")
Set fso = CreateObject("Scripting.FileSystemObject")
'Set objInText = fso.OpenTextFile(str1)
Set objOutText_t = fso.CreateTextFile(str2 & "\" & fso.getbasename(str1) & "_t.csv")
Set objOutText_m = fso.CreateTextFile(str2 & "\" & fso.getbasename(str1) & "_m.csv")
flg = False
Const JI_SYUUKEI = 1
Const FUN_SYUUKEI = 2
For i = 1 To 2
Set objInText = fso.OpenTextFile(str1)
flg_sum = i
cnt = 0
col1 = 0
col2 = 0
col3 = 0
Do While objInText.AtEndOfLine <> True
strval = cutQuotation(objInText.ReadLine)
fld = Split(strval, ",")
'最初はタイトルなので飛ばす
If flg Then
col0_pre = col0_cur
If flg_sum = JI_SYUUKEI Then
col0_cur = Left(fld(0), 13) '時単位
ElseIf flg_sum = FUN_SYUUKEI Then
col0_cur = Left(fld(0), 16) '分単位
End If
If col0_pre = col0_cur Or cnt = 0 Then
col1 = col1 + CDbl(fld(1))
col2 = col2 + CDbl(fld(2))
col3 = col3 + CDbl(fld(3))
cnt = cnt + 1
Else
'レコード作成
rec = Chr(&H22) & col0_pre & Chr(&H22)
rec = rec & "," & Chr(&H22) & col1 / cnt & Chr(&H22)
rec = rec & "," & Chr(&H22) & col2 / cnt & Chr(&H22)
rec = rec & "," & Chr(&H22) & col3 / cnt & Chr(&H22)
'カレントで初期化
col1 = CDbl(fld(1))
col2 = CDbl(fld(2))
col3 = CDbl(fld(3))
cnt = 1
'書き込み
'Print #2, rec
If flg_sum = JI_SYUUKEI Then
objOutText_t.WriteLine (rec)
ElseIf flg_sum = FUN_SYUUKEI Then
objOutText_m.WriteLine (rec)
End If
End If
Else
'タイトル
rec = Chr(&H22) & fld(0) & Chr(&H22)
rec = rec & "," & Chr(&H22) & fld(1) & Chr(&H22)
rec = rec & "," & Chr(&H22) & fld(2) & Chr(&H22)
rec = rec & "," & Chr(&H22) & fld(3) & Chr(&H22)
'書き込み
'Print #2, rec
If flg_sum = JI_SYUUKEI Then
objOutText_t.WriteLine (rec)
ElseIf flg_sum = FUN_SYUUKEI Then
objOutText_m.WriteLine (rec)
End If
End If
flg = True
If (objInText.AtEndOfLine And col0_pre = col0_cur) Or (objInText.AtEndOfLine And cnt = 1) Then
'レコード作成
If cnt = 1 Then
rec = Chr(&H22) & col0_cur & Chr(&H22)
Else
rec = Chr(&H22) & col0_pre & Chr(&H22)
End If
rec = rec & "," & Chr(&H22) & col1 / cnt & Chr(&H22)
rec = rec & "," & Chr(&H22) & col2 / cnt & Chr(&H22)
rec = rec & "," & Chr(&H22) & col3 / cnt & Chr(&H22)
If flg_sum = JI_SYUUKEI Then
objOutText_t.WriteLine (rec)
ElseIf flg_sum = FUN_SYUUKEI Then
objOutText_m.WriteLine (rec)
End If
End If
Loop
flg = False
cnt = 0
objInText.Close
Next
objOutText_t.Close
objOutText_m.Close
MsgBox "completed", vbInformation
Function cutQuotation(val)
'On Error GoTo ERR_HANDLER
Dim tmp
Dim ret
Dim i
For i = 0 To Len(val)
tmp = Mid(val, i + 1, 1)
'Debug.Print tmp
If tmp <> """" Then
ret = ret & tmp
End If
Next
cutQuotation = ret
Exit Function
'ERR_HANDLER:
' MsgBox Err.Description
End Function