|
| 1 | +locals { |
| 2 | + thresholds = { |
| 3 | + FreeStorageSpaceThreshold = "${max(var.free_storage_space_threshold, 0)}" |
| 4 | + MinimumAvailableNodes = "${max(var.min_available_nodes, 0)}" |
| 5 | + CPUUtilizationThreshold = "${min(max(var.cpu_utilization_threshold, 0), 100)}" |
| 6 | + JVMMemoryPressureThreshold = "${min(max(var.jvm_memory_pressure_threshold, 0), 100)}" |
| 7 | + MasterCPUUtilizationThreshold = "${min(max(coalesce(var.master_cpu_utilization_threshold, var.cpu_utilization_threshold), 0), 100)}" |
| 8 | + MasterJVMMemoryPressureThreshold = "${min(max(coalesce(var.master_jvm_memory_pressure_threshold, var.jvm_memory_pressure_threshold), 0), 100)}" |
| 9 | + } |
| 10 | +} |
| 11 | + |
| 12 | +resource "aws_cloudwatch_metric_alarm" "cluster_status_is_red" { |
| 13 | + count = "${var.monitor_cluster_status_is_red}" |
| 14 | + alarm_name = "${var.alarm_name_prefix}ElasticSearch-ClusterStatusIsRed${var.alarm_name_postfix}" |
| 15 | + comparison_operator = "GreaterThanOrEqualToThreshold" |
| 16 | + evaluation_periods = "1" |
| 17 | + metric_name = "ClusterStatus.red" |
| 18 | + namespace = "AWS/ES" |
| 19 | + period = "60" |
| 20 | + statistic = "Average" |
| 21 | + threshold = "1" |
| 22 | + alarm_description = "Average elasticsearch cluster status is in red over last 5 minutes" |
| 23 | + alarm_actions = ["${local.aws_sns_topic_arn}"] |
| 24 | + ok_actions = ["${local.aws_sns_topic_arn}"] |
| 25 | + |
| 26 | + dimensions { |
| 27 | + DomainName = "${var.domain_name}" |
| 28 | + ClientId = "${data.aws_caller_identity.default.account_id}" |
| 29 | + } |
| 30 | +} |
| 31 | + |
| 32 | +resource "aws_cloudwatch_metric_alarm" "cluster_status_is_yellow" { |
| 33 | + count = "${var.monitor_cluster_status_is_yellow}" |
| 34 | + alarm_name = "${var.alarm_name_prefix}ElasticSearch-ClusterStatusIsYellow${var.alarm_name_postfix}" |
| 35 | + comparison_operator = "GreaterThanOrEqualToThreshold" |
| 36 | + evaluation_periods = "1" |
| 37 | + metric_name = "ClusterStatus.yellow" |
| 38 | + namespace = "AWS/ES" |
| 39 | + period = "60" |
| 40 | + statistic = "Average" |
| 41 | + threshold = "1" |
| 42 | + alarm_description = "Average elasticsearch cluster status is in yellow over last 5 minutes" |
| 43 | + alarm_actions = ["${local.aws_sns_topic_arn}"] |
| 44 | + ok_actions = ["${local.aws_sns_topic_arn}"] |
| 45 | + |
| 46 | + dimensions { |
| 47 | + DomainName = "${var.domain_name}" |
| 48 | + ClientId = "${data.aws_caller_identity.default.account_id}" |
| 49 | + } |
| 50 | +} |
| 51 | + |
| 52 | +resource "aws_cloudwatch_metric_alarm" "free_storage_space_too_low" { |
| 53 | + count = "${var.monitor_free_storage_space_too_low}" |
| 54 | + alarm_name = "${var.alarm_name_prefix}ElasticSearch-FreeStorageSpaceTooLow${var.alarm_name_postfix}" |
| 55 | + comparison_operator = "LessThanOrEqualToThreshold" |
| 56 | + evaluation_periods = "1" |
| 57 | + metric_name = "FreeStorageSpace" |
| 58 | + namespace = "AWS/ES" |
| 59 | + period = "60" |
| 60 | + statistic = "Average" |
| 61 | + threshold = "${local.thresholds["FreeStorageSpaceThreshold"]}" |
| 62 | + alarm_description = "Average elasticsearch free storage space over last 1 minutes is too low" |
| 63 | + alarm_actions = ["${local.aws_sns_topic_arn}"] |
| 64 | + ok_actions = ["${local.aws_sns_topic_arn}"] |
| 65 | + |
| 66 | + dimensions { |
| 67 | + DomainName = "${var.domain_name}" |
| 68 | + ClientId = "${data.aws_caller_identity.default.account_id}" |
| 69 | + } |
| 70 | +} |
| 71 | + |
| 72 | +resource "aws_cloudwatch_metric_alarm" "cluster_index_writes_blocked" { |
| 73 | + count = "${var.monitor_cluster_index_writes_blocked}" |
| 74 | + alarm_name = "${var.alarm_name_prefix}ElasticSearch-ClusterIndexWritesBlocked${var.alarm_name_postfix}" |
| 75 | + comparison_operator = "GreaterThanOrEqualToThreshold" |
| 76 | + evaluation_periods = "1" |
| 77 | + metric_name = "ClusterIndexWritesBlocked" |
| 78 | + namespace = "AWS/ES" |
| 79 | + period = "300" |
| 80 | + statistic = "Average" |
| 81 | + threshold = "1" |
| 82 | + alarm_description = "Elasticsearch index writes being blocker over last 10 minutes" |
| 83 | + alarm_actions = ["${local.aws_sns_topic_arn}"] |
| 84 | + ok_actions = ["${local.aws_sns_topic_arn}"] |
| 85 | + |
| 86 | + dimensions { |
| 87 | + DomainName = "${var.domain_name}" |
| 88 | + ClientId = "${data.aws_caller_identity.default.account_id}" |
| 89 | + } |
| 90 | +} |
| 91 | + |
| 92 | +resource "aws_cloudwatch_metric_alarm" "insufficient_available_nodes" { |
| 93 | + count = "${var.monitor_insufficient_available_nodes}" |
| 94 | + alarm_name = "${var.alarm_name_prefix}ElasticSearch-InsufficientAvailableNodes${var.alarm_name_postfix}" |
| 95 | + comparison_operator = "LessThanOrEqualToThreshold" |
| 96 | + evaluation_periods = "1" |
| 97 | + metric_name = "Nodes" |
| 98 | + namespace = "AWS/ES" |
| 99 | + period = "86400" |
| 100 | + statistic = "Minimum" |
| 101 | + threshold = "${local.thresholds["MinimumAvailableNodes"]}" |
| 102 | + alarm_description = "Elasticsearch nodes minimum < ${local.thresholds["MinimumAvailableNodes"]} for 1 day" |
| 103 | + alarm_actions = ["${local.aws_sns_topic_arn}"] |
| 104 | + ok_actions = ["${local.aws_sns_topic_arn}"] |
| 105 | + |
| 106 | + dimensions { |
| 107 | + DomainName = "${var.domain_name}" |
| 108 | + ClientId = "${data.aws_caller_identity.default.account_id}" |
| 109 | + } |
| 110 | +} |
| 111 | + |
| 112 | +resource "aws_cloudwatch_metric_alarm" "automated_snapshot_failure" { |
| 113 | + count = "${var.monitor_automated_snapshot_failure}" |
| 114 | + alarm_name = "${var.alarm_name_prefix}ElasticSearch-AutomatedSnapshotFailure${var.alarm_name_postfix}" |
| 115 | + comparison_operator = "GreaterThanOrEqualToThreshold" |
| 116 | + evaluation_periods = "1" |
| 117 | + metric_name = "AutomatedSnapshotFailure" |
| 118 | + namespace = "AWS/ES" |
| 119 | + period = "600" |
| 120 | + statistic = "Maximum" |
| 121 | + threshold = "1" |
| 122 | + alarm_description = "Elasticsearch automated snapshot failed over last 10 minutes" |
| 123 | + alarm_actions = ["${local.aws_sns_topic_arn}"] |
| 124 | + ok_actions = ["${local.aws_sns_topic_arn}"] |
| 125 | + |
| 126 | + dimensions { |
| 127 | + DomainName = "${var.domain_name}" |
| 128 | + ClientId = "${data.aws_caller_identity.default.account_id}" |
| 129 | + } |
| 130 | +} |
| 131 | + |
| 132 | +resource "aws_cloudwatch_metric_alarm" "cpu_utilization_too_high" { |
| 133 | + count = "${var.monitor_cpu_utilization_too_high}" |
| 134 | + alarm_name = "${var.alarm_name_prefix}ElasticSearch-CPUUtilizationTooHigh${var.alarm_name_postfix}" |
| 135 | + comparison_operator = "GreaterThanOrEqualToThreshold" |
| 136 | + evaluation_periods = "3" |
| 137 | + metric_name = "CPUUtilization" |
| 138 | + namespace = "AWS/ES" |
| 139 | + period = "900" |
| 140 | + statistic = "Average" |
| 141 | + threshold = "${local.thresholds["CPUUtilizationThreshold"]}" |
| 142 | + alarm_description = "Average elasticsearch cluster CPU utilization over last 10 minutes too high" |
| 143 | + alarm_actions = ["${local.aws_sns_topic_arn}"] |
| 144 | + ok_actions = ["${local.aws_sns_topic_arn}"] |
| 145 | + |
| 146 | + dimensions { |
| 147 | + DomainName = "${var.domain_name}" |
| 148 | + ClientId = "${data.aws_caller_identity.default.account_id}" |
| 149 | + } |
| 150 | +} |
| 151 | + |
| 152 | +resource "aws_cloudwatch_metric_alarm" "jvm_memory_pressure_too_high" { |
| 153 | + count = "${var.monitor_jvm_memory_pressure_too_high}" |
| 154 | + alarm_name = "${var.alarm_name_prefix}ElasticSearch-JVMMemoryPressure${var.alarm_name_postfix}" |
| 155 | + comparison_operator = "GreaterThanOrEqualToThreshold" |
| 156 | + evaluation_periods = "1" |
| 157 | + metric_name = "JVMMemoryPressure" |
| 158 | + namespace = "AWS/ES" |
| 159 | + period = "900" |
| 160 | + statistic = "Maximum" |
| 161 | + threshold = "${local.thresholds["JVMMemoryPressureThreshold"]}" |
| 162 | + alarm_description = "Elasticsearch JVM memory pressure is too high over last 10 minutes" |
| 163 | + alarm_actions = ["${local.aws_sns_topic_arn}"] |
| 164 | + ok_actions = ["${local.aws_sns_topic_arn}"] |
| 165 | + |
| 166 | + dimensions { |
| 167 | + DomainName = "${var.domain_name}" |
| 168 | + ClientId = "${data.aws_caller_identity.default.account_id}" |
| 169 | + } |
| 170 | +} |
| 171 | + |
| 172 | +resource "aws_cloudwatch_metric_alarm" "master_cpu_utilization_too_high" { |
| 173 | + count = "${var.monitor_master_cpu_utilization_too_high}" |
| 174 | + alarm_name = "${var.alarm_name_prefix}ElasticSearch-MasterCPUUtilizationTooHigh${var.alarm_name_postfix}" |
| 175 | + comparison_operator = "GreaterThanOrEqualToThreshold" |
| 176 | + evaluation_periods = "3" |
| 177 | + metric_name = "MasterCPUUtilization" |
| 178 | + namespace = "AWS/ES" |
| 179 | + period = "900" |
| 180 | + statistic = "Average" |
| 181 | + threshold = "${local.thresholds["MasterCPUUtilizationThreshold"]}" |
| 182 | + alarm_description = "Average elasticsearch cluster CPU utilization over last 10 minutes too high" |
| 183 | + alarm_actions = ["${local.aws_sns_topic_arn}"] |
| 184 | + ok_actions = ["${local.aws_sns_topic_arn}"] |
| 185 | + |
| 186 | + dimensions { |
| 187 | + DomainName = "${var.domain_name}" |
| 188 | + ClientId = "${data.aws_caller_identity.default.account_id}" |
| 189 | + } |
| 190 | +} |
| 191 | + |
| 192 | +resource "aws_cloudwatch_metric_alarm" "master_jvm_memory_pressure_too_high" { |
| 193 | + count = "${var.monitor_master_jvm_memory_pressure_too_high}" |
| 194 | + alarm_name = "${var.alarm_name_prefix}ElasticSearch-JVMMemoryPressure${var.alarm_name_postfix}" |
| 195 | + comparison_operator = "GreaterThanOrEqualToThreshold" |
| 196 | + evaluation_periods = "1" |
| 197 | + metric_name = "MasterJVMMemoryPressure" |
| 198 | + namespace = "AWS/ES" |
| 199 | + period = "900" |
| 200 | + statistic = "Maximum" |
| 201 | + threshold = "${local.thresholds["MasterJVMMemoryPressureThreshold"]}" |
| 202 | + alarm_description = "Elasticsearch JVM memory pressure is too high over last 10 minutes" |
| 203 | + alarm_actions = ["${local.aws_sns_topic_arn}"] |
| 204 | + ok_actions = ["${local.aws_sns_topic_arn}"] |
| 205 | + |
| 206 | + dimensions { |
| 207 | + DomainName = "${var.domain_name}" |
| 208 | + ClientId = "${data.aws_caller_identity.default.account_id}" |
| 209 | + } |
| 210 | +} |
0 commit comments