public WebsiteAutoscalerHelper() { // Read configuration settings. var subscriptionId = ConfigurationManager.AppSettings["SubscriptionId"]; this.webspaceName = ConfigurationManager.AppSettings["WebspaceName"]; this.hostingPlanName = ConfigurationManager.AppSettings["HostingPlanName"]; // Get the certificate from appsettings. var cert = CertificateHelper.GetCertificateFromAppSettings("ManagementCertificate"); // Create the autoscale client. this.autoscaleClient = new AutoscaleClient(new CertificateCloudCredentials(subscriptionId, cert)); }
public VirtualMachineAutoscalerHelper() { // Read configuration settings. var subscriptionId = ConfigurationManager.AppSettings["SubscriptionId"]; var certThumbprint = ConfigurationManager.AppSettings["CertThumbprint"]; this.cloudServiceName = ConfigurationManager.AppSettings["VirtualMachineCloudServiceName"]; this.availabilitySetName = ConfigurationManager.AppSettings["AvailabilitySetName"]; // Get the certificate from the local store. var cert = CertificateHelper.GetCertificate(StoreName.My, StoreLocation.CurrentUser, certThumbprint); // Create the autoscale client. this.autoscaleClient = new AutoscaleClient(new CertificateCloudCredentials(subscriptionId, cert)); }
public CloudServiceAutoscalerHelper() { // Read configuration settings. var subscriptionId = ConfigurationManager.AppSettings["SubscriptionId"]; var certThumbprint = ConfigurationManager.AppSettings["CertThumbprint"]; this.cloudServiceName = ConfigurationManager.AppSettings["CloudServiceName"]; this.roleName = ConfigurationManager.AppSettings["RoleName"]; this.deploymentName = ConfigurationManager.AppSettings["DeploymentName"]; this.isProduction = bool.Parse(ConfigurationManager.AppSettings["IsProduction"]); // Get the certificate from the local store. var cert = CertificateHelper.GetCertificate(StoreName.My, StoreLocation.CurrentUser, certThumbprint); // Create the autoscale client. this.autoscaleClient = new AutoscaleClient(new CertificateCloudCredentials(subscriptionId, cert)); // Create the metrics client. this.metricsClient = new MetricsClient(new CertificateCloudCredentials(subscriptionId, cert)); }
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); }