Using groupBy(x) in a Query

Use the optional groupBy(x) element when querying metric data in Monitoring.

Aggregate query results by group to plot a value for each group. This option returns the combined value of all metric streams in each specified group for the selected statistic. Each group's combined value is plotted as a single line on the metric chart. This option is helpful when you want to identify trends by group rather than individual resource.

For query troubleshooting, see Troubleshooting Queries.

Examples

Example 1: Group by Fault Domain
CpuUtilization[1m].groupBy(faultDomain).mean()
Example 2: Group by Resource Group
CpuUtilization[1m].groupBy(resourceGroup).mean()
  • This section describes how to use groupBy(x) on the Metrics Explorer page. groupBy(x) is available in Advanced mode (MQL) only. For alarm query edits, see Creating a Basic Alarm.

    1. Create a basic query on the Metrics Explorer page.
    2. If the query isn't open, open it by clicking Edit queries.
    3. Click Advanced mode.
    4. Edit the text in the Query code editor box.

      The following example MQL expression groups by fault domain:

      CpuUtilization[1m].groupBy(faultDomain).mean()

      The graph from Example Query and Metric Chart now shows three metric streams. Each metric stream corresponds to a fault domain, aggregating all compute instances in that fault domain.

      Metric streams aggregated by fault domain.

    5. Click Update Chart.
  • Use the oci monitoring metric-data summarize-metrics-data command and required parameters to query metric data. Use the --query-text parameter to employ the groupBy(x) element (part of the MQL expression).

    oci monitoring metric-data summarize-metrics-data --query-text <mql_expression> [...]

    For a complete list of parameters and values for CLI commands, see the Command Line Reference for Monitoring.

  • Run the SummarizeMetricsData operation to query metric data. Use the query attribute to employ the groupBy(x) element (part of the MQL expression).