CodexBloom - Programming Q&A Platform

OCI Monitoring: how to to Retrieve Custom Metrics from OCI Monitoring Service with Python SDK

👀 Views: 206 đŸ’Ŧ Answers: 1 📅 Created: 2025-07-15
OCI Python Monitoring

I'm currently trying to integrate custom metrics from the Oracle Cloud Infrastructure (OCI) Monitoring service using the Python SDK, but I'm running into issues retrieving the metrics I created. I have set up the custom metrics in the OCI console, and I can see them listed there, but when I attempt to query these metrics programmatically, I get a `404 Not Found` behavior. Here's the code I'm using to fetch the custom metrics: ```python import oci # Configuration for OCI client config = oci.config.from_file() monitoring_client = oci.monitoring.MonitoringClient(config) namespace = 'my_namespace' metric_name = 'my_custom_metric' compartment_id = 'my_compartment_id' try: metrics_data = monitoring_client.list_metrics(namespace, compartment_id, metric_name=metric_name) for metric in metrics_data.data: print(metric) except oci.exceptions.ServiceError as e: print(f'behavior: {e}') ``` The behavior message I receive is: `oci.exceptions.ServiceError: (404, 'Not Found', 'The requested resource was not found.')`. I have double-checked the namespace and metric name, and they match exactly with what is shown in the OCI console. I've also verified that the compartment ID is correct and that I have the necessary permissions to access the custom metrics. This is the version of the OCI SDK I'm using: ``` oci==2.33.0 ``` I have tried adding some print statements to debug the values of `namespace`, `metric_name`, and `compartment_id`, and they are all correct. However, I still need to retrieve the metrics. Is there something I might be missing in the setup of the custom metrics, or could it be an scenario with the SDK version? Any guidance on how to troubleshoot this further would be greatly appreciated! Any ideas how to fix this?