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 DotNetMetric() { AgentId = agent.Id, Time = metric.Time, Value = metric.Value })); })); // сохраняем метрики foreach (var metrics in listMetrics) { foreach (var metric in metrics) { _metricsRepository.Create(metric); } } }
public Task Execute(IJobExecutionContext context) { var allAgentsInfo = _agentsRepository.GetAllAgentsInfo(); foreach (var agentInfo in allAgentsInfo) { var last = _repository.GetLast(agentInfo.AgentId); var request = new GetAllDotNetMetricsApiRequest() { AgentUrl = agentInfo.AgentUrl, FromTime = last, ToTime = DateTimeOffset.UtcNow, }; var response = _client.GetDonNetMetrics(request); if (response != null) { if (response.Metrics[0].Time == last) { response.Metrics.RemoveAt(0); } foreach (var metric in response.Metrics) { var formatedMetric = _mapper.Map <DotNetMetric>(metric); formatedMetric.AgentId = agentInfo.AgentId; _repository.Create(formatedMetric); } } } return(Task.CompletedTask); }
public Task Execute(IJobExecutionContext context) { DateTimeOffset toTime = DateTimeOffset.UtcNow; DateTimeOffset fromTime = _repositoryDotNet.LastTime(); IList <AgentModel> agents = _repositoryAgent.GetAll(); foreach (var agent in agents) { if (agent.Status == true) { AllDotNetMetricsApiResponse allDotNetMetrics = _client.GetAllDotNetMetrics(new GetAllDotNetMetricsApiRequest { FromTime = fromTime, ToTime = toTime, Addres = agent.Ipaddress }); if (allDotNetMetrics != null) { foreach (var metric in allDotNetMetrics.Metrics) { _repositoryDotNet.Create(new DotNetMetricModel { IdAgent = agent.Id, Time = metric.Time, Value = metric.Value }); } } } } 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.GetAllDotNetMetrics(new GetAllDotNetMetricsApiRequest { ClientBaseAddress = _uriAdress.GetUri(agentId), FromTime = fromTime, ToTime = toTime }); if (metrics != null) { foreach (var item in metrics.Metrics) { _repository.Create(new DotNetMetrics { AgentId = agentId, Time = item.Time, Value = item.Value }); } ; } return(Ok(metrics)); }
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.GetDotNetMetrics(new GetAllDotNetMetricsApiRequest { FromTime = fromTime, ToTime = toTime, ClientBaseAddress = agent.AgentUrl }); if (metrics != null) { foreach (var metric in metrics) { _repository.Create(new DotNetMetric { 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 = _repositoryDotNet.GetDateTimeOfLastRecord(agent.AgentId); var toTime = DateTimeOffset.UtcNow; var metrics = _metricsAgentClient.GetDotNetMetrics(new GetAllDotNetMetricsApiRequest() { FromTime = fromTime, ToTime = toTime, ClientBaseAddress = agentAddress }); if (metrics != null) { foreach (var metricFromAgent in metrics.Metrics) { _repositoryDotNet.Create(agent.AgentId, metricFromAgent); } } } return(Task.CompletedTask); }
private async Task SyncronizeMetricsFromAgent(AgentInfo agentInfo) { try { var lastTime = _metricsRepository.GetMetricsLastDateFormAgent(agentInfo.AgentId).AddSeconds(1); var response = await _agentClient.GetMetrics(new DotNetMetricClientRequest { BaseUrl = agentInfo.AgentUrl, FromTime = lastTime, ToTime = DateTimeOffset.Now }); if (response == null) { return; } foreach (var clientMetric in response.Metrics) { var DotNetMetric = _mapper.Map <DotNetMetric>(clientMetric); DotNetMetric.AgentId = agentInfo.AgentId; _metricsRepository.Create(DotNetMetric); } _logger.LogDebug($"Sincronized {response.Metrics.Count} DotNet Metrics from Agent ({agentInfo})"); } catch (Exception ex) { _logger.LogError(ex.Message); } }
public IActionResult Create([FromBody] DotNetMetricCreateRequest request) { _repository.Create(new DotNetMetric { Time = request.Time, Value = request.Value }); return(Ok()); }
public Task Execute(IJobExecutionContext context) { var DotNetUsageInPercents = Convert.ToInt32(_dotNetCounter.NextValue()); var time = DateTimeOffset.UtcNow; _repository.Create(new DotNetMetric { Time = time, Value = DotNetUsageInPercents }); return(Task.CompletedTask); }
public IActionResult Create([FromBody] DotNetMetricCreateRequest request) { repository.Create(new DotNetMetric { FromTime = request.FromTime, ToTime = request.ToTime, Count = request.Count }); return(Ok()); }
public IActionResult Create([FromBody] DotNetMetricsCreateRequest request) { _logger.LogInformation($"Метод Create {request}"); _repository.Create(new DotNetMetrics { Time = request.Time, Value = request.Value }); return(Ok()); }
public Task Execute(IJobExecutionContext context) { int value = Convert.ToInt32(_counter.NextValue()); var time = DateTimeOffset.UtcNow.ToUnixTimeSeconds(); _repository.Create(new DotNetMetric { Time = time, Value = value }); return(Task.CompletedTask); }
public Task Execute(IJobExecutionContext context) { var dotNetErrors = Convert.ToInt32(_dotnetCounter.NextValue()); var time = DateTimeOffset.UtcNow.ToUnixTimeSeconds(); _repository.Create(new DAL.Models.DotNetMetric { Time = time, Value = dotNetErrors }); return(Task.CompletedTask); }
public IActionResult Create([FromBody] DotNetMetricCreateRequest request) { _repository.Create(new DotNetMetric { Time = request.Time, Value = request.Value }); _logger.LogInformation(string.Concat("Create_DotNet: ", " Time: ", request.Time.ToString(), " Value: ", request.Value.ToString())); return(Ok()); }
public IActionResult Create([FromBody] DotNetMetricCreateRequest request) { _logger.LogInformation($"Создается запись с данными Time:{request.Time}; Value:{request.Value}"); _repository.Create(new DotNetMetric { Time = request.Time, Value = request.Value }); return(Ok()); }
public IActionResult Create([FromBody] DotNetMetricCreateRequest request) { _repository.Create(new DotNetMetric { Time = request.Time, Value = request.Value }); _logger.LogInformation($"Create - Value: {request.Value}, Time: {request.Time} - Entry added successfully"); return(Ok()); }
public Task Execute(IJobExecutionContext context) { int bytesInHeaps = Convert.ToInt32(_dotnetCounter.NextValue()); var time = DateTimeOffset.UtcNow; _repository.Create(new DotNetMetricModel() { Time = time, Value = bytesInHeaps }); return(Task.CompletedTask); }
public Task Execute(IJobExecutionContext context) { _logger.LogDebug("== DotNetMetricJob START - " + $"Time {DateTimeOffset.UtcNow}"); //Получаем из репозитория агентов список всех агентов var allAgentsInfo = _agentsRepository.GetAllAgentsInfo(); //Обрабатываем каждого агента в списке foreach (var agentInfo in allAgentsInfo.Agents) { //Временная метка, когда для текущего агента была снята последняя метрика var lastTime = _repository.GetLast(agentInfo.AgentId); // Создаем запрос для получения от текущего агента метрик за период времени // от последней проверки до текущего момента var request = new DotNetMetricGetByIntervalRequestByClient() { AgentUri = agentInfo.AgentUri, FromTime = lastTime, ToTime = DateTimeOffset.UtcNow, }; // Делаем запрос к Агенту метрик и получаем список метрик var response = _client.GetMetrics <DotNetMetricFromAgentDto>(request, ApiNames.DotNet); if (response != null) { // Убираем из выборки первую метрику если она совпадает с последней сохраненной в базе // для исключения дублирования данных в базе if (response.Metrics[0].Time == lastTime) { response.Metrics.RemoveAt(0); } // Перекладываем данные из Response в модели метрик var recievedMetrics = new AllMetrics <DotNetMetric>(); foreach (var metricDto in response.Metrics) { recievedMetrics.Metrics.Add(new DotNetMetric { AgentId = agentInfo.AgentId, Time = metricDto.Time, Value = metricDto.Value }); } _repository.Create(recievedMetrics); } } _logger.LogDebug("!= DotNetMetricJob END - " + $"Time {DateTimeOffset.UtcNow}"); return(Task.CompletedTask); }
public Task Execute(IJobExecutionContext context) { var heapSize = Convert.ToInt32(_dotNetCounter.NextValue()) / 1024 / 1024; _repository.Create(new DotNetMetric { Time = DateTimeOffset.Now, Value = heapSize }); _logger.LogDebug("CLR Memory gen 1 heap size {0} Мб by {1}", heapSize, DateTimeOffset.Now); return(Task.CompletedTask); }
public Task Execute(IJobExecutionContext context) { // Складываем характеристики всех экземпляров счетчиков int value = Convert.ToInt32(_counter.NextValue()); // Время когда была собрана метрика var time = DateTimeOffset.UtcNow; // Запись метрики в репозиторий _repository.Create(new DotNetMetric { Time = time, Value = value }); return(Task.CompletedTask); }
public IActionResult Create([FromBody] DotNetMetricCreateRequest metric) { try { _logger.Debug($"Route(api/metrics/dotnet): Running the Create method"); _repository.Create(_mapper.Map <DotNetMetric>(metric)); _logger.Debug($"Route(api/metrics/dotnet): Create method completed successfully"); return(Ok()); } catch (Exception e) { _logger.Error(e); return(BadRequest(e.Message)); } }
public Task Execute(IJobExecutionContext context) { var dotNet = Convert.ToInt32(_DotNetCounter.NextValue()); // узнаем когда мы сняли значение метрики. var time = DateTimeOffset.UtcNow; // теперь можно записать что-то при помощи репозитория _repository.Create(new DotNetMetric { Time = time, Value = dotNet }); return(Task.CompletedTask); }
public Task Execute(IJobExecutionContext context) { try { var dotnetCLRMemory = Convert.ToInt32(_dotnetCounter.NextValue()); var time = DateTimeOffset.Now.ToUnixTimeSeconds(); _repository.Create(new DotNetMetric() { Time = time, Value = dotnetCLRMemory }); } 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("dotnetmetrics", adressAgent.AgentId); AllDotNetMetricsApiResponse dotNetMetrics = null; if (fromTimeFromTable == null) { DateTimeOffset fromTime = DateTimeOffset.UnixEpoch; DateTimeOffset toTime = DateTimeOffset.UtcNow; dotNetMetrics = _metricsAgent.GetAllDotNetMetrics(new Requests.GetAllDotNetMetricsApiRequest { ClientBaseAddress = new Uri(adressAgent.AgentAddress), ToTime = toTime, FromTime = fromTime }); } else { DateTimeOffset toTime = DateTimeOffset.UtcNow; dotNetMetrics = _metricsAgent.GetAllDotNetMetrics(new Requests.GetAllDotNetMetricsApiRequest { ClientBaseAddress = new Uri(adressAgent.AgentAddress), ToTime = toTime, FromTime = fromTimeFromTable }); } if (dotNetMetrics != null) { foreach (var item in dotNetMetrics.Metrics) { _repository.Create(new DotNetMetrics { 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.GetDotNetMetrics(new GetAllDotNetMetricsApiRequest() { AgentAddress = agents[i].AgentAddress, FromTime = fromTime, ToTime = DateTimeOffset.Now }); if (metrics != null) { _logger.LogInformation(@"!!! DotNet metrics: {0}", metrics.Metrics.Count()); foreach (var metric in metrics.Metrics) { _repository.Create(new DotNetMetric() { 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.GetAllDonNetMetrics(new GetAllDotNetMetricsApiRequest { 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] DotNetMetricCreateRequest request) { _repository.Create(_mapper.Map <DotNetMetric>(request)); return(Ok()); }
public IActionResult Create([FromBody] DotNetMetricCreateRequest request) { _repository.Create(_mapper.Map <DotNetMetric>(request)); _logger.LogInformation($"Add item. Parameters: Time = {request.Time}, Value = {request.Value}"); return(Ok()); }