Configure a multi-statement query

Updated at:
Copy as MD

A pie chart displays data as proportional slices of a whole. Each slice represents a category, and its size shows the percentage of the total. You can configure a multi-statement query to combine results from multiple query statements into a single pie chart.

Prerequisites

Example

image

  1. Search and analyze data: Query and analyze logs to retrieve and aggregate statistics.

  2. Configure a pie chart: Add multiple query statements, configure a pie chart, and add it to a dashboard.

Step 1: Search and analyze data

  1. Log on to the Simple Log Service console. In the Projects section, click the project you want.

    image

  2. In the navigation pane on the left, click Log Storage. In the Logstore list, click your Logstore.

    image

  3. Enter the following query statement and click Search & Analyze to view the logs.

    * | SELECT request_method, COUNT(*) as c group by request_method

    image

Step 2: Configure a pie chart

1. Add a pie chart

In the navigation pane on the left, choose Dashboard > Dashboards. From the Dashboard list, click your dashboard. In the upper-right corner of the dashboard, click Edit. In edit mode, click Add > Add Chart.

image

2. Configure the multi-statement query

With data merging

  1. Configure queries: On the left side of the Edit Chart page, configure the time range, Logstore, Query A, and Query B, as shown in the following figure. The following query statement is used for both Query A and Query B:

    * | SELECT request_method, COUNT(*) as c group by request_method

    image

  2. Configure data conversion: On the Data Conversion tab on the left side of the Edit Chart page, click Add Conversion > Group By, and then click Add Field. Configure request_method > Group By and c > Calculate > Sum.

    image

  3. General Configurations: On the right side of the Edit Chart page, select General Configurations > Chart Type > image, and then configure the Query and Analysis settings.

    • General Configurations > Query and Analysis Configurations > Category: Categorizes the pie chart by the request_method field.

    • General Configurations > Query and Analysis Configurations > Value Column: Displays the value of each category using the c field.

    image

  4. View the chart.

    image

Without data merging

  1. On the right side of the page, select General Configurations > Chart Type > image. On the left side, configure the query time range, Logstore, and query statement. Then, click Apply at the top of the page to preview the chart.

    • General Configurations > Query and Analysis Configurations > Category: Categorizes the pie chart by the request_method field.

    • General Configurations > Query and Analysis Configurations > Value Column: Displays the value of each category using the c field.

    image

  2. The following figure shows the resulting chart.

    image