All Products
Search
Document Center

Simple Log Service:Filter dashboard and statistical chart

Last Updated:Dec 18, 2024

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

1. Add a statistical chart to the dashboard

  1. Add a dashboard.

  2. In edit mode of the target dashboard, click Add > Add New Chart.

  3. On the left side of the page, configure the query time range, Logstore, and query statement. On the right side of the page, select a table. Click Apply at the top of the page to view the chart configuration effect, and then click Confirm to save the chart.

    The query statement for querying the number of PVs per minute is as follows:

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

2. Add a filter of the filter type

  1. In edit mode of the target dashboard, click the 仪表盘过滤器-过滤器图标 icon at the top right of the page.

  2. In the Filter panel, complete the following settings, and then click Confirm.

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

    *|select distinct request_method

    image

    Filter type filter parameter description

    Parameter

    Description

    Name

    The name of the filter.

    Type

    Filter: Create a filter of the filter type to filter by field name and field value. When the filter operation is performed, it is added as a filter condition before the query statement, connected by AND or NOT. The default is AND.

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

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

    Add values in Static List Items. Multiple values can be set.

    Global Filter

    • Enable Global Filter to filter Value across all fields without specifying Key.

    • Disable Global Filter to filter Value only in the specified Key.

    Key Value

    Configure the target field name in Key Value.

    Alias

    The alias of the column.

    Auto Filter

    Enable Auto Filter to automatically filter out values that do not exist in the data source.

    Display Settings

    Set the display style 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 to the filter.

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

    Query Method

    Connect using AND Method or NOT Method.

    Static List Items

    Set the Value corresponding to the Key Value.

    Click + multiple times to add multiple Values. If Default Selected is enabled, the Value is used by default each time the dashboard is opened to perform filtering.

    Add Dynamic List Items

    Turn on the Add Dynamic List Items switch to add dynamic list items, that is, configure dynamic Values for the Key Value. Dynamic list items are the results of the query statement that you specify. The results vary based on the time range that you specify. After turning on the Add Dynamic List Items 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 Filter: After turning on the Inherit Filter switch, the existing filter conditions in the dashboard are inherited when the filter is executed.

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

    • Dynamic List Item Preview: Confirm the query result.

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

3. Verify the result

On the target dashboard page, select GET and PUT in the Request_method drop-down box to query the number of PVs for the 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 type filter

1. Set variables for the query statement of a statistical chart

  1. Add a dashboard.

  2. In edit mode of the target dashboard, click Add > Add New Chart.

  3. On the left side of the page, configure the query time range, Logstore, and query statement with variables. On the right side of the page, select a table. Click Apply at the top of the page to view the chart configuration effect, and then click Confirm to save the chart.

    The query statement for querying the number of PVs at different time intervals is as follows, where ${{interval|60}} represents 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 type filter

  1. In edit mode of the target dashboard, click the 仪表盘过滤器-过滤器图标 icon at the top right of the page.

  2. In the Filter panel, complete the following settings, and then click Confirm.

    Note
    • Key Value must be the variable that you set in the variable setting step. In this example, it is interval.

    • Static List Items are used to configure variable values for different query duration ranges.

    image

    Variable type filter parameter description

    Parameter

    Description

    Name

    The name of the filter.

    Type

    Variable Replacement: Create a variable type filter to specify variables and their values. If the dashboard contains a chart for which the same variable is configured, the variable in the query statement of the chart is replaced with the value that you specify after adding a variable type filter. Configure the variable values in Static List Items. Multiple variable values can be set.

    Key Value

    Configure the variable in Key Value.

    Note

    The chart for which you want to replace the variable must have a placeholder variable set, and it must be the same as the variable configured here.

    Alias

    The alias of the column.

    Display Settings

    Set the display style 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 to the filter.

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

    Display Component Type

    Select the method of component type:

    • Free Input.

    • Drop-down List.

    Static List Items

    Set the Value corresponding to the Key Value.

    Click + multiple times to add multiple Values. If Default Selected is enabled, the Value is used by default each time the dashboard is opened to perform filtering.

    Add Dynamic List Items

    Turn on the Add Dynamic List Items switch to add dynamic list items, that is, configure dynamic Values for the Key Value. Dynamic list items are the results of the query statement that you specify. The results vary based on the time range that you specify. After turning on the Add Dynamic List Items 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 Filter: After turning on the Inherit Filter switch, the existing filter conditions in the dashboard are inherited when the filter is executed.

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

    • Dynamic List Item Preview: Confirm the query result.

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

3. Verify the result

  • On the target dashboard page, set Interval in the PV Filter to 10, representing the query of PVs every 10 seconds.

    The corresponding query statement is as follows:

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

    image

  • On the target dashboard page, set Interval in the PV Filter to 60, representing the query of PVs every 60 seconds.

    The corresponding query statement is as follows:

    * | 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. Access metric data: For example, collect host monitoring data.

  2. Add a filter: After collecting host data, Simple Log Service automatically creates a dashboard named Host Monitoring. In edit mode of Host Monitoring, click the 仪表盘过滤器-过滤器图标 icon at the top right of the page. In the Filter panel, complete the following settings, and then click Confirm.

    image

    Metric filter parameter description

    Parameter

    Description

    Name

    The name of the filter.

    Type

    Metric Filter: Dynamically add Label and Value for filtering. After adding a metric filter, you can manually filter and display the Label and Value of a Metricstore.

    Key Value

    The unique identity of the filter.

    Alias

    The alias of the column.

    Display Settings

    Set the display style 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 to 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 dashboard: In the drop-down list at the top of the dashboard page, select Label and Value.

    image

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

  1. 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 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 variable replacement.

    1. On the right side of the Edit Chart page, select a table for the chart type, and click Variable Replacement > Add Variable Replacement.

      image

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

      变量替换

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

image

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.

image