Exemplo n.º 1
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);
            }
        }
Exemplo n.º 2
0
        // 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));
            }
        }