The syntax format of a variable is ${{variable name|default value}}
. It allows you to dynamically adjust placeholders in query parameters. By setting these variables, you can filter statistical charts or the entire dashboard without directly modifying query statements. This topic describes how to filter the entire dashboard and individual statistical charts.
Add a filter to filter data on a dashboard
Filter type
Each statistical chart is essentially a query statement. Filters are used to batch modify query conditions or replace placeholder variables for all statistical charts on a dashboard, enabling the filtering of data across the entire dashboard. Simple Log Service supports three types of filters:
Filter type filter: Filter by the Key and Value of log fields. In the results of the original query statement, find logs that contain or do not contain
Key:Value
. For example, to query the number of page views (PVs) for each request method, you can add a filter of the Filter type to quickly view through dynamic list items.Variable type filter: First add a variable, then add a filter. The variable in the query statement of the statistical chart is automatically replaced with the variable value that you select. For example, query the number of PVs per 10 seconds, 60 seconds, or 600 seconds.
Metric filter: After collecting metric data, you can filter by Label and Value. Multiple filter conditions take the intersection.
Filter type filter
Variable type filter
Metric filter
Add variable replacement to filter a single statistical chart
You can set Variable Replacement for a single statistical chart. Simple Log Service will add a filter to the upper-left corner of the current statistical chart to filter the single statistical chart. The following steps describe how to configure the table example for querying the number of PVs at different time intervals.
1. Configure variable replacement
On the left side of the Edit Chart page, configure the query time range, Logstore, and query statement with variables.
The query statement for querying the number of PVs at different time intervals is as follows, where
${{date|60}}
represents the variabledate
with a default value of 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 variable replacement.
On the right side of the Edit Chart page, select a table for the chart type, and click
.In the variable replacement dialog box, set the Variable Key to date, the Display Name of the variable to time, and the Display Name of the variable value to min and hour, with corresponding variable values of 60 and 3600.
Click Confirm at the top right of the page, and then click Save at the top right. In the Save Dashboard dialog box, click Confirm.
2. Filter statistical chart
After you configure the settings, a filter appears in the upper-left corner of the chart. If you select a value, Simple Log Service performs a query and analysis operation based on the value that you select. For example, if you select hour, the corresponding query statement is as follows:
(*)| 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 with interaction occurrences
When configuring Interaction Occurrences for a statistical chart, you can set variables so that each time you click the target interaction occurrence, the variable is automatically updated to the value of the triggering event, facilitating corresponding query and analysis. For specific examples, see Configuration example.