Creates or modifies a log monitoring metric.

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. OpenAPI Explorer dynamically generates the sample code of the operation for different SDKs.

Request parameters

Parameter Type Required Example Description
Action String Yes PutLogMonitor

The operation that you want to perform. Set the value to PutLogMonitor.

Aggregates.N.Alias String Yes Count

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

Aggregates.N.FieldName String Yes sourceCount

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

Aggregates.N.Function String Yes count

The function that is used to aggregate the monitoring data of logs within an aggregation 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: selects the maximum value.
  • min: selects the minimum value.
  • countps: calculates the counted number of the specified field divided by the total number of seconds of the aggregation period.
  • sumps: calculates the total value of the specified field divided by the total number of seconds of the aggregation period.
  • distinct: counts the number of logs where the specified field appears within the aggregation period.
MetricName String Yes cpu_total

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

SlsLogstore String Yes test-logstore

The name of the Log Service Logstore.

SlsProject String Yes test-project

The name of the Log Service project.

SlsRegionId String Yes cn-hangzhou

The region in which the Log Service project resides.

ValueFilterRelation String Yes and

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.
LogId String No 16****

The ID of the log monitoring metric.

GroupId String No 7301****

The ID of the application group.

MetricExpress String No null

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

For example, if 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.
Groupbys.N.Alias String No CPUUtilization

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

Groupbys.N.FieldName String No cpu

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

ValueFilter.N.Key String No lh_source

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

ValueFilter.N.Operator String No contain

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
  • >: be greater than
  • <: be less than
  • >=: be greater than or equal to
  • <=: be less than or equal to
ValueFilter.N.Value String No test

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

Tumblingwindows String No 60,300

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

Unit String No Percent

The unit.

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

Response parameters

Parameter Type Example Description
Code String 200

The HTTP status code.

Note The status code 200 indicates that the call is successful.
LogId String 16****

The ID of the log monitoring metric.

Message String successful

The returned message.

  • If the call is successful, the value successful is returned.
  • If the call fails, an error message is returned. Example: alias of aggreate must be set value.
RequestId String 91561287-0802-5F9C-9BDE-404C50D41B06

The ID of the request.

Success Boolean true

Indicates whether the call is successful. Valid values:

  • true: The call is successful.
  • false: The call fails.

Examples

Sample requests

http(s)://[Endpoint]/?Action=PutLogMonitor
&Aggregates.1.Alias=Count
&Aggregates.1.FieldName=sourceCount
&Aggregates.1.Function=count
&MetricName=cpu_total
&SlsLogstore=test-logstore
&SlsProject=test-project
&SlsRegionId=cn-hangzhou
&ValueFilterRelation=and
&<Common request parameters>

Sample success responses

XML format

<PutLogMonitorResponse>
	  <Message>successful</Message>
	  <RequestId>91561287-0802-5F9C-9BDE-404C50D41B06</RequestId>
	  <Code>200</Code>
	  <LogId>16****</LogId>
	  <Success>true</Success>
</PutLogMonitorResponse>

JSON format

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

Error codes

HttpCode Error code Error message Description
404 ResourceNotFound The specified resource is not found. The error message returned because the specified resource is not found.

For a list of error codes, visit the API Error Center.