Exemplo n.º 1
0
        public Task Execute(IJobExecutionContext context)
        {
            DateTimeOffset     toTime   = DateTimeOffset.UtcNow;
            DateTimeOffset     fromTime = _repositoryHdd.LastTime();
            IList <AgentModel> agents   = _repositoryAgent.GetAll();


            foreach (var agent in agents)
            {
                if (agent.Status == true)
                {
                    AllHddMetricsApiResponse allHddMetrics = _client.GetAllHddMetrics(new GetAllHddMetricsApiRequest
                    {
                        FromTime = fromTime,
                        ToTime   = toTime,
                        Addres   = agent.Ipaddress
                    });

                    if (allHddMetrics != null)
                    {
                        foreach (var metric in allHddMetrics.Metrics)
                        {
                            _repositoryHdd.Create(new HddMetricModel
                            {
                                IdAgent = agent.Id,
                                Time    = metric.Time,
                                Value   = metric.Value
                            });
                        }
                    }
                }
            }

            return(Task.CompletedTask);
        }
Exemplo n.º 2
0
        public IActionResult GetAll()
        {
            _logger.LogInformation($"Метод GetAll");
            IList <HddMetrics> metrics = _repository.GetAll();
            var response = new AllHddMetricsApiResponse()
            {
                Metrics = new List <HddMetricsDto>()
            };

            if (metrics != null)
            {
                foreach (var metric in metrics)
                {
                    response.Metrics.Add(_mapper.Map <HddMetricsDto>(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 AllHddMetricsApiResponse()
            {
                Metrics = new List <HddMetricsDto>()
            };

            if (metrics != null)
            {
                foreach (var metric in metrics)
                {
                    response.Metrics.Add(_mapper.Map <HddMetricsDto>(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("hddmetrics", adressAgent.AgentId);
                AllHddMetricsApiResponse hddMetrics = null;

                if (fromTimeFromTable == null)
                {
                    DateTimeOffset fromTime = DateTimeOffset.UnixEpoch;
                    DateTimeOffset toTime   = DateTimeOffset.UtcNow;
                    hddMetrics = _metricsAgent.GetAllHddMetrics(new Requests.GetAllHddMetricsApiRequest {
                        ClientBaseAddress = new Uri(adressAgent.AgentAddress), ToTime = toTime, FromTime = fromTime
                    });
                }
                else
                {
                    DateTimeOffset toTime = DateTimeOffset.UtcNow;
                    hddMetrics = _metricsAgent.GetAllHddMetrics(new Requests.GetAllHddMetricsApiRequest {
                        ClientBaseAddress = new Uri(adressAgent.AgentAddress), ToTime = toTime, FromTime = fromTimeFromTable
                    });
                }
                if (hddMetrics != null)
                {
                    foreach (var item in hddMetrics.Metrics)
                    {
                        _repository.Create(new HddMetrics
                        {
                            AgentId = adressAgent.AgentId,
                            Time    = item.Time,
                            Value   = item.Value
                        });
                    }
                }
            }
            return(Task.CompletedTask);
        }