From febd8ce295b67c699e915d8161b72249a06b2b49 Mon Sep 17 00:00:00 2001 From: Venugopal Naik Date: Mon, 19 Oct 2020 22:36:26 +1100 Subject: [PATCH 1/4] OCI Monitoring Post Metric example --- examples/javascript/monitoring-post-metric.js | 87 +++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 examples/javascript/monitoring-post-metric.js diff --git a/examples/javascript/monitoring-post-metric.js b/examples/javascript/monitoring-post-metric.js new file mode 100644 index 0000000000..83e1d6976d --- /dev/null +++ b/examples/javascript/monitoring-post-metric.js @@ -0,0 +1,87 @@ +/** + * Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved. + * 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. + */ + + /* @param args Arguments to provide to the example. The following arguments are expected: + * + * Refer https://docs.cloud.oracle.com/en-us/iaas/api/#/en/monitoring/20180401/MetricData/PostMetricData for more details. + */ + +const mt = require("oci-monitoring"); +const common = require("oci-common"); + +const configurationFilePath = "~/.oci/config"; +const configProfile = "DEFAULT"; + +const provider = new common.ConfigFileAuthenticationDetailsProvider( + configurationFilePath, + configProfile +); + +const args = process.argv.slice(1); +console.log(args); +if (args.length !== 2) { + console.error( + "Unexpected number of arguments received. Usage : monitoring-alarm.ts " + ); + process.exit(-1); +} + +const compartmentId = args[1]; + +const monitoringClient = new mt.MonitoringClient({ + authenticationDetailsProvider: provider +}); +monitoringClient.region = common.Region.US_PHOENIX_1; +monitoringClient.endpoint = "https://telemetry-ingestion.us-phoenix-1.oraclecloud.com"; + +(async () => { + try { + + var datenow = new Date(); + var dateutc = new Date(datenow.toUTCString()); + /* The timestamp datapoint format used is defined by RFC3339. + https://docs.cloud.oracle.com/en-us/iaas/api/#/en/monitoring/20180401/datatypes/Datapoint + */ + + const MetricDataDetails = [{ + "namespace": "mushopnamespace", + "resourceGroup": "mushop-rg", + "compartmentId": compartmentId, + "name": "mushop-401-http-error", + "dimensions": { + "appName": "Mushop", + "podName": "mushop-storefront" + }, + "metadata": { + "unit": "count", + "displayName": "MuShop Authorization errors" + }, + "datapoints": [{ + "timestamp": dateutc, + "value": 43, + "count": 43 + } + ] + }] + + const PostMetricDataDetails = { + "metricData" : MetricDataDetails + } + + const PostMetricDataRequest = { + "postMetricDataDetails": PostMetricDataDetails + }; + + const post_response = await monitoringClient.postMetricData(PostMetricDataRequest); + //console.log("Retrieved :" + response.postMetricDataResponseDetails.failedMetricsCount); + + console.log("Successfully posted custom metric with name: %s to namespace: %s in region: %s",MetricDataDetails[0].name,MetricDataDetails[0].namespace,common.Region.US_PHOENIX_1._regionId ) + + } catch (error) { + console.log(" Not able to run post metric monitoring example. Error: " + error); + } +})(); \ No newline at end of file From e319969c53a602e662146d8d12c507c1c0e56efa Mon Sep 17 00:00:00 2001 From: Venugopal Naik Date: Tue, 20 Oct 2020 13:18:41 +1100 Subject: [PATCH 2/4] OCI Monitoring Post Metric TypeScript example --- examples/typescript/monitoring-post-metric.ts | 88 +++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 examples/typescript/monitoring-post-metric.ts diff --git a/examples/typescript/monitoring-post-metric.ts b/examples/typescript/monitoring-post-metric.ts new file mode 100644 index 0000000000..d5e16f0572 --- /dev/null +++ b/examples/typescript/monitoring-post-metric.ts @@ -0,0 +1,88 @@ +/** + * Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved. + * 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. + */ + + /* @param args Arguments to provide to the example. The following arguments are expected: + *
    + *
  • The first argument is the OCID of the compartment.
  • + *
+ * Refer https://docs.cloud.oracle.com/en-us/iaas/api/#/en/monitoring/20180401/MetricData/PostMetricData for more details. + */ + +import mt = require("oci-monitoring"); +import common = require("oci-common"); +import { MetricDataDetails } from "oci-monitoring/lib/model"; + +const configurationFilePath = "~/.oci/config"; +const configProfile = "DEFAULT"; + +const provider: common.ConfigFileAuthenticationDetailsProvider = new common.ConfigFileAuthenticationDetailsProvider( + configurationFilePath, + configProfile +); + +const args = process.argv.slice(1); +console.log(args); +if (args.length !== 2) { + console.error( + "Unexpected number of arguments received. Usage : monitoring-alarm.ts " + ); + process.exit(-1); +} + +const compartmentId: string = args[1]; + +const monitoringClient: mt.MonitoringClient = new mt.MonitoringClient({ + authenticationDetailsProvider: provider +}); +monitoringClient.region = common.Region.US_PHOENIX_1; +monitoringClient.endpoint = "https://telemetry-ingestion.us-phoenix-1.oraclecloud.com"; + +(async () => { + try { + + var datenow = new Date(); + var dateutc = new Date(datenow.toUTCString()); + /* The timestamp datapoint format used is defined by RFC3339. + https://docs.cloud.oracle.com/en-us/iaas/api/#/en/monitoring/20180401/datatypes/Datapoint + */ + + const MetricDataDetails: Array = [{ + namespace: "mushopnamespace", + resourceGroup: "mushop-rg", + compartmentId: compartmentId, + name: "mushop-401-http-error", + dimensions: { + "appName": "Mushop", + "podName": "mushop-storefront" + }, + metadata: { + "unit": "count", + "displayName": "MuShop Authorization errors" + }, + datapoints: [{ + "timestamp": dateutc, + "value": 43, + "count": 43 + } + ] + }] + + const PostMetricDataDetails: mt.models.PostMetricDataDetails = { + metricData : MetricDataDetails + } + + const PostMetricDataRequest: mt.requests.PostMetricDataRequest = { + postMetricDataDetails: PostMetricDataDetails + }; + + const response = await monitoringClient.postMetricData(PostMetricDataRequest); + //console.log("Retrieved :" + response.postMetricDataResponseDetails.failedMetricsCount); + + console.log("Successfully posted custom metric with name: %s to namespace: %s ",MetricDataDetails[0].name,MetricDataDetails[0].namespace ) + + } catch (error) { + console.log(" Not able to run post metric monitoring example. Error: " + error); + } +})(); \ No newline at end of file From 9f5806c41de6e5966f734808d3b7a80d9d57321d Mon Sep 17 00:00:00 2001 From: Venugopal Naik Date: Thu, 22 Oct 2020 10:34:47 +1100 Subject: [PATCH 3/4] Updating json values to generic --- examples/javascript/monitoring-post-metric.js | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/examples/javascript/monitoring-post-metric.js b/examples/javascript/monitoring-post-metric.js index 83e1d6976d..6e2e3bbb7b 100644 --- a/examples/javascript/monitoring-post-metric.js +++ b/examples/javascript/monitoring-post-metric.js @@ -8,6 +8,8 @@ *
  • The first argument is the OCID of the compartment.
  • * * Refer https://docs.cloud.oracle.com/en-us/iaas/api/#/en/monitoring/20180401/MetricData/PostMetricData for more details. + * This example uses phoenix metric endpoint https://telemetry-ingestion.us-phoenix-1.oraclecloud.com + * we can change this to a different region (refer https://docs.cloud.oracle.com/en-us/iaas/api/#/en/monitoring/20180401/). */ const mt = require("oci-monitoring"); @@ -48,22 +50,22 @@ monitoringClient.endpoint = "https://telemetry-ingestion.us-phoenix-1.oracleclou */ const MetricDataDetails = [{ - "namespace": "mushopnamespace", - "resourceGroup": "mushop-rg", + "namespace": "", + "resourceGroup": "", "compartmentId": compartmentId, - "name": "mushop-401-http-error", + "name": "", "dimensions": { - "appName": "Mushop", - "podName": "mushop-storefront" + "appName": "", + "podName": "" }, "metadata": { "unit": "count", - "displayName": "MuShop Authorization errors" + "displayName": "" }, "datapoints": [{ "timestamp": dateutc, - "value": 43, - "count": 43 + "value": "", + "count": "" } ] }] From 666739f8ffcb25d2b768d38f34c26b5154969675 Mon Sep 17 00:00:00 2001 From: Venugopal Naik Date: Thu, 22 Oct 2020 10:38:22 +1100 Subject: [PATCH 4/4] Updating json values to generic --- examples/typescript/monitoring-post-metric.ts | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/examples/typescript/monitoring-post-metric.ts b/examples/typescript/monitoring-post-metric.ts index d5e16f0572..a7fb35d4ac 100644 --- a/examples/typescript/monitoring-post-metric.ts +++ b/examples/typescript/monitoring-post-metric.ts @@ -8,6 +8,8 @@ *
  • The first argument is the OCID of the compartment.
  • * * Refer https://docs.cloud.oracle.com/en-us/iaas/api/#/en/monitoring/20180401/MetricData/PostMetricData for more details. + * This example uses phoenix metric endpoint https://telemetry-ingestion.us-phoenix-1.oraclecloud.com + * we can change this to a different region (refer https://docs.cloud.oracle.com/en-us/iaas/api/#/en/monitoring/20180401/). */ import mt = require("oci-monitoring"); @@ -49,22 +51,22 @@ monitoringClient.endpoint = "https://telemetry-ingestion.us-phoenix-1.oracleclou */ const MetricDataDetails: Array = [{ - namespace: "mushopnamespace", - resourceGroup: "mushop-rg", + namespace: "", + resourceGroup: "", compartmentId: compartmentId, - name: "mushop-401-http-error", + name: "", dimensions: { - "appName": "Mushop", - "podName": "mushop-storefront" + "appName": "", + "podName": "" }, metadata: { "unit": "count", - "displayName": "MuShop Authorization errors" + "displayName": "" }, datapoints: [{ "timestamp": dateutc, - "value": 43, - "count": 43 + "value": "", + "count": "" } ] }]