All Products
Search
Document Center

Simple Log Service:Filter dashboards and charts

Last Updated:Mar 25, 2026

You can use variables to dynamically change values in your queries. Variables use the syntax ${{variable_name|default_value}} or ${{variable_name|default_value|prefix}} to act as placeholders. By defining variables, you can filter data on a single chart or an entire dashboard without modifying the underlying query statement. This topic describes how to filter an entire dashboard and individual charts.

Filter a dashboard

Filter types

Each chart is based on a query statement. You can add a filter to a dashboard to modify query conditions for all charts simultaneously. This lets you refine the data displayed across the entire dashboard. Simple Log Service (SLS) supports the following filter types:

  • Filter: Filters data based on log field key:value pairs. This filter narrows down the results of a query by finding logs that either contain or do not contain a specific key-value pair. For example, to view page views (PVs) for different request methods, you can add a filter with a dynamic list item.

  • Variable replacement: Replaces a placeholder in a query statement with a user-selected value. First, you add a variable to your chart's query statement. Then, you create a filter that provides values for that variable. This lets you dynamically change the query without editing it directly. For example, you can use it to view PVs over different time intervals, such as every 10, 60, or 600 seconds.

  • Metric filter: Filters time-series data based on metric labels and values. After you collect metric data, you can add a metric filter to your dashboard. You can specify multiple conditions, which are combined with a logical AND operation.

Standard filter

1. Add a chart to a dashboard

  1. Create a dashboard.

  2. On the dashboard, enter edit mode and click Add > Add New Chart.

  3. On the left side of the page, configure the time range, Logstore, and query statement. On the right side, select Table. Click Apply to preview the chart, and then click OK to save it.

    The following query statement calculates the number of PVs per minute:

    * | SELECT date_format(__time__ - __time__ % 60, '%H:%i:%s') as time, count(1) as count GROUP BY time ORDER BY time

2. Add the filter

  1. In edit mode on the dashboard, click the 仪表盘过滤器-过滤器图标 icon in the upper-right corner.

  2. In the Filter panel, configure the following settings, and then click OK.

    The following is an example of a query statement used for the dynamic list item preview:

    *|select distinct request_method

    image

    Standard filter parameters

    Parameter

    Description

    Name

    The name of the filter.

    Type

    Filter: Creates a standard filter that uses a field name and value to filter data. When the filter is applied, this condition is added to the beginning of the query statement using the AND or NOT operator. By default, the AND operator is used.

    • AND: value AND [search query] | [sql query]

    • NOT: value NOT [search query] | [sql query]

    You can add multiple values in the Static list items section.

    Global filtering

    • Enable Global filtering to search for the value across all fields without specifying a key.

    • Disable Global filtering to search only within the specified key.

    Key value

    Specify the target field name to use as the key for filtering.

    Alias

    An alias for the filter's display name.

    Automatic filtering

    If you enable Automatic filtering, the filter automatically removes values from its selection list that do not exist in the data source.

    Display settings

    Configure the appearance of the filter.

    • Turn on the Display Title switch to add a title to the filter.

    • Turn on the Display Border switch to add a border around the filter.

    • Turn on the Display Background switch to add a white background to the filter.

    Query method

    The operator used to join the filter condition with the query. Valid values: AND Operator and NOT Operator.

    Static list items

    Define the values for the specified key value.

    Click + to add multiple values. If you enable Select by Default, this value filters data each time the dashboard is opened.

    Add dynamic list item

    Turn on the Add dynamic list item switch to populate the filter's values dynamically from the result of a query statement for the specified key value. The list of values changes based on the selected time range. After you turn on the Add dynamic list item switch, configure the following parameters.

    • Select project: Select the project that you want to query.

    • Select Logstore: Select the Logstore that you want to query.

    • Inherit Filters: If you turn on the Inherit Filters switch, existing filter conditions in the dashboard are inherited when you apply a filter.

    • Query and analysis: Enter the query statement and set the time range.

    • Dynamic list item preview: Preview the query results.

  3. Adjust the page layout, click Save, and then in the Save Dashboard dialog box, click Confirm.

3. Verify the results

On the dashboard, select GET and PUT from the request_method drop-down list to query the PVs for GET and PUT methods. The corresponding query statement is as follows:

