All Products
Search
Document Center

Simple Log Service:Filter data on a chart or dashboard

Last Updated:Nov 03, 2025

Variables use the syntax ${{variable name|default value}} or ${{variable name|default value|prefix}} to dynamically adjust placeholders in query parameters. By setting these variables, you can filter charts or an entire dashboard without directly modifying query analysis statements. This topic describes how to filter an entire dashboard and individual charts.

Add a filter to filter data on a dashboard

Filter types

Each chart displays the query and analysis results of a query statement. 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 (SLS) 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, 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, 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, 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

1. Add a chart to a dashboard

  1. Add a dashboard. For more information, see Create a dashboard.

  2. In edit mode of the dashboard, choose Add > Add Chart. For more information, see Edit mode.

  3. On the left side of the Edit Chart page, configure the query time range, Logstore, and query statement for the chart. On the right side of the Edit Chart page, select Table Pro in the Chart Types section. After you complete the configuration, click Apply in the upper part of the page to view the configuration effects of the table. Then, click OK in the upper-right corner of the page to save the table.

    The following query statement is executed to query the numbers 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

Add a filter of the Filter type

  1. In edit mode of the dashboard, click the 仪表盘过滤器-过滤器图标 icon in the upper-right corner. For more information, see Edit mode.

  2. In the Filter panel, configure the parameters and click OK. The following table describes the parameters.

    The following sample code provides an example of the query statement that uses dynamic list items:

    *|select distinct request_method

    image

    Parameters for filters of the Filter type

    Parameter

    Description

    Name

    The name of the filter.

    Type

    Filter: the filter of the Filter type. This type of filter uses the key-value pairs of log fields to filter data. When the system filters data, the system adds the specified key-value pairs before a query statement by 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 specify multiple values in the Static List Items field.

    Global Filtering

    • If you want to filter all fields by value, turn on Global Filtering.

    • If you want to filter specific fields by value, turn off Global Filtering.

    Key Value

    The name of the field that you want to use to filter data.

    Alias

    The alias of the key.

    Automatic Filtering

    If you turn on Automatic Filtering, values that do not exist in the data source are automatically filtered out.

    Display Configuration

    The pattern settings of the filter. Valid values:

    • Display Title: adds a title to the filter.

    • Display Border: adds borders to the filter.

    • Display Background: adds a white background to the filter.

    Query Method

    The operator that you want to use to add key-value pairs before a query statement. Valid values: AND Operator and NOT Operator.

    Static List Items

    The value for the key specified in the Key Value field.

    Click the plus sign (+) to add more values for the specified key. If you turn on Select by Default for a value, the value is used to filter data each time you open a dashboard.

    Add Dynamic List Item

    If you turn on Add Dynamic List Item, values are dynamically retrieved for the key specified in the Key Value field. Dynamic list items are the results of the query statement that you specify. The results vary based on the time range that you specify. If you turn on Add Dynamic List Item, you must 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 Filter Condition: If you turn on Inherit Filter Condition, existing filter conditions on the dashboard are used for filtering.

    • Search & Analysis: Enter a query statement and specify a query time range.

    • Dynamic List Item Preview: Preview query and analysis results.

  3. Adjust the filter layout of the page and click Save. In the Save Dashboard dialog box, click OK.

3. Verify the results

On the dashboard page, select GET and PUT from the drop-down list of the request_method filter to query the numbers of PVs for the GET and PUT methods. The following query statement is executed:

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

Add a filter of the Variable Replacement type

1. Specify a variable for the query statement of a chart

  1. Add a dashboard. For more information, see Create a dashboard.

  2. In edit mode of the dashboard, choose Add > Add Chart. For more information, see Edit mode.

  3. 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. On the right side of the Edit Chart page, select Table Pro in the Chart Types section. After you complete the configuration, click Apply in the upper part of the page to view the configuration effects of the table. Then, click OK in the upper-right corner of the page to save the table.

    The following query statement is executed to query the numbers of PVs within different time ranges. ${{interval|60}} specifies that the name of the variable is interval and the default value of the variable is 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 filter of the Variable Replacement type

  1. In edit mode of the dashboard, click the 仪表盘过滤器-过滤器图标 icon in the upper-right corner. For more information, see Edit mode.

  2. In the Filter panel, configure the parameters and click OK. The following table describes the parameters.

    Note
    • You must set the Key Value parameter to the specified variable. In this example, the Key Value parameter is set to interval.

    • You can specify different values for the interval variable in the Static List Items field.

    image

    Parameters for filters of the Variable Replacement type

    Parameter

    Description

    Name

    The name of the filter.

    Type

    Variable Replacement: the filter of the Variable Replacement type. This type of filter uses variables and variable values to filter data. If the dashboard contains a chart for which the same variable is specified, the variable in the query statement of the chart is replaced with the value that you specify. You can specify multiple variable values in the Static List Items field.

    Key Value

    The variable that you want to use to filter data.

    Note

    The placeholder variable must be the same as the variable that you specify in the Key Value field.

    Alias

    The alias of the key.

    Display Configuration

    The pattern settings of the filter. Valid values:

    • Display Title: adds a title to the filter.

    • Display Border: adds borders to the filter.

    • Display Background: adds a white background to the filter.

    Show Component Types

    Valid values:

    • Enter a value

    • Drop-down List

    Static List Items

    The value for the key specified in the Key Value field.

    Click the plus sign (+) to add more values for the specified key. If you turn on Select by Default for a value, the value is used to filter data each time you open a dashboard.

    Add Dynamic List Item

    If you turn on Add Dynamic List Item, values are dynamically retrieved for the key specified in the Key Value field. Dynamic list items are the results of the query statement that you specify. The results vary based on the time range that you specify. If you turn on Add Dynamic List Item, you must 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 Filter Condition: If you turn on Inherit Filter Condition, existing filter conditions on the dashboard are used for filtering.

    • Search & Analysis: Enter a query statement and specify a query time range.

    • Dynamic List Item Preview: Preview query and analysis results.

  3. Adjust the filter layout of the page and click Save. In the Save Dashboard dialog box, click OK.

