コード例 #1
0
        //the limit seems to be 2880 metrics per request
		async System.Threading.Tasks.Task<ICollection<MetricValueSet>> GetMetricsForResourceId(string resourceId, TimeSpan forHistory, MetricsFilter filter) {
            var metricsResult = await MetricsClientFacade.ListDefinitionsAsync(_credentials, resourceId,null,null);

			var metrics = filter.FilterMetrics(metricsResult.MetricDefinitionCollection.Value.Where(_=>_.MetricAvailabilities.Any()).ToList());
            
			if(!metrics.Any()) {
				return new MetricValueSet[0];
			}

            var minTimeGrain = metrics.SelectMany(_=>_.MetricAvailabilities.Where(ma=>forHistory<ma.Retention).Select(a=>a.TimeGrain)).Min();

			var metricNames = metrics.Select(_=>_.Name).ToList();

            var till = DateTime.UtcNow.AddMinutes(1);
            var from = till.Add(forHistory.Negate());


			return await Fetch(new FetchData {
                ResourceId = resourceId,
                MetricNames = metricNames,
                TimeGrain = minTimeGrain,
                From = from,
                Till = till
            });
		}
コード例 #2
0
        internal async Task<ICollection<UsageObject>> GetUsage(ICollection<CloudServiceInstanceId> instances,TimeSpan history,MetricsFilter filter) {
            var res = await Task.WhenAll(
                instances.Select(_=>new CloudServiceUsage(_,_azureMetricsApiClient,filter).GetMetrics(history))
            );


            return res.SelectMany(_=>_).ToList();
        }
コード例 #3
0
		internal async Task<ICollection<UsageObject>> GetUsageCollectionForWebsite(AzureWebsiteId websiteId, TimeSpan history, MetricsFilter filter) {
			var metrics = await _metricsApiClient.GetMetricsForWebsite(websiteId, history,filter);
			var res = new List<UsageObject>();
			foreach(var metric in metrics) {
				foreach(var result in metric.MetricValues.OrderBy(_=>_.Timestamp)) {
					res.Add(new UsageObject {
						GraphiteCounterName =metric.Name  + "." +metric.Unit,
						Value = result.Average.Value,
						Timestamp = result.Timestamp.ToString("o")
					});
				}
			}

			return res;
		}
コード例 #4
0
		public async Task<ICollection<MetricValueSet>> GetMetricsForInstance(CloudServiceInstanceId instance, TimeSpan history, MetricsFilter filter) {
			//var resourceId=ResourceIdBuilder.BuildCloudServiceResourceId(instance.ServiceName,instance.DeploymentName,instance.RoleName,instance.InstanceName);
			return await _azureMetricsApiClient.GetMetricsForCloudService(instance, history,filter);

		}
コード例 #5
0
        internal async Task <ICollection <UsageObject> > GetUsageCollectionForWebsite(AzureWebsiteId websiteId, TimeSpan history, MetricsFilter filter)
        {
            var metrics = await _metricsApiClient.GetMetricsForWebsite(websiteId, history, filter);

            var res = new List <UsageObject>();

            foreach (var metric in metrics)
            {
                foreach (var result in metric.MetricValues.OrderBy(_ => _.Timestamp))
                {
                    res.Add(new UsageObject {
                        GraphiteCounterName = metric.Name + "." + metric.Unit,
                        Value     = result.Average.Value,
                        Timestamp = result.Timestamp.ToString("o")
                    });
                }
            }

            return(res);
        }
コード例 #6
0
        internal async Task <ICollection <UsageObject> > GetUsage(ICollection <CloudServiceInstanceId> instances, TimeSpan history, MetricsFilter filter)
        {
            var res = await Task.WhenAll(
                instances.Select(_ => new CloudServiceUsage(_, _azureMetricsApiClient, filter).GetMetrics(history))
                );


            return(res.SelectMany(_ => _).ToList());
        }