(*)and (request_method: GET OR request_method: PUT)| SELECT date_format(__time__ - __time__ % 60, '%H:%i:%s') as time, count(1) as count GROUP BY time ORDER BY time 

image

Variable replacement filter

1. Add a variable to a chart's query statement

  1. Create a dashboard.

  2. On the dashboard, enter edit mode and click Add > Add New Chart.

  3. On the left side of the page, configure the time range, Logstore, and a query statement that includes a variable. On the right side, select Table. Click Apply to preview the chart, and then click OK to save it.

    The query statement to view access PVs at different time intervals is as follows, where ${{interval|60}} defines the variable interval with a default value of 60.

    * | SELECT date_format(__time__ - __time__ % ${{interval|60}}, '%H:%i:%s') as time, count(1) as count GROUP BY time ORDER BY time

    设置变量

2. Add a variable replacement filter

  1. In edit mode on the dashboard, click the 仪表盘过滤器-过滤器图标 icon in the upper-right corner.

  2. In the Filter panel, configure the following settings, and then click OK.

    Note
    • The key value must match the variable name you defined in the query statement. In this example, the key is interval.

    • The Static list items section provides the selectable values for the variable.

    image

    Variable replacement filter parameters

    Parameter

    Description

    Name

    The name of the filter.

    Type

    Variable replacement: Creates a filter that replaces a variable in a query. If a chart on the dashboard contains a placeholder for this variable, its value is automatically replaced with the value you select from this filter. You can configure multiple values in the Static list items section.

    Key value

    Specify the variable name in the Key value field.

    Note

    The chart you want to filter must contain a placeholder for the same variable name.

    Alias

    An alias for the filter's display name.

    Display settings

    Configure the appearance of the filter.

    • Turn on the Display Title switch to add a title to the filter.

    • Turn on the Display Border switch to add a border around the filter.

    • Turn on the Display Background switch to add a white background to the filter.

    Display component type

    Select the component type:

    • Free Input

    • Dropdown List

    Static list items

    Define the values for the specified key value.

    Click + to add multiple values. If you enable Select by Default, this value filters data each time the dashboard is opened.

    Add dynamic list item

    Turn on the Add dynamic list item switch to populate the filter's values dynamically from the result of a query statement for the specified key value. The list of values changes based on the selected time range. After you turn on the Add dynamic list item switch, configure the following parameters.

    • Select project: Select the project that you want to query.

    • Select Logstore: Select the Logstore that you want to query.

    • Inherit Filters: If you turn on the Inherit Filters switch, existing filter conditions in the dashboard are inherited when you apply a filter.

    • Query and analysis: Enter the query statement and set the time range.

    • Dynamic list item preview: Preview the query results.

  3. Adjust the page layout, click Save, and then in the Save Dashboard dialog box, click Confirm.

3. Verify the results

  • On the dashboard, in the PV Filter, set interval to 10. This queries the number of PVs per 10 seconds.

    The following query statement is executed:

    * | SELECT date_format(__time__ - __time__ % 10, '%H:%i:%s') as time, count(1) as count GROUP BY time ORDER BY time

    image

  • On the dashboard, in the PV Filter, set interval to 60. This queries the number of PVs per 60 seconds.

    The following query statement is executed:

    * | SELECT date_format(__time__ - __time__ % 60, '%H:%i:%s') as time, count(1) as count GROUP BY time ORDER BY time

    image

Metric filter

  1. Ingest time-series data. For example, collect host monitoring data.

  2. Add a filter. After you ingest the host data, SLS automatically creates a dashboard named Host Monitoring. In edit mode on the Host Monitoring dashboard, click the 仪表盘过滤器-过滤器图标 icon in the upper-right corner. In the Filter panel, configure the following settings, and then click OK.

    image

    Metric filter parameters

    Parameter

    Description

    Name

    The name of the filter.

    Type

    Metric filter: Dynamically adds labels and values for filtering. After you add a metric filter, you can manually filter a Metricstore by its labels and values.

    Key value

    A unique identifier for the filter.

    Alias

    An alias for the filter's display name.

    Display settings

    Configure the appearance of the filter.

    • Turn on the Display Title switch to add a title to the filter.

    • Turn on the Display Border switch to add a border around the filter.

    • Turn on the Display Background switch to add a white background to the filter.

    Select project

    Select the project that you want to query.

    Select Metricstore

    Select the Metricstore that you want to query.

  3. Filter data on the dashboard. From the drop-down lists at the top of the dashboard, select a label and value.

    image

