After you use Log Service to collect NGINX access logs, you can use a query statement to view the numbers of page views (PVs) per minute. If you want to view the numbers of PVs per 10 seconds, you must modify the query statement. To simplify this operation, you can add a filter of the Replace Variable type on the dashboard. This topic describes how to add a filter of the Replace Variable type to query the numbers of PVs per 10 seconds on the NGINX Access Log dashboard.

Prerequisites

Procedure

The following figure shows how to add the filter of the Replace Variable type on the NGINX Access Log dashboard.

Add a filter of the Replace Variable type

Step 1: Query number of PVs

The following procedure describes how to query the numbers of PVs per minute by using a query statement:

  1. Log on to the Log Service console.
  2. In the Projects section, click the name of the project that you want to view.
  3. Choose Log Storage > Logstores. On the Logstores tab, click the Logstore that you want to view.
  4. Query the numbers of PVs.
    1. In the search box, enter a query statement.

      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

      For more information about query and analysis, see Log search overview and Log analysis overview.

    2. Click 15 Minutes(Relative) to specify a time range for the query.
      You can select a relative time or a time frame, or customize a time range.
      Note The query results may contain logs that are generated 1 minute earlier or later than the specified time range.
    3. Click Search & Analyze.

      The following figure shows the query results.

      visualization_best_practice_variable_query_result

Step 2: Configure a placeholder variable

The following procedure describes how to configure the time range to a placeholder variable:

  1. On the Graph tab, click the Data Source tab.
  2. On the Data Source tab, select the keyword 60 in the query statement and click Generate Variable.
  3. In the Variable Config section, set Variable Name to interval.
    Logservice_visualization_set_variable

Step 3: Add a chart to the dashboard

The following procedure describes how to add a PV chart to the NGINX Access Log dashboard:

  1. On the Graph tab, click Add to New Dashboard.
  2. In the Add to New Dashboard dialog box, configure the following parameters and click OK.
    add_to_new_dashboard_cn
    For more information about dashboard parameters, see Add charts to a dashboard.

Step 4: Add a filter

The following procedure describes how to add a filter by using the placeholder variable that you configure:

  1. In the left navigation sidebar, click the Dashboard icon icon.
  2. In the Dashboard pane, click NGINX Access Log.

    The NGINX Access Log dashboard displays the numbers of PVs per minute.

    nginx access log dashboard cn
  3. In the upper-right corner of the NGINX Access Log page, click Edit. Then, click the Filter icon icon.
  4. In the Filter panel, configure the following parameters and click OK.
    Filter of the Replace Variable type
    For more information about filter parameters, see Add a filter.
  5. Adjust the filter layout on the page and click Save.
  6. In the Save message, click OK.

    The NGINX Access Log dashboard displays the interval filter.

    Dashboard with a filter

Step 5: Verify the results

In the interval section of the NGINX Access Log dashboard, set interval to 10.
Execute the following statement to query the numbers of PVs per 10 seconds:
* | 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.

new interval result cn