コード例 #7
0
 public CloudServiceUsage(CloudServiceInstanceId instanceId, AzureCloudServiceMetricsApiClient azureMetricsApiClient, MetricsFilter filter)
 {
     _azureMetricsApiClient = azureMetricsApiClient;
     _instanceId            = instanceId;
     _filter = filter;
 }
コード例 #8
0
		internal async System.Threading.Tasks.Task<ICollection<MetricValueSet>> GetMetricsForWebsite(AzureWebsiteId websiteId, TimeSpan history,MetricsFilter filter) {
			
			return await GetMetricsForResourceId(websiteId.ResourceId,history,filter);
		}
コード例 #9
0
        public Task <ICollection <UsageObject> > GetWebsitesUsageForWebsite(string webspace, string websiteName, TimeSpan history, params string[] filters)
        {
            var websiteId = new AzureWebsiteId(websiteName, webspace);

            return(new AzureWebsitesUsageClient(_client, _credentials).GetUsageCollectionForWebsite(websiteId, history, MetricsFilter.FromRegexes(filters)));
        }
コード例 #10
0
		internal async System.Threading.Tasks.Task<ICollection<MetricValueSet>> GetMetricsForCloudService(CloudServiceInstanceId instance,TimeSpan history, MetricsFilter filter) {
			return await GetMetricsForResourceId(instance.ResourceId,history, filter);
		}
コード例 #11
0
		public CloudServiceUsage(CloudServiceInstanceId instanceId,AzureCloudServiceMetricsApiClient azureMetricsApiClient, MetricsFilter filter) {
			_azureMetricsApiClient = azureMetricsApiClient;
			_instanceId = instanceId;
            _filter = filter;
		}
コード例 #12
0
 public async Task <ICollection <MetricValueSet> > GetMetricsForInstance(CloudServiceInstanceId instance, TimeSpan history, MetricsFilter filter)
 {
     //var resourceId=ResourceIdBuilder.BuildCloudServiceResourceId(instance.ServiceName,instance.DeploymentName,instance.RoleName,instance.InstanceName);
     return(await _azureMetricsApiClient.GetMetricsForCloudService(instance, history, filter));
 }
コード例 #13
0
        //the limit seems to be 2880 metrics per request
        async System.Threading.Tasks.Task <ICollection <MetricValueSet> > GetMetricsForResourceId(string resourceId, TimeSpan forHistory, MetricsFilter filter)
        {
            var metricsResult = await MetricsClientFacade.ListDefinitionsAsync(_credentials, resourceId, null, null);

            var metrics = filter.FilterMetrics(metricsResult.MetricDefinitionCollection.Value.Where(_ => _.MetricAvailabilities.Any()).ToList());

            if (!metrics.Any())
            {
                return(new MetricValueSet[0]);
            }

            var minTimeGrain = metrics.SelectMany(_ => _.MetricAvailabilities.Where(ma => forHistory < ma.Retention).Select(a => a.TimeGrain)).Min();

            var metricNames = metrics.Select(_ => _.Name).ToList();

            var till = DateTime.UtcNow.AddMinutes(1);
            var from = till.Add(forHistory.Negate());


            return(await Fetch(new FetchData {
                ResourceId = resourceId,
                MetricNames = metricNames,
                TimeGrain = minTimeGrain,
                From = from,
                Till = till
            }));
        }
コード例 #14
0
 internal async System.Threading.Tasks.Task <ICollection <MetricValueSet> > GetMetricsForWebsite(AzureWebsiteId websiteId, TimeSpan history, MetricsFilter filter)
 {
     return(await GetMetricsForResourceId(websiteId.ResourceId, history, filter));
 }
コード例 #15
0
 internal async System.Threading.Tasks.Task <ICollection <MetricValueSet> > GetMetricsForCloudService(CloudServiceInstanceId instance, TimeSpan history, MetricsFilter filter)
 {
     return(await GetMetricsForResourceId(instance.ResourceId, history, filter));
 }