示例#1
0
        private static bool CheckMonitoringEnabled()
        {
            MonitoringSessionController sessionController = new MonitoringSessionController();
            var session = sessionController.GetActiveSession();

            if (session == null)
            {
                return(false);
            }
            else
            {
                if (m_MonitoringSession == null)
                {
                    m_MonitoringSession = session;
                }
                else
                {
                    // Check if it is the same session or not
                    if (m_MonitoringSession.SessionId != session.SessionId)
                    {
                        Logger.LogCpuMonitoringVerboseEvent($"Reloading monitoring session as session has changed, old={m_MonitoringSession.SessionId}, new={session.SessionId}", m_MonitoringSession.SessionId);
                        m_MonitoringSession = session;
                        m_CpuMonitoring.InitializeMonitoring(m_MonitoringSession);
                    }
                }

                return(true);
            }
        }
示例#2
0
        private static void StopMonitoringSession()
        {
            SessionMode sessionMode = SessionMode.Collect;
            string      sessionId   = "";

            if (m_MonitoringSession != null)
            {
                sessionMode = m_MonitoringSession.Mode;
                sessionId   = m_MonitoringSession.SessionId;
            }
            Logger.LogCpuMonitoringVerboseEvent($"Stopping a monitoring session", sessionId);

            MonitoringSessionController sessionController = new MonitoringSessionController();
            var sessionStopped = sessionController.StopMonitoringSession();

            if (!sessionStopped)
            {
                Logger.LogCpuMonitoringVerboseEvent($"Failed while stopping the session", sessionId);
                m_FailedStoppingSession = true;
            }
            else
            {
                var blobSasUri = m_MonitoringSession.BlobSasUri;
                m_MonitoringEnabled     = false;
                m_MonitoringSession     = null;
                m_FailedStoppingSession = false;
                if (sessionMode == SessionMode.CollectKillAndAnalyze && !string.IsNullOrWhiteSpace(sessionId))
                {
                    MonitoringSessionController controller = new MonitoringSessionController();
                    controller.AnalyzeSession(sessionId, blobSasUri);
                }
            }
        }
        public HttpResponseMessage GetActiveSession()
        {
            var monitoringController = new MonitoringSessionController();

            try
            {
                var session = monitoringController.GetActiveSession();
                return(Request.CreateResponse(HttpStatusCode.OK, session));
            }
            catch (Exception ex)
            {
                Logger.LogCpuMonitoringErrorEvent("Controller API Failure - GetActiveSession", ex, string.Empty);
                return(Request.CreateErrorResponse(HttpStatusCode.NotFound, ex.Message));
            }
        }
        // GET: api/CpuMonitoring
        public HttpResponseMessage Get()
        {
            var monitoringController = new MonitoringSessionController();

            try
            {
                var sessions = monitoringController.GetAllCompletedSessions();
                return(Request.CreateResponse(HttpStatusCode.OK, sessions));
            }
            catch (Exception ex)
            {
                Logger.LogCpuMonitoringErrorEvent("Controller API Failure - Get", ex, string.Empty);
                return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex.Message));
            }
        }
        // DELETE: api/CpuMonitoring/5
        public HttpResponseMessage Delete(string sessionId)
        {
            var monitoringController = new MonitoringSessionController();

            try
            {
                monitoringController.DeleteSession(sessionId);
                return(Request.CreateResponse(HttpStatusCode.OK));
            }
            catch (Exception ex)
            {
                Logger.LogCpuMonitoringErrorEvent("Controller API Failure - DELETE", ex, string.Empty);
                return(Request.CreateErrorResponse(HttpStatusCode.Conflict, ex.Message));
            }
        }
        // POST: api/CpuMonitoring
        public HttpResponseMessage Post([FromBody] MonitoringSession session)
        {
            var monitoringController = new MonitoringSessionController();

            try
            {
                var submittedSession = monitoringController.CreateSession(session);
                return(Request.CreateResponse(HttpStatusCode.OK, session.SessionId));
            }
            catch (Exception ex)
            {
                Logger.LogCpuMonitoringErrorEvent("Controller API Failure - POST", ex, string.Empty);
                return(Request.CreateErrorResponse(HttpStatusCode.Conflict, ex.Message));
            }
        }
        public HttpResponseMessage StopMonitoringSession()
        {
            var monitoringController = new MonitoringSessionController();

            try
            {
                var monitoringSessionStopped = monitoringController.StopMonitoringSession();
                return(Request.CreateResponse(HttpStatusCode.OK, monitoringSessionStopped));
            }
            catch (Exception ex)
            {
                Logger.LogCpuMonitoringErrorEvent("Controller API Failure - StopMonitoringSession", ex, string.Empty);
                return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex.Message));
            }
        }
        public HttpResponseMessage Analyze(string sessionId)
        {
            var monitoringController = new MonitoringSessionController();
            var session = monitoringController.GetSession(sessionId);

            try
            {
                var result = monitoringController.AnalyzeSession(sessionId, session.BlobSasUri);
                return(Request.CreateResponse(HttpStatusCode.OK, result));
            }
            catch (Exception ex)
            {
                Logger.LogCpuMonitoringErrorEvent("Controller API Failure - Analyze", ex, string.Empty);
                return(Request.CreateErrorResponse(HttpStatusCode.NotFound, ex.Message));
            }
        }
