All Products
Search
Document Center

Simple Log Service:Add a filter of the Variable Replacement type

Last Updated:Oct 11, 2024

After NGINX access logs are collected to Simple Log Service, you can execute a query statement in Simple Log Service to query the numbers of page views (PVs) per minute. If you want to query the numbers of PVs per 10 seconds, 60 seconds, or 600 seconds, you must modify the query statement multiple times. To simplify operations, you can add a filter of the Variable Replacement type. This topic describes how to add a filter of the Variable Replacement type to query the numbers of PVs based on NGINX access logs.

Prerequisites

Procedure

The following figure shows the operations that you need to perform to add a filter of the Variable Replacement type.

流程

Step 1: Query and analyze data

To query the numbers of PVs per minute by using a query statement, perform the following operations:

  1. Log on to the Simple Log Service console.

  2. In the Projects section, click the project that you want to manage.

    image

  3. In the left-side navigation pane, click Log Storage. In the Logstores list, click the Logstore that you want to manage.

    image

  4. Enter a query statement in the search box, click Last 15 Minutes, and then specify a query time range.

    In this example, enter the following query statement 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

    The query and analysis results are displayed in a chart.

    查询与分析

Step 2: Add the chart to a dashboard

To add the chart that displays the numbers of PVs per minute to the NGINX Access Log dashboard, perform the following operations:

  1. On the Graph tab, click Add to New Dashboard.

  2. In the Add to New Dashboard dialog box, configure the parameters based on your business requirements and click OK.

    仪表盘

    For more information about the dashboard parameters, see Add a chart (Pro) to a dashboard or Add a chart to a dashboard.

Step 3: Configure a variable

To configure the query time range as a variable, perform the following operations:

  1. In the left-side navigation pane, click the Dashboard icon and then click Dashboards.

  2. In the Dashboard list, click NGINX Access Log.

  3. In the upper-right corner of the NGINX Access Log page, click Edit. Find the chart for which you want to configure a variable and choose 配置监控与告警 > Edit.

  4. Change 60 in the query statement to ${{interval|60}}, click Apply, and then click OK.

    interval is the name of the variable and 60 is the value of the variable. After the variable is configured, you can specify the value of the variable when you add a filter. If you use ${{interval}} to configure the variable, an error is reported when you query and analyze data.

    • The following example shows the original query statement:

      * | SELECT date_format(__time__ - __time__ % 60, '%H:%i:%s') as time, count(1) as count GROUP BY time ORDER BY time
    • The following example shows the query statement after you configure the variable:

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

    For more information about variables, see Variables.设置变量

Step 4: Add a filter

To add a filter by using the variable that you configure, perform the following operations:

  1. In the upper-right corner of the NGINX Access Log page, click the 仪表盘过滤器-过滤器图标 icon.

  2. In the Filter panel, configure the parameters and click OK.

    Note
    • You must set Type to Variable Replacement.

    • You must set Key Value to the variable that you configure in the "Step 3: Configure a variable" section. In this example, set Key Value to interval.

    • In the Static List Items section, you can specify different values for the interval variable.

    过滤器For more information about filter parameters, see Add a filter.

  3. Adjust the filter layout of the page and click Save.

  4. In the Save Dashboard dialog box, click OK.

    The NGINX Access Log dashboard displays the interval filter.

    带过滤器的仪表盘

Step 5: Verify the results

  • In the PV Filter section of the NGINX Access Log page, set interval 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

    The NGINX Access Log dashboard displays the numbers of PVs per 10 seconds.10秒

  • In the PV Filter section of the NGINX Access Log page, set interval 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

    The NGINX Access Log dashboard displays the numbers of PVs per 60 seconds.60秒