예제 #1
0
    private void SaveNetworkBandwidth()
    {
        string[] arrInstanceNames;

        dtNI.Rows.Clear();

        try
        {
            PerformanceCounterCategory pcCat = new PerformanceCounterCategory();

            if (PerformanceCounterCategory.Exists("Network Interface"))
            {
                pcCat.CategoryName = "Network Interface";
                arrInstanceNames   = pcCat.GetInstanceNames();
                foreach (string strInterface in arrInstanceNames)
                {
                    PerformanceCounter PC = new PerformanceCounter();

                    PC.CategoryName = "Network Interface";
                    PC.CounterName  = "Current bandwidth";
                    PC.InstanceName = strInterface;
                    PC.NextValue();

                    System.Threading.Thread.Sleep(50);

                    dtNI.Rows.Add(strInterface, PC.NextValue());
                }
            }
        }
        catch (Exception ex)
        {
            WSPEvent.WriteEvent(ex.Message, "E", 1110);
        }
    }
예제 #2
0
    public int CheckAndUpdateSQLServerStatus()
    {
        DataTable     dtHeartBeat  = new DataTable();
        SqlConnection conReadQuery = new SqlConnection(g_SharedData.LOCAL_SQL_SETTING.strConnectionString);
        string        sCommand     = "SELECT 1";

        TimeSpan tsElapsed  = new TimeSpan();
        DateTime dtSaved    = new DateTime();
        DateTime dtNow      = new DateTime();
        int      iTimeSpent = 0;

        using (SqlDataAdapter da = new SqlDataAdapter(sCommand, conReadQuery))
        {
            try
            {
                dtSaved = DateTime.Now; // 아래 구간의 실행 시간을 구한다.
                /////////////////////////////////////////////////////////////////////////////
                conReadQuery.Open();

                int iRows = da.Fill(dtHeartBeat);

                /////////////////////////////////////////////////////////////////////////////

                dtNow      = DateTime.Now;
                tsElapsed  = dtNow - dtSaved;
                iTimeSpent = tsElapsed.Milliseconds;

                if (iRows > 0)
                {
                    return(iTimeSpent);
                }
                else
                {
                    return(-1);
                }
            }
            catch (Exception ex)
            {
                WSPEvent.WriteEvent("Service Point Agent just alerted the failure of running SQL Heat Beat Query. - " + ex.Message, "W", 1177);
                return(-1);
            }
            finally
            {
                conReadQuery.Close();
            }
        }
    }
예제 #3
0
    public void CheckCustomRules(DataRow dr)
    {
        try
        {
            GetCurrentRuleRecord(dr);

            string strReasonCode = CurrentRule.strReasonCode;
            int    iDuration     = CurrentRule.iDuration;
            int    iOperator     = CurrentRule.iOperator;

            if (iPerfLogCollectInterval >= iDuration && iDuration != 0)
            {
                iDuration = iPerfLogCollectInterval;
            }

            DateTime tmNow = new DateTime();
            tmNow = DateTime.Now;
            //DateTime tmDuration = DateTime.Now.Subtract(TimeSpan.FromSeconds(iDuration + iPerfLogCollectInterval / 2));
            DateTime tmDuration = dtLastUpdatedTime.AddSeconds(Convert.ToDouble((iDuration) * (-1)));

            if (iOperator == 4)                            // amend for value chages
            {
                iDuration = iPerfLogCollectInterval;
            }

            if (strReasonCode == "R059" || strReasonCode == "R067")
            {
                R059_R067_Rule(tmDuration);
            }

            if (strReasonCode == "R057" || strReasonCode == "R058")
            {
                R057_R058_Rule(tmDuration);
            }
        }
        catch (Exception ex)
        {
            WSPEvent.WriteEvent(ex.Message, "E", 1148);
        }
    }
