///GENMHASH:680066A5310B6D51053B6E9324843124:764AD6D9C9BFFEBA35D2F0506CA6C91F public ScaleRuleImpl WithStatistic(TimeSpan duration, TimeSpan frequency, MetricStatisticType statisticType) { this.Inner.MetricTrigger.Statistic = statisticType; this.Inner.MetricTrigger.TimeWindow = duration; this.Inner.MetricTrigger.TimeGrain = frequency; return(this); }
/// <summary> /// Initializes a new instance of the MetricTrigger class. /// </summary> /// <param name="metricName">the name of the metric that defines what /// the rule monitors.</param> /// <param name="metricResourceUri">the resource identifier of the /// resource the rule monitors.</param> /// <param name="timeGrain">the granularity of metrics the rule /// monitors. Must be one of the predefined values returned from metric /// definitions for the metric. Must be between 12 hours and 1 /// minute.</param> /// <param name="statistic">the metric statistic type. How the metrics /// from multiple instances are combined. Possible values include: /// 'Average', 'Min', 'Max', 'Sum'</param> /// <param name="timeWindow">the range of time in which instance data /// is collected. This value must be greater than the delay in metric /// collection, which can vary from resource-to-resource. Must be /// between 12 hours and 5 minutes.</param> /// <param name="timeAggregation">time aggregation type. How the data /// that is collected should be combined over time. The default value /// is Average. Possible values include: 'Average', 'Minimum', /// 'Maximum', 'Total', 'Count'</param> /// <param name="operatorProperty">the operator that is used to compare /// the metric data and the threshold. Possible values include: /// 'Equals', 'NotEquals', 'GreaterThan', 'GreaterThanOrEqual', /// 'LessThan', 'LessThanOrEqual'</param> /// <param name="threshold">the threshold of the metric that triggers /// the scale action.</param> public MetricTrigger(string metricName, string metricResourceUri, System.TimeSpan timeGrain, MetricStatisticType statistic, System.TimeSpan timeWindow, TimeAggregationType timeAggregation, ComparisonOperationType operatorProperty, double threshold) { MetricName = metricName; MetricResourceUri = metricResourceUri; TimeGrain = timeGrain; Statistic = statistic; TimeWindow = timeWindow; TimeAggregation = timeAggregation; OperatorProperty = operatorProperty; Threshold = threshold; }
internal MetricTrigger(string metricName, string metricNamespace, string metricResourceUri, TimeSpan timeGrain, MetricStatisticType statistic, TimeSpan timeWindow, TimeAggregationType timeAggregation, ComparisonOperationType @operator, double threshold, IList <ScaleRuleMetricDimension> dimensions) { MetricName = metricName; MetricNamespace = metricNamespace; MetricResourceUri = metricResourceUri; TimeGrain = timeGrain; Statistic = statistic; TimeWindow = timeWindow; TimeAggregation = timeAggregation; Operator = @operator; Threshold = threshold; Dimensions = dimensions; }
/// <summary> /// Initializes a new instance of the MetricTrigger class. /// </summary> /// <param name="metricName">the name of the metric that defines what /// the rule monitors.</param> /// <param name="metricResourceUri">the resource identifier of the /// resource the rule monitors.</param> /// <param name="timeGrain">the granularity of metrics the rule /// monitors. Must be one of the predefined values returned from metric /// definitions for the metric. Must be between 12 hours and 1 /// minute.</param> /// <param name="statistic">the metric statistic type. How the metrics /// from multiple instances are combined. Possible values include: /// 'Average', 'Min', 'Max', 'Sum'</param> /// <param name="timeWindow">the range of time in which instance data /// is collected. This value must be greater than the delay in metric /// collection, which can vary from resource-to-resource. Must be /// between 12 hours and 5 minutes.</param> /// <param name="timeAggregation">time aggregation type. How the data /// that is collected should be combined over time. The default value /// is Average. Possible values include: 'Average', 'Minimum', /// 'Maximum', 'Total', 'Count', 'Last'</param> /// <param name="operatorProperty">the operator that is used to compare /// the metric data and the threshold. Possible values include: /// 'Equals', 'NotEquals', 'GreaterThan', 'GreaterThanOrEqual', /// 'LessThan', 'LessThanOrEqual'</param> /// <param name="threshold">the threshold of the metric that triggers /// the scale action.</param> /// <param name="metricNamespace">the namespace of the metric that /// defines what the rule monitors.</param> /// <param name="dimensions">List of dimension conditions. For example: /// [{"DimensionName":"AppName","Operator":"Equals","Values":["App1"]},{"DimensionName":"Deployment","Operator":"Equals","Values":["default"]}].</param> public MetricTrigger(string metricName, string metricResourceUri, System.TimeSpan timeGrain, MetricStatisticType statistic, System.TimeSpan timeWindow, TimeAggregationType timeAggregation, ComparisonOperationType operatorProperty, double threshold, string metricNamespace = default(string), IList <ScaleRuleMetricDimension> dimensions = default(IList <ScaleRuleMetricDimension>)) { MetricName = metricName; MetricNamespace = metricNamespace; MetricResourceUri = metricResourceUri; TimeGrain = timeGrain; Statistic = statistic; TimeWindow = timeWindow; TimeAggregation = timeAggregation; OperatorProperty = operatorProperty; Threshold = threshold; Dimensions = dimensions; CustomInit(); }
internal MetricTrigger(string metricName, string metricNamespace, string metricResourceId, string metricResourceLocation, TimeSpan timeGrain, MetricStatisticType statistic, TimeSpan timeWindow, TimeAggregationType timeAggregation, ComparisonOperationType @operator, double threshold, IList <ScaleRuleMetricDimension> dimensions, bool?dividePerInstance) { MetricName = metricName; MetricNamespace = metricNamespace; MetricResourceId = metricResourceId; MetricResourceLocation = metricResourceLocation; TimeGrain = timeGrain; Statistic = statistic; TimeWindow = timeWindow; TimeAggregation = timeAggregation; Operator = @operator; Threshold = threshold; Dimensions = dimensions; DividePerInstance = dividePerInstance; }
internal static string ToSerializedValue(this MetricStatisticType value) { switch (value) { case MetricStatisticType.Average: return("Average"); case MetricStatisticType.Min: return("Min"); case MetricStatisticType.Max: return("Max"); case MetricStatisticType.Sum: return("Sum"); } return(null); }
public MetricTrigger(string metricName, string metricResourceUri, TimeSpan timeGrain, MetricStatisticType statistic, TimeSpan timeWindow, TimeAggregationType timeAggregation, ComparisonOperationType @operator, double threshold) { if (metricName == null) { throw new ArgumentNullException(nameof(metricName)); } if (metricResourceUri == null) { throw new ArgumentNullException(nameof(metricResourceUri)); } MetricName = metricName; MetricResourceUri = metricResourceUri; TimeGrain = timeGrain; Statistic = statistic; TimeWindow = timeWindow; TimeAggregation = timeAggregation; Operator = @operator; Threshold = threshold; Dimensions = new ChangeTrackingList <ScaleRuleMetricDimension>(); }
/// <param name='resourceId'> /// Required. The resource ID. /// </param> /// <param name='cancellationToken'> /// Cancellation token. /// </param> /// <returns> /// A standard service response including an HTTP status code and /// request ID. /// </returns> public async System.Threading.Tasks.Task <Microsoft.WindowsAzure.Management.Monitoring.Autoscale.Models.AutoscaleSettingGetResponse> GetAsync(string resourceId, CancellationToken cancellationToken) { // Validate if (resourceId == null) { throw new ArgumentNullException("resourceId"); } // Tracing bool shouldTrace = CloudContext.Configuration.Tracing.IsEnabled; string invocationId = null; if (shouldTrace) { invocationId = Tracing.NextInvocationId.ToString(); Dictionary <string, object> tracingParameters = new Dictionary <string, object>(); tracingParameters.Add("resourceId", resourceId); Tracing.Enter(invocationId, this, "GetAsync", tracingParameters); } // Construct URL string url = "/" + (this.Client.Credentials.SubscriptionId != null ? this.Client.Credentials.SubscriptionId.Trim() : "") + "/services/monitoring/autoscalesettings?"; url = url + "resourceId=" + Uri.EscapeDataString(resourceId.Trim()); string baseUrl = this.Client.BaseUri.AbsoluteUri; // Trim '/' character from the end of baseUrl and beginning of url. if (baseUrl[baseUrl.Length - 1] == '/') { baseUrl = baseUrl.Substring(0, baseUrl.Length - 1); } if (url[0] == '/') { url = url.Substring(1); } url = baseUrl + "/" + url; url = url.Replace(" ", "%20"); // Create HTTP transport objects HttpRequestMessage httpRequest = null; try { httpRequest = new HttpRequestMessage(); httpRequest.Method = HttpMethod.Get; httpRequest.RequestUri = new Uri(url); // Set Headers httpRequest.Headers.Add("Accept", "application/json"); httpRequest.Headers.Add("x-ms-version", "2013-10-01"); // Set Credentials cancellationToken.ThrowIfCancellationRequested(); await this.Client.Credentials.ProcessHttpRequestAsync(httpRequest, cancellationToken).ConfigureAwait(false); // Send Request HttpResponseMessage httpResponse = null; try { if (shouldTrace) { Tracing.SendRequest(invocationId, httpRequest); } cancellationToken.ThrowIfCancellationRequested(); httpResponse = await this.Client.HttpClient.SendAsync(httpRequest, cancellationToken).ConfigureAwait(false); if (shouldTrace) { Tracing.ReceiveResponse(invocationId, httpResponse); } HttpStatusCode statusCode = httpResponse.StatusCode; if (statusCode != HttpStatusCode.OK) { cancellationToken.ThrowIfCancellationRequested(); CloudException ex = CloudException.Create(httpRequest, null, httpResponse, await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false)); if (shouldTrace) { Tracing.Error(invocationId, ex); } throw ex; } // Create Result AutoscaleSettingGetResponse result = null; // Deserialize Response cancellationToken.ThrowIfCancellationRequested(); string responseContent = await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); result = new AutoscaleSettingGetResponse(); JToken responseDoc = null; if (string.IsNullOrEmpty(responseContent) == false) { responseDoc = JToken.Parse(responseContent); } if (responseDoc != null && responseDoc.Type != JTokenType.Null) { AutoscaleSetting settingInstance = new AutoscaleSetting(); result.Setting = settingInstance; JToken profilesArray = responseDoc["Profiles"]; if (profilesArray != null && profilesArray.Type != JTokenType.Null) { foreach (JToken profilesValue in ((JArray)profilesArray)) { AutoscaleProfile autoscaleProfileInstance = new AutoscaleProfile(); settingInstance.Profiles.Add(autoscaleProfileInstance); JToken nameValue = profilesValue["Name"]; if (nameValue != null && nameValue.Type != JTokenType.Null) { string nameInstance = ((string)nameValue); autoscaleProfileInstance.Name = nameInstance; } JToken capacityValue = profilesValue["Capacity"]; if (capacityValue != null && capacityValue.Type != JTokenType.Null) { ScaleCapacity capacityInstance = new ScaleCapacity(); autoscaleProfileInstance.Capacity = capacityInstance; JToken minimumValue = capacityValue["Minimum"]; if (minimumValue != null && minimumValue.Type != JTokenType.Null) { string minimumInstance = ((string)minimumValue); capacityInstance.Minimum = minimumInstance; } JToken maximumValue = capacityValue["Maximum"]; if (maximumValue != null && maximumValue.Type != JTokenType.Null) { string maximumInstance = ((string)maximumValue); capacityInstance.Maximum = maximumInstance; } JToken defaultValue = capacityValue["Default"]; if (defaultValue != null && defaultValue.Type != JTokenType.Null) { string defaultInstance = ((string)defaultValue); capacityInstance.Default = defaultInstance; } } JToken rulesArray = profilesValue["Rules"]; if (rulesArray != null && rulesArray.Type != JTokenType.Null) { foreach (JToken rulesValue in ((JArray)rulesArray)) { ScaleRule scaleRuleInstance = new ScaleRule(); autoscaleProfileInstance.Rules.Add(scaleRuleInstance); JToken metricTriggerValue = rulesValue["MetricTrigger"]; if (metricTriggerValue != null && metricTriggerValue.Type != JTokenType.Null) { MetricTrigger metricTriggerInstance = new MetricTrigger(); scaleRuleInstance.MetricTrigger = metricTriggerInstance; JToken metricNameValue = metricTriggerValue["MetricName"]; if (metricNameValue != null && metricNameValue.Type != JTokenType.Null) { string metricNameInstance = ((string)metricNameValue); metricTriggerInstance.MetricName = metricNameInstance; } JToken metricNamespaceValue = metricTriggerValue["MetricNamespace"]; if (metricNamespaceValue != null && metricNamespaceValue.Type != JTokenType.Null) { string metricNamespaceInstance = ((string)metricNamespaceValue); metricTriggerInstance.MetricNamespace = metricNamespaceInstance; } JToken metricSourceValue = metricTriggerValue["MetricSource"]; if (metricSourceValue != null && metricSourceValue.Type != JTokenType.Null) { string metricSourceInstance = ((string)metricSourceValue); metricTriggerInstance.MetricSource = metricSourceInstance; } JToken timeGrainValue = metricTriggerValue["TimeGrain"]; if (timeGrainValue != null && timeGrainValue.Type != JTokenType.Null) { TimeSpan timeGrainInstance = TypeConversion.From8601TimeSpan(((string)timeGrainValue)); metricTriggerInstance.TimeGrain = timeGrainInstance; } JToken statisticValue = metricTriggerValue["Statistic"]; if (statisticValue != null && statisticValue.Type != JTokenType.Null) { MetricStatisticType statisticInstance = ((MetricStatisticType)Enum.Parse(typeof(MetricStatisticType), ((string)statisticValue), true)); metricTriggerInstance.Statistic = statisticInstance; } JToken timeWindowValue = metricTriggerValue["TimeWindow"]; if (timeWindowValue != null && timeWindowValue.Type != JTokenType.Null) { TimeSpan timeWindowInstance = TypeConversion.From8601TimeSpan(((string)timeWindowValue)); metricTriggerInstance.TimeWindow = timeWindowInstance; } JToken timeAggregationValue = metricTriggerValue["TimeAggregation"]; if (timeAggregationValue != null && timeAggregationValue.Type != JTokenType.Null) { TimeAggregationType timeAggregationInstance = ((TimeAggregationType)Enum.Parse(typeof(TimeAggregationType), ((string)timeAggregationValue), true)); metricTriggerInstance.TimeAggregation = timeAggregationInstance; } JToken operatorValue = metricTriggerValue["Operator"]; if (operatorValue != null && operatorValue.Type != JTokenType.Null) { ComparisonOperationType operatorInstance = ((ComparisonOperationType)Enum.Parse(typeof(ComparisonOperationType), ((string)operatorValue), true)); metricTriggerInstance.Operator = operatorInstance; } JToken thresholdValue = metricTriggerValue["Threshold"]; if (thresholdValue != null && thresholdValue.Type != JTokenType.Null) { double thresholdInstance = ((double)thresholdValue); metricTriggerInstance.Threshold = thresholdInstance; } } JToken scaleActionValue = rulesValue["ScaleAction"]; if (scaleActionValue != null && scaleActionValue.Type != JTokenType.Null) { ScaleAction scaleActionInstance = new ScaleAction(); scaleRuleInstance.ScaleAction = scaleActionInstance; JToken directionValue = scaleActionValue["Direction"]; if (directionValue != null && directionValue.Type != JTokenType.Null) { ScaleDirection directionInstance = ((ScaleDirection)Enum.Parse(typeof(ScaleDirection), ((string)directionValue), true)); scaleActionInstance.Direction = directionInstance; } JToken typeValue = scaleActionValue["Type"]; if (typeValue != null && typeValue.Type != JTokenType.Null) { ScaleType typeInstance = ((ScaleType)Enum.Parse(typeof(ScaleType), ((string)typeValue), true)); scaleActionInstance.Type = typeInstance; } JToken valueValue = scaleActionValue["Value"]; if (valueValue != null && valueValue.Type != JTokenType.Null) { string valueInstance = ((string)valueValue); scaleActionInstance.Value = valueInstance; } JToken cooldownValue = scaleActionValue["Cooldown"]; if (cooldownValue != null && cooldownValue.Type != JTokenType.Null) { TimeSpan cooldownInstance = TypeConversion.From8601TimeSpan(((string)cooldownValue)); scaleActionInstance.Cooldown = cooldownInstance; } } } } JToken fixedDateValue = profilesValue["FixedDate"]; if (fixedDateValue != null && fixedDateValue.Type != JTokenType.Null) { TimeWindow fixedDateInstance = new TimeWindow(); autoscaleProfileInstance.FixedDate = fixedDateInstance; JToken timeZoneValue = fixedDateValue["TimeZone"]; if (timeZoneValue != null && timeZoneValue.Type != JTokenType.Null) { string timeZoneInstance = ((string)timeZoneValue); fixedDateInstance.TimeZone = timeZoneInstance; } JToken startValue = fixedDateValue["Start"]; if (startValue != null && startValue.Type != JTokenType.Null) { DateTime startInstance = ((DateTime)startValue); fixedDateInstance.Start = startInstance; } JToken endValue = fixedDateValue["End"]; if (endValue != null && endValue.Type != JTokenType.Null) { DateTime endInstance = ((DateTime)endValue); fixedDateInstance.End = endInstance; } } JToken recurrenceValue = profilesValue["Recurrence"]; if (recurrenceValue != null && recurrenceValue.Type != JTokenType.Null) { Recurrence recurrenceInstance = new Recurrence(); autoscaleProfileInstance.Recurrence = recurrenceInstance; JToken frequencyValue = recurrenceValue["Frequency"]; if (frequencyValue != null && frequencyValue.Type != JTokenType.Null) { RecurrenceFrequency frequencyInstance = ((RecurrenceFrequency)Enum.Parse(typeof(RecurrenceFrequency), ((string)frequencyValue), true)); recurrenceInstance.Frequency = frequencyInstance; } JToken scheduleValue = recurrenceValue["Schedule"]; if (scheduleValue != null && scheduleValue.Type != JTokenType.Null) { RecurrentSchedule scheduleInstance = new RecurrentSchedule(); recurrenceInstance.Schedule = scheduleInstance; JToken timeZoneValue2 = scheduleValue["TimeZone"]; if (timeZoneValue2 != null && timeZoneValue2.Type != JTokenType.Null) { string timeZoneInstance2 = ((string)timeZoneValue2); scheduleInstance.TimeZone = timeZoneInstance2; } JToken daysArray = scheduleValue["Days"]; if (daysArray != null && daysArray.Type != JTokenType.Null) { foreach (JToken daysValue in ((JArray)daysArray)) { scheduleInstance.Days.Add(((string)daysValue)); } } JToken hoursArray = scheduleValue["Hours"]; if (hoursArray != null && hoursArray.Type != JTokenType.Null) { foreach (JToken hoursValue in ((JArray)hoursArray)) { scheduleInstance.Hours.Add(((int)hoursValue)); } } JToken minutesArray = scheduleValue["Minutes"]; if (minutesArray != null && minutesArray.Type != JTokenType.Null) { foreach (JToken minutesValue in ((JArray)minutesArray)) { scheduleInstance.Minutes.Add(((int)minutesValue)); } } } } } } JToken enabledValue = responseDoc["Enabled"]; if (enabledValue != null && enabledValue.Type != JTokenType.Null) { bool enabledInstance = ((bool)enabledValue); settingInstance.Enabled = enabledInstance; } } result.StatusCode = statusCode; if (httpResponse.Headers.Contains("x-ms-request-id")) { result.RequestId = httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault(); } if (shouldTrace) { Tracing.Exit(invocationId, result); } return(result); } finally { if (httpResponse != null) { httpResponse.Dispose(); } } } finally { if (httpRequest != null) { httpRequest.Dispose(); } } }
///GENMHASH:FF2A080FF12D83F694D1FBC9A0BF2CE0:CC5FA33537C949636ABCF5F9AEB86A73 public ScaleRuleImpl WithStatistic(TimeSpan duration, MetricStatisticType statisticType) { return(this.WithStatistic(duration, TimeSpan.FromMinutes(1), statisticType)); }
/// <summary> /// Sets statistics for autoscale trigger action with default values of 1 minute for frequency(time grain). /// </summary> /// <param name="duration">The range of time in which instance data is collected. This value must be greater than the delay in metric collection, which can vary from resource-to-resource. Must be between 12 hours and 5 minutes.</param> /// <param name="statisticType">The metric statistic type. How the metrics from multiple instances are combined. Possible values include: 'Average', 'Min', 'Max', 'Sum'.</param> /// <return>The next stage of the definition.</return> ScaleRule.Definition.IWithCondition ScaleRule.Definition.IWithStatistic.WithStatistic(TimeSpan duration, MetricStatisticType statisticType) { return(this.WithStatistic(duration, statisticType)); }
/// <summary> /// Sets statistics for autoscale trigger action. /// </summary> /// <param name="duration">The range of time in which instance data is collected. This value must be greater than the delay in metric collection, which can vary from resource-to-resource. Must be between 12 hours and 5 minutes.</param> /// <param name="frequency">The granularity of metrics the rule monitors. Must be one of the predefined values returned from metric definitions for the metric. Must be between 12 hours and 1 minute.</param> /// <param name="statisticType">The metric statistic type. How the metrics from multiple instances are combined. Possible values include: 'Average', 'Min', 'Max', 'Sum'.</param> /// <return>The next stage of the definition.</return> ScaleRule.UpdateDefinition.IWithCondition ScaleRule.UpdateDefinition.IWithStatistic.WithStatistic(TimeSpan duration, TimeSpan frequency, MetricStatisticType statisticType) { return(this.WithStatistic(duration, frequency, statisticType)); }
/// <summary> /// Sets statistics for autoscale trigger action with default values of 1 minute for frequency(time grain). /// </summary> /// <param name="duration">The range of time in which instance data is collected. This value must be greater than the delay in metric collection, which can vary from resource-to-resource. Must be between 12 hours and 5 minutes.</param> /// <param name="statisticType">The metric statistic type. How the metrics from multiple instances are combined. Possible values include: 'Average', 'Min', 'Max', 'Sum'.</param> /// <return>The next stage of the definition.</return> ScaleRule.Update.IUpdate ScaleRule.Update.IUpdate.WithStatistic(TimeSpan duration, MetricStatisticType statisticType) { return(this.WithStatistic(duration, statisticType)); }
public static string ToSerialString(this MetricStatisticType value) => value switch {
internal static MetricTrigger DeserializeMetricTrigger(JsonElement element) { string metricName = default; Optional <string> metricNamespace = default; string metricResourceUri = default; TimeSpan timeGrain = default; MetricStatisticType statistic = default; TimeSpan timeWindow = default; TimeAggregationType timeAggregation = default; ComparisonOperationType @operator = default; double threshold = default; Optional <IList <ScaleRuleMetricDimension> > dimensions = default; foreach (var property in element.EnumerateObject()) { if (property.NameEquals("metricName")) { metricName = property.Value.GetString(); continue; } if (property.NameEquals("metricNamespace")) { metricNamespace = property.Value.GetString(); continue; } if (property.NameEquals("metricResourceUri")) { metricResourceUri = property.Value.GetString(); continue; } if (property.NameEquals("timeGrain")) { timeGrain = property.Value.GetTimeSpan("P"); continue; } if (property.NameEquals("statistic")) { statistic = property.Value.GetString().ToMetricStatisticType(); continue; } if (property.NameEquals("timeWindow")) { timeWindow = property.Value.GetTimeSpan("P"); continue; } if (property.NameEquals("timeAggregation")) { timeAggregation = property.Value.GetString().ToTimeAggregationType(); continue; } if (property.NameEquals("operator")) { @operator = property.Value.GetString().ToComparisonOperationType(); continue; } if (property.NameEquals("threshold")) { threshold = property.Value.GetDouble(); continue; } if (property.NameEquals("dimensions")) { List <ScaleRuleMetricDimension> array = new List <ScaleRuleMetricDimension>(); foreach (var item in property.Value.EnumerateArray()) { array.Add(ScaleRuleMetricDimension.DeserializeScaleRuleMetricDimension(item)); } dimensions = array; continue; } } return(new MetricTrigger(metricName, metricNamespace.Value, metricResourceUri, timeGrain, statistic, timeWindow, timeAggregation, @operator, threshold, Optional.ToList(dimensions))); }
static public Management.Monitor.Management.Models.MetricStatisticType ConvertNamespace(MetricStatisticType operatorType) { int value = (int)operatorType; return((Management.Monitor.Management.Models.MetricStatisticType)value); }