private void CheckForHighResponseTime(MonitorRequest request, RequestSummary requestSummary) { EventType type = Facade.EventTypeDomainController.GetTypeByName(StaticStrings.ResponseTimeHigh); if (request.RequestTimeMiliSeconds > type.PeakValue) { //Lav notification Notification notification = new Notification(); notification.Seen = false; notification.Created = DateTime.Now; notification = Facade.NotificationDomainController.Create(notification); //request should have serverId SOMEDAY // Facade.ServerDetailDomainController.GetLatestServerDetail(request.ServerId); int serverInterval = Facade.SettingDomainController.GetValueByName(StaticStrings.ServerDetailInterval); //If interval = 10min -> check 15min back ServerDetail latestServerDetailSummary = Facade.ServerDetailDomainController.GetLatestServerDetailByInterval(serverInterval + (serverInterval / 2)); Event e = new Event(); e.Created = DateTime.Now; e.Value = Convert.ToInt32(request.RequestTimeMiliSeconds); e.EventTypeId = type.Id; e.NotificationId = notification.Id; e.RequestSummaryId = requestSummary == null ? 0 : requestSummary.Id; e.ServerDetailId = latestServerDetailSummary == null ? 0 : latestServerDetailSummary.Id; Facade.EventDomainController.Create(e); } }
public async ValueTask <RequestSummary> RecordRequestAsync( string url, Stage stage, Dictionary <string, string> headers, CancellationToken cancellationToken) { var report = new RequestSummary { Id = Guid.NewGuid(), Stage = stage, Url = url, Start = DateTime.UtcNow }; var httpRequestMessage = BuildHttpRequestMessage(url, headers); var client = new HttpClient(); _timeHandler.Start(); var response = await client.SendAsync(httpRequestMessage, cancellationToken); _timeHandler.Stop(); report.End = DateTime.UtcNow; report.DurationMs = _timeHandler.ElapsedMilliseconds(); report.StatusCode = response.StatusCode; _logger.LogInformation($"Request sent: {report}"); return(report); }
private void CreateServerDownEvent(ServerDataViewModel sdvm) { try { Model.EventType type = Facade.EventTypeDomainController.GetTypeByName(StaticStrings.ServerDown); int serverInterval = Facade.SettingDomainController.GetValueByName(StaticStrings.ServerDetailInterval); RequestSummary requestSummary = Facade.RequestSummaryDomainController.GetRequestSummaryLastMinutes(serverInterval); ServerDetail latestServerDetailSummary = Facade.ServerDetailDomainController.GetLatestServerDetailByInterval(serverInterval + (serverInterval / 2)); Notification n = new Notification(); n.Seen = false; n = Facade.NotificationDomainController.Create(n); Model.Event e = new Model.Event(); e.Created = DateTime.Now; e.Value = 1; e.EventTypeId = type.Id; e.RequestSummaryId = requestSummary == null ? 0 : requestSummary.Id; e.ServerDetailId = latestServerDetailSummary == null ? 0 : latestServerDetailSummary.Id; e.NotificationId = n.Id; Facade.EventDomainController.Create(e); sdvm.Uptime = CalculateUpTime(0); sdvm.CurrentStatus = false; } catch (Exception e) { log.Error("ServerLogic - CreateServerDownEvent: " + e); } }
public static JobStatuses?SingleJobStatus(this RequestSummary requestSummary) { return(requestSummary.JobStatusDictionary().Count() switch { 0 => JobStatuses.Cancelled, 1 => requestSummary.JobStatusDictionary().First().Key, _ => null });
public List <UserSummary> GetUserSummariesByRequestSummary(RequestSummary requestSummary) { try { using (var ctx = new DatabaseModelDataContext()) { var userSummaries = ctx.UserSummaries.Where(x => x.RequestSummaryId == requestSummary.Id).ToList(); return(userSummaries); } } catch (Exception e) { Log.Error("Database error - GetUserSummaries: " + e); throw; } }
public HttpResponseMessage PostServerDetailCurrent(ServerDetailModel serverDetails) { try { if (serverDetails == null || serverDetails.ServerName == null) { return(new HttpResponseMessage(HttpStatusCode.BadRequest)); } //Server regonized? Server s = Facade.ServerDomainController.GetServerByName(serverDetails.ServerName); if (s == null) { s = new Server(); s.Name = serverDetails.ServerName; s = Facade.ServerDomainController.CreateServer(s); } //Create everytime! ServerDetailCurrent currentServerDetail = new ServerDetailCurrent(); currentServerDetail.Handles = serverDetails.Handles; currentServerDetail.Utilization = serverDetails.Utilization; currentServerDetail.Thread = serverDetails.Thread; currentServerDetail.Processes = serverDetails.Processes; currentServerDetail.UpTime = serverDetails.Uptime; currentServerDetail.RAMUtilization = serverDetails.RAMUtilization; currentServerDetail.RAMAvailable = serverDetails.RAMAvailable; currentServerDetail.RAMTotal = serverDetails.RAMTotal; currentServerDetail.BytesReceived = serverDetails.BytesReceived; currentServerDetail.BytesSent = serverDetails.BytesSent; currentServerDetail.NetworkUtilization = serverDetails.NetworkUtilization; currentServerDetail.ServerId = s.Id; Facade.ServerDetailCurrentDomainController.CreateServerDetailCurrent(currentServerDetail); //Styrer den sidste del af grafen (Bliver slettet løbende) //ServerSummary hvert interval! //der gemmes et summary hvert interval (10 MIN). DVS 13:35, består af data fra 13:30-13:40 //ved 13:30, kan vi gemme (summary 13:45) //ved 13:40, kan vi gemme (summary 13:35) OSV //KL 13:50:01, tjekker vi 15minutter tilbage (1,5 interval) //Get the interval int serverInterval = Facade.SettingDomainController.GetValueByName(StaticStrings.ServerDetailInterval); //If interval = 10min -> check 15min back ServerDetail latestServerDetailSummary = Facade.ServerDetailDomainController.GetLatestServerDetailByInterval(serverInterval + (serverInterval / 2)); //If null, create new if (latestServerDetailSummary == null) { //get all servercurrent List <ServerDetailCurrent> currentServerDetailsList = Facade.ServerDetailCurrentDomainController.GetAll(); //create new serverdetailSummary with the averages from all servercurrent ServerDetail serverDetailSummary = new ServerDetail(); serverDetailSummary.Handles = Convert.ToInt32(currentServerDetailsList.Average(x => x.Handles)); serverDetailSummary.RAMAvailable = Convert.ToInt32(currentServerDetailsList.Average(x => x.RAMAvailable)); serverDetailSummary.RAMTotal = Convert.ToInt32(currentServerDetailsList.Average(x => x.RAMTotal)); serverDetailSummary.Thread = Convert.ToInt32(currentServerDetailsList.Average(x => x.Thread)); serverDetailSummary.Processes = Convert.ToInt32(currentServerDetailsList.Average(x => x.Processes)); serverDetailSummary.Utilization = Convert.ToInt32(currentServerDetailsList.Average(x => x.Utilization)); serverDetailSummary.ServerId = currentServerDetailsList.FirstOrDefault().ServerId; serverDetailSummary.UpTime = currentServerDetailsList.LastOrDefault().UpTime; serverDetailSummary.Created = GetStartOfInterval(DateTime.Now, serverInterval); serverDetailSummary.BytesSent = currentServerDetailsList.Sum(x => x.BytesSent); serverDetailSummary.BytesReceived = currentServerDetailsList.Sum(x => x.BytesReceived); serverDetailSummary.NetworkUtilization = Convert.ToInt32(currentServerDetailsList.Average(x => x.NetworkUtilization)); latestServerDetailSummary = Facade.ServerDetailDomainController.Create(serverDetailSummary); } //Events - Could add more RequestSummary requestSummary = Facade.RequestSummaryDomainController.GetRequestSummaryLastMinutes(serverInterval); EventLogic ev = new EventLogic(); //Move most logic to this. Maybe make generic method for creating events? Model.EventType cpuEventType = Facade.EventTypeDomainController.GetTypeByName(StaticStrings.CpuUsageHigh); if (currentServerDetail.Utilization > cpuEventType.PeakValue) { //Notification Notification n = Facade.NotificationDomainController.Create(new Notification()); //Event Model.Event e = new Model.Event(); //ServerDetail -> tage nuværende snapshot, eller tage summary eller begge? e.ServerDetailId = latestServerDetailSummary.Id; //Server summary // requestSummary i dette tidsrum e.RequestSummaryId = requestSummary == null ? 0 : requestSummary.Id; e.Created = DateTime.Now; e.EventTypeId = cpuEventType.Id; e.NotificationId = n.Id; e.Value = serverDetails.Utilization; Model.Event createdEvent = Facade.EventDomainController.Create(e); //Notify by email? if (cpuEventType.Notify) { EmailManager emailManager = new EmailManager(); } } Model.EventType ramEventType = Facade.EventTypeDomainController.GetTypeByName(StaticStrings.LowMemory); if (currentServerDetail.RAMAvailable < ramEventType.PeakValue) { //Notification Notification n = Facade.NotificationDomainController.Create(new Notification()); //Event Model.Event e = new Model.Event(); e.ServerDetailId = latestServerDetailSummary.Id; e.RequestSummaryId = requestSummary == null ? 0 : requestSummary.Id; e.Created = DateTime.Now; e.EventTypeId = ramEventType.Id; e.NotificationId = n.Id; e.Value = serverDetails.RAMAvailable; Model.Event createdEvent = Facade.EventDomainController.Create(e); //Notify by email? if (ramEventType.Notify) { EmailManager emailManager = new EmailManager(); } } } catch (Exception e) { var response = new HttpResponseMessage(HttpStatusCode.BadRequest); response.Content = new StringContent("Error: " + e); return(response); } //Slet Dem her? int setupInterval = Facade.SettingDomainController.GetValueByName(StaticStrings.ServerDetailInterval); Facade.ServerDetailCurrentDomainController.DeleteAllOlderThanInterval(setupInterval); return(new HttpResponseMessage(HttpStatusCode.OK)); }
public static Dictionary <JobStatuses, int> JobStatusDictionary(this RequestSummary requestSummary) { return(requestSummary.UncancelledJobs().GroupBy(j => j.JobStatus) .Select(g => new KeyValuePair <JobStatuses, int>(g.Key, g.Count())) .ToDictionary(a => a.Key, a => a.Value)); }
public RequestDataViewModel GetRequestData() { RequestDataViewModel rdvm = new RequestDataViewModel(); try { int interval = Facade.SettingDomainController.GetValueByName(StaticStrings.ResponseTimeInterval); rdvm.Interval = interval; //this is for getting the total/total mobil/total web requests made by users, in the last given interval RequestSummary requestSummary = Facade.RequestSummaryDomainController.GetLatestFinishedRequestSummary(interval); if (requestSummary != null) { rdvm.DataLastInterval = true; List <UserSummary> LatestUserSummary = Facade.UserSummaryDomainController.GetUserSummariesByRequestSummary(requestSummary); //total request last interval int totalRequests = LatestUserSummary.Sum(x => x.Request); rdvm.TotalRequests = totalRequests; //total web/mobile request last interval int webRequestsLastInterval = LatestUserSummary.Where(x => x.Device == (int)MyEnums.DeviceTypes.Web).Sum(xx => xx.Request); int mobileRequestsLastInterval = LatestUserSummary.Where(x => x.Device == (int)MyEnums.DeviceTypes.Mobile).Sum(xx => xx.Request); rdvm.MobilRequests = mobileRequestsLastInterval; rdvm.WebRequests = webRequestsLastInterval; } else { rdvm.DataLastInterval = false; } //For average calculations List <UserSummary> UsersSummaries = Facade.UserSummaryDomainController.GetAllUserSummeriesLastMinutes(minutesADay).ToList(); int webRequests = UsersSummaries.Where(x => x.Device == (int)MyEnums.DeviceTypes.Web).Sum(xx => xx.Request); int mobileRequests = UsersSummaries.Where(x => x.Device == (int)MyEnums.DeviceTypes.Mobile).Sum(xx => xx.Request); int webUsers = UsersSummaries.Where(x => x.Device == (int)MyEnums.DeviceTypes.Web).ToList().Count == 0 ? 1 : UsersSummaries.Where(x => x.Device == (int)MyEnums.DeviceTypes.Web).ToList().Count; int mobileUsers = UsersSummaries.Where(x => x.Device == (int)MyEnums.DeviceTypes.Mobile).ToList().Count == 0 ? 1 : UsersSummaries.Where(x => x.Device == (int)MyEnums.DeviceTypes.Mobile).ToList().Count; int totalUsers = UsersSummaries.ToList().Count == 0 ? 1 : UsersSummaries.ToList().Count; rdvm.AverageWebRequests = webRequests / webUsers; rdvm.AverageMobilRequests = mobileRequests / mobileUsers; rdvm.TotalAverageRequests = (webRequests + mobileRequests) / totalUsers; //Active users model ActiveUser activeUsers = Facade.ActiveUsersDomainController.GetActiveUsers(); if (activeUsers == null) { activeUsers = new ActiveUser() { MobilUsers = 0, WebUsers = 0 }; } rdvm.ActiveUserModel = new ActiveUsersModel(); rdvm.ActiveUserModel.WebUsers = activeUsers.WebUsers; rdvm.ActiveUserModel.MobilUsers = activeUsers.MobilUsers; } catch (Exception e) { Log.Error("RequestLogic - GetRequestData: ", e); } return(rdvm); }
public void AddRequestReport(RequestSummary requestSummary) => RequestReports.Add(requestSummary);
public HttpResponseMessage PostRequest(MonitorRequest request) { if (request == null) { return(new HttpResponseMessage(HttpStatusCode.BadRequest)); } int interval = Facade.SettingDomainController.GetValueByName(StaticStrings.ResponseTimeInterval); RequestSummary requestSummary = Facade.RequestSummaryDomainController.GetRequestSummaryLastMinutes(interval); if (requestSummary == null) { requestSummary = Facade.RequestSummaryDomainController.CreateRequestSummary(requestSummary, interval); } //System.Configuration.ConfigurationManager.AppSettings["RequestTimeWatchUrl"]; if (request.Url.Contains(Model.Properties.Settings.Default["RequestTimeWatchUrl"].ToString())) { //total requests var totalRequests = requestSummary.Requests; //Current average time var averageTime = requestSummary.ResponseTime; //total request time var totalRequestsTime = averageTime * totalRequests; totalRequests++; //the new average = total time + the requests time split by totalrequest + 1 var newAverageTime = (totalRequestsTime + (int)request.RequestTimeMiliSeconds) / totalRequests; requestSummary.ResponseTime = newAverageTime; requestSummary.Requests = totalRequests; CheckForHighResponseTime(request, requestSummary); Facade.RequestSummaryDomainController.UpdateRequestSummary(requestSummary); } UserSummary userSummary = Facade.UserSummaryDomainController.GetUserSummeryByUserAndRequestSummary(request.UserId, request.Device, requestSummary.Id); if (userSummary != null) { userSummary.Request++; Facade.UserSummaryDomainController.UpdateUserSummary(userSummary); } else { UserSummary newUserSummary = new UserSummary(); newUserSummary.UserId = request.UserId; newUserSummary.DateTimeCreated = DateTime.Now; newUserSummary.Device = request.Device; newUserSummary.RequestSummaryId = requestSummary.Id; newUserSummary.Request = 1; Facade.UserSummaryDomainController.CreateUserSummary(newUserSummary); if (request.Device == (int)MyEnums.DeviceTypes.Mobile) { requestSummary.MobileUsers++; } if (request.Device == (int)MyEnums.DeviceTypes.Web) { requestSummary.WebUsers++; } Facade.RequestSummaryDomainController.UpdateRequestSummary(requestSummary); } try { Request r = new Request(); r.DateCreated = DateTime.Now; r.RequestTimeMiliSeconds = Convert.ToInt32(request.RequestTimeMiliSeconds); r.Url = request.Url; r.UserId = request.UserId; r.Device = request.Device; Facade.RequestDomainController.Create(r); } catch (Exception e) { log.Error("Error in request api controller. Request Part: " + e); } return(new HttpResponseMessage(HttpStatusCode.OK)); }