tencent cloud

文档反馈

CreateScalingPolicy

最后更新时间:2024-12-03 17:50:46

    1. API Description

    Domain name for API request: as.intl.tencentcloudapi.com.

    This API (CreateScalingPolicy) is used to create an alarm trigger policy.

    A maximum of 20 requests can be initiated per second for this API.

    We recommend you to use API Explorer
    Try it
    API Explorer provides a range of capabilities, including online call, signature authentication, SDK code generation, and API quick search. It enables you to view the request, response, and auto-generated examples.

    2. Input Parameters

    The following request parameter list only provides API request parameters and some common parameters. For the complete common parameter list, see Common Request Parameters.

    Parameter Name Required Type Description
    Action Yes String Common Params. The value used for this API: CreateScalingPolicy.
    Version Yes String Common Params. The value used for this API: 2018-04-19.
    Region Yes String Common Params. For more information, please see the list of regions supported by the product.
    AutoScalingGroupId Yes String Auto scaling group ID.
    ScalingPolicyName Yes String Alarm trigger policy name.
    ScalingPolicyType No String Scaling policy type. Valid values:
  • SIMPLE (default): A simple policy
  • TARGET_TRACKING: A target tracking policy
  • .
    AdjustmentType No String The method to adjust the desired capacity after the alarm is triggered. It’s only available when ScalingPolicyType is Simple. Valid values:
  • CHANGE_IN_CAPACITY: Increase or decrease the desired capacity
  • EXACT_CAPACITY: Adjust to the specified desired capacity
  • PERCENT_CHANGE_IN_CAPACITY: Adjust the desired capacity by percentage
  • AdjustmentValue No Integer Adjustment value for the expected number of instances after an alarm is triggered, which is applicable only to simple policies.
  • When AdjustmentType is set to CHANGE_IN_CAPACITY, a positive value of AdjustmentValue indicates an increase in the number of instances after the alarm is triggered, while a negative value indicates a decrease in the number of instances after the alarm is triggered.
  • When AdjustmentType is set to EXACT_CAPACITY, the value of AdjustmentValue indicates the new desired number of instances after the alarm is triggered. It should be greater than or equal to 0.
  • When AdjustmentType is set to PERCENT_CHANGE_IN_CAPACITY, a positive value of AdjustmentValue indicates an increase in the number of instances by a percentage after the alarm is triggered, while a negative value indicates a decrease in the number of instances by a percentage after the alarm is triggered. Unit: %.
  • Cooldown No Integer Cooldown period (in seconds). This parameter is only applicable to a simple policy. Default value: 300.
    MetricAlarm No MetricAlarm Alarm monitoring metric. It’s only available when ScalingPolicyType is Simple.
    PredefinedMetricType No String Predefined monitoring item, which is applicable only to target tracking policies. Valid values:
  • ASG_AVG_CPU_UTILIZATION: average CPU utilization.
  • ASG_AVG_LAN_TRAFFIC_OUT: average outbound private network bandwidth.
  • ASG_AVG_LAN_TRAFFIC_IN: average inbound private network bandwidth.
  • ASG_AVG_WAN_TRAFFIC_OUT: average outbound public network bandwidth.
  • ASG_AVG_WAN_TRAFFIC_IN: average inbound public network bandwidth.
  • TargetValue No Integer Target value, which is applicable only to target tracking policies.
  • ASG_AVG_CPU_UTILIZATION: value range: [1, 100); unit: %.
  • ASG_AVG_LAN_TRAFFIC_OUT: value range: > 0; unit: Mbps.
  • ASG_AVG_LAN_TRAFFIC_IN: value range: > 0; unit: Mbps.
  • ASG_AVG_WAN_TRAFFIC_OUT: value range: > 0; unit: Mbps.
  • ASG_AVG_WAN_TRAFFIC_IN: value range: > 0; unit: Mbps.
  • EstimatedInstanceWarmup No Integer Instance warm-up period (in seconds). It’s only available when ScalingPolicyType is TARGET_TRACKING. Value range: 0-3600. Default value: 300.
    DisableScaleIn No Boolean Whether to disable scale-in, which is applicable only to target tracking policies. Default value: false. Valid values:
  • true: Target tracking policies trigger only scale-out.
  • false: Target tracking policies trigger both scale-out and scale-in.
  • NotificationUserGroupIds.N No Array of String This parameter is diused. Please use CreateNotificationConfiguration instead.
    Notification group ID, which is the set of user group IDs.

    3. Output Parameters

    Parameter Name Type Description
    AutoScalingPolicyId String Alarm trigger policy ID.
    RequestId String The unique request ID, generated by the server, will be returned for every request (if the request fails to reach the server for other reasons, the request will not obtain a RequestId). RequestId is required for locating a problem.

    4. Example

    Example1 Creating a Simple Policy: Average CPU Utilization

    This example shows you how to increase the expected instance number by 1 when the average CPU utilization exceeds 50% for five consecutive times within 1 minute.

    Input Example

    POST / HTTP/1.1
    Host: as.intl.tencentcloudapi.com
    Content-Type: application/json
    X-TC-Action: CreateScalingPolicy
    <Common request parameters>
    
    {
        "AutoScalingGroupId": "asg-12wjuh0s",
        "Cooldown": "60",
        "ScalingPolicyType": "SIMPLE",
        "ScalingPolicyName": "cpu_policy_test",
        "AdjustmentType": " CHANGE_IN_CAPACITY",
        "MetricAlarm": {
            "Period": "60",
            "ContinuousTime": "5",
            "ComparisonOperator": "GREATER_THAN",
            "Statistic": "AVERAGE",
            "Threshold": "50",
            "MetricName": "CPU_UTILIZATION"
        },
        "NotificationUserGroupIds": [
            "1678"
        ],
        "AdjustmentValue": "1"
    }
    

    Output Example

    {
        "Response": {
            "AutoScalingPolicyId": "asp-iir70sxv",
            "RequestId": "fb02c8bd-5f38-4786-91b6-0c6e06a88832"
        }
    }
    

    Example2 Creating a Simple Policy: Average Memory Utilization

    This example shows you how to decrease the expected instance number by 50% when the average CPU utilization falls below 35% for five consecutive times within 1 minute.

    Input Example

    POST / HTTP/1.1
    Host: as.intl.tencentcloudapi.com
    Content-Type: application/json
    X-TC-Action: CreateScalingPolicy
    <Common request parameters>
    
    {
        "AutoScalingGroupId": "asg-12wjuh0s",
        "Cooldown": "300",
        "ScalingPolicyType": "SIMPLE",
        "ScalingPolicyName": "mem_policy_test",
        "AdjustmentType": " PERCENT_CHANGE_IN_CAPACITY",
        "MetricAlarm": {
            "Period": "60",
            "ContinuousTime": "5",
            "ComparisonOperator": "LESS_THAN",
            "Statistic": "AVERAGE",
            "Threshold": "50",
            "MetricName": "MEM_UTILIZATION"
        },
        "NotificationUserGroupIds": [
            "1678"
        ],
        "AdjustmentValue": "-50"
    }
    

    Output Example

    {
        "Response": {
            "AutoScalingPolicyId": "asp-f59pppuh",
            "RequestId": "116213d6-2269-44cc-af76-c4a8dc7dbdf9"
        }
    }
    

    Example3 Creating a Target Tracking Policy: Average CPU Utilization

    This example shows you how to keep the average CPU utilization of the scaling group close to 60%, how to set the parameter for scale-out instance preheating to 300 after the alarm is triggered, and how to set the disabling scale-in parameter value to false.

    Input Example

    POST / HTTP/1.1
    Host: as.intl.tencentcloudapi.com
    Content-Type: application/json
    X-TC-Action: CreateScalingPolicy
    <Common request parameters>
    
    {
        "AutoScalingGroupId": "asg-9dn1a5y6",
        "ScalingPolicyName": "cpu_target_tracking_test",
        "ScalingPolicyType": "TARGET_TRACKING",
        "PredefinedMetricType": "ASG_AVG_CPU_UTILIZATION",
        "EstimatedInstanceWarmup": 300,
        "DisableScaleIn": false,
        "TargetValue": 60
    }
    

    Output Example

    {
        "Response": {
            "AutoScalingPolicyId": "asp-ljr51ssq",
            "RequestId": "58a8ac17-e864-4bf6-81c7-c5dc63b0057d"
        }
    }
    

    5. Developer Resources

    SDK

    TencentCloud API 3.0 integrates SDKs that support various programming languages to make it easier for you to call APIs.

    Command Line Interface

    6. Error Code

    The following only lists the error codes related to the API business logic. For other error codes, see Common Error Codes.

    Error Code Description
    InternalError.CallMonitorError Monitor API call failed.
    InternalError.CallNotificationError The notification service API call failed.
    InternalError.RequestError An internal request error occurred.
    InvalidParameter.ActionNotFound Invalid Action request.
    InvalidParameterValue.InvalidAutoScalingGroupId Invalid scaling group ID.
    InvalidParameterValue.InvalidNotificationUserGroupId The notification group ID should be a numeric string.
    InvalidParameterValue.LimitExceeded The value exceeds the limit.
    InvalidParameterValue.Range The value is outside the specified range.
    InvalidParameterValue.ScalingPolicyNameDuplicate The alarm policy name already exists.
    InvalidParameterValue.ThresholdOutOfRange The specified threshold must be within the valid range.
    InvalidParameterValue.TooLong Too many values.
    InvalidParameterValue.UserGroupIdNotFound The user group does not exist.
    LimitExceeded.QuotaNotEnough You are short of the quota.
    LimitExceeded.TargetTrackingScalingPolicy Only one target tracking policy can be created for a scaling group.
    ResourceNotFound.AutoScalingGroupNotFound The scaling group does not exist.