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}" -}