MON-122 update common

This commit is contained in:
Quentin Manfroi 2018-09-14 19:30:04 +02:00
parent ea9625144f
commit 7877118023
4 changed files with 83 additions and 159 deletions

View File

@ -1,71 +1,61 @@
AWS RDS Instance DataDog monitors # CLOUD AWS RDS DataDog monitors
=================================
How to use this module ## How to use this module
----------------------
For a single RDS instance :
``` ```
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}" 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}" 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}" 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 ## Purpose
-------
Creates a DataDog monitors with the following checks :
* CPU High Creates DataDog monitors with the following checks:
* Free disk space low (only for single RDS instances)
* Aurora Replica Lag (only for Aurora Cluster Mysql or PostgreSQL)
Inputs - RDS instance CPU high
------ - RDS instance free space
## Inputs
| Name | Description | Type | Default | Required | | Name | Description | Type | Default | Required |
|------|-------------|:----:|:-----:|:-----:| |------|-------------|:----:|:-----:|:-----:|
| aurora_cluster_type | RDS Aurora cluster monitoring. If empty, single RDS instance monitoring. [available values: `mysql`, `postgresql`] | string | `` | no | | cpu_enabled | Flag to enable RDS CPU usage monitor | string | `true` | no |
| aurora_replicalag_message | Custom message for RDS Aurora replica lag monitor | string | `` | no | | cpu_extra_tags | Extra tags for RDS CPU usage monitor | list | `<list>` | no |
| aurora_replicalag_silenced | Groups to mute for RDS Aurora replica lag monitor | map | `<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_message | Custom message for RDS CPU usage monitor | string | `` | no |
| cpu_silenced | Groups to mute for RDS CPU usage monitor | map | `<map>` | no | | cpu_silenced | Groups to mute for RDS CPU usage monitor | map | `<map>` | no |
| cpu_threshold_critical | CPU usage in percent (critical threshold) | string | `90` | 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_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 | | 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 | `<list>` | no |
| diskspace_message | Custom message for RDS free diskspace monitor | string | `` | no | | diskspace_message | Custom message for RDS free diskspace monitor | string | `` | no |
| diskspace_silenced | Groups to mute for RDS free diskspace monitor | map | `<map>` | no | | diskspace_silenced | Groups to mute for RDS free diskspace monitor | map | `<map>` | no |
| diskspace_threshold_critical | Disk free space in percent (critical threshold) | string | `10` | 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_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 | | 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 | | 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_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 | | filter_tags_use_defaults | Use default filter tags convention | string | `true` | no |
| message | Message sent when an alert is triggered | string | - | yes | | 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/) 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) 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)

View File

@ -5,11 +5,16 @@ variable "environment" {
} }
# Global DataDog # Global DataDog
variable "delay" { variable "evaluation_delay" {
description = "Delay in seconds for the metric evaluation" description = "Delay in seconds for the metric evaluation"
default = 900 default = 900
} }
variable "new_host_delay" {
description = "Delay in seconds before monitor new resource"
default = 300
}
variable "message" { variable "message" {
description = "Message sent when an alert is triggered" description = "Message sent when an alert is triggered"
} }
@ -24,12 +29,6 @@ variable "filter_tags_custom" {
default = "*" 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 # AWS RDS instance specific
variable "cpu_silenced" { variable "cpu_silenced" {
@ -38,12 +37,30 @@ variable "cpu_silenced" {
default = {} 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" { variable "cpu_message" {
description = "Custom message for RDS CPU usage monitor" description = "Custom message for RDS CPU usage monitor"
type = "string" type = "string"
default = "" 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" { 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`]" 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" type = "string"
@ -66,12 +83,30 @@ variable "diskspace_silenced" {
default = {} 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" { variable "diskspace_message" {
description = "Custom message for RDS free diskspace monitor" description = "Custom message for RDS free diskspace monitor"
type = "string" type = "string"
default = "" 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" { 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`]" 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" type = "string"
@ -88,30 +123,3 @@ variable "diskspace_threshold_critical" {
default = "10" 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"
}

View File

@ -6,3 +6,4 @@ module "filter-tags" {
filter_tags_use_defaults = "${var.filter_tags_use_defaults}" filter_tags_use_defaults = "${var.filter_tags_use_defaults}"
filter_tags_custom = "${var.filter_tags_custom}" filter_tags_custom = "${var.filter_tags_custom}"
} }

View File

@ -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 ### ### RDS instance CPU monitor ###
resource "datadog_monitor" "rds_cpu_90_15min" { 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}}" 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)}" message = "${coalesce(var.cpu_message, var.message)}"
type = "metric alert" type = "metric alert"
query = <<EOF query = <<EOF
avg(${var.cpu_timeframe}): ( ${var.cpu_time_aggregator}(${var.cpu_timeframe}): (
avg:aws.rds.cpuutilization{${data.template_file.filter.rendered}} by {region,name} avg:aws.rds.cpuutilization${module.filter-tags.query_alert} by {region,name}
) > ${var.cpu_threshold_critical} ) > ${var.cpu_threshold_critical}
EOF EOF
@ -25,30 +18,31 @@ EOF
} }
notify_no_data = true notify_no_data = true
evaluation_delay = "${var.delay}" evaluation_delay = "${var.evaluation_delay}"
notify_audit = false notify_audit = false
timeout_h = 0 timeout_h = 0
include_tags = true include_tags = true
locked = false locked = false
require_full_window = false require_full_window = false
new_host_delay = "${var.delay}" new_host_delay = "${var.new_host_delay}"
silenced = "${var.cpu_silenced}" 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 ### ### RDS instance free space monitor ###
resource "datadog_monitor" "rds_free_space_low" { 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}}" 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)}" message = "${coalesce(var.diskspace_message, var.message)}"
type = "metric alert" type = "metric alert"
query = <<EOF query = <<EOF
avg(${var.diskspace_timeframe}): ( ${var.diskspace_time_aggregator}(${var.diskspace_timeframe}): (
avg:aws.rds.free_storage_space{${data.template_file.filter.rendered}} by {region,name} / avg:aws.rds.free_storage_space${module.filter-tags.query_alert} by {region,name} /
avg:aws.rds.total_storage_space{${data.template_file.filter.rendered}} by {region,name} * 100 avg:aws.rds.total_storage_space${module.filter-tags.query_alert} by {region,name} * 100
) < ${var.diskspace_threshold_critical} ) < ${var.diskspace_threshold_critical}
EOF EOF
@ -58,85 +52,16 @@ EOF
} }
notify_no_data = true notify_no_data = true
evaluation_delay = "${var.delay}" evaluation_delay = "${var.evaluation_delay}"
notify_audit = false notify_audit = false
timeout_h = 0 timeout_h = 0
include_tags = true include_tags = true
locked = false locked = false
require_full_window = false require_full_window = false
new_host_delay = "${var.delay}" new_host_delay = "${var.new_host_delay}"
silenced = "${var.diskspace_silenced}" silenced = "${var.diskspace_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.diskspace_extra_tags}"]
count = "${var.aurora_cluster_type == "" ? 1 : 0}"
} }
### 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 = <<EOF
avg(${var.aurora_replicalag_timeframe}): (
avg:aws.rds.rdsto_aurora_postgre_sqlreplica_lag{${data.template_file.filter.rendered}} by {region,name}
) > ${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 = <<EOF
avg(${var.aurora_replicalag_timeframe}): (
avg:aws.rds.aws.rds.aurora_replica_lag{${data.template_file.filter.rendered}} by {region,name}
) > ${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}"
}