示例#9
0
        private static void CompletedSessionCleanup()
        {
            int maxSessionsToKeep = _DaaS.MaxDiagnosticSessionsToKeep;
            int numberOfDays      = _DaaS.MaxNumberOfDaysForSessions;
            var completedSessions = _DaaS.GetAllInActiveSessions().OrderByDescending(s => s.StartTime).ToList();
            MonitoringSessionController controllerMonitoring = new MonitoringSessionController();
            var completedMonitoringSessions = controllerMonitoring.GetAllCompletedSessions();

            Logger.LogVerboseEvent($"Starting cleanup for Completed Sessions MaxDiagnosticSessionsToKeep = [{maxSessionsToKeep}] MaxNumberOfDaysForSessions= [{numberOfDays}]");
            while (true)
            {
                List <Session> sessionsToRemove = completedSessions.Skip(maxSessionsToKeep).ToList();
                string         logMessage       = $"[MaxDiagnosticSessionsToKeep] Found {sessionsToRemove.Count()} sessions to remove as we have {completedSessions.Count()} completed sessions";
                DeleteSessions(sessionsToRemove, async(session) => { await _DaaS.Delete(session); }, logMessage);

                completedSessions = _DaaS.GetAllInActiveSessions().OrderByDescending(s => s.StartTime).ToList();

                if (CheckIfTimeToCleanupSymbols(completedSessions))
                {
                    CleanupSymbolsDirectory();
                }

                List <Session> olderSessions = completedSessions.Where(x => x.StartTime < DateTime.UtcNow.AddDays(-1 * numberOfDays)).ToList();
                logMessage = $"[MaxNumberOfDaysForSessions] Found {olderSessions.Count()} older sessions to remove";
                DeleteSessions(olderSessions, async(session) => { await _DaaS.Delete(session); }, logMessage);

                List <MonitoringSession> monitoringSessionsToRemove = completedMonitoringSessions.Skip(maxSessionsToKeep).ToList();
                logMessage = $"[MaxDiagnosticSessionsToKeep] Found {monitoringSessionsToRemove.Count()} monitoring sessions to remove as we have {completedMonitoringSessions.Count()} completed sessions";
                DeleteSessions(monitoringSessionsToRemove, (session) => { controllerMonitoring.DeleteSession(session.SessionId); }, logMessage);

                completedMonitoringSessions = controllerMonitoring.GetAllCompletedSessions().OrderByDescending(s => s.StartDate).ToList();
                List <MonitoringSession> olderSessionsMonitoring = completedMonitoringSessions.Where(x => x.StartDate < DateTime.UtcNow.AddDays(-1 * numberOfDays)).ToList();
                logMessage = $"[MaxNumberOfDaysForSessions] Found {olderSessionsMonitoring.Count()} older monitoring sessions to remove";
                DeleteSessions(olderSessionsMonitoring, (session) => { controllerMonitoring.DeleteSession(session.SessionId); }, logMessage);

                Thread.Sleep(5 * 60 * 1000);
            }
        }
        public HttpResponseMessage GetActiveSessionDetails()
        {
            ActiveMonitoringSession activeSession = new ActiveMonitoringSession();
            var monitoringController = new MonitoringSessionController();

            try
            {
                activeSession.Session = monitoringController.GetActiveSession();
                if (activeSession.Session != null)
                {
                    var sessionLogs = monitoringController.GetActiveSessionMonitoringLogs();
                    activeSession.MonitoringLogs         = sessionLogs.ToList();
                    activeSession.Session.FilesCollected = monitoringController.GetCollectedLogsForSession(activeSession.Session.SessionId, activeSession.Session.BlobSasUri);
                }

                return(Request.CreateResponse(HttpStatusCode.OK, activeSession));
            }
            catch (Exception ex)
            {
                Logger.LogCpuMonitoringErrorEvent("Controller API Failure - GetActiveSessionDetails", ex, string.Empty);
                return(Request.CreateErrorResponse(HttpStatusCode.NotFound, ex.Message));
            }
        }