Skip to content

Commit f7a74c7

Browse files
Himanshu Sapraravinitp
authored andcommitted
Added - Support for Stack Monitoring: Metric Extensions
1 parent 24e811f commit f7a74c7

20 files changed

+4404
-0
lines changed
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
// Copyright (c) 2017, 2023, Oracle and/or its affiliates. All rights reserved.
2+
// Licensed under the Mozilla Public License v2.0
3+
4+
variable "tenancy_ocid" {}
5+
variable "user_ocid" {}
6+
variable "fingerprint" {}
7+
variable "private_key_path" {}
8+
variable "region" {}
9+
variable "compartment_ocid" {}
10+
variable "stack_mon_management_agent_id_resource1" {}
11+
variable "stack_mon_hostname_resource1" {}
12+
variable "publish_trigger" {default = false} // setting to false to create DRAFT Metric extension
13+
14+
15+
provider "oci" {
16+
tenancy_ocid = var.tenancy_ocid
17+
user_ocid = var.user_ocid
18+
fingerprint = var.fingerprint
19+
private_key_path = var.private_key_path
20+
region = var.region
21+
}
22+
23+
resource "oci_stack_monitoring_metric_extension" "test_metric_extension_example" {
24+
#Required
25+
compartment_id = var.compartment_ocid
26+
name = "ME_MetricExtensionTerraformExample"
27+
resource_type = "ebs_instance"
28+
display_name = "Count of Running Instances"
29+
collection_recurrences = "FREQ=MINUTELY;INTERVAL=10"
30+
metric_list {
31+
name = "NumberOfUpInstances"
32+
display_name = "NumberOfUpInstances"
33+
is_dimension = false
34+
data_type = "NUMBER"
35+
is_hidden = false
36+
metric_category = "AVAILABILITY"
37+
}
38+
query_properties {
39+
collection_method = "SQL"
40+
sql_type = "STATEMENT"
41+
sql_details {
42+
content = "U0VMRUNUIGNvdW50KGluc3RhbmNlX2lkKSBGUk9NIG1vbml0b3JpbmdfdGFibGUgV0hFUkUgc3RhdHVzID0gJ1VQJyBBTkQgY29tcGFydG1lbnRfdHlwZSA9IDox"
43+
}
44+
in_param_details {
45+
in_param_position = 1
46+
in_param_value = "staging"
47+
}
48+
}
49+
#Optional
50+
description = "Collects count of instances in 'UP' status in staging compartments from monitoring table"
51+
publish_trigger = var.publish_trigger
52+
}
53+
54+
55+
data "oci_stack_monitoring_metric_extension" "test_metric_extension_example" {
56+
#Required
57+
metric_extension_id = oci_stack_monitoring_metric_extension.test_metric_extension_example.id
58+
}
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
// Copyright (c) 2017, 2023, Oracle and/or its affiliates. All rights reserved.
2+
// Licensed under the Mozilla Public License v2.0
3+
4+
variable "tenancy_ocid" {}
5+
variable "user_ocid" {}
6+
variable "fingerprint" {}
7+
variable "private_key_path" {}
8+
variable "region" {}
9+
variable "compartment_ocid" {}
10+
variable "stack_mon_management_agent_id_resource1" {}
11+
variable "stack_mon_hostname_resource1" {}
12+
variable "publish_trigger" {default = true} // setting to true so that enable testing can happen on a published ME
13+
14+
15+
provider "oci" {
16+
tenancy_ocid = var.tenancy_ocid
17+
user_ocid = var.user_ocid
18+
fingerprint = var.fingerprint
19+
private_key_path = var.private_key_path
20+
region = var.region
21+
}
22+
23+
resource "oci_stack_monitoring_metric_extension" "test_metric_extension_on_given_resource" {
24+
#Required
25+
compartment_id = var.compartment_ocid
26+
name = "ME_MetricExtensionEnableTerraformExample"
27+
resource_type = "host_linux"
28+
display_name = "OS File System Utilization"
29+
collection_recurrences = "FREQ=HOURLY;INTERVAL=6"
30+
metric_list {
31+
name = "MountPoint"
32+
is_dimension = true
33+
data_type = "STRING"
34+
is_hidden = false
35+
}
36+
metric_list {
37+
name = "FileSystemSize"
38+
is_dimension = false
39+
data_type = "NUMBER"
40+
is_hidden = true
41+
}
42+
metric_list {
43+
name = "FileSystemUsed"
44+
is_dimension = false
45+
data_type = "NUMBER"
46+
is_hidden = true
47+
}
48+
metric_list {
49+
name = "FileSystemUsage"
50+
display_name = "NumberOfUpInstances"
51+
is_dimension = false
52+
data_type = "NUMBER"
53+
is_hidden = false
54+
metric_category = "UTILIZATION"
55+
unit = "percent"
56+
compute_expression = "(FileSystemUsed / FileSystemSize) * 100"
57+
}
58+
query_properties {
59+
collection_method = "OS_COMMAND"
60+
command = "/bin/bash"
61+
script_details {
62+
name = "fileSystem.sh"
63+
content = "IyEvYmluL2Jhc2gKIyBDb3B5cmlnaHQgKGMpIDIwMjIsIE9yYWNsZSBhbmQvb3IgaXRzIGFmZmlsaWF0ZXMuIEFsbCByaWdodHMgcmVzZXJ2ZWQuCiMKIyBTdGFjayBNb25pdG9yaW5nIC8gSG9zdDogY29sbGVjdCBmaWxlc3lzdGVtIHN0YXRpc3RpY3MgZnJvbSBMaW51eCBob3N0cwojCiMgT3V0cHV0IGZvcm1hdDoKIwojIHJlc3VsdD1tb3VudHxzaXplfHVzZWQKCmV4ZWMgMTA+JjEKZXhlYyAxPiYyCgoKd2hpbGUgcmVhZCAtciBkZXYgc2l6ZSB1c2VkIGF2YWlsIHVzZWRwIG1vdW50IG90aGVyCmRvCiAgICBpZiBbWyAiJHtkZXZ9IiA9fiAvIF1dCiAgICB0aGVuCiAgICAgICAgaWYgWyAiJHt0b3R9IiA9PSAiMCIgXQogICAgICAgIHRoZW4KICAgICAgICAgICAgIyBQcmV2ZW50IGRldmlzaW9uIGJ5IHplcm8KICAgICAgICAgICAgdXNlZD0wCiAgICAgICAgICAgIHVzZWRwPTAKICAgICAgICBmaQoKICAgICAgICBwcmludGYgIm9jaV9yZXN1bHQ9JXN8JXN8JXNcbiIgIiR7bW91bnR9IiAiJHtzaXplfSIgIiR7dXNlZH0iID4mMTAKICAgIGZpCmRvbmUgPCA8KGRmIC1rIDI+L2Rldi9udWxsKQ=="
64+
}
65+
delimiter = "|"
66+
starts_with = "oci_result="
67+
}
68+
#Optional
69+
description = "Computes File System Utilization Percentage of various mount points"
70+
publish_trigger = var.publish_trigger
71+
72+
}
73+
74+
resource "oci_stack_monitoring_monitored_resource" "test_monitored_resource_enable_example" {
75+
#Required
76+
compartment_id = var.compartment_ocid
77+
name = "ResourceMetricExtEnableTerraformExample"
78+
type = "host"
79+
80+
#Optional
81+
display_name = "ResourceMetricExtEnableTerraformExample"
82+
host_name = var.stack_mon_hostname_resource1
83+
management_agent_id = var.stack_mon_management_agent_id_resource1
84+
properties {
85+
name = "osName"
86+
value = "Linux"
87+
}
88+
properties {
89+
name = "osVersion"
90+
value = "7.0"
91+
}
92+
resource_time_zone = "en"
93+
lifecycle {
94+
ignore_changes = [
95+
credentials,
96+
properties,
97+
external_id,
98+
defined_tags]
99+
}
100+
}
101+
102+
resource "oci_stack_monitoring_metric_extension_metric_extension_on_given_resources_management" "test_metric_extension_on_given_resource_management" {
103+
#Required
104+
metric_extension_id = oci_stack_monitoring_metric_extension.test_metric_extension_on_given_resource.id
105+
resource_ids = [
106+
oci_stack_monitoring_monitored_resource.test_monitored_resource_enable_example.id]
107+
enable_metric_extension_on_given_resources = true
108+
}
109+
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
// Copyright (c) 2017, 2023, Oracle and/or its affiliates. All rights reserved.
2+
// Licensed under the Mozilla Public License v2.0
3+
4+
variable "tenancy_ocid" {}
5+
variable "user_ocid" {}
6+
variable "fingerprint" {}
7+
variable "private_key_path" {}
8+
variable "region" {}
9+
variable "compartment_ocid" {}
10+
variable "stack_mon_management_agent_id_resource1" {}
11+
variable "stack_mon_hostname_resource1" {}
12+
13+
14+
provider "oci" {
15+
tenancy_ocid = var.tenancy_ocid
16+
user_ocid = var.user_ocid
17+
fingerprint = var.fingerprint
18+
private_key_path = var.private_key_path
19+
region = var.region
20+
}
21+
22+
resource "oci_stack_monitoring_metric_extension" "test_metric_extension_test_management" {
23+
#Required
24+
compartment_id = var.compartment_ocid
25+
name = "ME_MetricExtensionTestTerraformExample"
26+
resource_type = "host_linux"
27+
display_name = "OS File System Utilization"
28+
collection_recurrences = "FREQ=HOURLY;INTERVAL=6"
29+
metric_list {
30+
name = "MountPoint"
31+
is_dimension = true
32+
data_type = "STRING"
33+
is_hidden = false
34+
}
35+
metric_list {
36+
name = "FileSystemSize"
37+
is_dimension = false
38+
data_type = "NUMBER"
39+
is_hidden = true
40+
}
41+
metric_list {
42+
name = "FileSystemUsed"
43+
is_dimension = false
44+
data_type = "NUMBER"
45+
is_hidden = true
46+
}
47+
metric_list {
48+
name = "FileSystemUsage"
49+
display_name = "NumberOfUpInstances"
50+
is_dimension = false
51+
data_type = "NUMBER"
52+
is_hidden = false
53+
metric_category = "UTILIZATION"
54+
unit = "percent"
55+
compute_expression = "(FileSystemUsed / FileSystemSize) * 100"
56+
}
57+
query_properties {
58+
collection_method = "OS_COMMAND"
59+
command = "/bin/bash"
60+
script_details {
61+
name = "fileSystem.sh"
62+
content = "IyEvYmluL2Jhc2gKIyBDb3B5cmlnaHQgKGMpIDIwMjIsIE9yYWNsZSBhbmQvb3IgaXRzIGFmZmlsaWF0ZXMuIEFsbCByaWdodHMgcmVzZXJ2ZWQuCiMKIyBTdGFjayBNb25pdG9yaW5nIC8gSG9zdDogY29sbGVjdCBmaWxlc3lzdGVtIHN0YXRpc3RpY3MgZnJvbSBMaW51eCBob3N0cwojCiMgT3V0cHV0IGZvcm1hdDoKIwojIHJlc3VsdD1tb3VudHxzaXplfHVzZWQKCmV4ZWMgMTA+JjEKZXhlYyAxPiYyCgoKd2hpbGUgcmVhZCAtciBkZXYgc2l6ZSB1c2VkIGF2YWlsIHVzZWRwIG1vdW50IG90aGVyCmRvCiAgICBpZiBbWyAiJHtkZXZ9IiA9fiAvIF1dCiAgICB0aGVuCiAgICAgICAgaWYgWyAiJHt0b3R9IiA9PSAiMCIgXQogICAgICAgIHRoZW4KICAgICAgICAgICAgIyBQcmV2ZW50IGRldmlzaW9uIGJ5IHplcm8KICAgICAgICAgICAgdXNlZD0wCiAgICAgICAgICAgIHVzZWRwPTAKICAgICAgICBmaQoKICAgICAgICBwcmludGYgIm9jaV9yZXN1bHQ9JXN8JXN8JXNcbiIgIiR7bW91bnR9IiAiJHtzaXplfSIgIiR7dXNlZH0iID4mMTAKICAgIGZpCmRvbmUgPCA8KGRmIC1rIDI+L2Rldi9udWxsKQ=="
63+
}
64+
delimiter = "|"
65+
starts_with = "oci_result="
66+
}
67+
#Optional
68+
description = "Computes File System Utilization Percentage of various mount points"
69+
70+
}
71+
72+
resource "oci_stack_monitoring_monitored_resource" "test_monitored_resource_metric_ext_test" {
73+
#Required
74+
compartment_id = var.compartment_ocid
75+
name = "metricExtensionTestTerraformExample"
76+
type = "host"
77+
78+
#Optional
79+
display_name = "metricExtensionTestTerraformExample"
80+
host_name = var.stack_mon_hostname_resource1
81+
management_agent_id = var.stack_mon_management_agent_id_resource1
82+
properties {
83+
name = "osName"
84+
value = "Linux"
85+
}
86+
properties {
87+
name = "osVersion"
88+
value = "7.0"
89+
}
90+
resource_time_zone = "en"
91+
lifecycle {
92+
ignore_changes = [
93+
credentials,
94+
properties,
95+
external_id,
96+
defined_tags]
97+
}
98+
}
99+
100+
resource "oci_stack_monitoring_metric_extensions_test_management" "test_metric_extension_test_management" {
101+
#Required
102+
metric_extension_id = oci_stack_monitoring_metric_extension.test_metric_extension_test_management.id
103+
resource_ids = [
104+
oci_stack_monitoring_monitored_resource.test_monitored_resource_metric_ext_test.id]
105+
}

0 commit comments

Comments
 (0)