//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 }); }
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(); }
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; }
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); }
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); }
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()); }
public CloudServiceUsage(CloudServiceInstanceId instanceId, AzureCloudServiceMetricsApiClient azureMetricsApiClient, MetricsFilter filter) { _azureMetricsApiClient = azureMetricsApiClient; _instanceId = instanceId; _filter = filter; }
internal async System.Threading.Tasks.Task<ICollection<MetricValueSet>> GetMetricsForWebsite(AzureWebsiteId websiteId, TimeSpan history,MetricsFilter filter) { return await GetMetricsForResourceId(websiteId.ResourceId,history,filter); }
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))); }
internal async System.Threading.Tasks.Task<ICollection<MetricValueSet>> GetMetricsForCloudService(CloudServiceInstanceId instance,TimeSpan history, MetricsFilter filter) { return await GetMetricsForResourceId(instance.ResourceId,history, filter); }
public CloudServiceUsage(CloudServiceInstanceId instanceId,AzureCloudServiceMetricsApiClient azureMetricsApiClient, MetricsFilter filter) { _azureMetricsApiClient = azureMetricsApiClient; _instanceId = instanceId; _filter = filter; }
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)); }
//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 })); }
internal async System.Threading.Tasks.Task <ICollection <MetricValueSet> > GetMetricsForWebsite(AzureWebsiteId websiteId, TimeSpan history, MetricsFilter filter) { return(await GetMetricsForResourceId(websiteId.ResourceId, history, filter)); }
internal async System.Threading.Tasks.Task <ICollection <MetricValueSet> > GetMetricsForCloudService(CloudServiceInstanceId instance, TimeSpan history, MetricsFilter filter) { return(await GetMetricsForResourceId(instance.ResourceId, history, filter)); }