|
| 1 | +# coding: utf-8 |
| 2 | +# Copyright (c) 2016, 2025, Oracle and/or its affiliates. All rights reserved. |
| 3 | +# This software is dual-licensed to you under the Universal Permissive License (UPL) 1.0 as shown at https://oss.oracle.com/licenses/upl or Apache License 2.0 as shown at http://www.apache.org/licenses/LICENSE-2.0. You may choose either license. |
| 4 | + |
| 5 | +# This script gives an example on passing in a request model for an API to the pagination call. |
| 6 | + |
| 7 | +# !!! THIS EXAMPLE HAS INFORMATION ABOUT R1 AND IS INTENDED FOR INTERNAL CUSTOMERS. MASK DETAILS FOR PUBLIC VERSION !!! |
| 8 | + |
| 9 | +from datetime import datetime, timedelta, timezone |
| 10 | + |
| 11 | +from oci.auth.signers import InstancePrincipalsSecurityTokenSigner, OauthExchangeTokenSigner |
| 12 | +from oci.monitoring import MonitoringClient, models |
| 13 | + |
| 14 | +metrics_endpoint = "https://telemetry-ingestion.us-ashburn-1.oraclecloud.com" |
| 15 | + |
| 16 | +target_compartment = "" |
| 17 | +root_cert_path = "" |
| 18 | + |
| 19 | +instance_principal_signer = InstancePrincipalsSecurityTokenSigner( |
| 20 | + federation_endpoint='https://auth.us-ashburn-1.oraclecloud.com/v1/x509') |
| 21 | + |
| 22 | +oauth_exchange_signer = OauthExchangeTokenSigner(instance_principal_signer, |
| 23 | + scope=f"monitoring_write_urn-{target_compartment}:instance", |
| 24 | + cert_bundle_verify=root_cert_path, |
| 25 | + target_compartment=target_compartment, |
| 26 | + oauth_token_endpoint="https://auth.region.oraclecloud.com}/v1/oauth2/scoped") |
| 27 | + |
| 28 | +monitoring = MonitoringClient({}, service_endpoint=metrics_endpoint, signer=oauth_exchange_signer) |
| 29 | + |
| 30 | +metric_data = [models.MetricDataDetails( |
| 31 | + namespace="", |
| 32 | + resource_group="", |
| 33 | + compartment_id=target_compartment, |
| 34 | + name="SDKTestMetric", |
| 35 | + dimensions={ |
| 36 | + "resourceId": "exampleDimensionResource" |
| 37 | + }, |
| 38 | + metadata={ |
| 39 | + "unit": "count", |
| 40 | + }, |
| 41 | + datapoints=[ |
| 42 | + { |
| 43 | + "timestamp": ( |
| 44 | + datetime.now(timezone.utc) - timedelta(minutes=5) |
| 45 | + ).strftime('%Y-%m-%dT%H:%M:%S.000Z'), |
| 46 | + "value": 15, |
| 47 | + "count": 1 |
| 48 | + } |
| 49 | + ] |
| 50 | +) for i in range(4)] |
| 51 | +print("Posting metric data....") |
| 52 | + |
| 53 | +post_metric_data_details = models.PostMetricDataDetails( |
| 54 | + metric_data=metric_data, |
| 55 | + batch_atomicity=models.PostMetricDataDetails.BATCH_ATOMICITY_ATOMIC |
| 56 | +) |
| 57 | +post_metric_result = monitoring.post_metric_data(post_metric_data_details) |
| 58 | + |
| 59 | +print("post metrics response status: ", post_metric_result.status) |
| 60 | +print("post metrics response data: ", post_metric_result.data) |
0 commit comments