From c5b384d8b50d4b6985b743d0dde618922d663417 Mon Sep 17 00:00:00 2001 From: Guillaume Kerivel Date: Fri, 8 Jun 2018 17:13:00 +0200 Subject: [PATCH 01/10] MON-122 Add Aurora replica lag monitor (mysql and postgresql) and update rds free space monitor --- cloud/aws/rds/README.md | 63 ++++++++++++--------- cloud/aws/rds/inputs.tf | 77 ++++++++++++------------- cloud/aws/rds/monitors-rds.tf | 102 +++++++++++++++++++++++++++++----- 3 files changed, 161 insertions(+), 81 deletions(-) diff --git a/cloud/aws/rds/README.md b/cloud/aws/rds/README.md index 38a67e9..fd61eb7 100644 --- a/cloud/aws/rds/README.md +++ b/cloud/aws/rds/README.md @@ -1,59 +1,70 @@ -# CLOUD AWS RDS DataDog monitors +AWS RDS Instance DataDog monitors +================================= -## How to use this module +How to use this module +---------------------- + +For a single RDS instance : ``` -module "datadog-monitors-cloud-aws-rds" { +module "datadog-monitors-aws-rds" { source = "git::ssh://git@bitbucket.org/morea/terraform.feature.datadog.git//cloud/aws/rds?ref={revision}" - environment = "${var.environment}" message = "${module.datadog-message-alerting.alerting-message}" + environment = "${var.environment}" } - ``` -## Purpose +For a RDS Aurora cluster : -Creates DataDog monitors with the following checks: +``` +module "datadog-monitors-aws-rds-aurora" { + source = "git::ssh://git@bitbucket.org/morea/terraform.feature.datadog.git//cloud/aws/rds?ref={revision}" -- RDS instance CPU high -- RDS instance free space + message = "${module.datadog-message-alerting.alerting-message}" + environment = "${var.environment}" -## Inputs + aurora_cluster_type = "mysql" # if Aurora cluster Mysql. Else "postgresql" if Aurora cluster PostgreSQL. +} +``` + +Purpose +------- +Creates a DataDog monitors with the following checks : + +* CPU High +* Free disk space low (only for single RDS instances) +* Aurora Replica Lag (only for Aurora Cluster Mysql or PostgreSQL) + +Inputs +------ | Name | Description | Type | Default | Required | |------|-------------|:----:|:-----:|:-----:| -| cpu_enabled | Flag to enable RDS CPU usage monitor | string | `true` | no | -| cpu_extra_tags | Extra tags for RDS CPU usage monitor | list | `` | no | +| aurora_cluster_type | RDS Aurora cluster monitoring. If empty, single RDS instance monitoring. [available values: `mysql`, `postgresql`] | string | `` | no | +| aurora_replicalag_message | Custom message for RDS Aurora replica lag monitor | string | `` | no | +| aurora_replicalag_silenced | Groups to mute for RDS Aurora replica lag monitor | map | `` | no | +| aurora_replicalag_threshold_critical | Aurora replica lag in milliseconds (critical threshold) | string | `200` | no | +| aurora_replicalag_threshold_warning | Aurora replica lag in milliseconds (warning threshold) | string | `100` | no | +| aurora_replicalag_timeframe | Monitor timeframe for RDS Aurora replica lag monitor [available values: `last_#m` (1, 5, 10, 15, or 30), `last_#h` (1, 2, or 4), or `last_1d`] | string | `last_5m` | no | | cpu_message | Custom message for RDS CPU usage monitor | string | `` | no | | cpu_silenced | Groups to mute for RDS CPU usage monitor | map | `` | no | | cpu_threshold_critical | CPU usage in percent (critical threshold) | string | `90` | no | | cpu_threshold_warning | CPU usage in percent (warning threshold) | string | `80` | no | -| cpu_time_aggregator | Monitor aggregator for RDS CPU usage [available values: min, max or avg] | string | `min` | no | | cpu_timeframe | Monitor timeframe for RDS CPU usage [available values: `last_#m` (1, 5, 10, 15, or 30), `last_#h` (1, 2, or 4), or `last_1d`] | string | `last_15m` | no | -| diskspace_enabled | Flag to enable RDS free diskspace monitor | string | `true` | no | -| diskspace_extra_tags | Extra tags for RDS free diskspace monitor | list | `` | no | +| delay | Delay in seconds for the metric evaluation | string | `900` | no | | diskspace_message | Custom message for RDS free diskspace monitor | string | `` | no | | diskspace_silenced | Groups to mute for RDS free diskspace monitor | map | `` | no | | diskspace_threshold_critical | Disk free space in percent (critical threshold) | string | `10` | no | | diskspace_threshold_warning | Disk free space in percent (warning threshold) | string | `20` | no | -| diskspace_time_aggregator | Monitor aggregator for RDS free diskspace [available values: min, max or avg] | string | `min` | no | | diskspace_timeframe | Monitor timeframe for RDS free diskspace [available values: `last_#m` (1, 5, 10, 15, or 30), `last_#h` (1, 2, or 4), or `last_1d`] | string | `last_15m` | no | | environment | Architecture Environment | string | - | yes | -| evaluation_delay | Delay in seconds for the metric evaluation | string | `900` | no | | filter_tags_custom | Tags used for custom filtering when filter_tags_use_defaults is false | string | `*` | no | | filter_tags_use_defaults | Use default filter tags convention | string | `true` | no | | message | Message sent when an alert is triggered | string | - | yes | -| new_host_delay | Delay in seconds before monitor new resource | string | `300` | no | -## Outputs - -| Name | Description | -|------|-------------| -| rds_cpu_90_15min_id | id for monitor rds_cpu_90_15min | -| rds_free_space_low_id | id for monitor rds_free_space_low | - -## Related documentation +Related documentation +--------------------- DataDog documentation: [https://docs.datadoghq.com/integrations/amazon_rds/](https://docs.datadoghq.com/integrations/amazon_rds/) diff --git a/cloud/aws/rds/inputs.tf b/cloud/aws/rds/inputs.tf index 54cf425..75cdbd3 100644 --- a/cloud/aws/rds/inputs.tf +++ b/cloud/aws/rds/inputs.tf @@ -5,16 +5,11 @@ variable "environment" { } # Global DataDog -variable "evaluation_delay" { +variable "delay" { description = "Delay in seconds for the metric evaluation" default = 900 } -variable "new_host_delay" { - description = "Delay in seconds before monitor new resource" - default = 300 -} - variable "message" { description = "Message sent when an alert is triggered" } @@ -29,6 +24,12 @@ variable "filter_tags_custom" { default = "*" } +variable "aurora_cluster_type" { + description = "RDS Aurora cluster monitoring. If empty, single RDS instance monitoring. [available values: `mysql`, `postgresql`]" + type = "string" + default = "" +} + # AWS RDS instance specific variable "cpu_silenced" { @@ -37,30 +38,12 @@ variable "cpu_silenced" { default = {} } -variable "cpu_enabled" { - description = "Flag to enable RDS CPU usage monitor" - type = "string" - default = "true" -} - -variable "cpu_extra_tags" { - description = "Extra tags for RDS CPU usage monitor" - type = "list" - default = [] -} - variable "cpu_message" { description = "Custom message for RDS CPU usage monitor" type = "string" default = "" } -variable "cpu_time_aggregator" { - description = "Monitor aggregator for RDS CPU usage [available values: min, max or avg]" - type = "string" - default = "min" -} - variable "cpu_timeframe" { description = "Monitor timeframe for RDS CPU usage [available values: `last_#m` (1, 5, 10, 15, or 30), `last_#h` (1, 2, or 4), or `last_1d`]" type = "string" @@ -83,30 +66,12 @@ variable "diskspace_silenced" { default = {} } -variable "diskspace_enabled" { - description = "Flag to enable RDS free diskspace monitor" - type = "string" - default = "true" -} - -variable "diskspace_extra_tags" { - description = "Extra tags for RDS free diskspace monitor" - type = "list" - default = [] -} - variable "diskspace_message" { description = "Custom message for RDS free diskspace monitor" type = "string" default = "" } -variable "diskspace_time_aggregator" { - description = "Monitor aggregator for RDS free diskspace [available values: min, max or avg]" - type = "string" - default = "min" -} - variable "diskspace_timeframe" { description = "Monitor timeframe for RDS free diskspace [available values: `last_#m` (1, 5, 10, 15, or 30), `last_#h` (1, 2, or 4), or `last_1d`]" type = "string" @@ -122,3 +87,31 @@ variable "diskspace_threshold_critical" { description = "Disk free space in percent (critical threshold)" default = "10" } + +variable "aurora_replicalag_silenced" { + description = "Groups to mute for RDS Aurora replica lag monitor" + type = "map" + default = {} +} + +variable "aurora_replicalag_message" { + description = "Custom message for RDS Aurora replica lag monitor" + type = "string" + default = "" +} + +variable "aurora_replicalag_timeframe" { + description = "Monitor timeframe for RDS Aurora replica lag monitor [available values: `last_#m` (1, 5, 10, 15, or 30), `last_#h` (1, 2, or 4), or `last_1d`]" + type = "string" + default = "last_5m" +} + +variable "aurora_replicalag_threshold_warning" { + description = "Aurora replica lag in milliseconds (warning threshold)" + default = "100" +} + +variable "aurora_replicalag_threshold_critical" { + description = "Aurora replica lag in milliseconds (critical threshold)" + default = "200" +} diff --git a/cloud/aws/rds/monitors-rds.tf b/cloud/aws/rds/monitors-rds.tf index 3168194..2c30ed0 100644 --- a/cloud/aws/rds/monitors-rds.tf +++ b/cloud/aws/rds/monitors-rds.tf @@ -1,14 +1,21 @@ +data "template_file" "filter" { + template = "$${filter}" + + vars { + filter = "${var.filter_tags_use_defaults == "true" ? format("dd_monitoring:enabled,dd_aws_rds:enabled,env:%s", var.environment) : "${var.filter_tags_custom}"}" + } +} + ### RDS instance CPU monitor ### resource "datadog_monitor" "rds_cpu_90_15min" { - count = "${var.cpu_enabled ? 1 : 0}" name = "[${var.environment}] RDS instance CPU high {{#is_alert}}{{{comparator}}} {{threshold}}% ({{value}}%){{/is_alert}}{{#is_warning}}{{{comparator}}} {{warn_threshold}}% ({{value}}%){{/is_warning}}" message = "${coalesce(var.cpu_message, var.message)}" type = "metric alert" query = < ${var.cpu_threshold_critical} EOF @@ -18,31 +25,30 @@ EOF } notify_no_data = true - evaluation_delay = "${var.evaluation_delay}" + evaluation_delay = "${var.delay}" notify_audit = false timeout_h = 0 include_tags = true locked = false require_full_window = false - new_host_delay = "${var.new_host_delay}" + new_host_delay = "${var.delay}" silenced = "${var.cpu_silenced}" - tags = ["env:${var.environment}", "type:cloud", "provider:aws", "resource:rds", "team:claranet", "created-by:terraform", "${var.cpu_extra_tags}"] + tags = ["env:${var.environment}", "resource:rds", "team:aws", "provider:aws"] } ### RDS instance free space monitor ### resource "datadog_monitor" "rds_free_space_low" { - count = "${var.diskspace_enabled ? 1 : 0}" name = "[${var.environment}] RDS instance free space {{#is_alert}}{{{comparator}}} {{threshold}}% ({{value}}%){{/is_alert}}{{#is_warning}}{{{comparator}}} {{warn_threshold}}% ({{value}}%){{/is_warning}}" message = "${coalesce(var.diskspace_message, var.message)}" type = "metric alert" query = < ${var.aurora_replicalag_threshold_critical} +EOF + + thresholds { + warning = "${var.aurora_replicalag_threshold_warning}" + critical = "${var.aurora_replicalag_threshold_critical}" + } + + notify_no_data = true + evaluation_delay = "${var.delay}" + notify_audit = false + timeout_h = 0 + include_tags = true + locked = false + require_full_window = false + new_host_delay = "${var.delay}" + + silenced = "${var.aurora_replicalag_silenced}" + + tags = ["env:${var.environment}", "resource:rds", "team:aws", "provider:aws"] + + count = "${var.aurora_cluster_type == "postgresql" ? 1 : 0}" +} + +### RDS Aurora Mysql Replica Lag monitor ### +resource "datadog_monitor" "rds_aurora_mysql_replica_lag" { + name = "[${var.environment}] RDS Aurora Mysql replica lag {{#is_alert}}{{{comparator}}} {{threshold}} ms ({{value}}%){{/is_alert}}{{#is_warning}}{{{comparator}}} {{warn_threshold}} ms ({{value}}%){{/is_warning}}" + message = "${coalesce(var.aurora_replicalag_message, var.message)}" + + type = "metric alert" + + query = < ${var.aurora_replicalag_threshold_critical} +EOF + + thresholds { + warning = "${var.aurora_replicalag_threshold_warning}" + critical = "${var.aurora_replicalag_threshold_critical}" + } + + notify_no_data = true + evaluation_delay = "${var.delay}" + notify_audit = false + timeout_h = 0 + include_tags = true + locked = false + require_full_window = false + new_host_delay = "${var.delay}" + + silenced = "${var.aurora_replicalag_silenced}" + + tags = ["env:${var.environment}", "resource:rds", "team:aws", "provider:aws"] + + count = "${var.aurora_cluster_type == "mysql" ? 1 : 0}" } From ea9625144fe4fa081c673514b2caad2197f60f51 Mon Sep 17 00:00:00 2001 From: Quentin Manfroi Date: Fri, 14 Sep 2018 19:29:40 +0200 Subject: [PATCH 02/10] MON-122 split directory --- cloud/aws/rds/{ => common}/README.md | 0 cloud/aws/rds/{ => common}/inputs.tf | 0 cloud/aws/rds/{ => common}/modules.tf | 0 cloud/aws/rds/{monitors-rds.tf => common/monitors-rds-common.tf} | 0 cloud/aws/rds/{ => common}/outputs.tf | 0 5 files changed, 0 insertions(+), 0 deletions(-) rename cloud/aws/rds/{ => common}/README.md (100%) rename cloud/aws/rds/{ => common}/inputs.tf (100%) rename cloud/aws/rds/{ => common}/modules.tf (100%) rename cloud/aws/rds/{monitors-rds.tf => common/monitors-rds-common.tf} (100%) rename cloud/aws/rds/{ => common}/outputs.tf (100%) diff --git a/cloud/aws/rds/README.md b/cloud/aws/rds/common/README.md similarity index 100% rename from cloud/aws/rds/README.md rename to cloud/aws/rds/common/README.md diff --git a/cloud/aws/rds/inputs.tf b/cloud/aws/rds/common/inputs.tf similarity index 100% rename from cloud/aws/rds/inputs.tf rename to cloud/aws/rds/common/inputs.tf diff --git a/cloud/aws/rds/modules.tf b/cloud/aws/rds/common/modules.tf similarity index 100% rename from cloud/aws/rds/modules.tf rename to cloud/aws/rds/common/modules.tf diff --git a/cloud/aws/rds/monitors-rds.tf b/cloud/aws/rds/common/monitors-rds-common.tf similarity index 100% rename from cloud/aws/rds/monitors-rds.tf rename to cloud/aws/rds/common/monitors-rds-common.tf diff --git a/cloud/aws/rds/outputs.tf b/cloud/aws/rds/common/outputs.tf similarity index 100% rename from cloud/aws/rds/outputs.tf rename to cloud/aws/rds/common/outputs.tf From 7877118023061c06956125f072689e4c45aa5065 Mon Sep 17 00:00:00 2001 From: Quentin Manfroi Date: Fri, 14 Sep 2018 19:30:04 +0200 Subject: [PATCH 03/10] MON-122 update common --- cloud/aws/rds/common/README.md | 64 ++++++------- cloud/aws/rds/common/inputs.tf | 76 ++++++++------- cloud/aws/rds/common/modules.tf | 1 + cloud/aws/rds/common/monitors-rds-common.tf | 101 +++----------------- 4 files changed, 83 insertions(+), 159 deletions(-) diff --git a/cloud/aws/rds/common/README.md b/cloud/aws/rds/common/README.md index fd61eb7..efb750a 100644 --- a/cloud/aws/rds/common/README.md +++ b/cloud/aws/rds/common/README.md @@ -1,71 +1,61 @@ -AWS RDS Instance DataDog monitors -================================= +# CLOUD AWS RDS DataDog monitors -How to use this module ----------------------- - -For a single RDS instance : +## How to use this module ``` -module "datadog-monitors-aws-rds" { +module "datadog-monitors-cloud-aws-rds" { source = "git::ssh://git@bitbucket.org/morea/terraform.feature.datadog.git//cloud/aws/rds?ref={revision}" - message = "${module.datadog-message-alerting.alerting-message}" environment = "${var.environment}" -} -``` - -For a RDS Aurora cluster : - -``` -module "datadog-monitors-aws-rds-aurora" { - source = "git::ssh://git@bitbucket.org/morea/terraform.feature.datadog.git//cloud/aws/rds?ref={revision}" - message = "${module.datadog-message-alerting.alerting-message}" - environment = "${var.environment}" - - aurora_cluster_type = "mysql" # if Aurora cluster Mysql. Else "postgresql" if Aurora cluster PostgreSQL. } + ``` -Purpose -------- -Creates a DataDog monitors with the following checks : +## Purpose -* CPU High -* Free disk space low (only for single RDS instances) -* Aurora Replica Lag (only for Aurora Cluster Mysql or PostgreSQL) +Creates DataDog monitors with the following checks: -Inputs ------- +- RDS instance CPU high +- RDS instance free space + +## Inputs | Name | Description | Type | Default | Required | |------|-------------|:----:|:-----:|:-----:| -| aurora_cluster_type | RDS Aurora cluster monitoring. If empty, single RDS instance monitoring. [available values: `mysql`, `postgresql`] | string | `` | no | -| aurora_replicalag_message | Custom message for RDS Aurora replica lag monitor | string | `` | no | -| aurora_replicalag_silenced | Groups to mute for RDS Aurora replica lag monitor | map | `` | no | -| aurora_replicalag_threshold_critical | Aurora replica lag in milliseconds (critical threshold) | string | `200` | no | -| aurora_replicalag_threshold_warning | Aurora replica lag in milliseconds (warning threshold) | string | `100` | no | -| aurora_replicalag_timeframe | Monitor timeframe for RDS Aurora replica lag monitor [available values: `last_#m` (1, 5, 10, 15, or 30), `last_#h` (1, 2, or 4), or `last_1d`] | string | `last_5m` | no | +| cpu_enabled | Flag to enable RDS CPU usage monitor | string | `true` | no | +| cpu_extra_tags | Extra tags for RDS CPU usage monitor | list | `` | no | | cpu_message | Custom message for RDS CPU usage monitor | string | `` | no | | cpu_silenced | Groups to mute for RDS CPU usage monitor | map | `` | no | | cpu_threshold_critical | CPU usage in percent (critical threshold) | string | `90` | no | | cpu_threshold_warning | CPU usage in percent (warning threshold) | string | `80` | no | +| cpu_time_aggregator | Monitor aggregator for RDS CPU usage [available values: min, max or avg] | string | `min` | no | | cpu_timeframe | Monitor timeframe for RDS CPU usage [available values: `last_#m` (1, 5, 10, 15, or 30), `last_#h` (1, 2, or 4), or `last_1d`] | string | `last_15m` | no | -| delay | Delay in seconds for the metric evaluation | string | `900` | no | +| diskspace_enabled | Flag to enable RDS free diskspace monitor | string | `true` | no | +| diskspace_extra_tags | Extra tags for RDS free diskspace monitor | list | `` | no | | diskspace_message | Custom message for RDS free diskspace monitor | string | `` | no | | diskspace_silenced | Groups to mute for RDS free diskspace monitor | map | `` | no | | diskspace_threshold_critical | Disk free space in percent (critical threshold) | string | `10` | no | | diskspace_threshold_warning | Disk free space in percent (warning threshold) | string | `20` | no | +| diskspace_time_aggregator | Monitor aggregator for RDS free diskspace [available values: min, max or avg] | string | `min` | no | | diskspace_timeframe | Monitor timeframe for RDS free diskspace [available values: `last_#m` (1, 5, 10, 15, or 30), `last_#h` (1, 2, or 4), or `last_1d`] | string | `last_15m` | no | | environment | Architecture Environment | string | - | yes | +| evaluation_delay | Delay in seconds for the metric evaluation | string | `900` | no | | filter_tags_custom | Tags used for custom filtering when filter_tags_use_defaults is false | string | `*` | no | | filter_tags_use_defaults | Use default filter tags convention | string | `true` | no | | message | Message sent when an alert is triggered | string | - | yes | +| new_host_delay | Delay in seconds before monitor new resource | string | `300` | no | -Related documentation ---------------------- +## Outputs + +| Name | Description | +|------|-------------| +| rds_cpu_90_15min_id | id for monitor rds_cpu_90_15min | +| rds_free_space_low_id | id for monitor rds_free_space_low | + +## Related documentation DataDog documentation: [https://docs.datadoghq.com/integrations/amazon_rds/](https://docs.datadoghq.com/integrations/amazon_rds/) AWS RDS Instance metrics documentation: [https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/rds-metricscollected.html](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/rds-metricscollected.html) + diff --git a/cloud/aws/rds/common/inputs.tf b/cloud/aws/rds/common/inputs.tf index 75cdbd3..f7e22b5 100644 --- a/cloud/aws/rds/common/inputs.tf +++ b/cloud/aws/rds/common/inputs.tf @@ -5,11 +5,16 @@ variable "environment" { } # Global DataDog -variable "delay" { +variable "evaluation_delay" { description = "Delay in seconds for the metric evaluation" default = 900 } +variable "new_host_delay" { + description = "Delay in seconds before monitor new resource" + default = 300 +} + variable "message" { description = "Message sent when an alert is triggered" } @@ -24,12 +29,6 @@ variable "filter_tags_custom" { default = "*" } -variable "aurora_cluster_type" { - description = "RDS Aurora cluster monitoring. If empty, single RDS instance monitoring. [available values: `mysql`, `postgresql`]" - type = "string" - default = "" -} - # AWS RDS instance specific variable "cpu_silenced" { @@ -38,12 +37,30 @@ variable "cpu_silenced" { default = {} } +variable "cpu_enabled" { + description = "Flag to enable RDS CPU usage monitor" + type = "string" + default = "true" +} + +variable "cpu_extra_tags" { + description = "Extra tags for RDS CPU usage monitor" + type = "list" + default = [] +} + variable "cpu_message" { description = "Custom message for RDS CPU usage monitor" type = "string" default = "" } +variable "cpu_time_aggregator" { + description = "Monitor aggregator for RDS CPU usage [available values: min, max or avg]" + type = "string" + default = "min" +} + variable "cpu_timeframe" { description = "Monitor timeframe for RDS CPU usage [available values: `last_#m` (1, 5, 10, 15, or 30), `last_#h` (1, 2, or 4), or `last_1d`]" type = "string" @@ -66,12 +83,30 @@ variable "diskspace_silenced" { default = {} } +variable "diskspace_enabled" { + description = "Flag to enable RDS free diskspace monitor" + type = "string" + default = "true" +} + +variable "diskspace_extra_tags" { + description = "Extra tags for RDS free diskspace monitor" + type = "list" + default = [] +} + variable "diskspace_message" { description = "Custom message for RDS free diskspace monitor" type = "string" default = "" } +variable "diskspace_time_aggregator" { + description = "Monitor aggregator for RDS free diskspace [available values: min, max or avg]" + type = "string" + default = "min" +} + variable "diskspace_timeframe" { description = "Monitor timeframe for RDS free diskspace [available values: `last_#m` (1, 5, 10, 15, or 30), `last_#h` (1, 2, or 4), or `last_1d`]" type = "string" @@ -88,30 +123,3 @@ variable "diskspace_threshold_critical" { default = "10" } -variable "aurora_replicalag_silenced" { - description = "Groups to mute for RDS Aurora replica lag monitor" - type = "map" - default = {} -} - -variable "aurora_replicalag_message" { - description = "Custom message for RDS Aurora replica lag monitor" - type = "string" - default = "" -} - -variable "aurora_replicalag_timeframe" { - description = "Monitor timeframe for RDS Aurora replica lag monitor [available values: `last_#m` (1, 5, 10, 15, or 30), `last_#h` (1, 2, or 4), or `last_1d`]" - type = "string" - default = "last_5m" -} - -variable "aurora_replicalag_threshold_warning" { - description = "Aurora replica lag in milliseconds (warning threshold)" - default = "100" -} - -variable "aurora_replicalag_threshold_critical" { - description = "Aurora replica lag in milliseconds (critical threshold)" - default = "200" -} diff --git a/cloud/aws/rds/common/modules.tf b/cloud/aws/rds/common/modules.tf index 1e7e2d4..4f49810 100644 --- a/cloud/aws/rds/common/modules.tf +++ b/cloud/aws/rds/common/modules.tf @@ -6,3 +6,4 @@ module "filter-tags" { filter_tags_use_defaults = "${var.filter_tags_use_defaults}" filter_tags_custom = "${var.filter_tags_custom}" } + diff --git a/cloud/aws/rds/common/monitors-rds-common.tf b/cloud/aws/rds/common/monitors-rds-common.tf index 2c30ed0..62ba1b7 100644 --- a/cloud/aws/rds/common/monitors-rds-common.tf +++ b/cloud/aws/rds/common/monitors-rds-common.tf @@ -1,21 +1,14 @@ -data "template_file" "filter" { - template = "$${filter}" - - vars { - filter = "${var.filter_tags_use_defaults == "true" ? format("dd_monitoring:enabled,dd_aws_rds:enabled,env:%s", var.environment) : "${var.filter_tags_custom}"}" - } -} - ### RDS instance CPU monitor ### resource "datadog_monitor" "rds_cpu_90_15min" { + count = "${var.cpu_enabled ? 1 : 0}" name = "[${var.environment}] RDS instance CPU high {{#is_alert}}{{{comparator}}} {{threshold}}% ({{value}}%){{/is_alert}}{{#is_warning}}{{{comparator}}} {{warn_threshold}}% ({{value}}%){{/is_warning}}" message = "${coalesce(var.cpu_message, var.message)}" type = "metric alert" query = < ${var.cpu_threshold_critical} EOF @@ -25,30 +18,31 @@ EOF } notify_no_data = true - evaluation_delay = "${var.delay}" + evaluation_delay = "${var.evaluation_delay}" notify_audit = false timeout_h = 0 include_tags = true locked = false require_full_window = false - new_host_delay = "${var.delay}" + new_host_delay = "${var.new_host_delay}" silenced = "${var.cpu_silenced}" - tags = ["env:${var.environment}", "resource:rds", "team:aws", "provider:aws"] + tags = ["env:${var.environment}", "type:cloud", "provider:aws", "resource:rds", "team:claranet", "created-by:terraform", "${var.cpu_extra_tags}"] } ### RDS instance free space monitor ### resource "datadog_monitor" "rds_free_space_low" { + count = "${var.diskspace_enabled ? 1 : 0}" name = "[${var.environment}] RDS instance free space {{#is_alert}}{{{comparator}}} {{threshold}}% ({{value}}%){{/is_alert}}{{#is_warning}}{{{comparator}}} {{warn_threshold}}% ({{value}}%){{/is_warning}}" message = "${coalesce(var.diskspace_message, var.message)}" type = "metric alert" query = < ${var.aurora_replicalag_threshold_critical} -EOF - - thresholds { - warning = "${var.aurora_replicalag_threshold_warning}" - critical = "${var.aurora_replicalag_threshold_critical}" - } - - notify_no_data = true - evaluation_delay = "${var.delay}" - notify_audit = false - timeout_h = 0 - include_tags = true - locked = false - require_full_window = false - new_host_delay = "${var.delay}" - - silenced = "${var.aurora_replicalag_silenced}" - - tags = ["env:${var.environment}", "resource:rds", "team:aws", "provider:aws"] - - count = "${var.aurora_cluster_type == "postgresql" ? 1 : 0}" -} - -### RDS Aurora Mysql Replica Lag monitor ### -resource "datadog_monitor" "rds_aurora_mysql_replica_lag" { - name = "[${var.environment}] RDS Aurora Mysql replica lag {{#is_alert}}{{{comparator}}} {{threshold}} ms ({{value}}%){{/is_alert}}{{#is_warning}}{{{comparator}}} {{warn_threshold}} ms ({{value}}%){{/is_warning}}" - message = "${coalesce(var.aurora_replicalag_message, var.message)}" - - type = "metric alert" - - query = < ${var.aurora_replicalag_threshold_critical} -EOF - - thresholds { - warning = "${var.aurora_replicalag_threshold_warning}" - critical = "${var.aurora_replicalag_threshold_critical}" - } - - notify_no_data = true - evaluation_delay = "${var.delay}" - notify_audit = false - timeout_h = 0 - include_tags = true - locked = false - require_full_window = false - new_host_delay = "${var.delay}" - - silenced = "${var.aurora_replicalag_silenced}" - - tags = ["env:${var.environment}", "resource:rds", "team:aws", "provider:aws"] - - count = "${var.aurora_cluster_type == "mysql" ? 1 : 0}" -} From 81c523743b660b2620d15ed1f83a7ab81874f917 Mon Sep 17 00:00:00 2001 From: Quentin Manfroi Date: Fri, 14 Sep 2018 19:30:39 +0200 Subject: [PATCH 04/10] MON-122 add aurora --- cloud/aws/rds/aurora/mysql/inputs.tf | 61 +++++++++++++++++++ .../aurora/mysql/monitors-rds-aurora-mysql.tf | 34 +++++++++++ cloud/aws/rds/aurora/postgresql/inputs.tf | 61 +++++++++++++++++++ .../monitors-rds-aurora-postgresql.tf | 35 +++++++++++ 4 files changed, 191 insertions(+) create mode 100644 cloud/aws/rds/aurora/mysql/inputs.tf create mode 100644 cloud/aws/rds/aurora/mysql/monitors-rds-aurora-mysql.tf create mode 100644 cloud/aws/rds/aurora/postgresql/inputs.tf create mode 100644 cloud/aws/rds/aurora/postgresql/monitors-rds-aurora-postgresql.tf diff --git a/cloud/aws/rds/aurora/mysql/inputs.tf b/cloud/aws/rds/aurora/mysql/inputs.tf new file mode 100644 index 0000000..43c9dc3 --- /dev/null +++ b/cloud/aws/rds/aurora/mysql/inputs.tf @@ -0,0 +1,61 @@ +# Global Terraform +variable "environment" { + description = "Architecture Environment" + type = "string" +} + +# Global DataDog +variable "evaluation_delay" { + description = "Delay in seconds for the metric evaluation" + default = 900 +} + +variable "new_host_delay" { + description = "Delay in seconds before monitor new resource" + default = 300 +} + +variable "message" { + description = "Message sent when an alert is triggered" +} + +variable "filter_tags_use_defaults" { + description = "Use default filter tags convention" + default = "true" +} + +variable "filter_tags_custom" { + description = "Tags used for custom filtering when filter_tags_use_defaults is false" + default = "*" +} + +# AWS RDS Aurora instance specific + +variable "aurora_replicalag_silenced" { + description = "Groups to mute for RDS Aurora replica lag monitor" + type = "map" + default = {} +} + +variable "aurora_replicalag_message" { + description = "Custom message for RDS Aurora replica lag monitor" + type = "string" + default = "" +} + +variable "aurora_replicalag_timeframe" { + description = "Monitor timeframe for RDS Aurora replica lag monitor [available values: `last_#m` (1, 5, 10, 15, or 30), `last_#h` (1, 2, or 4), or `last_1d`]" + type = "string" + default = "last_5m" +} + +variable "aurora_replicalag_threshold_warning" { + description = "Aurora replica lag in milliseconds (warning threshold)" + default = "100" +} + +variable "aurora_replicalag_threshold_critical" { + description = "Aurora replica lag in milliseconds (critical threshold)" + default = "200" +} + diff --git a/cloud/aws/rds/aurora/mysql/monitors-rds-aurora-mysql.tf b/cloud/aws/rds/aurora/mysql/monitors-rds-aurora-mysql.tf new file mode 100644 index 0000000..5d252f3 --- /dev/null +++ b/cloud/aws/rds/aurora/mysql/monitors-rds-aurora-mysql.tf @@ -0,0 +1,34 @@ +### RDS Aurora Mysql Replica Lag monitor ### +resource "datadog_monitor" "rds_aurora_mysql_replica_lag" { + name = "[${var.environment}] RDS Aurora Mysql replica lag {{#is_alert}}{{{comparator}}} {{threshold}} ms ({{value}}%){{/is_alert}}{{#is_warning}}{{{comparator}}} {{warn_threshold}} ms ({{value}}%){{/is_warning}}" + message = "${coalesce(var.aurora_replicalag_message, var.message)}" + + type = "metric alert" + + query = < ${var.aurora_replicalag_threshold_critical} +EOF + + thresholds { + warning = "${var.aurora_replicalag_threshold_warning}" + critical = "${var.aurora_replicalag_threshold_critical}" + } + + notify_no_data = true + evaluation_delay = "${var.delay}" + notify_audit = false + timeout_h = 0 + include_tags = true + locked = false + require_full_window = false + new_host_delay = "${var.delay}" + + silenced = "${var.aurora_replicalag_silenced}" + + tags = ["env:${var.environment}", "resource:rds", "team:aws", "provider:aws"] + + count = "${var.aurora_cluster_type == "mysql" ? 1 : 0}" +} + diff --git a/cloud/aws/rds/aurora/postgresql/inputs.tf b/cloud/aws/rds/aurora/postgresql/inputs.tf new file mode 100644 index 0000000..43c9dc3 --- /dev/null +++ b/cloud/aws/rds/aurora/postgresql/inputs.tf @@ -0,0 +1,61 @@ +# Global Terraform +variable "environment" { + description = "Architecture Environment" + type = "string" +} + +# Global DataDog +variable "evaluation_delay" { + description = "Delay in seconds for the metric evaluation" + default = 900 +} + +variable "new_host_delay" { + description = "Delay in seconds before monitor new resource" + default = 300 +} + +variable "message" { + description = "Message sent when an alert is triggered" +} + +variable "filter_tags_use_defaults" { + description = "Use default filter tags convention" + default = "true" +} + +variable "filter_tags_custom" { + description = "Tags used for custom filtering when filter_tags_use_defaults is false" + default = "*" +} + +# AWS RDS Aurora instance specific + +variable "aurora_replicalag_silenced" { + description = "Groups to mute for RDS Aurora replica lag monitor" + type = "map" + default = {} +} + +variable "aurora_replicalag_message" { + description = "Custom message for RDS Aurora replica lag monitor" + type = "string" + default = "" +} + +variable "aurora_replicalag_timeframe" { + description = "Monitor timeframe for RDS Aurora replica lag monitor [available values: `last_#m` (1, 5, 10, 15, or 30), `last_#h` (1, 2, or 4), or `last_1d`]" + type = "string" + default = "last_5m" +} + +variable "aurora_replicalag_threshold_warning" { + description = "Aurora replica lag in milliseconds (warning threshold)" + default = "100" +} + +variable "aurora_replicalag_threshold_critical" { + description = "Aurora replica lag in milliseconds (critical threshold)" + default = "200" +} + diff --git a/cloud/aws/rds/aurora/postgresql/monitors-rds-aurora-postgresql.tf b/cloud/aws/rds/aurora/postgresql/monitors-rds-aurora-postgresql.tf new file mode 100644 index 0000000..953d3d2 --- /dev/null +++ b/cloud/aws/rds/aurora/postgresql/monitors-rds-aurora-postgresql.tf @@ -0,0 +1,35 @@ +### RDS Aurora Postgresql Replica Lag monitor ### +resource "datadog_monitor" "rds_aurora_postgresql_replica_lag" { + name = "[${var.environment}] RDS Aurora PostgreSQL replica lag {{#is_alert}}{{{comparator}}} {{threshold}} ms ({{value}}%){{/is_alert}}{{#is_warning}}{{{comparator}}} {{warn_threshold}} ms ({{value}}%){{/is_warning}}" + message = "${coalesce(var.aurora_replicalag_message, var.message)}" + + type = "metric alert" + + query = < ${var.aurora_replicalag_threshold_critical} +EOF + + thresholds { + warning = "${var.aurora_replicalag_threshold_warning}" + critical = "${var.aurora_replicalag_threshold_critical}" + } + + notify_no_data = true + evaluation_delay = "${var.delay}" + notify_audit = false + timeout_h = 0 + include_tags = true + locked = false + require_full_window = false + new_host_delay = "${var.delay}" + + silenced = "${var.aurora_replicalag_silenced}" + + tags = ["env:${var.environment}", "resource:rds", "team:aws", "provider:aws"] + + count = "${var.aurora_cluster_type == "postgresql" ? 1 : 0}" +} + + From bc0a2e0cebe53a347a9f81f5b67987ee74c63a67 Mon Sep 17 00:00:00 2001 From: Quentin Manfroi Date: Fri, 14 Sep 2018 19:44:08 +0200 Subject: [PATCH 05/10] MON-122 update to new best practices --- README.md | 4 ++ cloud/aws/rds/aurora/mysql/README.md | 46 +++++++++++++++++++ cloud/aws/rds/aurora/mysql/inputs.tf | 13 +++++- cloud/aws/rds/aurora/mysql/modules.tf | 8 ++++ .../aurora/mysql/monitors-rds-aurora-mysql.tf | 12 ++--- cloud/aws/rds/aurora/mysql/outputs.tf | 4 ++ cloud/aws/rds/aurora/postgresql/README.md | 46 +++++++++++++++++++ cloud/aws/rds/aurora/postgresql/inputs.tf | 13 +++++- cloud/aws/rds/aurora/postgresql/modules.tf | 8 ++++ .../monitors-rds-aurora-postgresql.tf | 13 ++---- cloud/aws/rds/aurora/postgresql/outputs.tf | 4 ++ cloud/aws/rds/common/README.md | 6 +-- cloud/aws/rds/common/inputs.tf | 1 - cloud/aws/rds/common/modules.tf | 1 - cloud/aws/rds/common/monitors-rds-common.tf | 1 - 15 files changed, 157 insertions(+), 23 deletions(-) create mode 100644 cloud/aws/rds/aurora/mysql/README.md create mode 100644 cloud/aws/rds/aurora/mysql/modules.tf create mode 100644 cloud/aws/rds/aurora/mysql/outputs.tf create mode 100644 cloud/aws/rds/aurora/postgresql/README.md create mode 100644 cloud/aws/rds/aurora/postgresql/modules.tf create mode 100644 cloud/aws/rds/aurora/postgresql/outputs.tf diff --git a/README.md b/README.md index 5d7a6f0..ef5bd6f 100644 --- a/README.md +++ b/README.md @@ -84,6 +84,10 @@ The `//` is very important, it's a terraform specific syntax used to separate gi - [elb](https://bitbucket.org/morea/terraform.feature.datadog/src/master/cloud/aws/elb/) - [kinesis-firehose](https://bitbucket.org/morea/terraform.feature.datadog/src/master/cloud/aws/kinesis-firehose/) - [rds](https://bitbucket.org/morea/terraform.feature.datadog/src/master/cloud/aws/rds/) + - [aurora](https://bitbucket.org/morea/terraform.feature.datadog/src/master/cloud/aws/rds/aurora/) + - [mysql](https://bitbucket.org/morea/terraform.feature.datadog/src/master/cloud/aws/rds/aurora/mysql/) + - [postgresql](https://bitbucket.org/morea/terraform.feature.datadog/src/master/cloud/aws/rds/aurora/postgresql/) + - [common](https://bitbucket.org/morea/terraform.feature.datadog/src/master/cloud/aws/rds/common/) - [vpn](https://bitbucket.org/morea/terraform.feature.datadog/src/master/cloud/aws/vpn/) - [azure](https://bitbucket.org/morea/terraform.feature.datadog/src/master/cloud/azure/) - [apimanagement](https://bitbucket.org/morea/terraform.feature.datadog/src/master/cloud/azure/apimanagement/) diff --git a/cloud/aws/rds/aurora/mysql/README.md b/cloud/aws/rds/aurora/mysql/README.md new file mode 100644 index 0000000..a4d9ae1 --- /dev/null +++ b/cloud/aws/rds/aurora/mysql/README.md @@ -0,0 +1,46 @@ +# CLOUD AWS RDS AURORA MYSQL DataDog monitors + +## How to use this module + +``` +module "datadog-monitors-cloud-aws-rds-aurora-mysql" { + source = "git::ssh://git@bitbucket.org/morea/terraform.feature.datadog.git//cloud/aws/rds/aurora/mysql?ref={revision}" + + environment = "${var.environment}" + message = "${module.datadog-message-alerting.alerting-message}" +} + +``` + +## Purpose + +Creates DataDog monitors with the following checks: + +- RDS Aurora Mysql replica lag + +## Inputs + +| Name | Description | Type | Default | Required | +|------|-------------|:----:|:-----:|:-----:| +| aurora_replicalag_enabled | Flag to enable RDS CPU usage monitor | string | `true` | no | +| aurora_replicalag_extra_tags | Extra tags for RDS CPU usage monitor | list | `` | no | +| aurora_replicalag_message | Custom message for RDS Aurora replica lag monitor | string | `` | no | +| aurora_replicalag_silenced | Groups to mute for RDS Aurora replica lag monitor | map | `` | no | +| aurora_replicalag_threshold_critical | Aurora replica lag in milliseconds (critical threshold) | string | `200` | no | +| aurora_replicalag_threshold_warning | Aurora replica lag in milliseconds (warning threshold) | string | `100` | no | +| aurora_replicalag_timeframe | Monitor timeframe for RDS Aurora replica lag monitor [available values: `last_#m` (1, 5, 10, 15, or 30), `last_#h` (1, 2, or 4), or `last_1d`] | string | `last_5m` | no | +| environment | Architecture Environment | string | - | yes | +| evaluation_delay | Delay in seconds for the metric evaluation | string | `900` | no | +| filter_tags_custom | Tags used for custom filtering when filter_tags_use_defaults is false | string | `*` | no | +| filter_tags_use_defaults | Use default filter tags convention | string | `true` | no | +| message | Message sent when an alert is triggered | string | - | yes | +| new_host_delay | Delay in seconds before monitor new resource | string | `300` | no | + +## Outputs + +| Name | Description | +|------|-------------| +| rds_aurora_mysql_replica_lag_id | id for monitor rds_aurora_mysql_replica_lag | + +## Related documentation + diff --git a/cloud/aws/rds/aurora/mysql/inputs.tf b/cloud/aws/rds/aurora/mysql/inputs.tf index 43c9dc3..97793c3 100644 --- a/cloud/aws/rds/aurora/mysql/inputs.tf +++ b/cloud/aws/rds/aurora/mysql/inputs.tf @@ -37,6 +37,18 @@ variable "aurora_replicalag_silenced" { default = {} } +variable "aurora_replicalag_enabled" { + description = "Flag to enable RDS CPU usage monitor" + type = "string" + default = "true" +} + +variable "aurora_replicalag_extra_tags" { + description = "Extra tags for RDS CPU usage monitor" + type = "list" + default = [] +} + variable "aurora_replicalag_message" { description = "Custom message for RDS Aurora replica lag monitor" type = "string" @@ -58,4 +70,3 @@ variable "aurora_replicalag_threshold_critical" { description = "Aurora replica lag in milliseconds (critical threshold)" default = "200" } - diff --git a/cloud/aws/rds/aurora/mysql/modules.tf b/cloud/aws/rds/aurora/mysql/modules.tf new file mode 100644 index 0000000..0f449e0 --- /dev/null +++ b/cloud/aws/rds/aurora/mysql/modules.tf @@ -0,0 +1,8 @@ +module "filter-tags" { + source = "../../common/filter-tags" + + environment = "${var.environment}" + resource = "rds" + filter_tags_use_defaults = "${var.filter_tags_use_defaults}" + filter_tags_custom = "${var.filter_tags_custom}" +} diff --git a/cloud/aws/rds/aurora/mysql/monitors-rds-aurora-mysql.tf b/cloud/aws/rds/aurora/mysql/monitors-rds-aurora-mysql.tf index 5d252f3..09c2f18 100644 --- a/cloud/aws/rds/aurora/mysql/monitors-rds-aurora-mysql.tf +++ b/cloud/aws/rds/aurora/mysql/monitors-rds-aurora-mysql.tf @@ -1,5 +1,6 @@ ### RDS Aurora Mysql Replica Lag monitor ### resource "datadog_monitor" "rds_aurora_mysql_replica_lag" { + count = "${var.aurora_replicalag_enabled ? 1 : 0}" name = "[${var.environment}] RDS Aurora Mysql replica lag {{#is_alert}}{{{comparator}}} {{threshold}} ms ({{value}}%){{/is_alert}}{{#is_warning}}{{{comparator}}} {{warn_threshold}} ms ({{value}}%){{/is_warning}}" message = "${coalesce(var.aurora_replicalag_message, var.message)}" @@ -7,7 +8,7 @@ resource "datadog_monitor" "rds_aurora_mysql_replica_lag" { query = < ${var.aurora_replicalag_threshold_critical} EOF @@ -17,18 +18,15 @@ EOF } notify_no_data = true - evaluation_delay = "${var.delay}" + evaluation_delay = "${var.evaluation_delay}" notify_audit = false timeout_h = 0 include_tags = true locked = false require_full_window = false - new_host_delay = "${var.delay}" + new_host_delay = "${var.new_host_delay}" silenced = "${var.aurora_replicalag_silenced}" - tags = ["env:${var.environment}", "resource:rds", "team:aws", "provider:aws"] - - count = "${var.aurora_cluster_type == "mysql" ? 1 : 0}" + tags = ["env:${var.environment}", "type:cloud", "provider:aws", "resource:rds-aurora-mysql", "team:claranet", "created-by:terraform", "${var.aurora_replicalag_extra_tags}"] } - diff --git a/cloud/aws/rds/aurora/mysql/outputs.tf b/cloud/aws/rds/aurora/mysql/outputs.tf new file mode 100644 index 0000000..dd13b44 --- /dev/null +++ b/cloud/aws/rds/aurora/mysql/outputs.tf @@ -0,0 +1,4 @@ +output "rds_aurora_mysql_replica_lag_id" { + description = "id for monitor rds_aurora_mysql_replica_lag" + value = "${datadog_monitor.rds_aurora_mysql_replica_lag.*.id}" +} diff --git a/cloud/aws/rds/aurora/postgresql/README.md b/cloud/aws/rds/aurora/postgresql/README.md new file mode 100644 index 0000000..0674fb7 --- /dev/null +++ b/cloud/aws/rds/aurora/postgresql/README.md @@ -0,0 +1,46 @@ +# CLOUD AWS RDS AURORA POSTGRESQL DataDog monitors + +## How to use this module + +``` +module "datadog-monitors-cloud-aws-rds-aurora-postgresql" { + source = "git::ssh://git@bitbucket.org/morea/terraform.feature.datadog.git//cloud/aws/rds/aurora/postgresql?ref={revision}" + + environment = "${var.environment}" + message = "${module.datadog-message-alerting.alerting-message}" +} + +``` + +## Purpose + +Creates DataDog monitors with the following checks: + +- RDS Aurora PostgreSQL replica lag + +## Inputs + +| Name | Description | Type | Default | Required | +|------|-------------|:----:|:-----:|:-----:| +| aurora_replicalag_enabled | Flag to enable RDS CPU usage monitor | string | `true` | no | +| aurora_replicalag_extra_tags | Extra tags for RDS CPU usage monitor | list | `` | no | +| aurora_replicalag_message | Custom message for RDS Aurora replica lag monitor | string | `` | no | +| aurora_replicalag_silenced | Groups to mute for RDS Aurora replica lag monitor | map | `` | no | +| aurora_replicalag_threshold_critical | Aurora replica lag in milliseconds (critical threshold) | string | `200` | no | +| aurora_replicalag_threshold_warning | Aurora replica lag in milliseconds (warning threshold) | string | `100` | no | +| aurora_replicalag_timeframe | Monitor timeframe for RDS Aurora replica lag monitor [available values: `last_#m` (1, 5, 10, 15, or 30), `last_#h` (1, 2, or 4), or `last_1d`] | string | `last_5m` | no | +| environment | Architecture Environment | string | - | yes | +| evaluation_delay | Delay in seconds for the metric evaluation | string | `900` | no | +| filter_tags_custom | Tags used for custom filtering when filter_tags_use_defaults is false | string | `*` | no | +| filter_tags_use_defaults | Use default filter tags convention | string | `true` | no | +| message | Message sent when an alert is triggered | string | - | yes | +| new_host_delay | Delay in seconds before monitor new resource | string | `300` | no | + +## Outputs + +| Name | Description | +|------|-------------| +| rds_aurora_postgresql_replica_lag_id | id for monitor rds_aurora_postgresql_replica_lag | + +## Related documentation + diff --git a/cloud/aws/rds/aurora/postgresql/inputs.tf b/cloud/aws/rds/aurora/postgresql/inputs.tf index 43c9dc3..97793c3 100644 --- a/cloud/aws/rds/aurora/postgresql/inputs.tf +++ b/cloud/aws/rds/aurora/postgresql/inputs.tf @@ -37,6 +37,18 @@ variable "aurora_replicalag_silenced" { default = {} } +variable "aurora_replicalag_enabled" { + description = "Flag to enable RDS CPU usage monitor" + type = "string" + default = "true" +} + +variable "aurora_replicalag_extra_tags" { + description = "Extra tags for RDS CPU usage monitor" + type = "list" + default = [] +} + variable "aurora_replicalag_message" { description = "Custom message for RDS Aurora replica lag monitor" type = "string" @@ -58,4 +70,3 @@ variable "aurora_replicalag_threshold_critical" { description = "Aurora replica lag in milliseconds (critical threshold)" default = "200" } - diff --git a/cloud/aws/rds/aurora/postgresql/modules.tf b/cloud/aws/rds/aurora/postgresql/modules.tf new file mode 100644 index 0000000..0f449e0 --- /dev/null +++ b/cloud/aws/rds/aurora/postgresql/modules.tf @@ -0,0 +1,8 @@ +module "filter-tags" { + source = "../../common/filter-tags" + + environment = "${var.environment}" + resource = "rds" + filter_tags_use_defaults = "${var.filter_tags_use_defaults}" + filter_tags_custom = "${var.filter_tags_custom}" +} diff --git a/cloud/aws/rds/aurora/postgresql/monitors-rds-aurora-postgresql.tf b/cloud/aws/rds/aurora/postgresql/monitors-rds-aurora-postgresql.tf index 953d3d2..0c03a33 100644 --- a/cloud/aws/rds/aurora/postgresql/monitors-rds-aurora-postgresql.tf +++ b/cloud/aws/rds/aurora/postgresql/monitors-rds-aurora-postgresql.tf @@ -1,5 +1,6 @@ ### RDS Aurora Postgresql Replica Lag monitor ### resource "datadog_monitor" "rds_aurora_postgresql_replica_lag" { + count = "${var.aurora_replicalag_enabled ? 1 : 0}" name = "[${var.environment}] RDS Aurora PostgreSQL replica lag {{#is_alert}}{{{comparator}}} {{threshold}} ms ({{value}}%){{/is_alert}}{{#is_warning}}{{{comparator}}} {{warn_threshold}} ms ({{value}}%){{/is_warning}}" message = "${coalesce(var.aurora_replicalag_message, var.message)}" @@ -7,7 +8,7 @@ resource "datadog_monitor" "rds_aurora_postgresql_replica_lag" { query = < ${var.aurora_replicalag_threshold_critical} EOF @@ -17,19 +18,15 @@ EOF } notify_no_data = true - evaluation_delay = "${var.delay}" + evaluation_delay = "${var.evaluation_delay}" notify_audit = false timeout_h = 0 include_tags = true locked = false require_full_window = false - new_host_delay = "${var.delay}" + new_host_delay = "${var.new_host_delay}" silenced = "${var.aurora_replicalag_silenced}" - tags = ["env:${var.environment}", "resource:rds", "team:aws", "provider:aws"] - - count = "${var.aurora_cluster_type == "postgresql" ? 1 : 0}" + tags = ["env:${var.environment}", "type:cloud", "provider:aws", "resource:rds-aurora-postgresql", "team:claranet", "created-by:terraform", "${var.aurora_replicalag_extra_tags}"] } - - diff --git a/cloud/aws/rds/aurora/postgresql/outputs.tf b/cloud/aws/rds/aurora/postgresql/outputs.tf new file mode 100644 index 0000000..b88c1c4 --- /dev/null +++ b/cloud/aws/rds/aurora/postgresql/outputs.tf @@ -0,0 +1,4 @@ +output "rds_aurora_postgresql_replica_lag_id" { + description = "id for monitor rds_aurora_postgresql_replica_lag" + value = "${datadog_monitor.rds_aurora_postgresql_replica_lag.*.id}" +} diff --git a/cloud/aws/rds/common/README.md b/cloud/aws/rds/common/README.md index efb750a..1abb93e 100644 --- a/cloud/aws/rds/common/README.md +++ b/cloud/aws/rds/common/README.md @@ -1,10 +1,10 @@ -# CLOUD AWS RDS DataDog monitors +# CLOUD AWS RDS COMMON DataDog monitors ## How to use this module ``` -module "datadog-monitors-cloud-aws-rds" { - source = "git::ssh://git@bitbucket.org/morea/terraform.feature.datadog.git//cloud/aws/rds?ref={revision}" +module "datadog-monitors-cloud-aws-rds-common" { + source = "git::ssh://git@bitbucket.org/morea/terraform.feature.datadog.git//cloud/aws/rds/common?ref={revision}" environment = "${var.environment}" message = "${module.datadog-message-alerting.alerting-message}" diff --git a/cloud/aws/rds/common/inputs.tf b/cloud/aws/rds/common/inputs.tf index f7e22b5..54cf425 100644 --- a/cloud/aws/rds/common/inputs.tf +++ b/cloud/aws/rds/common/inputs.tf @@ -122,4 +122,3 @@ variable "diskspace_threshold_critical" { description = "Disk free space in percent (critical threshold)" default = "10" } - diff --git a/cloud/aws/rds/common/modules.tf b/cloud/aws/rds/common/modules.tf index 4f49810..1e7e2d4 100644 --- a/cloud/aws/rds/common/modules.tf +++ b/cloud/aws/rds/common/modules.tf @@ -6,4 +6,3 @@ module "filter-tags" { filter_tags_use_defaults = "${var.filter_tags_use_defaults}" filter_tags_custom = "${var.filter_tags_custom}" } - diff --git a/cloud/aws/rds/common/monitors-rds-common.tf b/cloud/aws/rds/common/monitors-rds-common.tf index 62ba1b7..3168194 100644 --- a/cloud/aws/rds/common/monitors-rds-common.tf +++ b/cloud/aws/rds/common/monitors-rds-common.tf @@ -64,4 +64,3 @@ EOF tags = ["env:${var.environment}", "type:cloud", "provider:aws", "resource:rds", "team:claranet", "created-by:terraform", "${var.diskspace_extra_tags}"] } - From 375e37586b068d2f4380e594b11db7029acb18df Mon Sep 17 00:00:00 2001 From: Quentin Manfroi Date: Fri, 14 Sep 2018 19:47:01 +0200 Subject: [PATCH 06/10] MON-122 fix aurora mysql replication lag metric --- cloud/aws/rds/aurora/mysql/monitors-rds-aurora-mysql.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cloud/aws/rds/aurora/mysql/monitors-rds-aurora-mysql.tf b/cloud/aws/rds/aurora/mysql/monitors-rds-aurora-mysql.tf index 09c2f18..8fc062f 100644 --- a/cloud/aws/rds/aurora/mysql/monitors-rds-aurora-mysql.tf +++ b/cloud/aws/rds/aurora/mysql/monitors-rds-aurora-mysql.tf @@ -8,7 +8,7 @@ resource "datadog_monitor" "rds_aurora_mysql_replica_lag" { query = < ${var.aurora_replicalag_threshold_critical} EOF From 050da5f76265e04c00cb577242962f532db6a836 Mon Sep 17 00:00:00 2001 From: Quentin Manfroi Date: Fri, 14 Sep 2018 19:49:29 +0200 Subject: [PATCH 07/10] MON-122 fix description --- cloud/aws/rds/aurora/mysql/inputs.tf | 4 ++-- cloud/aws/rds/aurora/postgresql/inputs.tf | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/cloud/aws/rds/aurora/mysql/inputs.tf b/cloud/aws/rds/aurora/mysql/inputs.tf index 97793c3..30629ad 100644 --- a/cloud/aws/rds/aurora/mysql/inputs.tf +++ b/cloud/aws/rds/aurora/mysql/inputs.tf @@ -38,13 +38,13 @@ variable "aurora_replicalag_silenced" { } variable "aurora_replicalag_enabled" { - description = "Flag to enable RDS CPU usage monitor" + description = "Flag to enable RDS Aurora replica lag monitor" type = "string" default = "true" } variable "aurora_replicalag_extra_tags" { - description = "Extra tags for RDS CPU usage monitor" + description = "Extra tags for RDS Aurora replica lag monitor" type = "list" default = [] } diff --git a/cloud/aws/rds/aurora/postgresql/inputs.tf b/cloud/aws/rds/aurora/postgresql/inputs.tf index 97793c3..30629ad 100644 --- a/cloud/aws/rds/aurora/postgresql/inputs.tf +++ b/cloud/aws/rds/aurora/postgresql/inputs.tf @@ -38,13 +38,13 @@ variable "aurora_replicalag_silenced" { } variable "aurora_replicalag_enabled" { - description = "Flag to enable RDS CPU usage monitor" + description = "Flag to enable RDS Aurora replica lag monitor" type = "string" default = "true" } variable "aurora_replicalag_extra_tags" { - description = "Extra tags for RDS CPU usage monitor" + description = "Extra tags for RDS Aurora replica lag monitor" type = "list" default = [] } From 2e9a14a49b9871671adf2e1192bf04b0377197a7 Mon Sep 17 00:00:00 2001 From: Quentin Manfroi Date: Fri, 14 Sep 2018 19:55:07 +0200 Subject: [PATCH 08/10] MON-122 add replication lag for rds --- cloud/aws/rds/aurora/mysql/README.md | 4 +-- cloud/aws/rds/aurora/postgresql/README.md | 4 +-- cloud/aws/rds/common/README.md | 9 +++++ cloud/aws/rds/common/inputs.tf | 40 +++++++++++++++++++++ cloud/aws/rds/common/monitors-rds-common.tf | 33 +++++++++++++++++ cloud/aws/rds/common/outputs.tf | 5 +++ 6 files changed, 91 insertions(+), 4 deletions(-) diff --git a/cloud/aws/rds/aurora/mysql/README.md b/cloud/aws/rds/aurora/mysql/README.md index a4d9ae1..bf01779 100644 --- a/cloud/aws/rds/aurora/mysql/README.md +++ b/cloud/aws/rds/aurora/mysql/README.md @@ -22,8 +22,8 @@ Creates DataDog monitors with the following checks: | Name | Description | Type | Default | Required | |------|-------------|:----:|:-----:|:-----:| -| aurora_replicalag_enabled | Flag to enable RDS CPU usage monitor | string | `true` | no | -| aurora_replicalag_extra_tags | Extra tags for RDS CPU usage monitor | list | `` | no | +| aurora_replicalag_enabled | Flag to enable RDS Aurora replica lag monitor | string | `true` | no | +| aurora_replicalag_extra_tags | Extra tags for RDS Aurora replica lag monitor | list | `` | no | | aurora_replicalag_message | Custom message for RDS Aurora replica lag monitor | string | `` | no | | aurora_replicalag_silenced | Groups to mute for RDS Aurora replica lag monitor | map | `` | no | | aurora_replicalag_threshold_critical | Aurora replica lag in milliseconds (critical threshold) | string | `200` | no | diff --git a/cloud/aws/rds/aurora/postgresql/README.md b/cloud/aws/rds/aurora/postgresql/README.md index 0674fb7..9f6f6d7 100644 --- a/cloud/aws/rds/aurora/postgresql/README.md +++ b/cloud/aws/rds/aurora/postgresql/README.md @@ -22,8 +22,8 @@ Creates DataDog monitors with the following checks: | Name | Description | Type | Default | Required | |------|-------------|:----:|:-----:|:-----:| -| aurora_replicalag_enabled | Flag to enable RDS CPU usage monitor | string | `true` | no | -| aurora_replicalag_extra_tags | Extra tags for RDS CPU usage monitor | list | `` | no | +| aurora_replicalag_enabled | Flag to enable RDS Aurora replica lag monitor | string | `true` | no | +| aurora_replicalag_extra_tags | Extra tags for RDS Aurora replica lag monitor | list | `` | no | | aurora_replicalag_message | Custom message for RDS Aurora replica lag monitor | string | `` | no | | aurora_replicalag_silenced | Groups to mute for RDS Aurora replica lag monitor | map | `` | no | | aurora_replicalag_threshold_critical | Aurora replica lag in milliseconds (critical threshold) | string | `200` | no | diff --git a/cloud/aws/rds/common/README.md b/cloud/aws/rds/common/README.md index 1abb93e..0337b2f 100644 --- a/cloud/aws/rds/common/README.md +++ b/cloud/aws/rds/common/README.md @@ -18,6 +18,7 @@ Creates DataDog monitors with the following checks: - RDS instance CPU high - RDS instance free space +- RDS replica lag ## Inputs @@ -45,6 +46,13 @@ Creates DataDog monitors with the following checks: | filter_tags_use_defaults | Use default filter tags convention | string | `true` | no | | message | Message sent when an alert is triggered | string | - | yes | | new_host_delay | Delay in seconds before monitor new resource | string | `300` | no | +| replicalag_enabled | Flag to enable RDS replica lag monitor | string | `true` | no | +| replicalag_extra_tags | Extra tags for RDS replica lag monitor | list | `` | no | +| replicalag_message | Custom message for RDS replica lag monitor | string | `` | no | +| replicalag_silenced | Groups to mute for RDS replica lag monitor | map | `` | no | +| replicalag_threshold_critical | replica lag in seconds (critical threshold) | string | `300` | no | +| replicalag_threshold_warning | replica lag in seconds (warning threshold) | string | `200` | no | +| replicalag_timeframe | Monitor timeframe for RDS replica lag monitor [available values: `last_#m` (1, 5, 10, 15, or 30), `last_#h` (1, 2, or 4), or `last_1d`] | string | `last_5m` | no | ## Outputs @@ -52,6 +60,7 @@ Creates DataDog monitors with the following checks: |------|-------------| | rds_cpu_90_15min_id | id for monitor rds_cpu_90_15min | | rds_free_space_low_id | id for monitor rds_free_space_low | +| rds_replica_lag_id | id for monitor rds_replica_lag | ## Related documentation diff --git a/cloud/aws/rds/common/inputs.tf b/cloud/aws/rds/common/inputs.tf index 54cf425..c046875 100644 --- a/cloud/aws/rds/common/inputs.tf +++ b/cloud/aws/rds/common/inputs.tf @@ -122,3 +122,43 @@ variable "diskspace_threshold_critical" { description = "Disk free space in percent (critical threshold)" default = "10" } + +variable "replicalag_silenced" { + description = "Groups to mute for RDS replica lag monitor" + type = "map" + default = {} +} + +variable "replicalag_enabled" { + description = "Flag to enable RDS replica lag monitor" + type = "string" + default = "true" +} + +variable "replicalag_extra_tags" { + description = "Extra tags for RDS replica lag monitor" + type = "list" + default = [] +} + +variable "replicalag_message" { + description = "Custom message for RDS replica lag monitor" + type = "string" + default = "" +} + +variable "replicalag_timeframe" { + description = "Monitor timeframe for RDS replica lag monitor [available values: `last_#m` (1, 5, 10, 15, or 30), `last_#h` (1, 2, or 4), or `last_1d`]" + type = "string" + default = "last_5m" +} + +variable "replicalag_threshold_warning" { + description = "replica lag in seconds (warning threshold)" + default = "200" +} + +variable "replicalag_threshold_critical" { + description = "replica lag in seconds (critical threshold)" + default = "300" +} diff --git a/cloud/aws/rds/common/monitors-rds-common.tf b/cloud/aws/rds/common/monitors-rds-common.tf index 3168194..fdf5105 100644 --- a/cloud/aws/rds/common/monitors-rds-common.tf +++ b/cloud/aws/rds/common/monitors-rds-common.tf @@ -64,3 +64,36 @@ EOF tags = ["env:${var.environment}", "type:cloud", "provider:aws", "resource:rds", "team:claranet", "created-by:terraform", "${var.diskspace_extra_tags}"] } + +### RDS Replica Lag monitor ### +resource "datadog_monitor" "rds_replica_lag" { + count = "${var.replicalag_enabled ? 1 : 0}" + name = "[${var.environment}] RDS replica lag {{#is_alert}}{{{comparator}}} {{threshold}} ms ({{value}}%){{/is_alert}}{{#is_warning}}{{{comparator}}} {{warn_threshold}} ms ({{value}}%){{/is_warning}}" + message = "${coalesce(var.replicalag_message, var.message)}" + + type = "metric alert" + + query = < ${var.replicalag_threshold_critical} +EOF + + thresholds { + warning = "${var.replicalag_threshold_warning}" + critical = "${var.replicalag_threshold_critical}" + } + + notify_no_data = true + evaluation_delay = "${var.evaluation_delay}" + notify_audit = false + timeout_h = 0 + include_tags = true + locked = false + require_full_window = false + new_host_delay = "${var.new_host_delay}" + + silenced = "${var.replicalag_silenced}" + + tags = ["env:${var.environment}", "type:cloud", "provider:aws", "resource:rds", "team:claranet", "created-by:terraform", "${var.replicalag_extra_tags}"] +} diff --git a/cloud/aws/rds/common/outputs.tf b/cloud/aws/rds/common/outputs.tf index 4d2c8c5..e112047 100644 --- a/cloud/aws/rds/common/outputs.tf +++ b/cloud/aws/rds/common/outputs.tf @@ -7,3 +7,8 @@ output "rds_free_space_low_id" { description = "id for monitor rds_free_space_low" value = "${datadog_monitor.rds_free_space_low.*.id}" } + +output "rds_replica_lag_id" { + description = "id for monitor rds_replica_lag" + value = "${datadog_monitor.rds_replica_lag.*.id}" +} From 81e344a81db2fdfba1665cdd191a5242fb7d3d90 Mon Sep 17 00:00:00 2001 From: Quentin Manfroi Date: Mon, 17 Sep 2018 11:04:33 +0200 Subject: [PATCH 09/10] MON-122 fix filter tags module path --- cloud/aws/rds/aurora/mysql/modules.tf | 2 +- cloud/aws/rds/aurora/postgresql/modules.tf | 2 +- cloud/aws/rds/common/modules.tf | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/cloud/aws/rds/aurora/mysql/modules.tf b/cloud/aws/rds/aurora/mysql/modules.tf index 0f449e0..21cb3ae 100644 --- a/cloud/aws/rds/aurora/mysql/modules.tf +++ b/cloud/aws/rds/aurora/mysql/modules.tf @@ -1,5 +1,5 @@ module "filter-tags" { - source = "../../common/filter-tags" + source = "../../../../../common/filter-tags" environment = "${var.environment}" resource = "rds" diff --git a/cloud/aws/rds/aurora/postgresql/modules.tf b/cloud/aws/rds/aurora/postgresql/modules.tf index 0f449e0..21cb3ae 100644 --- a/cloud/aws/rds/aurora/postgresql/modules.tf +++ b/cloud/aws/rds/aurora/postgresql/modules.tf @@ -1,5 +1,5 @@ module "filter-tags" { - source = "../../common/filter-tags" + source = "../../../../../common/filter-tags" environment = "${var.environment}" resource = "rds" diff --git a/cloud/aws/rds/common/modules.tf b/cloud/aws/rds/common/modules.tf index 1e7e2d4..401c9a3 100644 --- a/cloud/aws/rds/common/modules.tf +++ b/cloud/aws/rds/common/modules.tf @@ -1,5 +1,5 @@ module "filter-tags" { - source = "../../../common/filter-tags" + source = "../../../../common/filter-tags" environment = "${var.environment}" resource = "rds" From 82ffa1e495125938883ba0bfc2701a128dc86375 Mon Sep 17 00:00:00 2001 From: Quentin Manfroi Date: Mon, 17 Sep 2018 11:38:17 +0200 Subject: [PATCH 10/10] MON-122 add aws prefix to tagging --- cloud/aws/alb/modules.tf | 2 +- cloud/aws/elasticsearch/modules.tf | 2 +- cloud/aws/elb/modules.tf | 2 +- cloud/aws/kinesis-firehose/modules.tf | 2 +- cloud/aws/rds/aurora/mysql/modules.tf | 2 +- cloud/aws/rds/aurora/postgresql/modules.tf | 2 +- cloud/aws/rds/common/modules.tf | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/cloud/aws/alb/modules.tf b/cloud/aws/alb/modules.tf index 94be5f4..1aae9bf 100644 --- a/cloud/aws/alb/modules.tf +++ b/cloud/aws/alb/modules.tf @@ -2,7 +2,7 @@ module "filter-tags" { source = "../../../common/filter-tags" environment = "${var.environment}" - resource = "alb" + resource = "aws_alb" filter_tags_use_defaults = "${var.filter_tags_use_defaults}" filter_tags_custom = "${var.filter_tags_custom}" } diff --git a/cloud/aws/elasticsearch/modules.tf b/cloud/aws/elasticsearch/modules.tf index 88ddb32..0abfe32 100644 --- a/cloud/aws/elasticsearch/modules.tf +++ b/cloud/aws/elasticsearch/modules.tf @@ -2,7 +2,7 @@ module "filter-tags" { source = "../../../common/filter-tags" environment = "${var.environment}" - resource = "elasticsearch" + resource = "aws_elasticsearch" filter_tags_use_defaults = "${var.filter_tags_use_defaults}" filter_tags_custom = "${var.filter_tags_custom}" } diff --git a/cloud/aws/elb/modules.tf b/cloud/aws/elb/modules.tf index 017032e..b64c814 100644 --- a/cloud/aws/elb/modules.tf +++ b/cloud/aws/elb/modules.tf @@ -2,7 +2,7 @@ module "filter-tags" { source = "../../../common/filter-tags" environment = "${var.environment}" - resource = "elb" + resource = "aws_elb" filter_tags_use_defaults = "${var.filter_tags_use_defaults}" filter_tags_custom = "${var.filter_tags_custom}" } diff --git a/cloud/aws/kinesis-firehose/modules.tf b/cloud/aws/kinesis-firehose/modules.tf index c2d691d..b7b2e72 100644 --- a/cloud/aws/kinesis-firehose/modules.tf +++ b/cloud/aws/kinesis-firehose/modules.tf @@ -2,7 +2,7 @@ module "filter-tags" { source = "../../../common/filter-tags" environment = "${var.environment}" - resource = "kinesis-firehose" + resource = "aws_kinesis-firehose" filter_tags_use_defaults = "${var.filter_tags_use_defaults}" filter_tags_custom = "${var.filter_tags_custom}" } diff --git a/cloud/aws/rds/aurora/mysql/modules.tf b/cloud/aws/rds/aurora/mysql/modules.tf index 21cb3ae..9f52fb1 100644 --- a/cloud/aws/rds/aurora/mysql/modules.tf +++ b/cloud/aws/rds/aurora/mysql/modules.tf @@ -2,7 +2,7 @@ module "filter-tags" { source = "../../../../../common/filter-tags" environment = "${var.environment}" - resource = "rds" + resource = "aws_rds" filter_tags_use_defaults = "${var.filter_tags_use_defaults}" filter_tags_custom = "${var.filter_tags_custom}" } diff --git a/cloud/aws/rds/aurora/postgresql/modules.tf b/cloud/aws/rds/aurora/postgresql/modules.tf index 21cb3ae..9f52fb1 100644 --- a/cloud/aws/rds/aurora/postgresql/modules.tf +++ b/cloud/aws/rds/aurora/postgresql/modules.tf @@ -2,7 +2,7 @@ module "filter-tags" { source = "../../../../../common/filter-tags" environment = "${var.environment}" - resource = "rds" + resource = "aws_rds" filter_tags_use_defaults = "${var.filter_tags_use_defaults}" filter_tags_custom = "${var.filter_tags_custom}" } diff --git a/cloud/aws/rds/common/modules.tf b/cloud/aws/rds/common/modules.tf index 401c9a3..dcbe336 100644 --- a/cloud/aws/rds/common/modules.tf +++ b/cloud/aws/rds/common/modules.tf @@ -2,7 +2,7 @@ module "filter-tags" { source = "../../../../common/filter-tags" environment = "${var.environment}" - resource = "rds" + resource = "aws_rds" filter_tags_use_defaults = "${var.filter_tags_use_defaults}" filter_tags_custom = "${var.filter_tags_custom}" }