예제 #4
0
    public void CheckCustomRules(DataRow dr)
    {
        try
        {
            GetCurrentRuleRecord(dr);

            string strReasonCode = CurrentRule.strReasonCode;
            int    iDuration     = CurrentRule.iDuration;
            int    iOperator     = CurrentRule.iOperator;

            if (iPerfLogCollectInterval >= iDuration && iDuration != 0)
            {
                iDuration = iPerfLogCollectInterval;
            }

            if (iDuration == 0)
            {
                iDuration = 1;
            }

            if (iOperator == 4)                            // amend for value chages
            {
                iDuration = iPerfLogCollectInterval;
            }

            DateTime tmNow = new DateTime();
            tmNow = DateTime.Now;
            //DateTime tmDuration = DateTime.Now.Subtract(TimeSpan.FromSeconds(iDuration + iPerfLogCollectInterval / 2));
            DateTime tmDuration = dtLastUpdatedTime.AddSeconds(Convert.ToDouble((iDuration) * (-1)));

            TimeSpan tsGap = tmDuration - dtmPValueTimeIn;
            if (tsGap.Seconds >= 0)             //  if tmDuraion is greater than PValue TimeIn
            {
                tmDuration = dtmPValueTimeIn.AddSeconds(-1);
            }

            RunSQLCustomRules(tmDuration);
        }
        catch (Exception ex)
        {
            WSPEvent.WriteEvent("SHST failed to check custom SQL Rules to be alerted. - " + ex.Message, "E", 1152);
        }
    }
