Creating a Query for a Custom Metric

Define a query for a custom metric in Monitoring.

For information about custom metrics, see Publishing Custom Metrics. For query troubleshooting, see Troubleshooting Queries.

  • To create a user-defined query for metric data in the Console, use the Metrics Explorer page.

    These steps show how to create a query in Basic mode. To create a query in Advanced mode (MQL), see Editing the MQL Expression for a Query.

    1. Create a basic query on the Metrics Explorer page.
    2. Select the Compartment that contains the custom metric that you want.
    3. Select the Metric namespace that contains the custom metric that you want.
      Example: mymetricsnamespace
    4. (Optional) Select the Resource group that you want.
      Example: divisionX
    5. Select a Metric name.
      Example: productOrder
    6. (Optional) Update the Interval or Statistic.
      Example: Select 1m for Interval, Sum for Statistic.
    7. To view and update the MQL expression, click Advanced mode.

      The MQL expression is in Query code editor. Example:

      productOrder[1m].sum()
    8. Click Update Chart.
      The chart shows data points for the custom metric, in a graph view. Example:
      Metric streams and values in a graph.
    9. (Optional) To switch to a table view, click Show Data Table.
      The chart shows data points for the custom metric, in a table view.
  • Use the oci monitoring metric-data summarize-metrics-data command and required parameters to query metric data.

    oci monitoring metric-data summarize-metrics-data [OPTIONS]

    The following example uses the --from-json parameter to retrieve custom metric information from a JSON file.

    oci monitoring metric-data summarize-metrics-data [...] --from-json file://./get-metrics.json [OPTIONS]

    For a complete list of flags and variable options for CLI commands, see the Command Line Reference for Monitoring.

    Example JSON file for request

    Compare this file to the example of posted metric data at Publishing Custom Metrics.

    {
      "compartmentId": "$compartmentId",
      "endTime": "2023-01-08T20:00:00+00:00",
      "namespace": "mymetricsnamespace",
      "queryText": "productOrder[1m].sum()",
      "resolution": "5m",
      "resourceGroup": "divisionX",
      "startTime": "2023-01-07T23:00:00+00:00"
    }
    Example response

    This example response includes data points for the resource group division X only (ball product, NL country). Aggregation uses a one-minute interval, resulting in three timestamps.

    Compare this response to the example of posted metric data at Publishing Custom Metrics.

    {
      "data": [
        {
          "aggregated-datapoints": [
            {
              "timestamp": "2023-01-08T09:20:00+00:00",
              "value": 100.0
            },
            {
              "timestamp": "2023-01-08T10:15:00+00:00",
              "value": 110.0
            },
            {
              "timestamp": "2023-01-08T10:25:00+00:00",
              "value": 30.0
            },
          "compartmentId": "$compartmentId",
          "dimensions": {
            "country": "NL",
            "product": "ball"
          },
          "metadata": {
            "category": "toys",
            "note": "national holiday"
          },
          "name": "productOrder",
          "namespace": "mymetricsnamespace",
          "resourceGroup": "divisionX"
        }
      ]
    }
  • Run the SummarizeMetricsData operation to query metric data.