Пример #1
0
        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 CpuMetric()
                {
                    AgentId = agent.Id,
                    Time = metric.Time,
                    Value = metric.Value
                }));
            }));

            // сохраняем метрики
            foreach (var metrics in listMetrics)
            {
                foreach (var metric in metrics)
                {
                    _metricsRepository.Create(metric);
                }
            }
        }
Пример #2
0
        public Task Execute(IJobExecutionContext context)
        {
            var value = Convert.ToInt32(_counter.NextValue());

            var time = DateTimeOffset.UtcNow;

            _repository.Create(new CpuMetric {
                Time = time, Value = value
            });

            return(Task.CompletedTask);
        }