Variables in a query statement are placeholders in the {{Variable name|Default value}}
format that can be used to dynamically modify the parameters of the query statement. You can specify variables for a query statement to filter data on a chart or dashboard without the need to modify the query statement. This topic describes how to filter data on a chart or dashboard.
Add a filter to filter data on a dashboard
Filter types
Each chart displays the query and analysis results of a query statement. You can add a filter to modify search conditions or replace placeholder variables for all charts on a dashboard to filter data on the dashboard. Simple Log Service provides the following types of filters:
Filters of the Filter type: This type of filter uses the key-value pairs of log fields as filter conditions. A filter of the Filter type searches the results of the specified query statement for logs that contain or do not contain the specified
key-value
pair. For example, you can add a filter of the Filter type to query the number of page views (PVs) for each request method by using dynamic list items.Filters of the Variable Replacement type: This type of filter uses variables as filter conditions. Before you add a filter of the Variable Replacement type, you must specify a variable for the query statements of related charts on your dashboard. After you add the filter, the variable in the query statements of the charts is replaced with the value that you specify for the variable. For example, you can query the numbers of PVs per 10 seconds, 60 seconds, or 600 seconds.
Filters of the Metric Filter type: This type of filter uses labels and values of metrics as filter conditions. After you collect metrics, you can add a filter of the Metric Filter type. You can add multiple filter conditions. The filter conditions are evaluated by using a logical AND.
Filters of the Filter type
Add a filter of the Variable Replacement type
Filters of the Metric Filter type
Configure settings for variable replacement to filter data on a chart
You can configure settings for variable replacement for a chart. After you configure the settings, Simple Log Service adds a filter in the upper-right corner of the chart. This way, you can use the filter to filter data on the chart. The following section describes the operations that you must perform to query the numbers of PVs within different time ranges in a table.
1. Configure settings for variable replacement
On the left side of the Edit Chart page, configure the query time range, Logstore, and query statement for which you want to specify a variable.
The following query statement is executed to query the numbers of PVs within different time ranges.
${{date|60}}
specifies that the name of the variable isdate
and the default value of the variable is 60.* | select __time__ - __time__ % ${{date | 60}} as time, COUNT(*) as pv, avg(request_time) as duration, request_method GROUP BY time, request_method order by time limit 1000
Configure settings for variable replacement
On the right side of the Edit Chart page, select Table Pro in the Chart Types section and choose
in the Variable Replacement section.In the Variable Replacement dialog box, set the Variable Key parameter to data, the Display Name parameter to time, the Display Name parameter below the Variable Values parameter to min and hour, and the Replacement Value parameter to 60 and 3600.
In the upper-right corner of the Edit Chart page, click OK. Then, in the upper-right corner of the dashboard page, click Save. In the Save Dashboard dialog box, click OK.
2. Filter data on the chart
After you configure the settings, a filter appears in the upper-left corner of the chart. If you select a value from the filter drop-down list, Simple Log Service performs a query and analysis operation based on the value that you select. For example, if you select hour, Simple Log Service executes the following query statement:
(*)| select __time__ - __time__ % 3600 as time, COUNT(*) as pv, avg(request_time) as duration, request_method GROUP BY time, request_method order by time limit 1000
Use variables together with interaction occurrences
When you configure an interaction occurrence for a chart, you can also specify a variable. When you click a value on a chart to trigger an interaction occurrence, the system automatically replaces the specified variable with the value. This facilitates data query and analysis. For more information, see Configuration examples.