All Products
Search
Document Center

Cloud Monitor:PutLogMonitor

Last Updated:Jun 13, 2026

Creates or modifies a log monitoring metric by calling the PutLogMonitor operation.

Operation description

This topic provides an example of how to create a log monitoring metric named cpu_total. The response shows that the log monitoring metric is created. The log monitoring metric ID is 16****.

Try it now

Try this API in OpenAPI Explorer, no manual signing needed. Successful calls auto-generate SDK code matching your parameters. Download it with built-in credential security for local usage.

Test

RAM authorization

The table below describes the authorization required to call this API. You can define it in a Resource Access Management (RAM) policy. The table's columns are detailed below:

  • Action: The actions can be used in the Action element of RAM permission policy statements to grant permissions to perform the operation.

  • API: The API that you can call to perform the action.

  • Access level: The predefined level of access granted for each API. Valid values: create, list, get, update, and delete.

  • Resource type: The type of the resource that supports authorization to perform the action. It indicates if the action supports resource-level permission. The specified resource must be compatible with the action. Otherwise, the policy will be ineffective.

    • For APIs with resource-level permissions, required resource types are marked with an asterisk (*). Specify the corresponding Alibaba Cloud Resource Name (ARN) in the Resource element of the policy.

    • For APIs without resource-level permissions, it is shown as All Resources. Use an asterisk (*) in the Resource element of the policy.

  • Condition key: The condition keys defined by the service. The key allows for granular control, applying to either actions alone or actions associated with specific resources. In addition to service-specific condition keys, Alibaba Cloud provides a set of common condition keys applicable across all RAM-supported services.

  • Dependent action: The dependent actions required to run the action. To complete the action, the RAM user or the RAM role must have the permissions to perform all dependent actions.

Action

Access level

Resource type

Condition key

Dependent action

cms:PutLogMonitor

create

*All Resource

*

None None

Request parameters

Parameter

Type

Required

Description

Example

LogId

string

No

The ID of the log monitoring metric.

16****

SlsRegionId

string

Yes

The region where the Log Service project resides.

cn-hangzhou

SlsProject

string

Yes

The name of the Log Service project.

test-project

SlsLogstore

string

Yes

The name of the Log Service Logstore.

test-logstore

MetricName

string

Yes

The metric name. For information about the metrics supported by CloudMonitor for Alibaba Cloud services, see Cloud service monitoring metrics.

cpu_total

MetricExpress

string

No

The extended field. The extended field provides arithmetic operations on the results of the statistical methods.

For example, if you configure the total number of HTTP status code requests (TotalNumber) and the number of requests with HTTP status codes greater than 499 (5xxNumber) in the statistical methods, you can use the extended field to calculate the server error rate: 5xxNumber/TotalNumber*100.

JSON format: {"extend":{"errorPercent":"5xxNumber/TotalNumber*100"}}. Field description:

  • extend: required.

  • errorPercent: the alias of the new field generated from the calculation result. You can specify a custom name.

  • errorPercent: the calculation expression for existing fields.

{"extend":{"errorPercent":"5XXNumber/TotalNumber*100"}}

GroupId

string

No

The ID of the application group.

7301****

ValueFilterRelation

string

Yes

The logical operator used to combine log filter conditions. Valid values:

  • and

  • or

Note

This parameter must be used together with ValueFilter.N.Key.

and

Tumblingwindows

string

No

The tumbling window size for pre-aggregation. Unit: seconds. CloudMonitor performs an aggregation calculation on the data at the specified interval.

60,300

Unit

string

No

The unit.

Percent

Aggregates

array<object>

Yes

The aggregate function definitions.

object

No

FieldName

string

Yes

The name of the original field for aggregation. Valid values of N: 1 to 10.

sourceCount

Function

string

Yes

The statistical method used to aggregate log data within a statistical period. Valid values of N: 1 to 10. Valid values:

  • count: counts the number of occurrences.

  • sum: calculates the sum.

  • avg: calculates the average.

  • max: returns the maximum value.

  • min: returns the minimum value.

  • countps: calculates the average count per second for the specified field within the statistical period.

  • sumps: calculates the average sum per second for the specified field within the statistical period.

  • distinct: counts the number of occurrences of the specified field after deduplication within the statistical period.

count

Alias

string

Yes

The alias of the aggregate function. Valid values of N: 1 to 10.

Count

Groupbys

array<object>

No

The dimensions used for spatial aggregation. This is equivalent to the Group By clause in SQL, which groups monitoring data by specified dimensions. If no dimension is specified, all monitoring data is aggregated based on the aggregate function.

object

No

FieldName

string

No

The name of the Group By field. Valid values of N: 1 to 10.

cpu

Alias

string

No

The alias of the Group By field. Valid values of N: 1 to 10.

CPUUtilization

ValueFilter

array<object>

No

The filter rules, used together with ValueFilterRelation. This is equivalent to the Where clause in SQL. If this parameter is not specified, all data is processed. For example, if the log contains Level and Error fields and you want to count the number of Error occurrences per minute, you can define the statistical method to sum the Level field with the condition Level=Error.

object

No

Key

string

No

The name of the log field to match. Valid values of N: 1 to 10.

lh_source

Value

string

No

The value of the log field to match. Valid values of N: 1 to 10.

test

Operator

string

No

The matching method for the field value. Valid values of N: 1 to 10. Valid values:

  • contain: contains.

  • notContain: does not contain.

  • >: greater than.

  • <: less than.

  • >=: greater than or equal to.

  • <=: less than or equal to.

contain

For more information about common request parameters, see Common parameters.

Response elements

Element

Type

Description

Example

object

Code

string

The HTTP status code.

Note

200 indicates success.

200

Message

string

The returned message. Results:

  • If the operation is successful, successful is returned.

  • If the operation fails, an error message is returned, such as alias of aggreate must be set value..

successful

RequestId

string

The request ID.

91561287-0802-5F9C-9BDE-404C50D41B06

LogId

string

The ID of the log monitoring metric.

16****

Success

boolean

Indicates whether the operation is successful. Valid values:

  • true: The operation is successful.

  • false: The operation failed.

true

Examples

Success response

JSON format

{
  "Code": "200",
  "Message": "successful",
  "RequestId": "91561287-0802-5F9C-9BDE-404C50D41B06",
  "LogId": "16****",
  "Success": true
}

Error codes

HTTP status code

Error code

Error message

Description

400 ParameterInvalid %s
400 LimitorError Log monitor limit is not enough
500 InternalError The request processing has failed due to some unknown error.
403 AccessForbidden User not authorized to operate on the specified resource.
404 ResourceNotFound The specified resource is not found. The specified resource is not found.

See Error Codes for a complete list.

Release notes

See Release Notes for a complete list.