3. Verify the results

  • In the PV Filter filter of the dashboard page, set the interval parameter to 10 to query the numbers 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

  • In the PV Filter filter of the dashboard page, set the interval parameter to 60 to query the numbers 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

Filters of the Metric Filter type

  1. Collect metrics to SLS. For more information, see Collect metric data from hosts.

  2. Add a filter. After the metrics are collected, SLS automatically creates a dashboard named Host Monitoring. In edit mode of the Host Monitoring dashboard, click the 仪表盘过滤器-过滤器图标 icon in the upper-right corner. For more information, see Edit mode. In the Filter panel, configure the parameters and click OK. The following table describes the parameters.

    image

    Parameters for filters of the Metric Filter type

    Parameter

    Description

    Name

    The name of the filter.

    Type

    Metric Filter: the filter of the Metric Filter type. This type of filter uses labels and values that are dynamically added to filter data. After you add a filter of the Metric Filter type, filter data of a Metricstore by using labels and values.

    Key Value

    The unique identifier of the filter.

    Alias

    The alias of the key.

    Display Configuration

    The pattern settings of the filter. Valid values:

    • Display Title: adds a title to the filter.

    • Display Border: adds borders to the filter.

    • Display Background: adds a white background to the filter.

    Select Project

    The project that you want to query.

    Select Metricstore

    The Metricstore that you want to query.

  3. Filter data on the dashboard: In the upper part of the dashboard page, select a label and a value from the drop-down list.

Configure settings for variable replacement to filter data on a chart

Configure settings for variable replacement for a chart. After you configure the settings, SLS adds a filter in the upper-right corner of the chart. 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

  1. 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 is date 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

    image

  2. Configure settings for variable replacement

    1. On the right side of the Edit Chart page, select Table Pro in the Chart Types section and choose Variable Replacement > AddVariable Replacement in the Variable Replacement section.

      image

    2. 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.

      变量替换

  3. 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, SLS performs a query and analysis operation based on the value that you select. For example, if you select hour, SLS 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 

image

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.

image

Advanced use of variables (using prefixes)

Important

When you filter a dashboard or a chart, you can also use the ${{variable_name|default_value|prefix}} syntax with a prefix.

  • If you do not set a value for the variable, the query uses the default value.

  • If you set a value for the variable, the query statement combines the prefix and the variable value.

Filter a dashboard: HTTP method (http_method) filtering

Variable description

  • 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

    • If the variable is not set: By default, the query analyzes the distribution of errors with a status code of 400 or higher for GET or POST requests. The query statement is:

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

    • If the variable is set to 'DELETE': The query switches to analyze the error status for the DELETE method. The query statement is:

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

Procedure

  1. Configure the chart: In the panel on the left, set the time range, select the logstore, and enter the query statement that contains the variable. In the panel on the right, select Table. Click Apply at the top of the page to preview the chart. Then, click OK to save the chart.

    image

  2. Configure a variable filter: In the Filter panel, add values to the drop-down list for the method_filter variable, as shown in the following figure.

    image

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

    image

Filter a chart: Request time (request_time) threshold filtering

Variable description

  • 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

    • If the variable is not set: By default, the query filters for APIs with a request time greater than 50 ms and sorts them by average request time in descending order. The 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

    • If the variable is set to 1000 ms: The query is adjusted to analyze slow APIs that take longer than 1,000 ms. The query statement 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: In the left panel of the Edit Chart page, set the time range, select the logstore, and enter the query statement that contains the variable.

    image

  2. Configure variable replacement: In the right panel of the Edit Chart page, click Variable Replacement. In the Variable Replacement dialog box, add values to the drop-down list for the slow_query variable, as shown in the following figure.

    image

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

    image