示例#1
0
        private async Task <ChartData> GetCloudServiceMetrics(AMDCloudServiceRoleId serviceRoleId, TimeSpan history, string label, string regex, Func <string, string, string> formatSeriesLabel)
        {
            var client = new AzureCloudServicesClient(new AzureManagementRestClient(GetCredentials().GetCertificateCloudCredentials()), GetCredentials().GetCertificateCloudCredentials());

            var instances = await client.ListInstancesForServiceRole(serviceRoleId);

            var usages = await client.GetUsage(instances, history, MetricsFilter.FromRegexes(regex));

            var usagesPartitioned = PartitionByInstanceNameAndMetric(usages);

            return(new ChartData {
                Name = string.Format("{0} {1} (Cloud Service)", serviceRoleId.DisplayName, label),
                Series = usagesPartitioned.Keys.SelectMany(
                    instance => usagesPartitioned[instance].Keys.Select(metricName => new SeriesData {
                    Name = formatSeriesLabel(instance, metricName),
                    DataPoints = usagesPartitioned[instance][metricName].Select(uo => new DataPoint {
                        Timestamp = uo.Timestamp, Value = uo.Value
                    }).ToList()
                })).ToList()
            });


            //usages.Select(_=> new SeriesData{
            //    Name = formatInstanceName(_.Key.InstanceName),
            //    DataPoints = _.Value.Select(uo=>new DataPoint { Timestamp = uo.Timestamp, Value = uo.Value }).ToList()
            //}).ToList()
        }
        internal async Task<ICollection<CloudServiceInstanceId>> ListInstancesForServiceRole(AMDCloudServiceRoleId roleId) {
            //serviceResourceId = /hostedservices/wge-win/deployments/wge-win/roles/wge-win

            var instances = await _azureCloudServiceInfoClient.ListInstancesForServiceName(roleId.CloudServiceName);

            return instances.Where(_=>_.RoleId.Equals(roleId)).ToList();
        }
示例#3
0
 private Task <ChartData> GetCloudServiceDisk(AMDCloudServiceRoleId serviceRoleId, TimeSpan history)
 {
     return(GetCloudServiceMetrics(serviceRoleId, history,
                                   label: "Disk performance",
                                   regex: "Disk",
                                   formatSeriesLabel: (instanceName, metricName) => string.Format("{0} {1}", instanceName, metricName)
                                   ));
 }
示例#4
0
 private Task <ChartData> GetCloudServiceNetwork(AMDCloudServiceRoleId serviceRoleId, TimeSpan history)
 {
     return(GetCloudServiceMetrics(serviceRoleId, history,
                                   label: "Network traffic",
                                   regex: "Network",
                                   formatSeriesLabel: (instanceName, metricName) => string.Format("{0} {1} bytes", instanceName, metricName)
                                   ));
 }
示例#5
0
        private static ICollection<ChartInfo> GetCloudServiceCharts(string serviceName, AMDCloudServiceRoleId cs) {
            Func<string,Uri,ChartInfo> buildChartInfo = (counter,uri)=>
                new ChartInfo {
                    ResourceName = cs.DisplayName,
                    ResourceType = "cloud service",
                    ServiceName = serviceName,
                    ServiceType = "Azure Subscription",
                    Name = string.Format("{0} (cloud service) {1}", cs.DisplayName,counter),
                    Uri = uri.ToString()
                };

            return new ChartInfo[] {
                buildChartInfo("CPU", cs.AppendToUri("/cpu")),
                buildChartInfo("Network", cs.AppendToUri("/network")),
                buildChartInfo("Disk Performance", cs.AppendToUri("/disk"))
            };
        }
示例#6
0
        private Task <ChartData> GetCloudServiceChartData(TimeSpan interval)
        {
            var serviceId = AMDCloudServiceRoleId.FromUri(_uri);

            var counter = _path[_path.Length - 1];

            switch (counter)
            {
            case "cpu":
                return(GetCloudServiceCPU(serviceId, interval));

            case "disk":
                return(GetCloudServiceDisk(serviceId, interval));

            case "network":
                return(GetCloudServiceNetwork(serviceId, interval));

            default:
                throw new ArgumentException("don't now how to get " + counter);
            }
        }
