Esempio n. 1
0
 private ScaleRule CreateCpuRule(bool increase)
 {
     return(new ScaleRule()
     {
         // Define the MetricTrigger Properties
         MetricTrigger = new MetricTrigger()
         {
             MetricName = "Percentage CPU",
             MetricNamespace = "",
             MetricSource = AutoscaleMetricSourceBuilder.BuildVirtualMachineMetricSource(cloudServiceName, availabilitySetName),
             TimeGrain = TimeSpan.FromMinutes(5),   // recomended 5 min, at least 1 min
             TimeWindow = TimeSpan.FromMinutes(25), //recomended 25 min, at least 5 min
             TimeAggregation = TimeAggregationType.Average,
             Statistic = MetricStatisticType.Average,
             Operator = increase ? ComparisonOperationType.GreaterThanOrEqual : ComparisonOperationType.LessThanOrEqual,
             Threshold = increase ? 40.0 : 20.0
         },
         // Define the ScaleAction Properties
         ScaleAction = new ScaleAction()
         {
             Direction = increase ? ScaleDirection.Increase : ScaleDirection.Decrease,
             Type = ScaleType.ChangeCount,
             Value = "1",
             Cooldown = TimeSpan.FromMinutes(10) // at least 5 min
         }
     });
 }
Esempio n. 2
0
        public string AutoScaleCloudService(string serviceName, string roleName)
        {
            AutoscaleClient autoscaleClient = new AutoscaleClient(cloudCredentials);

            AutoscaleSettingCreateOrUpdateParameters autoscaleCreateParams = new AutoscaleSettingCreateOrUpdateParameters()
            {
                Setting = new AutoscaleSetting()
                {
                    Enabled  = true,
                    Profiles = new List <AutoscaleProfile>
                    {
                        new AutoscaleProfile
                        {
                            Capacity = new ScaleCapacity
                            {
                                Default = "1",
                                Maximum = "10",
                                Minimum = "1"
                            },
                            Name       = "sampleProfile",
                            Recurrence = new Recurrence
                            {
                                Frequency = RecurrenceFrequency.Week,
                                Schedule  = new RecurrentSchedule
                                {
                                    Days = new List <String> {
                                        "Monday", "Thursday", "Friday"
                                    },
                                    Hours   = { 7, 19 },
                                    Minutes = new List <int> {
                                        0
                                    },
                                    TimeZone = "Eastern Standard Time"
                                }
                            },
                            Rules = new List <ScaleRule>
                            {
                                new ScaleRule
                                {
                                    MetricTrigger = new MetricTrigger
                                    {
                                        MetricName      = "PercentageCPU",
                                        MetricNamespace = "",
                                        MetricSource    = AutoscaleMetricSourceBuilder.BuildCloudServiceMetricSource(serviceName, roleName, true),
                                        Operator        = ComparisonOperationType.GreaterThanOrEqual,
                                        Threshold       = 80,
                                        Statistic       = MetricStatisticType.Average,
                                        TimeGrain       = TimeSpan.FromMinutes(5),
                                        TimeAggregation = TimeAggregationType.Average,
                                        TimeWindow      = TimeSpan.FromMinutes(30)
                                    },
                                    ScaleAction = new ScaleAction
                                    {
                                        Direction = ScaleDirection.Increase,
                                        Cooldown  = TimeSpan.FromMinutes(20),
                                        Type      = ScaleType.ChangeCount,
                                        Value     = "1"
                                    },
                                },
                                new ScaleRule
                                {
                                    MetricTrigger = new MetricTrigger
                                    {
                                        MetricName      = "PercentageCPU",
                                        MetricNamespace = "",
                                        MetricSource    = AutoscaleMetricSourceBuilder.BuildCloudServiceMetricSource(serviceName, roleName, true),
                                        Operator        = ComparisonOperationType.LessThanOrEqual,
                                        Threshold       = 60,
                                        Statistic       = MetricStatisticType.Average,
                                        TimeGrain       = TimeSpan.FromMinutes(5),
                                        TimeAggregation = TimeAggregationType.Average,
                                        TimeWindow      = TimeSpan.FromMinutes(30)
                                    },
                                    ScaleAction = new ScaleAction
                                    {
                                        Direction = ScaleDirection.Decrease,
                                        Cooldown  = TimeSpan.FromMinutes(20),
                                        Type      = ScaleType.ChangeCount,
                                        Value     = "1"
                                    },
                                }
                            }
                        }
                    }
                }
            };


            OperationResponse autoscaleResponse = autoscaleClient.Settings.CreateOrUpdate(
                AutoscaleResourceIdBuilder.BuildCloudServiceResourceId(serviceName, roleName, true),
                autoscaleCreateParams);

            string statusCode = autoscaleResponse.StatusCode.ToString();

            AutoscaleSettingGetResponse settingReponse   = autoscaleClient.Settings.Get(AutoscaleResourceIdBuilder.BuildCloudServiceResourceId(serviceName, roleName, true));
            AutoscaleSetting            autoscaleSetting = settingReponse.Setting;

            return(statusCode);
        }