public async Task <QueueMetricViewModel> GetMetrics(int interval, DateTime?startTime, DateTime?endTime, string metricName = null)
        {
            if (startTime is null || endTime is null || interval <= 0)
            {
                throw new HttpResponseException(HttpStatusCode.BadRequest);
            }

            if (!(metricName is null) && !Default.ServiceBusMetricsList.Contains(metricName))
            {
                throw new HttpResponseException(HttpStatusCode.BadRequest);
            }

            if (startTime.Value == endTime.Value)
            {
                endTime = endTime.Value.AddHours(24);
            }

            var models = await _queuesMetricRepository.GetMetricsAsync(interval, startTime.Value, endTime.Value, metricName);

            var viewModel = new QueueMetricViewModel
            {
                QueueMetrics = models.ToList()
            };

            return(viewModel);
        }
Exemplo n.º 2
0
        private QueueMetricViewModel CreateMetricModel(List <IncomingMetrics> incomingMetrics)
        {
            List <QueueMetricModel> metricModels = new List <QueueMetricModel>();
            QueueMetricViewModel    model        = new QueueMetricViewModel();

            foreach (var incomingMetric in incomingMetrics)
            {
                foreach (var value in incomingMetric.Value)
                {
                    foreach (var time in value.Timeseries)
                    {
                        foreach (var metadata in time.Metadatavalues)
                        {
                            QueueMetricModel   metricModel = new QueueMetricModel();
                            List <QueueMetric> metrics     = new List <QueueMetric>();
                            foreach (var data in time.Data)
                            {
                                QueueMetric metric = new QueueMetric(data.TimeStamp, data.Total);
                                metrics.Add(metric);
                            }
                            metricModel.MetricName   = value.Name.Value;
                            metricModel.QueueMetrics = metrics;
                            metricModel.QueueName    = metadata.Value;
                            metricModels.Add(metricModel);
                        }
                    }
                }
            }
            model.QueueMetrics = metricModels;
            return(model);
        }
        public async Task <QueueMetricViewModel> GetMetricsForHours(int hour, int interval)
        {
            if (hour <= 0 || interval <= 0)
            {
                throw new HttpResponseException(HttpStatusCode.BadRequest);
            }

            var currentTime = DateTime.UtcNow;
            var models      = await _queuesMetricRepository.GetMetricsAsync(interval, currentTime.AddHours(-hour), currentTime);

            var viewModel = new QueueMetricViewModel
            {
                QueueMetrics = models.ToList()
            };

            return(viewModel);
        }