private void GetWPList() { if (g_SharedData.SYSINFO.iWinVer == 2003) { GetIIS6WPList(); return; } int iIndex = 0; string strCommand; string strOutput; string[] astrPID = new string[MAX_APP_POOLS]; string[] astrAppPoolDesc = new string[MAX_APP_POOLS]; //g_SharedData.WEBINFO.iNumberOfAppPools = 0; string strCommandPath = "c:\\Windows\\System32\\inetsrv\\appcmd.exe"; if (File.Exists(strCommandPath)) { strCommand = LaunchEXE.Run("c:\\windows\\system32\\inetsrv\\appcmd.exe", "list wp", 10); } else { return; } //WP "3676" (applicationPool:DefaultAppPool) strOutput = strCommand; ////test code //if(g_SharedData.WSP_AGENT_SETTING.strWS_URL.Contains("juliabook")) // WSPEvent.WriteEvent(strOutput, "I", 4001); iIndex = strOutput.Length; int i = 0; if (iIndex > 1) { do { iIndex = strOutput.IndexOf('"', 0); if (iIndex > 1) { strOutput = strOutput.Substring(iIndex + 1); iIndex = strOutput.IndexOf('"', 0); if (iIndex > 0) { astrPID[i] = strOutput.Substring(0, iIndex); strOutput = strOutput.Substring(iIndex + 1); i = i + 1; } } } while (iIndex > 0 && i < MAX_APP_POOLS); g_SharedData.WEBINFO.iNumberOfAppPools = i; } i = 0; iIndex = strCommand.Length; strOutput = strCommand; if (iIndex > 1) { do { iIndex = strOutput.IndexOf(':', 0); if (iIndex > 1) { strOutput = strOutput.Substring(iIndex + 1); iIndex = strOutput.IndexOf(')', 0); if (iIndex > 0) { astrAppPoolDesc[i] = strOutput.Substring(0, iIndex); strOutput = strOutput.Substring(iIndex + 1); i = i + 1; } } } while (iIndex > 0 && i < MAX_APP_POOLS); } if (g_SharedData.WEBINFO.iNumberOfAppPools > 0) { g_SharedData.SYSINFO.bIsIIS = true; // Set IIS is true to avoid java process checking every 5 seconds. } string[] arrInstanceNames; PerformanceCounterCategory pcCat = new PerformanceCounterCategory(); pcCat.CategoryName = "Process"; arrInstanceNames = pcCat.GetInstanceNames(); int iCount = 0; foreach (string strProcess in arrInstanceNames) { if (strProcess == "w3wp" || strProcess.Contains("w3wp#")) { PerformanceCounter PC = new PerformanceCounter(); PC.CategoryName = "Process"; PC.CounterName = "ID Process"; PC.InstanceName = strProcess; PC.NextValue(); System.Threading.Thread.Sleep(100); string strPValue = PC.NextValue().ToString(); for (i = 0; i < g_SharedData.WEBINFO.iNumberOfAppPools; i++) { if (astrPID[i] == strPValue) { //dtWPList.Rows.Add(strProcess, strPValue, astrAppPoolDesc[i]); g_SharedData.arrWPList[iCount].strPID = strPValue; g_SharedData.arrWPList[iCount].strAppPoolDesc = astrAppPoolDesc[i]; g_SharedData.arrWPList[iCount].strInstanceName = strProcess; iCount++; } } } } }
public void GetRunningWebApplications() { int iRequests = 0; DataTable dtWebApps = new DataTable(); dtWebApps.Columns.Add(new DataColumn("URL", typeof(string))); dtWebApps.Columns.Add(new DataColumn("TIME_TAKEN", typeof(int))); dtWebApps.Columns.Add(new DataColumn("CLIENT", typeof(string))); if (g_SharedData.SYSINFO.iWinVer < 2008) { g_SharedData.WEBINFO.iNumberOfRequests = 0; return; } int iIndex = 0; string strCommand = ""; string strOutput = ""; string[] astrURLs = new string[MAX_WEB_REQUESTS]; string[] astrClients = new string[MAX_WEB_REQUESTS]; string[] astsrTimeTaken = new string[MAX_WEB_REQUESTS]; try { string strCommandPath = "c:\\Windows\\System32\\inetsrv\\appcmd.exe"; if (File.Exists(strCommandPath)) { // if (System.IO.Directory.Exists(strCommandPath)) strCommand = LaunchEXE.Run("c:\\windows\\system32\\inetsrv\\appcmd", "LIST REQUEST", 10); } else { g_SharedData.WEBINFO.iNumberOfRequests = 0; return; } } catch (Exception ex) { WSPEvent.WriteEvent(ex.Message, "E", 1109); } strOutput = strCommand.ToUpper(); if (!strOutput.Contains("REQUEST")) { g_SharedData.WEBINFO.iNumberOfRequests = 0; return; } int i = 0; iIndex = strCommand.Length; strOutput = strCommand; do { iIndex = strOutput.IndexOf("/"); if (iIndex > 1) { strOutput = strOutput.Substring(iIndex); iIndex = strOutput.IndexOf(',', 0); if (iIndex > 0) { astrURLs[i] = strOutput.Substring(0, iIndex); strOutput = strOutput.Substring(iIndex + 1); i = i + 1; } } } while (iIndex > 0 && i < MAX_WEB_REQUESTS); iRequests = i; i = 0; iIndex = 0; strOutput = strCommand.ToLower(); do { iIndex = strOutput.IndexOf("time:"); if (iIndex > 1) { strOutput = strOutput.Substring(iIndex + 5); iIndex = strOutput.IndexOf(' ', 0); if (iIndex > 0) { astsrTimeTaken[i] = strOutput.Substring(0, iIndex); strOutput = strOutput.Substring(iIndex + 1); i = i + 1; } } } while (iIndex > 0 && i < MAX_WEB_REQUESTS); i = 0; iIndex = 0; strOutput = strCommand.ToLower(); do { iIndex = strOutput.IndexOf("client:"); if (iIndex > 1) { strOutput = strOutput.Substring(iIndex + 7); iIndex = strOutput.IndexOf(',', 0); if (iIndex > 0) { astrClients[i] = strOutput.Substring(0, iIndex); strOutput = strOutput.Substring(iIndex + 1); i = i + 1; } } } while (iIndex > 0 && i < MAX_WEB_REQUESTS); for (i = 0; i < iRequests; i++) { //dtWebApps.Rows.Add(astrURLs[i], Convert.ToInt32(astsrTimeTaken[i]), astrClients[i]); g_SharedData.arrWebRequests[i].strURL = astrURLs[i]; g_SharedData.arrWebRequests[i].iTimeTaken = Convert.ToInt32(astsrTimeTaken[i]); g_SharedData.arrWebRequests[i].strClientIP = astrClients[i]; } g_SharedData.WEBINFO.iNumberOfRequests = iRequests; return; }
public void GetIIS6WPList() { int iIndex = 0; int i = 0; string strCommand; string strOutput; string[] astrPID = new string[40]; string[] astrAppPoolDesc = new string[40]; //g_SharedData.WEBINFO.iNumberOfAppPools = 0; strCommand = LaunchEXE.Run("cscript", "c:\\windows\\system32\\iisapp.vbs", 10); //W3WP.exe PID: 5268 AppPoolId: DefaultAppPool strOutput = strCommand; iIndex = strOutput.Length; if (iIndex > 1) { do { iIndex = strOutput.IndexOf("PID: "); if (iIndex > 1) { strOutput = strOutput.Substring(iIndex + 5); iIndex = strOutput.IndexOf(' ', 0); if (iIndex > 0) { astrPID[i] = strOutput.Substring(0, iIndex); strOutput = strOutput.Substring(iIndex + 1); i = i + 1; } } } while (iIndex > 0 && i < MAX_APP_POOLS); g_SharedData.WEBINFO.iNumberOfAppPools = i; } strOutput = strCommand; iIndex = strOutput.Length; i = 0; if (iIndex > 1) { do { iIndex = strOutput.IndexOf("AppPoolId: "); if (iIndex > 1) { strOutput = strOutput.Substring(iIndex + 11); iIndex = strOutput.IndexOf('\r', 0); if (iIndex > 0) { astrAppPoolDesc[i] = strOutput.Substring(0, iIndex); strOutput = strOutput.Substring(iIndex + 1); i = i + 1; } } } while (iIndex > 0 && i < MAX_APP_POOLS); } if (g_SharedData.WEBINFO.iNumberOfAppPools > 0) { g_SharedData.SYSINFO.bIsIIS = true; // Set IIS is true to avoid java process checking every 5 seconds. } string[] arrInstanceNames; PerformanceCounterCategory pcCat = new PerformanceCounterCategory(); pcCat.CategoryName = "Process"; arrInstanceNames = pcCat.GetInstanceNames(); int iCount = 0; foreach (string strProcess in arrInstanceNames) { if (strProcess == "w3wp" || strProcess.Contains("w3wp#")) { PerformanceCounter PC = new PerformanceCounter(); PC.CategoryName = "Process"; PC.CounterName = "ID Process"; PC.InstanceName = strProcess; PC.NextValue(); System.Threading.Thread.Sleep(100); string strPValue = PC.NextValue().ToString(); for (i = 0; i < g_SharedData.WEBINFO.iNumberOfAppPools; i++) { if (astrPID[i] == strPValue) { //dtWPList.Rows.Add(strProcess, strPValue, astrAppPoolDesc[i]); g_SharedData.arrWPList[iCount].strAppPoolDesc = astrAppPoolDesc[i]; g_SharedData.arrWPList[iCount].strInstanceName = strProcess; g_SharedData.arrWPList[iCount].strPID = strPValue; } } } } }
private bool GetSiteList() { // SITE "myCMS" (id:2,bindings:http/*:80:mycms,state:Started) if (g_SharedData.SYSINFO.iWinVer == 0) { return(false); } if (g_SharedData.SYSINFO.iWinVer == 2003) { GetIIS6SiteList(); return(true); } string strCommand = LaunchEXE.Run("c:\\windows\\system32\\inetsrv\\appcmd.exe", "list site", 10); string strOutput = strCommand; int iIndex = strCommand.Length; string[] astrSiteID = new string[40]; string[] astrSiteDesc = new string[40]; int i = 0; if (iIndex > 1) { do { iIndex = strOutput.IndexOf('"', 0); if (iIndex > 1) { strOutput = strOutput.Substring(iIndex + 1); iIndex = strOutput.IndexOf('"', 0); if (iIndex > 1) { astrSiteDesc[i] = strOutput.Substring(0, iIndex); strOutput = strOutput.Substring(iIndex + 1); i = i + 1; } } } while (iIndex > 0 && i < 40); g_SharedData.WEBINFO.iNumberOfSites = i; } i = 0; iIndex = strCommand.Length; strOutput = strCommand; if (iIndex > 1) { do { iIndex = strOutput.IndexOf("id:"); if (iIndex > 1) { strOutput = strOutput.Substring(iIndex + 3); iIndex = strOutput.IndexOf(","); if (iIndex > 0) { astrSiteID[i] = strOutput.Substring(0, iIndex); strOutput = strOutput.Substring(iIndex + 1); i = i + 1; } } } while (iIndex > 0 && i < 40); } //dtSiteList.Rows.Clear(); //for (i = 0; i < g_SharedData.WEBINFO.iNumberOfSites; i++) // dtSiteList.Rows.Add(astrSiteID[i], astrSiteDesc[i]); for (i = 0; i < g_SharedData.WEBINFO.iNumberOfSites; i++) { g_SharedData.arrSiteList[i].strSiteDesc = astrSiteDesc[i]; g_SharedData.arrSiteList[i].strSiteID = astrSiteID[i]; g_SharedData.WEBINFO.iNumberOfSites = i + 1; } return(true); }
public void GetIIS6SiteList() { string[] astrSiteID = new string[40]; string[] astrSiteDesc = new string[40]; string strCommand = LaunchEXE.Run("cscript", "c:\\windows\\system32\\iisweb.vbs /query", 10); string strOutput = strCommand; int iIndex = strCommand.Length; int i = 0; if (iIndex > 1) { do { iIndex = strOutput.IndexOf("(W3SVC/"); if (iIndex > 1) { strOutput = strOutput.Substring(iIndex + 7); iIndex = strOutput.IndexOf(")"); if (iIndex > 0) { astrSiteID[i] = strOutput.Substring(0, iIndex); strOutput = strOutput.Substring(iIndex + 1); i = i + 1; } } } while (iIndex > 0 && i < MAX_SITES); g_SharedData.WEBINFO.iNumberOfSites = i; } i = 0; strOutput = strCommand; iIndex = strOutput.IndexOf("==\r\n"); strOutput = strOutput.Substring(iIndex); if (iIndex > 1) { do { iIndex = strOutput.IndexOf("\r\n"); if (iIndex > 1) { strOutput = strOutput.Substring(iIndex + 2); iIndex = strOutput.IndexOf(" ("); if (iIndex > 0) { astrSiteDesc[i] = strOutput.Substring(0, iIndex); strOutput = strOutput.Substring(iIndex + 1); i = i + 1; } } } while (iIndex > 0 && i < MAX_SITES); } //dtSiteList.Rows.Clear(); for (i = 0; i < g_SharedData.WEBINFO.iNumberOfSites; i++) { g_SharedData.arrSiteList[i].strSiteDesc = astrSiteDesc[i]; g_SharedData.arrSiteList[i].strSiteID = astrSiteID[i]; g_SharedData.WEBINFO.iNumberOfSites = i + 1; //dtSiteList.Rows.Add(astrSiteID[i], astrSiteDesc[i]); } }
private bool AnalyzeIISLog() { string strPath = g_SharedData.WEB_SETTING.strLogFilesDirectory + "\\" + strIISLogFileName; // Creating temp log file string strQuery = "select cs-uri-stem, count(cs-uri-stem) as Hits, max(time-taken) as MaxTaken, avg(TO_INT(time-taken)) as AvgTaken, sum(TO_INT(sc-bytes)) as TotalSCBytes, sum(TO_INT(cs-bytes)) as TotalCSBytes from " + strWinTempPath + "\\shst.iis.log to " + strWinTempPath + "\\shst.temp.csv GROUP BY cs-uri-stem ORDER BY AvgTaken DESC"; string strCommand = LaunchEXE.Run(logparser_path, "\"" + strQuery + "\" -i:W3C -o:CSV", 3600); Thread.Sleep(1000); string path = strWinTempPath + "\\shst.temp.csv"; if (!File.Exists(path)) { WSPEvent.WriteEvent("Generating temperary file from IIS log has been failed.", "W", 1115); return(false); } strQuery = "select top 20 cs-uri-stem, Hits from " + strWinTempPath + "\\shst.temp.csv to " + strWinTempPath + "\\top20.hits.csv ORDER BY Hits DESC"; strCommand = LaunchEXE.Run(logparser_path, "\"" + strQuery + "\" -i:CSV -o:CSV", 3600); Thread.Sleep(1000); strQuery = "select top 20 cs-uri-stem, Hits from " + strWinTempPath + "\\shst.temp.csv to " + strWinTempPath + "\\top20.apphits.csv where cs-uri-stem like '%.asmx' or cs-uri-stem like '%.asp' or cs-uri-stem like '%.aspx' or cs-uri-stem like '%.jsp' or cs-uri-stem like '%.php' ORDER BY Hits DESC"; strCommand = LaunchEXE.Run(logparser_path, "\"" + strQuery + "\" -i:CSV -o:CSV", 3600); Thread.Sleep(1000); strQuery = "select top 20 cs-uri-stem, Hits, MaxTaken, AvgTaken from " + strWinTempPath + "\\shst.temp.csv to " + strWinTempPath + "\\top20.loggest.csv ORDER BY AvgTaken DESC"; strCommand = LaunchEXE.Run(logparser_path, "\"" + strQuery + "\" -i:CSV -o:CSV", 3600); Thread.Sleep(1000); strQuery = "select top 20 cs-uri-stem, Hits, TotalSCBytes from " + strWinTempPath + "\\shst.temp.csv to " + strWinTempPath + "\\top20.scbytes.csv ORDER BY TotalSCBytes DESC"; strCommand = LaunchEXE.Run(logparser_path, "\"" + strQuery + "\" -i:CSV -o:CSV", 3600); Thread.Sleep(1000); strQuery = "select top 20 cs-uri-stem, Hits, TotalCSBytes from " + strWinTempPath + "\\shst.temp.csv to " + strWinTempPath + "\\top20.csbytes.csv ORDER BY TotalCSBytes DESC"; strCommand = LaunchEXE.Run(logparser_path, "\"" + strQuery + "\" -i:CSV -o:CSV", 3600); Thread.Sleep(1000); strQuery = "select top 20 cs-uri-stem, count(cs-uri-stem) as ErrCount, sc-status, sc-win32-status from " + strWinTempPath + "\\shst.iis.log to " + strWinTempPath + "\\top20.errors.csv GROUP BY cs-uri-stem, sc-status,sc-win32-status ORDER BY ErrCount DESC"; strCommand = LaunchEXE.Run(logparser_path, "\"" + strQuery + "\" -i:W3C -o:CSV", 3600); Thread.Sleep(1000); strQuery = "select top 20 c-ip, count(c-ip) as IP_Total from " + strWinTempPath + "\\shst.iis.log to " + strWinTempPath + "\\top20.ip.csv GROUP BY c-ip ORDER BY IP_Total DESC"; strCommand = LaunchEXE.Run(logparser_path, "\"" + strQuery + "\" -i:W3C -o:CSV", 3600); Thread.Sleep(1000); strQuery = "select top 20 sc-status, count(status) as Status_Total from " + strWinTempPath + "\\shst.iis.log to " + strWinTempPath + "\\top20.status.csv GROUP BY sc-status ORDER BY Status_Total DESC"; strCommand = LaunchEXE.Run(logparser_path, "\"" + strQuery + "\" -i:W3C -o:CSV", 3600); Thread.Sleep(1000); strQuery = "select top 20 EXTRACT_EXTENSION(cs-uri-stem) AS Extension, sum(TotalSCBytes) as Bytes_Sum from " + strWinTempPath + "\\shst.temp.csv to " + strWinTempPath + "\\top20.ext.csv GROUP BY Extension ORDER BY Bytes_Sum DESC"; strCommand = LaunchEXE.Run(logparser_path, "\"" + strQuery + "\" -i:CSV -o:CSV", 3600); Thread.Sleep(1000); //added, service status strQuery = "select count(*) AS Hits, sum(TO_REAL(sc-bytes)) AS SCBytes, sum(TO_REAL(cs-bytes)) AS CSBytes from " + strWinTempPath + "\\shst.iis.log to " + strWinTempPath + "\\svc.total.csv"; strCommand = LaunchEXE.Run(logparser_path, "\"" + strQuery + "\" -i:W3C -o:CSV", 3600); Thread.Sleep(1000); strQuery = "select count(distinct c-ip) AS ClientIPs from " + strWinTempPath + "\\shst.iis.log to " + strWinTempPath + "\\svc.ips.csv"; strCommand = LaunchEXE.Run(logparser_path, "\"" + strQuery + "\" -i:W3C -o:CSV", 3600); Thread.Sleep(1000); strQuery = "select count(*) AS Errors from " + strWinTempPath + "\\shst.iis.log to " + strWinTempPath + "\\svc.errors.csv where sc-status >= 400"; strCommand = LaunchEXE.Run(logparser_path, "\"" + strQuery + "\" -i:W3C -o:CSV", 3600); Thread.Sleep(1000); strSavedLogTime = strAnalyzedLogTime; //record history for this log analysis return(true); }
public bool BuildAnalsysIISLog() { //strWinTempPath = "c:\\temp\\logs"; strWinTempPath = "c:\\Windows\\Temp\\sp_iislogs"; try { if (!System.IO.Directory.Exists(strWinTempPath)) { System.IO.Directory.CreateDirectory(strWinTempPath); } if (dtIISLog.Columns.Count < 1) { InitializeTables(); } IsTurnOverBySize(); if (GetLogSettingsToAnalyze()) { if (CheckIfAnalyzied()) //check if data in this hour was analyzed already. { return(false); } } else { return(false); // log files, or logparser doesn't exist. } } catch (Exception ex) { WSPEvent.WriteEvent(ex.Message, "E", 1111); } string strPath = g_SharedData.WEB_SETTING.strLogFilesDirectory + "\\" + strIISLogFileName; string strFields = "date,time,c-ip,s-sitename,cs-uri-stem,sc-status,sc-win32-status,sc-bytes,cs-bytes,time-taken"; string strQuery = " \"select " + strFields + " from '" + strPath + "' to " + strWinTempPath + "\\shst.iis.log where date = '" + strLogTimeDate + "' AND time >= '" + strLogTimeFrom + "' AND time <= '" + strLogTimeTo + "'\""; if (bIsFileBySize) { strQuery = " \"select " + strFields + " from '" + strIISLogFileName + "' to " + strWinTempPath + "\\shst.iis.log " + "\""; } try { string strCommand = LaunchEXE.Run(logparser_path, strQuery + " -o:W3C -recurse 3", 3600); Thread.Sleep(10000); } catch (Exception ex) { WSPEvent.WriteEvent(ex.Message, "W", 1111); } if (File.Exists(strWinTempPath + "\\shst.iis.log")) { return(true); } return(false); }