예제 #5
0
        public bool LoadXMLConfig()
        {
            var dir = AppDomain.CurrentDomain.BaseDirectory;

            string strPath = dir.ToString();

            if (strPath.Substring(strPath.Length - 1).Contains("\\"))
            {
                strPath = strPath + @"ServicePoint.Settings.xml";
            }
            else
            {
                strPath = strPath + @"\\ServicePoint.Settings.xml";
            }

            GetSystemInformation();

            try
            {
                XmlDocument xml = new XmlDocument();

                xml.Load(@strPath);

                if (xml.FirstChild.NodeType == XmlNodeType.XmlDeclaration)
                {
                    XmlDeclaration dec = (XmlDeclaration)xml.FirstChild;
                    dec.Encoding = "UTF-8";
                }
                else
                {
                    XmlDeclaration dec = xml.CreateXmlDeclaration("1.0", null, null);
                    dec.Encoding = "UTF-8";
                    xml.InsertBefore(dec, xml.DocumentElement);
                }

                XmlNodeList xnList = xml.SelectNodes("/ServicePoint/AGENT");
                foreach (XmlNode xn in xnList)
                {
                    g_SharedData.WSP_AGENT_SETTING.strServerKey = xn["SERVER_KEY"].InnerText;
                    g_SharedData.WSP_AGENT_SETTING.iBuildNumber = "2.1"; //xn["BuildNumber"].InnerText;
                    g_SharedData.WSP_AGENT_SETTING.strWS_URL    = xn["WS_URL"].InnerText;

                    //g_SharedData.WSP_AGENT_SETTING.iPerfLogCollectInterval = Convert.ToInt32(xn["PerformanceCollectInterval"].InnerText);
                    //if (g_SharedData.WSP_AGENT_SETTING.iPerfLogCollectInterval < 5 || g_SharedData.WSP_AGENT_SETTING.iPerfLogCollectInterval > 3600)
                    //    g_SharedData.WSP_AGENT_SETTING.iPerfLogCollectInterval = 15;
                    g_SharedData.WSP_AGENT_SETTING.iPerfLogCollectInterval = 15;
                    g_SharedData.WSP_AGENT_SETTING.iMaxAgentMemorySizeMB   = 70; // Convert.ToInt32(xn["MaxAgentMemorySizeMB"].InnerText);
                }

                xnList = xml.SelectNodes("/ServicePoint/WEB");
                foreach (XmlNode xn in xnList)
                {
                    g_SharedData.WEB_SETTING.iMaxConnectionPoolSize = Convert.ToInt32(xn["MaxPoolSize"].InnerText);
                    g_SharedData.WEB_SETTING.strLogFilesDirectory   = xn["LogFileDirectory"].InnerText;
                    g_SharedData.WEB_SETTING.strLastLogFileName     = xn["LastLogFile"].InnerText;

                    if (xn["IISLogAnalysis"].InnerText.ToLower() == "false")
                    {
                        g_SharedData.WEB_SETTING.bIISLogAnalysis = false;
                    }
                    else
                    {
                        g_SharedData.WEB_SETTING.bIISLogAnalysis = true;
                    }

                    if (xn["HC_Enabled"].InnerText.ToLower() == "false")
                    {
                        g_SharedData.HC_SETTING.bHC_Enabled = false;
                    }
                    else
                    {
                        g_SharedData.HC_SETTING.bHC_Enabled = true;
                    }

                    g_SharedData.WEB_SETTING.strHostHeader = xn["HostHeader"].InnerText;
                    g_SharedData.HC_SETTING.iHC_Interval   = Convert.ToInt32(xn["HC_Interval"].InnerText);

                    if (g_SharedData.HC_SETTING.iHC_Interval < 1 || g_SharedData.HC_SETTING.iHC_Interval > 60)
                    {
                        g_SharedData.HC_SETTING.iHC_Interval = 30;
                    }

                    g_SharedData.HC_SETTING.iHC_Timeout = Convert.ToInt32(xn["HC_TimeOut"].InnerText);
                    if (g_SharedData.HC_SETTING.iHC_Timeout < 1)
                    {
                        g_SharedData.HC_SETTING.iHC_Timeout = 1;
                    }

                    // Initialize HC List in dtHC_URL datatable
                    if (g_SharedData.HC_SETTING.dtHC_URL == null)
                    {
                        g_SharedData.HC_SETTING.dtHC_URL = new DataTable();
                        g_SharedData.HC_SETTING.dtHC_URL.Columns.Add(new DataColumn("HC_URL", typeof(string)));
                    }
                    else
                    {
                        g_SharedData.HC_SETTING.dtHC_URL.Rows.Clear();
                    }

                    XmlNodeList xnURLS = xml.SelectNodes("/ServicePoint/WEB/HC_URLS/URL");

                    foreach (XmlNode xn2 in xnURLS)
                    {
                        g_SharedData.HC_SETTING.dtHC_URL.Rows.Add(xn2.InnerText);
                    }
                }

                xnList = xml.SelectNodes("/ServicePoint/SQL");
                foreach (XmlNode xn in xnList)
                {
                    g_SharedData.LOCAL_SQL_SETTING.strServerName     = xn["ServerName"].InnerText;
                    g_SharedData.LOCAL_SQL_SETTING.strAuthentication = xn["Authentication"].InnerText;
                    g_SharedData.LOCAL_SQL_SETTING.strAccount        = xn["UserName"].InnerText;
                    g_SharedData.LOCAL_SQL_SETTING.strPassword       = xn["Password"].InnerText;
                    g_SharedData.LOCAL_SQL_SETTING.strEncrypted      = xn["LocalDB_EncrtypedPassword"].InnerText;
                    g_SharedData.LOCAL_SQL_SETTING.iQueryInterval    = Convert.ToInt32(xn["LocalDB_minQueryInterval"].InnerText);

                    if (xn["EnableCollectingRunningQueries"].InnerText.ToUpper() == "TRUE")
                    {
                        g_SharedData.LOCAL_SQL_SETTING.bEnableCollectingRunningQueries = true;
                    }
                    else
                    {
                        g_SharedData.LOCAL_SQL_SETTING.bEnableCollectingRunningQueries = false;
                    }
                }

                BuildLocalDBConnectionString();

                return(true);
            }
            catch (Exception ex)
            {
                WSPEvent.WriteEvent("Service Point Agent failed to read settings from ServicePoint.Settings.XML. Please review your cofigurations in the file. - " + ex.Message, "E", 1137);
                return(false);
            }
        }
