Пример #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);
        }
Пример #2
0
        public Task Execute(IJobExecutionContext context)
        {
            var allAgentsInfo = _agentsRepository.GetAllAgentsInfo();

            foreach (var agentInfo in allAgentsInfo)
            {
                var last    = _repository.GetLast(agentInfo.AgentId);
                var request = new GetAllHddMetricsApiRequest()
                {
                    AgentUrl = agentInfo.AgentUrl,
                    FromTime = last,
                    ToTime   = DateTimeOffset.UtcNow,
                };

                var response = _client.GetAllHddMetrics(request);

                if (response != null)
                {
                    if (response.Metrics[0].Time == last)
                    {
                        response.Metrics.RemoveAt(0);
                    }

                    foreach (var metric in response.Metrics)
                    {
                        var formatedMetric = _mapper.Map <HddMetric>(metric);
                        formatedMetric.AgentId = agentInfo.AgentId;
                        _repository.Create(formatedMetric);
                    }
                }
            }

            return(Task.CompletedTask);
        }