All Products
Search
Document Center

Simple Log Service:Filter data on a chart or dashboard

Last Updated:Jan 10, 2025

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

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.

    You can 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.

    You can 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 Simple Log Service. For more information, see Collect metric data from hosts.

  2. Add a filter. After the metrics are collected, Simple Log Service 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, you can 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

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

  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, 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 

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