public async Task Execute(IJobExecutionContext context) { var agents = _agentsRepository.GetActiveAgents(); // асинхронно собираем метрики var listMetrics = await Task.WhenAll(agents.Select(async agent => { var toTime = DateTimeOffset.UtcNow; var fromTime = _metricsRepository.GetDateUpdate(agent.Id); var response = await GetMetricsByPeriod(agent, fromTime, toTime); return(response.Select(metric => new RamMetric() { AgentId = agent.Id, Time = metric.Time, Value = metric.Value })); })); // сохраняем метрики foreach (var metrics in listMetrics) { foreach (var metric in metrics) { _metricsRepository.Create(metric); } } }
private async Task SyncronizeMetricsFromAgent(AgentInfo agentInfo) { try { var lastTime = _metricsRepository.GetMetricsLastDateFormAgent(agentInfo.AgentId).AddSeconds(1); var response = await _agentClient.GetMetrics(new RamMetricClientRequest { BaseUrl = agentInfo.AgentUrl, FromTime = lastTime, ToTime = DateTimeOffset.Now }); if (response == null) { return; } foreach (var clientMetric in response.Metrics) { var RamMetric = _mapper.Map <RamMetric>(clientMetric); RamMetric.AgentId = agentInfo.AgentId; _metricsRepository.Create(RamMetric); } _logger.LogDebug($"Sincronized {response.Metrics.Count} Ram Metrics from Agent ({agentInfo})"); } catch (Exception ex) { _logger.LogError(ex.Message); } }
public Task Execute(IJobExecutionContext context) { var allAgentsInfo = _agentsRepository.GetAllAgentsInfo(); foreach (var agentInfo in allAgentsInfo) { var last = _repository.GetLast(agentInfo.AgentId); var request = new GetAllRamMetricsApiRequest() { AgentUrl = agentInfo.AgentUrl, FromTime = last, ToTime = DateTimeOffset.UtcNow, }; var response = _client.GetAllRamMetrics(request); if (response != null) { if (response.Metrics[0].Time == last) { response.Metrics.RemoveAt(0); } foreach (var metric in response.Metrics) { var formatedMetric = _mapper.Map <RamMetric>(metric); formatedMetric.AgentId = agentInfo.AgentId; _repository.Create(formatedMetric); } } } return(Task.CompletedTask); }
public Task Execute(IJobExecutionContext context) { IList <Agents> _agents = _agentsRepository.GetAgents(); foreach (var agent in _agents) { var fromTime = _repository.GetLastDate(agent.AgentId); var toTime = DateTimeOffset.Now; var metrics = _metricsAgentClient.GetRamMetrics(new GetAllRamMetricsApiRequest { FromTime = fromTime, ToTime = toTime, ClientBaseAddress = agent.AgentUrl }); if (metrics != null) { foreach (var metric in metrics) { _repository.Create(new RamMetric { Time = metric.time.ToUnixTimeSeconds(), Value = metric.value, AgentId = agent.AgentId }); } } } return(Task.CompletedTask); }
public Task Execute(IJobExecutionContext context) { var agentList = _repositoryAgent.GetAllAgents(); foreach (var agent in agentList) { string agentAddress = _repositoryAgent.GetAddressForId(agent.AgentId); var fromTime = _repositoryRam.GetDateTimeOfLastRecord(agent.AgentId); var toTime = DateTimeOffset.UtcNow; var metrics = _metricsAgentClient.GetRamMetrics(new GetAllRamMetricsApiRequest() { FromTime = fromTime, ToTime = toTime, ClientBaseAddress = agentAddress }); if (metrics != null) { foreach (var metricFromAgent in metrics.Metrics) { _repositoryRam.Create(agent.AgentId, metricFromAgent); } } } return(Task.CompletedTask); }
public IActionResult GetMetricsAgentFromAgent([FromRoute] int agentId, [FromRoute] DateTimeOffset fromTime, [FromRoute] DateTimeOffset toTime) { _logger.LogInformation($"starting new request to metrics agent"); var metrics = _metricsAgentClient.GetAllRamMetrics(new GetAllRamMetricsApiRequest { ClientBaseAddress = _uriAdress.GetUri(agentId), FromTime = fromTime, ToTime = toTime }); if (metrics != null) { foreach (var item in metrics.Metrics) { _repository.Create(new RamMetrics { AgentId = agentId, Time = item.Time, Value = item.Value }); } ; } return(Ok(metrics)); }
public Task Execute(IJobExecutionContext context) { DateTimeOffset toTime = DateTimeOffset.UtcNow; DateTimeOffset fromTime = _repositoryRam.LastTime(); IList <AgentModel> agents = _repositoryAgent.GetAll(); foreach (var agent in agents) { if (agent.Status == true) { AllRamMetricsApiResponse allRamMetrics = _client.GetAllRamMetrics(new GetAllRamMetricsApiRequest { FromTime = fromTime, ToTime = toTime, Addres = agent.Ipaddress }); if (allRamMetrics != null) { foreach (var metric in allRamMetrics.Metrics) { _repositoryRam.Create(new RamMetricModel { IdAgent = agent.Id, Time = metric.Time, Value = metric.Value }); } } } } return(Task.CompletedTask); }
public IActionResult Create([FromBody] RamMetricCreateRequest request) { _repository.Create(new RamMetric { Time = request.Time, Value = request.Value }); return(Ok()); }
public IActionResult Create([FromBody] RamMetricCreateRequest request) { repository.Create(new RamMetric { Available = request.Available }); return(Ok()); }
public Task Execute(IJobExecutionContext context) { var ramUsageInPercents = Convert.ToInt32(_ramCounter.NextValue()); DateTimeOffset time = DateTimeOffset.UtcNow; _repository.Create(new Models.RamMetrics { Time = time, Value = ramUsageInPercents }); return(Task.CompletedTask); }
public Task Execute(IJobExecutionContext context) { int value = Convert.ToInt32(_counter.NextValue()); var time = DateTimeOffset.UtcNow.ToUnixTimeSeconds(); _repository.Create(new RamMetric { Time = time, Value = value }); return(Task.CompletedTask); }
public IActionResult Create([FromBody] RamMetricsCreateRequest request) { _logger.LogInformation($"Метод Create {request}"); _repository.Create(new RamMetrics { Time = request.Time, Value = request.Value }); return(Ok()); }
public Task Execute(IJobExecutionContext context) { var ramAvailable = Convert.ToInt32(_ramCounter.NextValue()); var time = DateTimeOffset.UtcNow.ToUnixTimeSeconds(); _repository.Create(new DAL.Models.RamMetric { Time = time, Value = ramAvailable }); return(Task.CompletedTask); }
public IActionResult Create([FromBody] RamMetricCreateRequest request) { _logger.LogInformation($"Создается запись с данными Time:{request.Time}; Value:{request.Value}"); _repository.Create(new RamMetric { Time = request.Time, Value = request.Value }); return(Ok()); }
public IActionResult Create([FromBody] RamMetricCreateRequest request) { _repository.Create(new RamMetric { Time = request.Time, Value = request.Value }); _logger.LogInformation($"Create - Value: {request.Value}, Time: {request.Time} - Entry added successfully"); return(Ok()); }
public IActionResult Create([FromBody] RamMetricCreateRequest request) { _repository.Create(new RamMetric { Time = request.Time, Value = request.Value }); _logger.LogInformation(string.Concat("Create_Ram: ", " Time: ", request.Time.ToString(), " Value: ", request.Value.ToString())); return(Ok()); }
public Task Execute(IJobExecutionContext context) { var ramAvialableMBytes = Convert.ToInt32(_ramCounter.NextValue()); //var time = TimeSpan.FromSeconds(DateTimeOffset.UtcNow.ToUnixTimeSeconds()); var time = DateTimeOffset.UtcNow; _repository.Create(new RamMetrics { Time = time, Value = ramAvialableMBytes }); return(Task.CompletedTask); }
public Task Execute(IJobExecutionContext context) { var ramAvailable = Convert.ToInt32(_ramCounter.NextValue()); var time = DateTimeOffset.UtcNow; _repository.Create(new RamMetricModel() { Time = time, Available = ramAvailable }); return(Task.CompletedTask); }
public Task Execute(IJobExecutionContext context) { _logger.LogDebug("== RamMetricJob START - " + $"Time {DateTimeOffset.UtcNow}"); //Получаем из репозитория агентов список всех агентов var allAgentsInfo = _agentsRepository.GetAllAgentsInfo(); //Обрабатываем каждого агента в списке foreach (var agentInfo in allAgentsInfo.Agents) { //Временная метка, когда для текущего агента была снята последняя метрика var lastTime = _repository.GetLast(agentInfo.AgentId); // Создаем запрос для получения от текущего агента метрик за период времени // от последней проверки до текущего момента var request = new RamMetricGetByIntervalRequestByClient() { AgentUri = agentInfo.AgentUri, FromTime = lastTime, ToTime = DateTimeOffset.UtcNow, }; // Делаем запрос к Агенту метрик и получаем список метрик var response = _client.GetMetrics <RamMetricFromAgentDto>(request, ApiNames.Ram); if (response != null) { // Убираем из выборки первую метрику если она совпадает с последней сохраненной в базе // для исключения дублирования данных в базе if (response.Metrics[0].Time == lastTime) { response.Metrics.RemoveAt(0); } // Перекладываем данные из Response в модели метрик var recievedMetrics = new AllMetrics <RamMetric>(); foreach (var metricDto in response.Metrics) { recievedMetrics.Metrics.Add(new RamMetric { AgentId = agentInfo.AgentId, Time = metricDto.Time, Value = metricDto.Value }); } _repository.Create(recievedMetrics); } } _logger.LogDebug("!= RamMetricJob END - " + $"Time {DateTimeOffset.UtcNow}"); return(Task.CompletedTask); }
public Task Execute(IJobExecutionContext context) { var availableInMb = Convert.ToInt32(_ramCounter.NextValue()); // узнаем когда мы сняли значение метрики. var time = DateTimeOffset.UtcNow; // теперь можно записать что-то при помощи репозитория _repository.Create(new Models.RamMetric { Time = time, Value = availableInMb }); return(Task.CompletedTask); }
public Task Execute(IJobExecutionContext context) { var ramAvailable = Convert.ToInt32(_ramCounter.NextValue()); _repository.Create(new RamMetric { Time = DateTimeOffset.Now, Value = ramAvailable }); _logger.LogDebug("Available {0} mbytes by {1}", ramAvailable, DateTimeOffset.Now); return(Task.CompletedTask); }
public IActionResult Create([FromBody] RamMetricCreateRequest metric) { try { _logger.Debug($"Route(api/metrics/ram): Running the Create method"); _repository.Create(_mapper.Map <RamMetric>(metric)); _logger.Debug($"Route(api/metrics/ram): Create method completed successfully"); return(Ok()); } catch (Exception e) { _logger.Error(e); return(BadRequest(e.Message)); } }
public Task Execute(IJobExecutionContext context) { // Складываем характеристики всех экземпляров счетчиков int value = Convert.ToInt32(_counter.NextValue()); // Время когда была собрана метрика var time = DateTimeOffset.UtcNow; // Запись метрики в репозиторий _repository.Create(new RamMetric { Time = time, Value = value }); return(Task.CompletedTask); }
public Task Execute(IJobExecutionContext context) { try { var ramAvailable = Convert.ToInt32(_ramCounter.NextValue()); var time = DateTimeOffset.Now.ToUnixTimeSeconds(); _repository.Create(new RamMetric() { Time = time, Value = ramAvailable }); } catch (Exception ex) { _logger.LogError(ex.Message); } return(Task.CompletedTask); }
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("rammetrics", adressAgent.AgentId); AllRamMetricsApiResponse ramMetrics = null; if (fromTimeFromTable == null) { DateTimeOffset fromTime = DateTimeOffset.UnixEpoch; DateTimeOffset toTime = DateTimeOffset.UtcNow; ramMetrics = _metricsAgent.GetAllRamMetrics(new Requests.GetAllRamMetricsApiRequest { ClientBaseAddress = new Uri(adressAgent.AgentAddress), ToTime = toTime, FromTime = fromTime }); } else { DateTimeOffset toTime = DateTimeOffset.UtcNow; ramMetrics = _metricsAgent.GetAllRamMetrics(new Requests.GetAllRamMetricsApiRequest { ClientBaseAddress = new Uri(adressAgent.AgentAddress), ToTime = toTime, FromTime = fromTimeFromTable }); } if (ramMetrics != null) { foreach (var item in ramMetrics.Metrics) { _repository.Create(new RamMetrics { AgentId = adressAgent.AgentId, Time = item.Time, Value = item.Value }); } } } return(Task.CompletedTask); }
public Task Execute(IJobExecutionContext context) { try { var agents = _agentsRepository.GetAgentsList(); for (int i = 0; i < agents.Count(); i++) { if (agents[i].Enabled) { long lastTime = _repository.GetLastTime(i); DateTimeOffset fromTime = DateTimeOffset.FromUnixTimeSeconds(lastTime); var metrics = _client.GetRamMetrics(new GetAllRamMetricsApiRequest() { AgentAddress = agents[i].AgentAddress, FromTime = fromTime, ToTime = DateTimeOffset.Now }); if (metrics != null) { foreach (var metric in metrics.Metrics) { _repository.Create(new RamMetric() { AgentId = metric.AgentId, Time = metric.Time.ToUnixTimeSeconds(), Value = metric.Value }); } } } } } catch (Exception ex) { _logger.LogError(ex.Message); } return(Task.CompletedTask); }
public Task Execute(IJobExecutionContext context) { var agentsList = _repositoryAgents.GetAll(); foreach (var agent in agentsList) { var metricsList = _metricsAgentClient.GetAllRamMetrics(new GetAllRamMetricsApiRequest { FromTime = _repository.GetMaxDate(agent.AgentId), ToTime = DateTimeOffset.UtcNow, ClientBaseAddress = agent.AgentURL }); if (!object.ReferenceEquals(metricsList, null)) { foreach (var metric in metricsList.Metrics) { _repository.Create(metric, agent.AgentId); } } } return(Task.CompletedTask); }
public IActionResult Create([FromBody] RamMetricCreateRequest request) { _repository.Create(_mapper.Map <RamMetric>(request)); _logger.LogInformation($"Add item. Parameters: Time = {request.Time}, Value = {request.Value}"); return(Ok()); }
public IActionResult Create([FromBody] RamMetricCreateRequest request) { _repository.Create(_mapper.Map <RamMetric>(request)); return(Ok()); }