public Task Execute(IJobExecutionContext context) { DateTimeOffset toTime = DateTimeOffset.UtcNow; DateTimeOffset fromTime = _repositoryNetwork.LastTime(); IList <AgentModel> agents = _repositoryAgent.GetAll(); foreach (var agent in agents) { if (agent.Status == true) { AllNetworkMetricsApiResponse allNetworkMetrics = _client.GetAllNetworkMetrics(new GetAllNetworkMetricsApiRequest { FromTime = fromTime, ToTime = toTime, Addres = agent.Ipaddress }); if (allNetworkMetrics != null) { foreach (var metric in allNetworkMetrics.Metrics) { _repositoryNetwork.Create(new NetworkMetricModel { IdAgent = agent.Id, Time = metric.Time, Value = metric.Value }); } } } } return(Task.CompletedTask); }
public IActionResult GetMetricsFromAgent([FromRoute] DateTimeOffset fromTime, [FromRoute] DateTimeOffset toTime) { _logger.LogInformation($"Метод GetMetricsFromAgent fromTime {fromTime.DateTime} toTime {toTime.DateTime}"); var metrics = _repository.GetByTimeInterval(fromTime, toTime); var response = new AllNetworkMetricsApiResponse() { Metrics = new List <NetworkMetricsDto>() }; if (metrics != null) { foreach (var metric in metrics) { response.Metrics.Add(_mapper.Map <NetworkMetricsDto>(metric)); } } return(Ok(response)); }
public IActionResult GetAll() { _logger.LogInformation($"Метод GetAll"); IList <NetworkMetrics> metrics = _repository.GetAll(); var response = new AllNetworkMetricsApiResponse() { Metrics = new List <NetworkMetricsDto>() }; if (metrics != null) { foreach (var metric in metrics) { response.Metrics.Add(_mapper.Map <NetworkMetricsDto>(metric)); } } return(Ok(response)); }
public Task Execute(IJobExecutionContext context) { var adress = new AdressAgentFormTable(); List <AgentInfo> uriAdress = adress.GetAllAdress(); foreach (var adressAgent in uriAdress) { var fromTimeTable = new LastDate(); var fromTimeFromTable = fromTimeTable.GetTimeFromTable("networkmetrics", adressAgent.AgentId); AllNetworkMetricsApiResponse networkMetrics = null; if (fromTimeFromTable == null) { DateTimeOffset fromTime = DateTimeOffset.UnixEpoch; DateTimeOffset toTime = DateTimeOffset.UtcNow; networkMetrics = _metricsAgent.GetAllNetworkMetrics(new Requests.GetAllNetworkMetricsApiRequest { ClientBaseAddress = new Uri(adressAgent.AgentAddress), ToTime = toTime, FromTime = fromTime }); } else { DateTimeOffset toTime = DateTimeOffset.UtcNow; networkMetrics = _metricsAgent.GetAllNetworkMetrics(new Requests.GetAllNetworkMetricsApiRequest { ClientBaseAddress = new Uri(adressAgent.AgentAddress), ToTime = toTime, FromTime = fromTimeFromTable }); } if (networkMetrics != null) { foreach (var item in networkMetrics.Metrics) { _repository.Create(new NetworkMetrics { AgentId = adressAgent.AgentId, Time = item.Time, Value = item.Value }); } } } return(Task.CompletedTask); }