Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        public IActionResult GetAll()
        {
            _logger.LogInformation($"Метод GetAll");
            IList <RamMetrics> metrics = _repository.GetAll();
            var response = new AllRamMetricsApiResponse()
            {
                Metrics = new List <RamMetricsDto>()
            };

            if (metrics != null)
            {
                foreach (var metric in metrics)
                {
                    response.Metrics.Add(_mapper.Map <RamMetricsDto>(metric));
                }
            }
            return(Ok(response));
        }
Exemplo n.º 3
0
        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 AllRamMetricsApiResponse()
            {
                Metrics = new List <RamMetricsDto>()
            };

            if (metrics != null)
            {
                foreach (var metric in metrics)
                {
                    response.Metrics.Add(_mapper.Map <RamMetricsDto>(metric));
                }
            }
            return(Ok(response));
        }
Exemplo n.º 4
0
        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);
        }