All Products
Search
Document Center

CloudMonitor:PutLogMonitor

Last Updated:Jul 26, 2024

Creates or modifies a log monitoring metric.

Operation description

In the example of this topic, the cpu_total log monitoring metric is created. The response shows that the log monitoring metric is created and the metric ID is 16****.

Debugging

OpenAPI Explorer automatically calculates the signature value. For your convenience, we recommend that you call this operation in OpenAPI Explorer.

Authorization information

The following table shows the authorization information corresponding to the API. The authorization information can be used in the Action policy element to grant a RAM user or RAM role the permissions to call this API operation. Description:

  • Operation: the value that you can use in the Action element to specify the operation on a resource.
  • Access level: the access level of each operation. The levels are read, write, and list.
  • Resource type: the type of the resource on which you can authorize the RAM user or the RAM role to perform the operation. Take note of the following items:
    • The required resource types are displayed in bold characters.
    • If the permissions cannot be granted at the resource level, All Resources is used in the Resource type column of the operation.
  • Condition Key: the condition key that is defined by the cloud service.
  • Associated operation: other operations that the RAM user or the RAM role must have permissions to perform to complete the operation. To complete the operation, the RAM user or the RAM role must have the permissions to perform the associated operations.
OperationAccess levelResource typeCondition keyAssociated operation
cms:PutLogMonitorcreate
  • All Resources
    *
    none
none

Request parameters

ParameterTypeRequiredDescriptionExample
LogIdstringNo

The ID of the log monitoring metric.

16****
SlsRegionIdstringYes

The region in which the Simple Log Service project resides.

cn-hangzhou
SlsProjectstringYes

The name of the Simple Log Service project.

test-project
SlsLogstorestringYes

The name of the Simple Log Service Logstore.

test-logstore
MetricNamestringYes

The metric name. For more information about the metrics for cloud services, see Appendix 1: Metrics.

cpu_total
MetricExpressstringNo

The extended field. The extended field allows you to perform basic operations on the aggregation results.

For example, you have calculated TotalNumber and 5XXNumber by aggregating the data. TotalNumber indicates the total number of HTTP requests, and 5XXNumber indicates the number of HTTP requests whose status code is greater than 499. You can calculate the server error rate by adding the following formula to the extended field: 5XXNumber/TotalNumber*100.

JSON format: {"extend":{"errorPercent":"5XXNumber/TotalNumber*100"}}. Description:

  • extend: required.
  • errorPercent: the alias of the field generated in the calculation result. You can specify the alias as needed.
  • 5XXNumber/TotalNumber*100: the calculation expression.
{"extend":{"errorPercent":"5XXNumber/TotalNumber*100"}}
GroupIdstringNo

The ID of the application group.

7301****
ValueFilterRelationstringYes

The logical operator that is used between log filter conditions. Valid values:

  • and
  • or
Note The ValueFilterRelation and ValueFilter.N.Key parameters must be used in pair.
and
TumblingwindowsstringNo

The size of the tumbling window for calculation. Unit: seconds. CloudMonitor performs aggregation for each tumbling window.

60,300
UnitstringNo

The unit.

Percent
Aggregatesarray<object>Yes

The aggregation logic.

objectYes

The aggregation logic.

FieldNamestringYes

The name of the field to be aggregated. Valid values of N: 1 to 10.

sourceCount
FunctionstringYes

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

  • count: counts the number.
  • sum: calculates the total value.
  • avg: calculates the average value.
  • max: calculates the maximum value.
  • min: calculates the minimum value.
  • countps: calculates the number of values of the specified field divided by the total number of seconds within a statistical period.
  • sumps: calculates the sum of the values of the specified field divided by the total number of seconds within a statistical period.
  • distinct: calculates the number of unique values of the specified field within a statistical period.
count
AliasstringYes

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

Count
Groupbysarray<object>No

The dimension based on which the data is grouped. This parameter is equivalent to the GROUP BY clause in SQL statements. If no dimension is specified, all data is aggregated based on the aggregate function.

objectNo
FieldNamestringNo

The name of the field that is specified as the dimension. Valid values of N: 1 to 10.

cpu
AliasstringNo

The alias of the dimension based on which the data is grouped. Valid values of N: 1 to 10.

CPUUtilization
ValueFilterarray<object>No

The condition that is used to filter logs. The ValueFilter and ValueFilterRelation parameters are used in pair. The filter condition is equivalent to the WHERE clause in SQL statements. If no filter condition is specified, all logs are processed. For example, logs contain the Level and Error fields. If you need to calculate the number of times that logs of the Error level appear every minute, you can set the filter condition to Level=Error and count the number of logs that meet this condition.

objectNo
KeystringNo

The name of the log field that is used for matching in the filter condition. Valid values of N: 1 to 10.

lh_source
ValuestringNo

The field value to be matched in the filter condition. Valid values of N: 1 to 10.

test
OperatorstringNo

The method that is used to match 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 parameters

ParameterTypeDescriptionExample
object
Codestring

The HTTP status code.

Note The status code 200 indicates that the request was successful.
200
Messagestring

The returned message.

  • If the request was successful, successful is returned.
  • If the request failed, an error message is returned. Example: alias of aggreate must be set value.
successful
RequestIdstring

The request ID.

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

The ID of the log monitoring metric.

16****
Successboolean

Indicates whether the request was successful. Valid values:

  • true
  • false
true

Examples

Sample success responses

JSONformat

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

Error codes

HTTP status codeError codeError messageDescription
400ParameterInvalid%s-
400LimitorErrorLog monitor limit is not enough-
403AccessForbiddenUser not authorized to operate on the specified resource.-
404ResourceNotFoundThe specified resource is not found.The specified resource is not found.
500InternalErrorThe request processing has failed due to some unknown error.-

For a list of error codes, visit the Service error codes.

Change history

Change timeSummary of changesOperation
No change history