예제 #6
0
    public void CheckCustomRules(DataRow dr)
    {
        try
        {
            GetCurrentRuleRecord(dr);

            string strReasonCode = CurrentRule.strReasonCode;
            int    iDuration     = CurrentRule.iDuration;
            int    iOperator     = CurrentRule.iOperator;

            if (g_SharedData.WSP_AGENT_SETTING.iPerfLogCollectInterval >= iDuration && iDuration != 0)
            {
                iDuration = g_SharedData.WSP_AGENT_SETTING.iPerfLogCollectInterval;
            }

            if (iDuration == 0)
            {
                iDuration = 1;
            }

            DateTime tmNow = new DateTime();
            tmNow = DateTime.Now;
            //DateTime tmDuration = DateTime.Now.Subtract(TimeSpan.FromSeconds(iDuration + iPerfLogCollectInterval / 2));
            DateTime tmDuration = dtLastUpdatedTime.AddSeconds(Convert.ToDouble((iDuration) * (-1)));

            TimeSpan tsGap = tmDuration - dtmPValueTimeIn;
            if (tsGap.Seconds >= 0)                 //  if tmDuraion is greater than PValue TimeIn
            {
                tmDuration = dtmPValueTimeIn.AddSeconds(-1);
            }

            if (iOperator == 4)                                // check value chages
            {
                iDuration = g_SharedData.WSP_AGENT_SETTING.iPerfLogCollectInterval;
            }

            if (strReasonCode == "R012" || strReasonCode == "R013" || strReasonCode == "R014")
            {
                R012_R013_R014_Rule(tmDuration);
            }

            if (strReasonCode == "R015" || strReasonCode == "R039" || strReasonCode == "R043")
            {
                R015_R039_R043_Rule_v2(tmDuration);
            }

            if (strReasonCode == "R022" || strReasonCode == "R023")
            {
                R022_R023_Rule(tmDuration);
            }

            if (strReasonCode == "R036" || strReasonCode == "R037" || strReasonCode == "R038" || strReasonCode == "R040" || strReasonCode == "R041" || strReasonCode == "R042")
            {
                R036_R037_R038_R040_R041_R042_Rule(tmDuration);
            }
        }
        catch (Exception ex)
        {
            WSPEvent.WriteEvent(ex.Message, "E", 1130);
        }
    }
예제 #7
0
    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;
    }
예제 #8
0
    public void ReadMonitoringQueriesWS()
    {
        int iServerNumber = g_SharedData.WSP_AGENT_SETTING.iServerNumber;

        try
        {
            SetMonitoringAlertDesc();           // Set Alert Description from Alert Rules table.

            int iSavedQueryCount = iQueryCount;

            WSP.Console.WS_AGENTINITIAL.AgentInitial QueryDefineList = new WSP.Console.WS_AGENTINITIAL.AgentInitial();
            QueryDefineList.Url     = g_SharedData.WSP_AGENT_SETTING.strWS_URL + "/AgentInitial.asmx";
            QueryDefineList.Timeout = 10000;

            DataTable dtParms = SetParmeterTable();

            byte[] dtResult = QueryDefineList.QueryDefineList(iServerNumber.ToString());

            if (dtResult == null)
            {
                return;
            }

            dtChkQuery.Clear();
            dtChkQuery = BytesToDataTable(dtResult);

            iQueryCount = dtChkQuery.Rows.Count;

            if (iQueryCount > 0)
            {
                int  i        = 0;
                bool bEnabled = false;
                int  iQueryID = 0;

                foreach (DataRow dr in dtChkQuery.Rows)            // save query interval foreach Query ID.
                {
                    try
                    {
                        iQueryID = Convert.ToInt32(dr["QueryID"].ToString());
                        bEnabled = Convert.ToBoolean(dr["Enabled"].ToString());

                        iaInterval[i, 0] = iQueryID;
                        iaInterval[i, 1] = Convert.ToInt32(dr["Interval"].ToString());
                        dtLastRun[i]     = DateTime.Now.AddHours(-24.00);
                        i++;

                        if (iQueryID == 4 && bEnabled)      // To Save Linked Server Checking
                        {
                            bMonitorLinkedServer      = true;
                            strLinkedServerQuery      = dr["Query"].ToString();
                            strLinkedServerSP         = dr["SPName"].ToString();
                            strLinkedServerQueryTable = dr["DestinationTable"].ToString();
                        }

                        if (iQueryID == 1)
                        {
                            strReadRunningQuery = dr["Query"].ToString();
                        }
                    }
                    catch (Exception ex)
                    {
                        WSPEvent.WriteEvent("Service Point Agent failed to read list of query definitions from DB - " + ex.Message, "W", 1302);
                    }
                }
            }
        }
        catch (Exception e)
        {
            WSPEvent.WriteEvent("Service Point Agent failed to read list of query definitions from DB - " + e.Message, "W", 1128);
        }
    }
