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 Using the API. For query troubleshooting, see Troubleshooting Queries.
These steps show how to create a query in Basic mode on the Metrics Explorer page. To create a query in Advanced mode (MQL), see Editing the MQL Expression for a Query.
Use the oci monitoring metric-data summarize-metrics-data command and required parameters to query metric data.
oci monitoring metric-data summarize-metrics-data --compartment-id <compartment_OCID> --namespace <metric_namespace> --query-text <mql_expression>
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 [...]
For a complete list of parameters and values for CLI commands, see the Command Line Reference for Monitoring.
Example JSON file for requestCompare this file to the example of posted metric data at Publishing Custom Metrics Using the API.
{ "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 responseThis 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 Using the API.
{ "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.