Filter a chart with variable replacement

You can apply variable replacement to a single chart. SLS adds a filter to the upper-left corner of the chart, allowing you to filter its data independently. The following example shows how to configure a table to display PVs over different time intervals.

1. Configure variable replacement

  1. On the chart editing page, configure the time range, Logstore, and a query statement that contains a variable.

    The query statement to view page views (PV) at different time intervals is as follows, where ${{date|60}} sets the variable date 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

    image

  2. Configure the variable replacement settings.

    1. On the right side of the chart editing page, select Table as the chart type, and then click Variable replacement > Add variable replacement.

      image

    2. In the Variable replacement dialog box, set Variable key to date and Display Name to Time. Then, define the values. For example, create two options with the Display Name values min and hour and corresponding variable values of 60 and 3600.

      变量替换

  3. In the upper-right corner of the page, click OK. Then, click Save. In the Save Dashboard dialog box, click Confirm.

2. Filter the chart

After you save the settings, a filter appears in the upper-left corner of the chart. When you select a value, SLS runs the query with the new value. For example, if you select hour, the executed query is:

(*)| 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 

image

Use variables with interaction events

When you configure an interaction event for a chart, you can set a variable. When you click a value on the chart that triggers the event, the variable automatically updates to that value. This lets you link charts and perform further analysis. For an example, see Configuration examples.

image

Advanced use of variables with a prefix

Important

When filtering a dashboard or chart, you can use the ${{variable_name|default_value|prefix}} syntax to include a prefix.

  • If no value is selected for the variable, the query uses the default value.

  • If a value is selected, the query combines the prefix and the selected value.

Filter a dashboard by HTTP method (http_method)

Variable format

  • Variable format: ${{method_filter|http_method in ('GET','POST')|http_method =}}

  • Query statement: (*)|select status, count(1) as err_count where ${{method_filter|request_method in ('GET','POST')|request_method =}} and status>=400 group by status

    • When no variable value is set: The query calculates the error distribution for GET and POST requests with a status code of 400 or higher. The executed query statement is:

      (*)|select status, count(1) as err_count where request_method in ('GET','POST') and status>=400 group by status

    • When the variable value is set to 'DELETE': The query analyzes the error status for the DELETE method. The executed query is:

      (*)| select status, count(1) as err_count where request_method ='DELETE' and status>=400 group by status

Procedure

  1. Configure the chart: On the left side of the page, configure the time range, Logstore, and a query statement that contains the variable. On the right side, select a chart type. Click Apply to preview the chart, and then click OK to save it.

    image

  2. Configure the variable filter: In the Filter panel, add selectable values for the method_filter variable, as shown in the following figure.

    image

  3. Filter the dashboard: Click the filter and select DELETE. The dashboard updates based on the following query statement: (*)| select status, count(1) as err_count where request_method ='DELETE' and status>=400 group by status

    image

Filter a chart by request_time threshold

Variable format

  • Variable format: ${{slow_query|request_time>50|request_time>}}

  • Query statement: (*)| select request_uri, avg(request_time) as avg_time where ${{slow_query|request_time>50|request_time>}} group by request_uri order by avg_time desc

    • When no variable value is set: The query filters for APIs with a request time greater than 50 ms and sorts them by average request time in descending order. The executed query statement is:

      (*)| select request_uri, avg(request_time) as avg_time where request_time>50 group by request_uri order by avg_time desc

    • When the variable value is set to 1000ms: The query analyzes slow APIs that take longer than 1,000 ms. The executed query is: (*)| select request_uri, avg(request_time) as avg_time where request_time>1000 group by request_uri order by avg_time desc

Procedure

  1. Configure the chart: On the chart editing page, configure the time range, Logstore, and a query statement that contains the variable.

    image

  2. Configure variable replacement: On the right side of the chart editing page, click Variable replacement. In the Variable replacement dialog box, add selectable values for the slow_query variable, as shown in the following figure.

    image

  3. Filter the chart: Click the filter in the upper-left corner of the chart. When you select 1000ms, the chart displays statistics using the following query: (*)| select request_uri, avg(request_time) as avg_time where request_time>1000 group by request_uri order by avg_time desc

    image