예제 #9
0
        private void InitService(object obj)
        {
            //////////////////////////////////////////////////////////////////
            //         Shell commands &  List of Web Site
            //////////////////////////////////////////////////////////////////

            bIsServiceReady = false;

            if (dtAgentStartTime == null)
            {
                dtAgentStartTime = DateTime.Now;
            }

            AppConfig.GetSystemInformation();

            g_SharedData.WEBINFO.iNumberOfAppPools  = 0;
            g_SharedData.WEBINFO.iNumberOfJavaPools = 0;
            g_SharedData.WEBINFO.iNumberOfSites     = 0;

            WSPDB.g_SharedData = g_SharedData;

            bool bRegisterd  = false;
            int  iRetryCount = 1;

            do
            {
                if (PerfReaders.IsPerformanceCounterReady() && WSPDB.IsServiceReady())    // p_AgentLogin OK
                {
                    g_SharedData.WSP_AGENT_SETTING.iServerNumber = WSPDB.g_iServerNumber; // GET SERVER NUMBER when it's checking WSP DB READY.

                    if (WSPDB.StartWSPDBOperation())                                      //StartSHSTDBOpertaion - includes license checking, and registration of this server.
                    {
                        bRegisterd = true;
                    }
                    else
                    {
                        bRegisterd = false;
                        Thread.Sleep(5000);
                    }

                    iRetryCount = iRetryCount + 1;
                    if (iRetryCount > 10)
                    {
                        WSPEvent.WriteEvent("Service Point Agent can not access Service Point Server.", "E", 1107);
                        iRetryCount = 1;
                    }

                    while (!WSPDB.ReadPerformanceCounters())
                    {
                        Thread.Sleep(1000);         //Read required counters from DB
                    }
                    while (!WSPDB.ReadAlertRules()) //Read alert rules
                    {
                        Thread.Sleep(1000);
                    }

                    bIsServiceReady = true;
                }
                else                                                     // if it can't read perfmon, and can't access database.
                {
                    bIsServiceReady = false;
                    iRetryCount     = iRetryCount + 1;
                    if (iRetryCount > 10)
                    {
                        WSPEvent.WriteEvent("Service Point Agent can not access Service Point Server, or read performance counters.", "E", 1135);
                        iRetryCount = 1;
                    }
                    Thread.Sleep(5000);
                }
            }while (!bRegisterd);

            Thread workerThread = new Thread(HandlingPerfValues);
            Thread loggerThread = new Thread(LoggerWork);
            Thread HCThread     = new Thread(WebHCWorker);
            Thread SQLChkThread = new Thread(SQLQueryMonitoringWorker);

            //Thread SQLHCThread = new Thread(SQLHCWorker);

            if (bRegisterd)
            {
                int iInterval = g_SharedData.WSP_AGENT_SETTING.iPerfLogCollectInterval * 1000;

                g_GlobalGUID = Guid.NewGuid();
                g_TimeIn     = Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
                g_TimeIn_UTC = Convert.ToDateTime(DateTime.UtcNow.ToString("yyyy-MM-dd HH:mm:ss"));

                // Run/Stop/Resume performance value collection thread.
                System.Threading.TimerCallback tc;
                System.Threading.Timer         tm;

                tc = new TimerCallback(ObserverCheck);
                tm = new System.Threading.Timer(tc, null, iInterval, iInterval);

                if (g_SharedData.WSP_AGENT_SETTING.strServerType == "Web")
                {
                    // Refresh Process Memory status & running applications every 3 seconds.
                    System.Threading.TimerCallback tcProcess;
                    System.Threading.Timer         tmProcess;

                    tcProcess = new TimerCallback(ProcessMemoryCheck);
                    tmProcess = new System.Threading.Timer(tcProcess, null, iInterval + 3000, 5000);
                }

                // Reload Application Configurations every 5 minutes
                System.Threading.TimerCallback tcAppConfg;
                System.Threading.Timer         tmAppConfig;

                tcAppConfg  = new TimerCallback(RefreshWSPService);
                tmAppConfig = new System.Threading.Timer(tcAppConfg, null, 300000, 300000);


                //////////////////////////////////////////////////////////////////
                //          Worker Threads
                //////////////////////////////////////////////////////////////////

                _bThreadFlag = true;

                //Performance counter thread start
                workerThread.Start();

                if (g_SharedData.WEB_SETTING.bIISLogAnalysis && (g_SharedData.WSP_AGENT_SETTING.strServerType == "Web"))
                {
                    _bLoggerThreadFlag = true;
                    loggerThread.Start();
                }

                if (g_SharedData.HC_SETTING.bHC_Enabled && (g_SharedData.WSP_AGENT_SETTING.strServerType == "Web"))
                {
                    _bHCThreadFlag = true;
                    HCThread.Start();
                }

                if (g_SharedData.WSP_AGENT_SETTING.strServerType.Contains("SQL"))
                {
                    SQLChkThread.Start();
                    //SQLHCThread.Start();
                }
            }

            while (!_shouldStop)
            {
                Thread.Sleep(10000);
            }

            if (_shouldStop)
            {
                workerThread.Join();

                if (g_SharedData.WEB_SETTING.bIISLogAnalysis && (g_SharedData.WSP_AGENT_SETTING.strServerType == "Web"))
                {
                    loggerThread.Join();
                }

                if (g_SharedData.HC_SETTING.bHC_Enabled && (g_SharedData.WSP_AGENT_SETTING.strServerType == "Web"))
                {
                    HCThread.Join();
                }

                if (g_SharedData.WSP_AGENT_SETTING.strServerType.Contains("SQL"))
                {
                    SQLChkThread.Join();
                    //SQLHCThread.Join();
                }
            }
        }