示例#7
0
        private static ICollection <ChartInfo> GetCloudServiceCharts(string serviceName, AMDCloudServiceRoleId cs)
        {
            Func <string, Uri, ChartInfo> buildChartInfo = (counter, uri) =>
                                                           new ChartInfo {
                ResourceName = cs.DisplayName,
                ResourceType = "cloud service",
                ServiceName  = serviceName,
                ServiceType  = "Azure Subscription",
                Name         = string.Format("{0} (cloud service) {1}", cs.DisplayName, counter),
                Uri          = uri.ToString()
            };

            return(new ChartInfo[] {
                buildChartInfo("CPU", cs.AppendToUri("/cpu")),
                buildChartInfo("Network", cs.AppendToUri("/network")),
                buildChartInfo("Disk Performance", cs.AppendToUri("/disk"))
            });
        }
示例#8
0
 private Task <ChartData> GetCloudServiceCPU(AMDCloudServiceRoleId serviceRoleId, TimeSpan history)
 {
     return(GetCloudServiceMetrics(serviceRoleId, history, label: "CPU", regex: "CPU", formatSeriesLabel: (instanceName, metricname) => instanceName));
 }
        internal async Task <ICollection <CloudServiceInstanceId> > ListInstancesForServiceRole(AMDCloudServiceRoleId roleId)
        {
            //serviceResourceId = /hostedservices/wge-win/deployments/wge-win/roles/wge-win

            var instances = await _azureCloudServiceInfoClient.ListInstancesForServiceName(roleId.CloudServiceName);

            return(instances.Where(_ => _.RoleId.Equals(roleId)).ToList());
        }
        private async Task<ChartData> GetCloudServiceMetrics(AMDCloudServiceRoleId serviceRoleId, TimeSpan history, string label,string regex,Func<string,string,string> formatSeriesLabel) {
            var client = new AzureCloudServicesClient(new AzureManagementRestClient(GetCredentials().GetCertificateCloudCredentials()),GetCredentials().GetCertificateCloudCredentials());

            var instances = await client.ListInstancesForServiceRole(serviceRoleId);

            var usages = await client.GetUsage(instances,history,MetricsFilter.FromRegexes(regex));

            var usagesPartitioned = PartitionByInstanceNameAndMetric(usages);

            return new ChartData {
                Name = string.Format("{0} {1} (Cloud Service)", serviceRoleId.DisplayName,label),
                Series = usagesPartitioned.Keys.SelectMany(
                    instance=>usagesPartitioned[instance].Keys.Select(metricName=>new SeriesData {
                        Name = formatSeriesLabel(instance,metricName),
                        DataPoints = usagesPartitioned[instance][metricName].Select(uo=>new DataPoint { Timestamp = uo.Timestamp, Value = uo.Value }).ToList()
                    })).ToList()
            };
                
                
                //usages.Select(_=> new SeriesData{
                //    Name = formatInstanceName(_.Key.InstanceName),
                //    DataPoints = _.Value.Select(uo=>new DataPoint { Timestamp = uo.Timestamp, Value = uo.Value }).ToList()
                //}).ToList()
            
        }
 private Task<ChartData> GetCloudServiceCPU(AMDCloudServiceRoleId serviceRoleId, TimeSpan history) {
     return GetCloudServiceMetrics(serviceRoleId,history, label: "CPU",regex:"CPU",formatSeriesLabel:(instanceName,metricname)=>instanceName);
 }
 private Task<ChartData> GetCloudServiceDisk(AMDCloudServiceRoleId serviceRoleId,TimeSpan history) {
     return GetCloudServiceMetrics(serviceRoleId,history, 
         label: "Disk performance",
         regex:"Disk",
         formatSeriesLabel:(instanceName,metricName)=>string.Format("{0} {1}", instanceName, metricName)
     );
 }
 private Task<ChartData> GetCloudServiceNetwork(AMDCloudServiceRoleId serviceRoleId,TimeSpan history) {
     return GetCloudServiceMetrics(serviceRoleId,history, 
         label: "Network traffic",
         regex:"Network",
         formatSeriesLabel:(instanceName,metricName)=>string.Format("{0} {1} bytes", instanceName, metricName)
     );
 }