You can create a metric and import logs from Simple Log Service to CloudMonitor based on the metric. After logs are imported from Simple Log Service to CloudMonitor, you can create a dashboard to view the monitoring chart of the metric.
Prerequisites
A project and a Logstore are created in Simple Log Service.
For more information, see Getting Started.
A namespace is created. For more information, see Create a namespace.
Create a metric
Log on to the CloudMonitor console.
In the left-side navigation pane, choose .
Click the Simple Log Service Log Monitoring tab.
On the Metric tab, click Metric Data in the upper-left corner.
In the Business monitoring tasks panel, configure the parameters on the Simple Log Service Log Monitoring tab.
Parameter
Description
Metric Name
The name of the metric for Simple Log Service.
Description
The description of the metric.
Log Service Log
The information about a Logstore in Simple Log Service. Valid values:
Select Logstore Group: Select an existing Logstore group.
Select Logstore: Select a region, a project, and a Logstore.
Select a Logstore and enter a name for the Logstore group in the Save as Logstore Group field. The information about the selected Logstore is stored and added to the Logstore group.
Aggregation Cycle
The statistical period of the metric. Unit: seconds. Valid values: 15 and 60.
NoteThe statistical period of the metric is based on the default timestamp that is specified by Simple Log Service. You cannot configure this parameter.
Statistical Method
The function that is used to aggregate log data of a statistical period. If the value of the specified field is a numeric value, you can use all statistical methods. Otherwise, you can use only the Count and countps methods to aggregate log data. Valid values:
Count: calculates the number of values of the specified field within a statistical period.
Sum: calculates the sum of the values of the specified field within the last minute.
Average: calculates the average of the values of the specified field within a statistical period.
Max: calculates the maximum value of the specified field within a statistical period.
Min: calculates the minimum value of the specified field within a statistical period.
Value: the value of the metric.
sumps: calculates the sum of the values of the specified field divided by the total number of seconds within a statistical period.
countps: calculates the number of 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.
Distribution: calculates the number of logs that meet a specified condition within a statistical period. For example, if you want to calculate the number of HTTP requests whose status code is 5xx within the last minute, set the value range to (499,599]. The value range is a left-open, right-closed interval.
percentile: sorts the values of the specified field in ascending order, and then returns the value that is at the specified percentile within the last minute. For example, if you set the percentile to 0.7 and 30 ms is returned, 70% of requests are processed within 30 milliseconds.
Extended Field
Performs basic operations on calculation results. For example, after you set the Statistical Method parameter to aggregate log data, you specify a field as TotalNumber to calculate the total number of HTTP requests. At the same time, you specify another field as 5xxNumber to calculate the number of HTTP requests whose status code is greater than 499. In this case, you can specify an extended field to calculate the server error rate by using the following formula: 5XXNumber/TotalNumber × 100%.
Log Filter
Filters log data. This parameter is equivalent to the WHERE clause in SQL. For example, if you want to monitor logs in which the value of the level field is ERROR, set the parameter to
level:ERROR
. The filtered log field and value must meet the following criteria:The log field cannot contain Chinese characters.
The log field and value are case-sensitive.
If you select Contain or Do Not Contain as the operator, keyword matching is performed without text segmentation. This is different from full-text indexing in Simple Log Service.
Group-By
The dimension based on which data is aggregated. This parameter is equivalent to the GROUP BY clause in SQL.
Log data is grouped by the specified dimension. If you do not specify a dimension, all data is aggregated based on the specified aggregate function.
For more information, see GROUP BY clause.
Namespace
The name of the namespace.
Tags
The tags of the metric. You can specify the key and value of each tag.
Click OK.
Modify a metric
Log on to the CloudMonitor console.
In the left-side navigation pane, choose .
Click the Simple Log Service Log Monitoring tab.
On the Metric tab, find the metric that you want to modify and click Modify in the Actions column.
In the Business monitoring tasks panel, configure the parameters on the Simple Log Service Log Monitoring tab.
Parameter
Description
Description
The description of the metric.
Aggregation Cycle
The statistical period of the metric. Unit: seconds. Valid values: 15 and 60.
Statistical Method
The function that is used to aggregate log data of a statistical period. If the value of the specified field is a numeric value, you can use all statistical methods. Otherwise, you can use only the Count and countps methods to aggregate log data. Valid values:
Count: calculates the number of values of the specified field within a statistical period.
Sum: calculates the sum of the values of the specified field within the last minute.
Average: calculates the average of the values of the specified field within a statistical period.
Max: calculates the maximum value of the specified field within a statistical period.
Min: calculates the minimum value of the specified field within a statistical period.
Value: the value of the metric.
sumps: calculates the sum of the values of the specified field divided by the total number of seconds within a statistical period.
countps: calculates the number of 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.
Distribution: calculates the number of logs that meet a specified condition within a statistical period. For example, if you want to calculate the number of HTTP requests whose status code is 5xx within the last minute, set the value range to (499,599]. The value range is a left-open, right-closed interval.
percentile: sorts the values of the specified field in ascending order, and then returns the value that is at the specified percentile within the last minute. For example, if you set the percentile to 0.7 and 30 ms is returned, 70% of requests are processed within 30 milliseconds.
Extended Field
Performs basic operations on calculation results. For example, after you set the Statistical Method parameter to aggregate log data, you specify a field as TotalNumber to calculate the total number of HTTP requests. At the same time, you specify another field as 5xxNumber to calculate the number of HTTP requests whose status code is greater than 499. In this case, you can specify an extended field to calculate the server error rate by using the following formula: 5XXNumber/TotalNumber × 100%.
Log Filter
Filters log data. This parameter is equivalent to the WHERE clause in SQL. For example, if you want to monitor logs in which the value of the level field is ERROR, set the parameter to
level:ERROR
. The filtered log field and value must meet the following criteria:The log field cannot contain Chinese characters.
The log field and value are case-sensitive.
If you select Contain or Do Not Contain as the operator, keyword matching is performed without text segmentation. This is different from full-text indexing in Simple Log Service.
Group-By
The dimension based on which data is aggregated. This parameter is equivalent to the GROUP BY clause in SQL.
Log data is grouped by the specified dimension. If you do not specify a dimension, all data is aggregated based on the specified aggregate function.
For more information, see GROUP BY clause.
Tags
The tags of the metric. You can specify the key and value of each tag.
Click OK.
Delete a metric
Log on to the CloudMonitor console.
In the left-side navigation pane, choose .
Click the Simple Log Service Log Monitoring tab.
On the Metric tab, find the metric that you want to delete, click in the Actions column, and then click Delete.
In the Confirm deletion message, click Confirm.
Copy a metric
Log on to the CloudMonitor console.
In the left-side navigation pane, choose .
Click the Simple Log Service Log Monitoring tab.
On the Metric tab, find the metric that you want to copy and click Copy in the Actions column.
In the Business monitoring tasks panel, configure the parameters on the Simple Log Service Log Monitoring tab.
By default, CloudMonitor uses all the parameters of the current metric. You can modify the parameter settings based on your business requirements.
Click OK.
In the message that appears, click Confirm. You are prompted that the metric is created successfully, and it takes several minutes to generate metric data.