예제 #10
0
        private void RegisterThisHost()
        {
            try
            {
                bRegisterd = false;

                InsertHostWS();
            }
            catch (Exception e)
            {
                WSPEvent.WriteEvent("Registering this host by Service Point agent has been failed. - " + e.Message, "E", 1105);
            }
        }
예제 #11
0
        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);
        }
예제 #12
0
    public void ReadW3WPMemory()
    {
        if (dtW3WPMemory.Rows.Count > 0)
        {
            DateTime tmNow = new DateTime();
            tmNow = DateTime.Now;

            DateTime tmDuration = new DateTime();
            tmDuration = tmNow.AddSeconds(-60);             // To save size of process memory duing 1 minute, to check process memory increasement with its new size

            try
            {
                var rows = dtW3WPMemory.Select("TimeIn < '" + tmDuration + "'");
                foreach (var row in rows)
                {
                    row.Delete();
                }

                dtW3WPMemory.AcceptChanges();
            }
            catch (Exception ex)
            {
                SHSTEvent.WriteEvent(ex.Message, "E", 1119);
            }
        }

        string[] arrInstanceNames;

        PerformanceCounterCategory pcCat = new PerformanceCounterCategory();
        PerformanceCounter         PC    = new PerformanceCounter();

        pcCat.CategoryName = "Process";
        DateTime dtNow = new DateTime();

        dtNow = DateTime.Now;
        float flPValue = 0;

        try
        {
            arrInstanceNames = pcCat.GetInstanceNames();

            foreach (string strProcess in arrInstanceNames)
            {
                if (strProcess == "w3wp" || strProcess.Contains("w3wp#") || strProcess == "java" || strProcess.Contains("java#") || strProcess == "javaw" || strProcess.Contains("javaw#"))
                {
                    PC.CategoryName = "Process";
                    PC.CounterName  = "Private Bytes";
                    PC.InstanceName = strProcess;

                    PC.NextValue();
                    System.Threading.Thread.Sleep(100);
                    flPValue = PC.NextValue();

                    string strReference = GetReferenceValue("Process", PC.CounterName, flPValue, PC.InstanceName);
                    dtW3WPMemory.Rows.Add("P013", strHostName, dtNow, flPValue, strReference, strProcess);
                }
            }
        }
        catch (Exception ex)
        {
            SHSTEvent.WriteEvent(ex.Message, "E", 1123);
        }
    }
