public MonitorJob GetMonitorJob(MonitorJobRequest request) { MonitorJobPayload payload = new MonitorJobPayload(); if (request.ResponseTimeOutMonitor != null) { payload.ResponseTimeOutMonitor = new ResponseTimeOutMonitorJob { Status = request.ResponseTimeOutMonitor.Status, TimeOutMs = request.ResponseTimeOutMonitor.TimeOutMs.ToInt(), Percentage = request.ResponseTimeOutMonitor.Percentage.Replace("%", "").ToDouble(2) }; } if (request.ErrorResponseMonitor != null) { payload.ErrorResponseMonitor = new ErrorResponseMonitorJob { Status = request.ErrorResponseMonitor.Status, HttpCodeStatus = request.ErrorResponseMonitor.HttpCodeStatus.Replace(",", ","), Percentage = request.ErrorResponseMonitor.Percentage.Replace("%", "").ToDouble(2) }; } if (request.IPMonitor != null) { payload.IPMonitor = new IPMonitorJob { Status = request.IPMonitor.Status, WhiteList = (request.IPMonitor.WhiteList ?? string.Empty), Percentage = request.IPMonitor.Percentage.Replace("%", "").ToDouble(2) }; } if (request.RequestCountMonitor != null) { payload.RequestCountMonitor = new RequestCountMonitorJob { Status = request.RequestCountMonitor.Status, Max = request.RequestCountMonitor.Max.ToInt() }; } MonitorJob model = new MonitorJob() { Id = request.Id, Title = request.Title, Description = (request.Description ?? string.Empty), CronLike = ParseJobRate(request.Interval), Emails = request.Emails.Replace(",", ","), WebHook = request.WebHook, Mobiles = (request.Mobiles ?? string.Empty).Replace(",", ","), Status = request.Status, Nodes = request.Nodes, Payload = JsonConvert.SerializeObject(payload), CreateTime = DateTime.Now }; return(model); }
/// <summary> /// 检查请求错误监控 /// </summary> /// <param name="job"></param> /// <param name="payload"></param> /// <returns></returns> private async Task <AlarmOption> CheckErrorResponseMonitor(IMonitorJob job, MonitorJobPayload payload) { if (payload.ErrorResponseMonitor == null) { return(null); } var(now, start, end) = GetNowTimes(_monitorService.ParseJobCron(job.CronLike)); _logger.LogInformation("CheckErrorResponseMonitor Start " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); var errorCount = await _storage.GetRequestCountAsync(new RequestCountFilterOption() { Nodes = job.Nodes.Split(','), StartTime = start, EndTime = end, StatusCodes = payload.ErrorResponseMonitor.HttpCodeStatus.Split(',').Select(x => x.ToInt()).ToArray() }); var count = await _storage.GetRequestCountAsync(new RequestCountFilterOption() { Nodes = job.Nodes.Split(','), StartTime = start, EndTime = end, }); if (count == 0) { return(null); } var percent = errorCount * 100.0 / count; _logger.LogInformation("CheckErrorResponseMonitor End " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + $" Result {(percent > payload.ErrorResponseMonitor.Percentage ? "预警" : "正常")}"); if (percent > payload.ErrorResponseMonitor.Percentage) { return(new AlarmOption() { IsHtml = true, Content = $@" <br> <b>【{_lang.Monitor_Type_RequestError}】 </b> <p>{_lang.Warning_Threshold}:{payload.ErrorResponseMonitor.Percentage.ToString("F2")}% {_lang.Warning_Current}:{percent.ToString("F2")}% </p> <p>{_lang.Warning_Title}:{job.Title}</p> <p>{_lang.Monitor_ServiceNode}:{job.Nodes}</p> <p>{_lang.Monitor_Frequency}:{_monitorService.ParseJobCronString(job.CronLike)} </p> <p>{_lang.Monitor_HttpStatusCode}:{payload.ErrorResponseMonitor.HttpCodeStatus}</p> <p>{_lang.Warning_TimeRange}:{start.ToStandardTime()}-{end.ToStandardTime()} </p>" }); } return(null); }
/// <summary> /// 检查请求错误监控 /// </summary> /// <param name="job"></param> /// <param name="payload"></param> /// <returns></returns> private async Task <AlarmOption> CheckErrorResponseMonitor(IMonitorJob job, MonitorJobPayload payload) { if (payload.ErrorResponseMonitor == null) { return(null); } var(now, start, end) = GetNowTimes(_monitorService.ParseJobCron(job.CronLike)); _logger.LogInformation("检查请求错误监控开始 " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); var errorCount = await _storage.GetRequestCountAsync(new RequestCountFilterOption() { Nodes = job.Nodes.Split(','), StartTime = start, EndTime = end, StatusCodes = payload.ErrorResponseMonitor.HttpCodeStatus.Split(',').Select(x => x.ToInt()).ToArray() }).ConfigureAwait(false); var count = await _storage.GetRequestCountAsync(new RequestCountFilterOption() { Nodes = job.Nodes.Split(','), StartTime = start, EndTime = end, }).ConfigureAwait(false); if (count == 0) { return(null); } var percent = errorCount * 100.0 / count; _logger.LogInformation("检查请求错误监控结束 " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + $" 检查结果 {(percent > payload.ErrorResponseMonitor.Percentage ? "预警" : "正常")}"); if (percent > payload.ErrorResponseMonitor.Percentage) { return(new AlarmOption() { IsHtml = true, Content = $@" <br> <b>【请求错误】触发预警 </b> <p>命中率预警值:{payload.ErrorResponseMonitor.Percentage.ToString("F2")}% 当前值:{percent.ToString("F2")}% </p> <p>任务标题:{job.Title}</p> <p>监控节点:{job.Nodes}</p> <p>监控频率:{_monitorService.ParseJobCron(job.CronLike)} 分钟</p> <p>设定Http状态码:{payload.ErrorResponseMonitor.HttpCodeStatus}</p> <p>时间段:{start.ToStandardTime()}-{end.ToStandardTime()} </p>" }); } return(null); }
public MonitorJobRequest GetMonitorJobRequest(IMonitorJob job) { MonitorJobPayload payload = JsonConvert.DeserializeObject <MonitorJobPayload>(job.Payload); MonitorJobRequest request = new MonitorJobRequest() { Id = job.Id, Title = job.Title, Description = job.Description, Emails = job.Emails, Interval = ParseJobCron(job.CronLike), Status = job.Status, Mobiles = job.Mobiles, Service = job.Service, Instance = job.Instance, WebHook = job.WebHook }; if (payload.ResponseTimeOutMonitor != null) { request.ResponseTimeOutMonitor = new ResponseTimeOutMonitorViewModel { Status = payload.ResponseTimeOutMonitor.Status, TimeOutMs = payload.ResponseTimeOutMonitor.TimeOutMs.ToString(), Percentage = payload.ResponseTimeOutMonitor.Percentage + "%" }; } if (payload.ErrorResponseMonitor != null) { request.ErrorResponseMonitor = new ErrorResponseMonitorViewModel { Status = payload.ErrorResponseMonitor.Status, HttpCodeStatus = payload.ErrorResponseMonitor.HttpCodeStatus, Percentage = payload.ErrorResponseMonitor.Percentage + "%" }; } if (payload.IPMonitor != null) { request.IPMonitor = new IPMonitorViewModel { Status = payload.IPMonitor.Status, WhiteList = payload.IPMonitor.WhiteList, Percentage = payload.IPMonitor.Percentage + "%" }; } if (payload.RequestCountMonitor != null) { request.RequestCountMonitor = new RequestCountMonitorViewModel { Status = payload.RequestCountMonitor.Status, Max = payload.RequestCountMonitor.Max.ToString() }; } return(request); }
public async Task <AlarmOption> RequestCountTask(MonitorJob job, MonitorJobPayload payload) { if (payload.CallMonitor == null) { return(null); } var(now, start, end) = GetNowTimes(ParseJobCron(job.CronLike)); if (payload.CallMonitor.Min == 0 && payload.CallMonitor.Max == 0) { return(null); } if (!job.StartTime.IsEmpty() && !job.EndTime.IsEmpty()) { var startTime = new DateTime(now.Year, now.Month, now.Day, job.StartTime.Split(':')[0].ToInt(), job.StartTime.Split(':')[1].ToInt(), 0, DateTimeKind.Local); var endTime = new DateTime(now.Year, now.Month, now.Day, job.EndTime.Split(':')[0].ToInt(), job.EndTime.Split(':')[1].ToInt(), 0, DateTimeKind.Local); if (now < startTime || now > endTime) { return(null); } } var total = await _storage.GetCallCountAsync(new CallCountTaskFilter { Service = job.Service, Instance = job.Instance, StartTime = start, EndTime = end }); if (total < payload.CallMonitor.Min || total > payload.CallMonitor.Max) { return(new AlarmOption() { IsHtml = true, Alarm = new MonitorAlarm { JobId = job.Id, Body = $"【{job.Title}】 {_lang.Monitor_Type_RequestCount} --- {_lang.Warning_Threshold}:{_lang.Min} {payload.CallMonitor.Min} {_lang.Max} {payload.CallMonitor.Max} {_lang.Warning_Current}:{total} ", CreateTime = DateTime.Now }, Content = $@" <br> <b>{_lang.Monitor_Type_RequestCount} </b> <p>{_lang.Monitor_Title}:{job.Title} </p> <p>{_lang.Warning_Threshold}:{_lang.Min}:{payload.CallMonitor.Min} {_lang.Max}:{payload.CallMonitor.Max} {_lang.Warning_Current}:{total} </p> <p>{_lang.Warning_Title}:{job.Title}</p> <p>{_lang.Monitor_ServiceNode}:{job.Service}</p> <p>{_lang.Monitor_InstanceName}:{(job.Instance.IsEmpty() ? "ALL" : job.Instance)} </p> <p>{_lang.Monitor_Frequency}:{ParseJobCronString(job.CronLike)} </p> <p>{_lang.Warning_TimeRange}:{start.ToStandardTime()} {_lang.To} {end.ToStandardTime()} </p>" }); } return(null); }
private async Task <AlarmOption> CheckIPMonitor(IMonitorJob job, MonitorJobPayload payload) { if (payload.IPMonitor == null) { return(null); } _logger.LogInformation("CheckIPMonitor Start " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); var(now, start, end) = GetNowTimes(_monitorService.ParseJobCron(job.CronLike)); var(max, count) = await _storage.GetRequestCountWithWhiteListAsync(new RequestCountWithListFilterOption() { Nodes = job.Nodes.Split(','), StartTime = start, EndTime = end, InList = false, List = payload.IPMonitor.WhiteList.Split(',').ToArray(), }); if (count == 0) { return(null); } var percent = max * 100.0 / count; _logger.LogInformation("CheckIPMonitor End " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + $" Result {(percent > payload.IPMonitor.Percentage ? "预警" : "正常")}"); if (percent > payload.IPMonitor.Percentage) { return(new AlarmOption() { IsHtml = true, Content = $@" <br> <b>【{_lang.Monitor_Type_IP}】 </b> <p>{_lang.Warning_Threshold}:{payload.IPMonitor.Percentage.ToString("F2")}% {_lang.Warning_Current}:{percent.ToString("F2")}% </p> <p>{_lang.Warning_Title}:{job.Title}</p> <p>{_lang.Monitor_ServiceNode}:{job.Nodes}</p> <p>{_lang.Monitor_Frequency}:{_monitorService.ParseJobCronString(job.CronLike)} </p> <p>{_lang.Monitor_IPWhiteList}:{payload.IPMonitor.WhiteList}</p> <p>{_lang.Warning_TimeRange}:{start.ToStandardTime()}-{end.ToStandardTime()} </p>" }); } return(null); }
/// <summary> /// 检查IP异常监控 /// </summary> /// <param name="job"></param> /// <param name="payload"></param> /// <returns></returns> private async Task <AlarmOption> CheckIPMonitor(IMonitorJob job, MonitorJobPayload payload) { if (payload.IPMonitor == null) { return(null); } _logger.LogInformation("检查IP异常监控开始 " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); var(now, start, end) = GetNowTimes(_monitorService.ParseJobCron(job.CronLike)); var(max, count) = await _storage.GetRequestCountWithWhiteListAsync(new RequestCountWithListFilterOption() { Nodes = job.Nodes.Split(','), StartTime = start, EndTime = end, InList = false, List = payload.IPMonitor.WhileList.Split(',').ToArray(), }).ConfigureAwait(false); if (count == 0) { return(null); } var percent = max * 100.0 / count; _logger.LogInformation("检查IP异常监控结束 " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + $" 检查结果 {(percent > payload.IPMonitor.Percentage ? "预警" : "正常")}"); if (percent > payload.IPMonitor.Percentage) { return(new AlarmOption() { IsHtml = true, Content = $@" <br> <b>【IP异常】触发预警 </b> <p>IP重复率预警值:{payload.IPMonitor.Percentage.ToString("F2")}% 当前值:{percent.ToString("F2")}% </p> <p>任务标题:{job.Title}</p> <p>监控节点:{job.Nodes}</p> <p>监控频率:{_monitorService.ParseJobCron(job.CronLike)} 分钟</p> <p>IP白名单:{payload.IPMonitor.WhileList}</p> <p>时间段:{start.ToStandardTime()}-{end.ToStandardTime()} </p>" }); } return(null); }
public async Task Execute(IJobExecutionContext context) { IMonitorJob job = context.JobDetail.JobDataMap.Get("job") as IMonitorJob; MonitorJobPayload payload = JsonConvert.DeserializeObject <MonitorJobPayload>(job.Payload); //开始调用任务 var response = GetCheckResponse(new List <Func <IMonitorJob, MonitorJobPayload, Task <AlarmOption> > > { CheckResponseTimeOutMonitor, CheckErrorResponseMonitor, CheckIPMonitor, CheckRequestCountMonitor }, job, payload); await AlarmAsync(response.Select(x => x.Result).ToList(), job); }
public async Task Execute(IJobExecutionContext context) { _storage = _storage ?? ServiceContainer.provider.GetService(typeof(IHttpReportsStorage)) as IHttpReportsStorage; _alarmService = _alarmService ?? ServiceContainer.provider.GetService(typeof(IAlarmService)) as IAlarmService; _logger = _logger ?? ServiceContainer.provider.GetService(typeof(ILogger <MonitorBackendJob>)) as ILogger <MonitorBackendJob>; _lang = _lang ?? (ServiceContainer.provider.GetService(typeof(ILocalizeService)) as ILocalizeService).Current; MonitorJob job = context.JobDetail.JobDataMap.Get("job") as MonitorJob; MonitorJobPayload payload = JsonConvert.DeserializeObject <MonitorJobPayload>(job.Payload); var response = GetCheckResponse(new List <Func <MonitorJob, MonitorJobPayload, Task <AlarmOption> > > { ResponseTimeTask, ResponseErrorTask, RequestCountTask }, job, payload); await AlarmAsync(response.Select(x => x.Result).ToList(), job); }
private async Task <AlarmOption> CheckRequestCountMonitor(IMonitorJob job, MonitorJobPayload payload) { if (payload.RequestCountMonitor == null) { return(null); } _logger.LogInformation("CheckRequestCountMonitor Start " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); var(now, start, end) = GetNowTimes(_monitorService.ParseJobCron(job.CronLike)); var count = await _storage.GetRequestCountAsync(new RequestCountFilterOption() { Nodes = job.Nodes.Split(','), StartTime = start, EndTime = end, }); _logger.LogInformation("CheckRequestCountMonitor End " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + $" Result {(count > payload.RequestCountMonitor.Max ? "预警" : "正常")}"); if (count > payload.RequestCountMonitor.Max) { return(new AlarmOption() { IsHtml = true, Content = $@" <br> <b>【{_lang.Monitor_Type_RequestCount}】 </b> <p>{_lang.Warning_Threshold}:{payload.RequestCountMonitor.Max} {_lang.Warning_Current}:{count} </p> <p>{_lang.Warning_Title}:{job.Title}</p> <p>{_lang.Monitor_ServiceNode}:{job.Nodes}</p> <p>{_lang.Monitor_Frequency}:{_monitorService.ParseJobCronString(job.CronLike)} </p> <p>{_lang.Warning_TimeRange}:{start.ToStandardTime()}-{end.ToStandardTime()} </p>" }); } return(null); }
/// <summary> /// 请求量监控 /// </summary> /// <param name="job"></param> /// <param name="payload"></param> /// <returns></returns> private async Task <AlarmOption> CheckRequestCountMonitor(IMonitorJob job, MonitorJobPayload payload) { if (payload.RequestCountMonitor == null) { return(null); } _logger.LogInformation("检查请求量监控开始 " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); var(now, start, end) = GetNowTimes(_monitorService.ParseJobCron(job.CronLike)); var count = await _storage.GetRequestCountAsync(new RequestCountFilterOption() { Nodes = job.Nodes.Split(','), StartTime = start, EndTime = end, }).ConfigureAwait(false); _logger.LogInformation("检查请求量监控结束 " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + $" 检查结果 {(count > payload.RequestCountMonitor.Max ? "预警" : "正常")}"); if (count > payload.RequestCountMonitor.Max) { return(new AlarmOption() { IsHtml = true, Content = $@" <br> <b>【请求量监控】触发预警 </b> <p>请求量最大预警值:{payload.RequestCountMonitor.Max} 当前值:{count} </p> <p>任务标题:{job.Title}</p> <p>监控节点:{job.Nodes}</p> <p>监控频率:{_monitorService.ParseJobCron(job.CronLike)} 分钟</p> <p>时间段:{start.ToStandardTime()}-{end.ToStandardTime()} </p>" }); } return(null); }
private IEnumerable <Task <AlarmOption> > GetCheckResponse(List <Func <IMonitorJob, MonitorJobPayload, Task <AlarmOption> > > funcs, IMonitorJob job, MonitorJobPayload payload) { List <Task <AlarmOption> > alarmOptions = new List <Task <AlarmOption> >(); foreach (var func in funcs) { alarmOptions.Add(Task.Run(() => func.Invoke(job, payload))); } return(alarmOptions); }
/// <summary> /// 检查超时监控 /// </summary> /// <returns></returns> private async Task <AlarmOption> CheckResponseTimeOutMonitor(IMonitorJob job, MonitorJobPayload payload) { if (payload.ResponseTimeOutMonitor == null) { return(null); } var(now, start, end) = GetNowTimes(_monitorService.ParseJobCron(job.CronLike)); _logger.LogInformation("CheckResponseTimeOutMonitor Start " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); var timeoutCount = await _storage.GetTimeoutResponeCountAsync(new RequestCountFilterOption() { StartTime = start, EndTime = end, }, payload.ResponseTimeOutMonitor.TimeOutMs); var count = await _storage.GetRequestCountAsync(new RequestCountFilterOption() { StartTime = start, EndTime = end, }); if (count == 0) { return(null); } var percent = timeoutCount * 100.0 / count; _logger.LogInformation("CheckResponseTimeOutMonitor End " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + $" Result {(percent > payload.ResponseTimeOutMonitor.Percentage ? "预警" : "正常")}"); if (percent > payload.ResponseTimeOutMonitor.Percentage) { return(new AlarmOption() { IsHtml = true, Content = $@" <br> <b>【{Localize.Monitor_Type_Timeout}】 </b> <p> {Localize.Warning_Threshold}:{payload.ResponseTimeOutMonitor.Percentage.ToString("F2")}% {Localize.Warning_Current}:{percent.ToString("F2")}% </p> <p>{Localize.Monitor_Title}:{job.Title}</p> <p>{Localize.Monitor_ServiceNode}:{job.Service}</p> <p>{Localize.Monitor_Frequency}:{_monitorService.ParseJobCronString(job.CronLike)} </p> <p>{Localize.Warning_TimeRange}:{start.ToStandardTime()}-{end.ToStandardTime()} </p>" }); } return(null); }
/// <summary> /// 检查超时监控 /// </summary> /// <returns></returns> private async Task <AlarmOption> CheckResponseTimeOutMonitor(IMonitorJob job, MonitorJobPayload payload) { if (payload.ResponseTimeOutMonitor == null) { return(null); } var(now, start, end) = GetNowTimes(_monitorService.ParseJobCron(job.CronLike)); _logger.LogInformation("检查超时监控开始 " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); var timeoutCount = await _storage.GetTimeoutResponeCountAsync(new RequestCountFilterOption() { Nodes = job.Nodes.Split(','), StartTime = start, EndTime = end, }, payload.ResponseTimeOutMonitor.TimeOutMs).ConfigureAwait(false); var count = await _storage.GetRequestCountAsync(new RequestCountFilterOption() { Nodes = job.Nodes.Split(','), StartTime = start, EndTime = end, }).ConfigureAwait(false); if (count == 0) { return(null); } var percent = timeoutCount * 100.0 / count; _logger.LogInformation("检查超时监控结束 " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + $" 检查结果 {(percent > payload.ResponseTimeOutMonitor.Percentage ? "预警":"正常")}"); if (percent > payload.ResponseTimeOutMonitor.Percentage) { return(new AlarmOption() { IsHtml = true, Content = $@" <br> <b>【响应超时】触发预警 </b> <p>超时率预警值:{payload.ResponseTimeOutMonitor.Percentage.ToString("F2")}% 当前值:{percent.ToString("F2")}% </p> <p>任务标题:{job.Title}</p> <p>监控节点:{job.Nodes}</p> <p>监控频率:{_monitorService.ParseJobCron(job.CronLike)} 分钟</p> <p>时间段:{start.ToStandardTime()}-{end.ToStandardTime()} </p>" }); } return(null); }
/// <summary> /// 检查超时监控 /// </summary> /// <returns></returns> private async Task <AlarmOption> CheckResponseTimeOutMonitor(MonitorJob job, MonitorJobPayload payload) { if (payload.ResponseTimeOutMonitor == null) { return(null); } var(now, start, end) = GetNowTimes(_monitorService.ParseJobCron(job.CronLike)); _logger.LogInformation("CheckResponseTimeOutMonitor Start " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); #region BuildService string LocalIP = ""; int LocalPort = 0; if (job.Instance.IsEmpty() || job.Instance == "ALL") { LocalIP = ""; LocalPort = 0; } else { LocalIP = job.Instance.Substring(0, job.Instance.LastIndexOf(':')); LocalPort = job.Instance.Substring(job.Instance.LastIndexOf(':') + 1).ToInt(); } #endregion var timeoutCount = await _storage.GetTimeoutResponeCountAsync(new RequestCountFilterOption() { Service = job.Service, LocalIP = LocalIP, LocalPort = LocalPort, StartTime = start, EndTime = end, }, payload.ResponseTimeOutMonitor.TimeOutMs); var count = await _storage.GetRequestCountAsync(new RequestCountFilterOption() { Service = job.Service, LocalIP = LocalIP, LocalPort = LocalPort, StartTime = start, EndTime = end, }); if (count == 0) { return(null); } var percent = timeoutCount * 100.0 / count; _logger.LogInformation("CheckResponseTimeOutMonitor End " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + $" {(percent > payload.ResponseTimeOutMonitor.Percentage ? "Alert notification trigger" : "Pass")}"); if (percent > payload.ResponseTimeOutMonitor.Percentage) { return(new AlarmOption() { IsHtml = true, Content = $@" <br> <b>【{_lang.Monitor_Type_Timeout}】 </b> <p> {_lang.Warning_Threshold}:{payload.ResponseTimeOutMonitor.Percentage.ToString("F2")}% {_lang.Warning_Current}:{percent.ToString("F2")}% </p> <p>{_lang.Monitor_Title}:{job.Title}</p> <p>{_lang.Monitor_ServiceNode}:{job.Service}</p> <p>{_lang.Monitor_InstanceName}:{(job.Instance.IsEmpty() ? BasicConfig.ALLTag : job.Instance)}</p> <p>{_lang.Monitor_Frequency}:{_monitorService.ParseJobCronString(job.CronLike)} </p> <p>{_lang.Warning_TimeRange}:{start.ToStandardTime()}-{end.ToStandardTime()} </p>" }); } return(null); }
private async Task <AlarmOption> ResponseTimeTask(MonitorJob job, MonitorJobPayload payload) { if (payload.ResponseTimeMonitor == null) { return(null); } var(now, start, end) = GetNowTimes(ParseJobCron(job.CronLike)); if (payload.ResponseTimeMonitor.Timeout == 0) { return(null); } if (!job.StartTime.IsEmpty() && !job.EndTime.IsEmpty()) { var startTime = new DateTime(now.Year, now.Month, now.Day, job.StartTime.Split(':')[0].ToInt(), job.StartTime.Split(':')[1].ToInt(), 0, DateTimeKind.Local); var endTime = new DateTime(now.Year, now.Month, now.Day, job.EndTime.Split(':')[0].ToInt(), job.EndTime.Split(':')[1].ToInt(), 0, DateTimeKind.Local); if (now < startTime || now > endTime) { return(null); } } var(timeout, total) = await _storage.GetTimeoutResponeCountAsync(new ResponseTimeTaskFilter { Service = job.Service, Instance = job.Instance, StartTime = start, EndTime = end, TimeoutMS = payload.ResponseTimeMonitor.Timeout }); if (total == 0) { return(null); } var percent = timeout * 1.00 / total * 1.00; if (percent > payload.ResponseTimeMonitor.Percentage * 0.01) { return(new AlarmOption() { IsHtml = true, Alarm = new MonitorAlarm { JobId = job.Id, Body = $@"【{job.Title}】 {_lang.Monitor_Type_Timeout} --- {_lang.Warning_Threshold}:{payload.ResponseTimeMonitor.Timeout}ms, {(payload.ResponseTimeMonitor.Percentage).ToString("F2")}% {_lang.Warning_Current}:{ (percent * 100.00) .ToString("F2")}% ", CreateTime = DateTime.Now }, Content = $@" <br> <b>{_lang.Monitor_Type_Timeout} </b> <p>{_lang.Monitor_Title}:{job.Title} </p> <p>{_lang.Warning_Threshold}: {payload.ResponseTimeMonitor.Timeout}ms {(payload.ResponseTimeMonitor.Percentage).ToString("F2")}% {_lang.Warning_Current}:{(percent * 100.00) .ToString("F2")}% </p> <p>{_lang.Warning_Title}:{job.Title}</p> <p>{_lang.Monitor_ServiceNode}:{job.Service}</p> <p>{_lang.Monitor_InstanceName}:{(job.Instance.IsEmpty() ? "ALL" : job.Instance)} </p> <p>{_lang.Monitor_Frequency}:{ParseJobCronString(job.CronLike)} </p> <p>{_lang.Warning_TimeRange}:{start.ToStandardTime()} {_lang.To} {end.ToStandardTime()} </p>" }); } return(null); }