How to post custom metrics to Oracle Cloud
Prerequisites
- You have the
METRIC_WRITE
policy permission.
Using the CLI
We follow this documentation for the CLI to post our metrics.
The custom metric data that I want to add is first put into this JSON file (met.json) where I classify the custom metrics in a new namespace. As you can see, it contains a number of values and counts across four timestamps. Note that all timestamps must be up to 2 hours into the past and up to 10 minutes into the future.
[
{
"compartmentId": "ocid1.compartment.oc1..aaaaaaaxxxxxxxxx",
"datapoints": [
{
"count": 10,
"timestamp": "2025-06-21T02:32:59+00:00",
"value": 5
},
{
"count": 10,
"timestamp": "2025-06-21T03:02:59+00:00",
"value": 1
},
{
"count": 20,
"timestamp": "2025-06-21T03:02:59+00:00",
"value": 1
},
{
"count": 10,
"timestamp": "2025-06-21T03:30:59+00:00",
"value": 2
}
],
"dimensions": {
"product": "ball",
"country": "NL"
},
"metadata": {
"category": "toys",
"note": "national holiday"
},
"name": "productOrder",
"namespace": "mycustommetricsns"
}
]
And using the CLI, I run this command to push the metrics into the cloud at the correct compartment:
oci monitoring metric-data post --metric-data file:///Users/fdurrani/Downloads/met.json --endpoint https://telemetry-ingestion.us-ashburn-1.oraclecloud.com
Note: you can also insert the entire JSON string into the --metric-data
value
The failed-metrics-count
value returned being 0 means all of our metrics were pushed successfully.
And looking at our Oracle Cloud console in ☰ > Observability & Management > Metrics Explorer, we see the uploaded metrics with mean values of 5, 1, and 2 respectively (since mean = total value ÷ total count within the interval):
References
- Oracle Cloud: Publishing Custom Metrics Using the API
- Medium: OCI Monitoring — Custom Metrics
- Oracle Docs: Monitor disk utilization using Oracle Cloud Infrastructure custom metrics
Safe harbor statement
The information provided on this channel/article/story is solely intended for informational purposes and cannot be used as a part of any contractual agreement. The content does not guarantee the delivery of any material, code, or functionality, and should not be the sole basis for making purchasing decisions. The postings on this site are my own and do not necessarily reflect the views or work of Oracle or Mythics, LLC.
This work is licensed under a Creative Commons Attribution 4.0 International License.