All Products
Search
Document Center

Auto Scaling:Custom monitoring event-triggered tasks

Last Updated:Apr 01, 2026

Custom monitoring event-triggered tasks let Auto Scaling trigger scaling actions based on your own business metrics—not just system-level metrics. To use this feature, report your custom metrics to CloudMonitor, then configure an event-triggered task in Auto Scaling to monitor those metrics and execute scaling rules when thresholds are crossed.

How it works

The end-to-end flow works as follows:

  1. Your application reports business metrics (for example, queue length or active sessions) to CloudMonitor using the API, Java SDK, or Alibaba Cloud command-line interface (CLI).

  2. CloudMonitor processes the data and evaluates your alarm rules.

Prerequisites

Before you begin, ensure that you have:

  • An Auto Scaling group

  • Access to CloudMonitor (to create an application group and alarm rules)

  • Maven installed (if using the Java SDK to report metrics)

Report custom metrics to CloudMonitor

CloudMonitor custom monitoring lets you define your own metrics and alarm rules. The monitoring data you report is processed by CloudMonitor, which generates alarms based on the results.

CloudMonitor supports three reporting methods: API, Java SDK, and CLI. The following example uses the Java SDK.

Step 1: Add the Maven dependencies

Add the following dependencies to your pom.xml:

<dependency>
    <groupId>com.aliyun</groupId>
    <artifactId>aliyun-java-sdk-core</artifactId>
    <version>3.2.6</version>
</dependency>
<dependency>
    <groupId>com.aliyun.openservices</groupId>
    <artifactId>aliyun-cms</artifactId>
    <version>0.2.4</version>
</dependency>

Step 2: Report a custom metric

The following example reports a single custom metric to CloudMonitor. Replace the placeholder values with your actual credentials and metric details.

static String endPoint = "https://metrichub-cms-cn-hangzhou.aliyuncs.com";

CMSClient cmsClient = new CMSClient(endPoint, accAutoScalingKey, accAutoScalingSecret);

CustomMetricUploadRequest request = CustomMetricUploadRequest.builder()
    .append(CustomMetric.builder()
        .setMetricName("myCustomMetric")  // Name of your custom metric
        .setGroupId(54504L)               // Application group ID in CloudMonitor
        .setTime(new Date())              // Timestamp of the data point
        .setType(CustomMetric.TYPE_VALUE) // Report the original (raw) value
        .appendValue(MetricAttribute.VALUE, number) // The raw metric value
        .appendDimension("key1", "value1")          // Add a dimension
        .appendDimension("key2", "value2")
        .build())
    .build();

CustomMetricUploadResponse response = cmsClient.putCustomMetric(request);

The groupId parameter specifies the application group in CloudMonitor. Specify the ID of an existing group, or specify a new ID—CloudMonitor creates the group automatically if it does not exist.

Push custom metrics to an existing application group whenever possible. An application group is a logical grouping of multiple cloud services, and associating your metrics with an existing group gives you more flexibility when configuring alarms across services.

Step 3: Verify the reported data

After reporting data, verify it in the CloudMonitor console:

  1. Go to Application Groups to view the application group and confirm it exists.

  2. Go to Custom Monitoring to see the reported metrics listed in chronological order.

Usage notes

  • CloudMonitor automatically aggregates the monitoring data you report. If you need to report large volumes of data, aggregate it locally before uploading to reduce the number of API calls.

  • Reported monitoring data is subject to limits. For details, see Overview.