public override void GetStats(string fileName) { string query = String.Format("select distinct s-computername as ComputerName FROM {0}", fileName); LogRecordSet recordSet = null; try { LogQuery logQuery = new LogQuery(); IISLogInputFormat iisInputFormat = new IISLogInputFormat(); recordSet = logQuery.Execute(query, iisInputFormat); _machineName = recordSet.getRecord().getValue("ComputerName").ToString(); outputlog = String.Format("{0}\\{1}_{2}_{3}_{4}", _directory, _machineName, logType, _fileprefix, ConfigurationManager.AppSettings["OutputFilename"]); ResetOutputFile(); if (!File.Exists(fileName)) { throw new Exception("File not found"); } } finally { if (recordSet != null) { recordSet.close(); recordSet = null; } } //get ripley stats query = string.Format("SELECT STRCAT( TO_STRING(date, 'yyyy-MM-dd '), TO_STRING( QUANTIZE( time, 3600 ), 'hh:mm:ss') ) AS DateTime, " + " s-computername as ComputerName, " + " cs-method as Method, " + " sc-status as Status, " + " TO_UPPERCASE(STRCAT( cs-uri-stem, STRCAT('?', SUBSTR(cs-uri-query, 0, INDEX_OF(cs-uri-query,'?') ) ) )) as URL," + " count(*) as Count, " + " MAX(time-taken) as Max, MIN(time-taken) as Min, AVG(time-taken) as Avg, " + " TO_UPPERCASE(EXTRACT_VALUE(cs-uri-query, '_si')) as Site" + " FROM {0} " + " where TO_UPPERCASE(EXTRACT_EXTENSION( cs-uri-stem ))='DLL'" + " group by DateTime, URL, Method, ComputerName, Site, Status", fileName); ProcessRecordset(query, fileName); query = string.Format("SELECT STRCAT( TO_STRING(date, 'yyyy-MM-dd '), TO_STRING(QUANTIZE( time, 3600 ), 'hh:mm:ss') ) AS DateTime, " + " s-computername as ComputerName, " + " cs-method as Method, " + " sc-status as Status, " + " TO_UPPERCASE( SUBSTR(cs-uri-stem, LAST_INDEX_OF(cs-uri-stem, '/'))) as URL, " + " count(*) as Count, " + " MAX(time-taken) as Max, MIN(time-taken) as Min, AVG(time-taken) as Avg, " + " TO_UPPERCASE(EXTRACT_VALUE(cs-uri-query, '_si')) as Site" + " FROM {0} " + " where TO_UPPERCASE(EXTRACT_EXTENSION( cs-uri-stem ))='ASPX'" + " group by DateTime, URL, Method, ComputerName, Site, Status", fileName); ProcessRecordset(query, fileName); }
protected override void ProcessRecordset(string query, string fileName) { using (StreamWriter stream = new StreamWriter(outputlog, true)) { LogQuery logQuery = new LogQuery(); IISLogInputFormat iisInputFormat = new IISLogInputFormat(); LogRecordSet recordSet = logQuery.Execute(query, iisInputFormat); if (newOutput) { for (int i = 0; i < recordSet.getColumnCount(); i++) { stream.Write(recordSet.getColumnName(i) + delimiter); } newOutput = false; stream.Write(stream.NewLine); } //read log file while (!recordSet.atEnd()) { DateTime logDate = DateTime.Parse(recordSet.getRecord().getValue("DateTime").ToString()); stream.WriteLine(recordSet.getRecord().toNativeString(delimiter)); stream.Flush(); ImportToDatabase(recordSet.getRecord(), logDate); recordSet.moveNext(); } recordSet.close(); recordSet = null; } }