mbt masai
 
Welcome !
         

                                
After experiencing a lot of down time, We decided to move this site to CrystalTech.com. CrystalTech.com is powered by only the finest Windows servers providing the best performance, reliability, and value anywhere.

 Query counter info from perflog CSV file

Author Message
daluu

  • Total Posts : 53
  • Scores: 0
  • Reward points : 0
  • Joined: 4/17/2006
  • Status: offline
Query counter info from perflog CSV file Sunday, January 31, 2010 3:32 PM (permalink)
0
In case anyone finds this helpful. However, you can do better reporting with PAL (http://www.codeplex.com/PAL), which also has a VBScript interface.

Here in this sample, we query the average values of the logged counter data in the CSV perflog, using ADO SQL queries. But due to limitations in MS Jet Text/CSV database driver, you can't do much querying against the CSV perflog, which uses CSV field parameters that are not very database driver friendly. The sample code covers some of the limitations found when querying a CSV perflog via ADO.

 Dim arguments, fso, conn
 Set arguments = WScript.Arguments
 
 If arguments.Count < 1 Then
     ShowUsage()
     Set arguments = Nothing
     WScript.Quit(0)
 End If
 
 Dim logFile, logDir, logFileName
 logFile = WScript.Arguments.Named.Item("file")
 Set arguments = Nothing
 
 Set fso = CreateObject("Scripting.FileSystemObject")
 logDir = fso.GetParentFolderName(logFile)
 If logDir = "" Then
     Dim tmpLen
     'tmpLen = Len(WScript.ScriptFullName) - Len(WScript.ScriptName)
     'logDir = Left(WScript.ScriptFullName,tmpLen)
     logDir = fso.GetParentFolderName(WScript.ScriptFullName)
 End If
 logFileName = fso.GetFileName(logFile)
 
 'Parse CSV headers field into Dictionary object
 Dim logFileObj
 Set logFileObj = fso.OpenTextFile(logDir & "\" & logFileName, 1)
 Dim headers, field, numHeaders, tmpField
 headers = split(logFileObj.ReadLine, ",")
 numHeaders = UBound(headers)
 Set field = CreateObject("Scripting.Dictionary")
 For i = 1 To numHeaders 'skip first column, the timestamp column
     'strip out quotes from CSV file, as SQL query of column name doesn't contain quotes
     tmpField = Replace(headers(i), """", "")
     'replace periods with #, as constrained by ADO and MS text driver
     tmpField = Replace(tmpField, ".", "#")
     'trim out CSV column headers to 64 chars as constrained by ADO and MS text driver
     tmpField = Left(tmpField,64)
     'don't add CSV header as field to query if there are duplicates
     If Not field.Exists(tmpField) Then
         field.Add tmpField,i
     End If
     'WScript.Echo headers(i)
 Next
 logFileObj.Close
 Set logFileObj = Nothing
 
 
 Set conn = CreateObject("ADODB.Connection")
 conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & logDir & ";Extended Properties=""text;HDR=Yes;FMT=Delimited"""
 'conn.Open "Driver={Microsoft Text Driver (*.txt; *.csv)};DefaultDir=" & logDir
 Dim rs, query
 On Error Resume Next
 For Each key In field.Keys
     query = "SELECT AVG(`" & key & "`) AS logstat FROM " & logFileName & ";"
 '    WScript.Echo query
     Set rs = conn.Execute(query)
     WScript.Echo "avg 4 " & key & " is " & FormatNumber(rs("logstat"),2,TristateTrue)
 '    For Each field In rs.Fields
 '        WScript.Echo field.Name & "= " & field.Value
 '    Next
     Set rs = Nothing
 Next
 
 conn.Close
 Set conn = Nothing
 Set fso = Nothing
 
 Sub ShowUsage
     WScript.Echo "Usage:"
     WScript.Echo ""
     WScript.Echo "    cscript parsePerfLog.vbs /file:perflog1.csv"
     WScript.Echo ""
     WScript.Echo "    cscript parsePerfLog.vbs /file:C:\perflogs\perflog1.csv"
     WScript.Echo ""
 End Sub
 

#1
    ebgreen

    • Total Posts : 8088
    • Scores: 95
    • Reward points : 0
    • Joined: 7/12/2005
    • Status: offline
    Re:Query counter info from perflog CSV file Monday, February 01, 2010 3:52 AM (permalink)
    0
    Thanks for sharing. Is there a reason for the On Error Resume Next? More importantly, is there a reason for there not being a matching On Error Goto 0?
    "... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
    Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
    http://www.visualbasicscript.com/m_47117/tm.htm
    #2
      daluu

      • Total Posts : 53
      • Scores: 0
      • Reward points : 0
      • Joined: 4/17/2006
      • Status: offline
      Re:Query counter info from perflog CSV file Monday, February 01, 2010 7:35 AM (permalink)
      0
      You know, that's a good point. I wrote that a long time back, so don't remember the logic to it.
      #3

        Online Bookmarks Sharing: Share/Bookmark

        Jump to:

        Current active users

        There are 0 members and 1 guests.

        Icon Legend and Permission

        • New Messages
        • No New Messages
        • Hot Topic w/ New Messages
        • Hot Topic w/o New Messages
        • Locked w/ New Messages
        • Locked w/o New Messages
        • Read Message
        • Post New Thread
        • Reply to message
        • Post New Poll
        • Submit Vote
        • Post reward post
        • Delete my own posts
        • Delete my own threads
        • Rate post

        2000-2012 ASPPlayground.NET Forum Version 3.8
        mbt shoes www.wileywilson.com