예제 #13
0
        public void CheckProcessMemory(DataTable dtW3WPMemory)
        {
            if (flMemoryDelta < (float)1000000)         // 20MB by default
            {
                flMemoryDelta = (float)20000000;
            }

            float flPValue1           = 0;
            float flPValue2           = 0;
            float flBaseProcessMemory = (float)250000000;         // 250MB, to start monitoring for process memory.

            DataTable dtProcessList = new DataTable();

            System.Data.DataRow[] rowsProcess;

            string strR035Desc    = "";
            string strR046Desc    = "";
            bool   bIsR035Enabled = false;
            bool   bIsR046Enabled = false;

            DataRow[] drRules = dtAlertRules.Select("ReasonCode IN ('R035', 'R046')");
            foreach (DataRow drDesc in drRules)
            {
                if (drDesc["ReasonCode"].ToString() == "R035")
                {
                    strR035Desc    = drDesc["ReasonCodeDesc"].ToString();
                    bIsR035Enabled = Convert.ToBoolean(drDesc["IsEnabled"]);
                }

                if (drDesc["ReasonCode"].ToString() == "R046")
                {
                    strR046Desc    = drDesc["ReasonCodeDesc"].ToString();
                    bIsR046Enabled = Convert.ToBoolean(drDesc["IsEnabled"]);
                }
            }

            if (!bIsR035Enabled && !bIsR046Enabled)
            {
                return;
            }

            try
            {
                if (dtW3WPMemory.Rows.Count < 1)
                {
                    return;
                }

                dtProcessList = dtW3WPMemory.DefaultView.ToTable(true, "InstanceName");

                foreach (DataRow drProcess in dtProcessList.Rows)
                {
                    string strProcess = drProcess["InstanceName"].ToString();
                    string strQuery   = "InstanceName = '" + strProcess + "'";

                    rowsProcess = dtW3WPMemory.Select(strQuery);
                    if (rowsProcess.Length < 1)
                    {
                        return;
                    }

                    foreach (DataRow drW3wp in rowsProcess)
                    {
                        flPValue2 = (float)Convert.ToSingle(drW3wp["PValue"]);

                        if (flPValue2 > flBaseProcessMemory && flPValue1 != 0)
                        {
                            float flChange = flPValue2 - flPValue1;
                            if (flChange > flMemoryDelta)
                            {
                                if (strProcess.Contains("w3wp"))
                                {
                                    string strAppPool = GetAppPoolDesc(strProcess);
                                    CurrentRule.strReasonCode        = "R035";
                                    CurrentRule.strReasonDescription = strR035Desc;
                                    CurrentRule.bRecordApp           = true;
                                    CurrentRule.strInstanceName      = strAppPool;

                                    AddThisAlert(flPValue2, strAppPool, drW3wp["RValue"].ToString());
                                }
                                else
                                {
                                    CurrentRule.strReasonCode        = "R046";
                                    CurrentRule.strReasonDescription = strR046Desc;
                                    CurrentRule.bRecordApp           = false;
                                    string strPID = GetJavaPID(strProcess);
                                    AddThisAlert(flPValue2, strProcess, strPID);
                                }
                                return;        // to avoid noisy alerts continuosly, if true, clear data tables.
                            }
                        }

                        flPValue1 = flPValue2;
                    }

                    flPValue1 = 0;
                }
            }
            catch (Exception ex)
            {
                WSPEvent.WriteEvent(ex.Message, "E", 1126);
            }

            return;
        }