From 9e5068065ec3fdcf6700f976961dd9ee79064a2d Mon Sep 17 00:00:00 2001 From: Alexandre Gaillet Date: Wed, 26 Sep 2018 10:14:08 +0200 Subject: [PATCH 1/2] MON-310 - Azure Postgre monitors added --- README.md | 1 + cloud/azure/postgresql/README.md | 85 +++++++ cloud/azure/postgresql/inputs.tf | 220 ++++++++++++++++++ cloud/azure/postgresql/modules.tf | 8 + .../azure/postgresql/monitors-postegresql.tf | 194 +++++++++++++++ cloud/azure/postgresql/outputs.tf | 29 +++ 6 files changed, 537 insertions(+) create mode 100644 cloud/azure/postgresql/README.md create mode 100644 cloud/azure/postgresql/inputs.tf create mode 100644 cloud/azure/postgresql/modules.tf create mode 100644 cloud/azure/postgresql/monitors-postegresql.tf create mode 100644 cloud/azure/postgresql/outputs.tf diff --git a/README.md b/README.md index 5cadf39..85e8d87 100644 --- a/README.md +++ b/README.md @@ -101,6 +101,7 @@ The `//` is very important, it's a terraform specific syntax used to separate gi - [eventhub](https://bitbucket.org/morea/terraform.feature.datadog/src/master/cloud/azure/eventhub/) - [iothubs](https://bitbucket.org/morea/terraform.feature.datadog/src/master/cloud/azure/iothubs/) - [keyvault](https://bitbucket.org/morea/terraform.feature.datadog/src/master/cloud/azure/keyvault/) + - [postgresql](https://bitbucket.org/morea/terraform.feature.datadog/src/master/cloud/azure/postgresql/) - [redis](https://bitbucket.org/morea/terraform.feature.datadog/src/master/cloud/azure/redis/) - [servicebus](https://bitbucket.org/morea/terraform.feature.datadog/src/master/cloud/azure/servicebus/) - [sql-database](https://bitbucket.org/morea/terraform.feature.datadog/src/master/cloud/azure/sql-database/) diff --git a/cloud/azure/postgresql/README.md b/cloud/azure/postgresql/README.md new file mode 100644 index 0000000..c042c55 --- /dev/null +++ b/cloud/azure/postgresql/README.md @@ -0,0 +1,85 @@ +# CLOUD AZURE POSTGRESQL DataDog monitors + +## How to use this module + +``` +module "datadog-monitors-cloud-azure-postgresql" { + source = "git::ssh://git@bitbucket.org/morea/terraform.feature.datadog.git//cloud/azure/postgresql?ref={revision}" + + environment = "${var.environment}" + message = "${module.datadog-message-alerting.alerting-message}" +} + +``` + +## Purpose + +Creates DataDog monitors with the following checks: + +- Postgresql Server compute consumption is high +- Postgresql Server CPU usage is high +- Postgresql Server has no connection +- Postgresql Server IO consumption is high +- Postgresql Server memory usage is high +- Postgresql Server storage is running low + +## Inputs + +| Name | Description | Type | Default | Required | +|------|-------------|:----:|:-----:|:-----:| +| compute_consumption_message | Custom message for Postgresql compute consumption monitor | string | `` | no | +| compute_consumption_silenced | Groups to mute for Postgresql compute consumption monitor | map | `{}` | no | +| compute_consumption_threshold_critical | Postgresql compute consumption in percent (critical threshold) | string | `90` | no | +| compute_consumption_threshold_warning | Postgresql compute consumption in percent (warning threshold) | string | `80` | no | +| compute_consumption_time_aggregator | Monitor aggregator for Postgresql compute consumption [available values: min, max or avg] | string | `min` | no | +| compute_consumption_timeframe | Monitor timeframe for Postgresql compute consumption [available values: `last_#m` (1, 5, 10, 15, or 30), `last_#h` (1, 2, or 4), or `last_1d`] | string | `last_15m` | no | +| cpu_usage_message | Custom message for Postgresql CPU monitor | string | `` | no | +| cpu_usage_silenced | Groups to mute for Postgresql CPU monitor | map | `{}` | no | +| cpu_usage_threshold_critical | Postgresql CPU usage in percent (critical threshold) | string | `90` | no | +| cpu_usage_threshold_warning | Postgresql CPU usage in percent (warning threshold) | string | `80` | no | +| cpu_usage_time_aggregator | Monitor aggregator for Postgresql CPU [available values: min, max or avg] | string | `min` | no | +| cpu_usage_timeframe | Monitor timeframe for Postgresql CPU [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 | +| environment | Architecture environment | string | - | yes | +| 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 | +| free_storage_message | Custom message for Postgresql Free Storage monitor | string | `` | no | +| free_storage_silenced | Groups to mute for Postgresql Free Storage monitor | map | `{}` | no | +| free_storage_threshold_critical | Postgresql Free Storage remaining in percent (critical threshold) | string | `10` | no | +| free_storage_threshold_warning | Postgresql Free Storage remaining in percent (warning threshold) | string | `20` | no | +| free_storage_time_aggregator | Monitor aggregator for Postgresql Free Storage [available values: min, max or avg] | string | `min` | no | +| free_storage_timeframe | Monitor timeframe for Postgresql Free Storage [available values: `last_#m` (1, 5, 10, 15, or 30), `last_#h` (1, 2, or 4), or `last_1d`] | string | `last_15m` | no | +| io_consumption_message | Custom message for Postgresql IO consumption monitor | string | `` | no | +| io_consumption_silenced | Groups to mute for Postgresql IO consumption monitor | map | `{}` | no | +| io_consumption_threshold_critical | Postgresql IO consumption in percent (critical threshold) | string | `90` | no | +| io_consumption_threshold_warning | Postgresql IO consumption in percent (warning threshold) | string | `80` | no | +| io_consumption_time_aggregator | Monitor aggregator for Postgresql IO consumption [available values: min, max or avg] | string | `min` | no | +| io_consumption_timeframe | Monitor timeframe for Postgresql IO consumption [available values: `last_#m` (1, 5, 10, 15, or 30), `last_#h` (1, 2, or 4), or `last_1d`] | string | `last_15m` | no | +| memory_usage_message | Custom message for Postgresql memory monitor | string | `` | no | +| memory_usage_silenced | Groups to mute for Postgresql memory monitor | map | `{}` | no | +| memory_usage_threshold_critical | Postgresql memory usage in percent (critical threshold) | string | `90` | no | +| memory_usage_threshold_warning | Postgresql memory usage in percent (warning threshold) | string | `80` | no | +| memory_usage_time_aggregator | Monitor aggregator for Postgresql memory [available values: min, max or avg] | string | `min` | no | +| memory_usage_timeframe | Monitor timeframe for Postgresql memory [available values: `last_#m` (1, 5, 10, 15, or 30), `last_#h` (1, 2, or 4), or `last_1d`] | string | `last_15m` | no | +| message | Message sent when a Redis monitor is triggered | string | - | yes | +| no_connection_message | Custom message for Postgresql no connection monitor | string | `` | no | +| no_connection_silenced | Groups to mute for Postgresql no connection monitor | map | `{}` | no | +| no_connection_time_aggregator | Monitor aggregator for Postgresql no connection [available values: min, max or avg] | string | `min` | no | +| no_connection_timeframe | Monitor timeframe for Postgresql no connection [available values: `last_#m` (1, 5, 10, 15, or 30), `last_#h` (1, 2, or 4), or `last_1d`] | string | `last_5m` | no | + +## Outputs + +| Name | Description | +|------|-------------| +| postgresql_compute_consumption_id | id for monitor postgresql_compute_consumption | +| postgresql_cpu_usage_id | id for monitor postgresql_cpu_usage | +| postgresql_free_storage_id | id for monitor postgresql_free_storage | +| postgresql_io_consumption_id | id for monitor postgresql_io_consumption | +| postgresql_memory_usage_id | id for monitor postgresql_memory_usage | +| postgresql_no_connection_id | id for monitor postgresql_no_connection | + +Related documentation +--------------------- + +DataDog documentation: [https://docs.datadoghq.com/integrations/azure/](https://docs.datadoghq.com/integrations/azure/) +You have to search `mysql` diff --git a/cloud/azure/postgresql/inputs.tf b/cloud/azure/postgresql/inputs.tf new file mode 100644 index 0000000..47dfa44 --- /dev/null +++ b/cloud/azure/postgresql/inputs.tf @@ -0,0 +1,220 @@ +# Global Terraform +variable "environment" { + description = "Architecture environment" + type = "string" +} + +# Global DataDog +variable "message" { + description = "Message sent when a Redis monitor is triggered" +} + +variable "delay" { + description = "Delay in seconds for the metric evaluation" + default = 900 +} + +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 = "*" +} + +# Azure Databases for Postgresql Servers specific variables +variable "cpu_usage_silenced" { + description = "Groups to mute for Postgresql CPU monitor" + type = "map" + default = {} +} + +variable "cpu_usage_message" { + description = "Custom message for Postgresql CPU monitor" + type = "string" + default = "" +} + +variable "cpu_usage_time_aggregator" { + description = "Monitor aggregator for Postgresql CPU [available values: min, max or avg]" + type = "string" + default = "min" +} + +variable "cpu_usage_timeframe" { + description = "Monitor timeframe for Postgresql CPU [available values: `last_#m` (1, 5, 10, 15, or 30), `last_#h` (1, 2, or 4), or `last_1d`]" + type = "string" + default = "last_15m" +} + +variable "cpu_usage_threshold_warning" { + description = "Postgresql CPU usage in percent (warning threshold)" + default = "80" +} + +variable "cpu_usage_threshold_critical" { + description = "Postgresql CPU usage in percent (critical threshold)" + default = "90" +} + +variable "no_connection_silenced" { + description = "Groups to mute for Postgresql no connection monitor" + type = "map" + default = {} +} + +variable "no_connection_message" { + description = "Custom message for Postgresql no connection monitor" + type = "string" + default = "" +} + +variable "no_connection_time_aggregator" { + description = "Monitor aggregator for Postgresql no connection [available values: min, max or avg]" + type = "string" + default = "min" +} + +variable "no_connection_timeframe" { + description = "Monitor timeframe for Postgresql no connection [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 "free_storage_silenced" { + description = "Groups to mute for Postgresql Free Storage monitor" + type = "map" + default = {} +} + +variable "free_storage_message" { + description = "Custom message for Postgresql Free Storage monitor" + type = "string" + default = "" +} + +variable "free_storage_time_aggregator" { + description = "Monitor aggregator for Postgresql Free Storage [available values: min, max or avg]" + type = "string" + default = "min" +} + +variable "free_storage_timeframe" { + description = "Monitor timeframe for Postgresql Free Storage [available values: `last_#m` (1, 5, 10, 15, or 30), `last_#h` (1, 2, or 4), or `last_1d`]" + type = "string" + default = "last_15m" +} + +variable "free_storage_threshold_warning" { + description = "Postgresql Free Storage remaining in percent (warning threshold)" + default = "20" +} + +variable "free_storage_threshold_critical" { + description = "Postgresql Free Storage remaining in percent (critical threshold)" + default = "10" +} + +variable "io_consumption_silenced" { + description = "Groups to mute for Postgresql IO consumption monitor" + type = "map" + default = {} +} + +variable "io_consumption_message" { + description = "Custom message for Postgresql IO consumption monitor" + type = "string" + default = "" +} + +variable "io_consumption_time_aggregator" { + description = "Monitor aggregator for Postgresql IO consumption [available values: min, max or avg]" + type = "string" + default = "min" +} + +variable "io_consumption_timeframe" { + description = "Monitor timeframe for Postgresql IO consumption [available values: `last_#m` (1, 5, 10, 15, or 30), `last_#h` (1, 2, or 4), or `last_1d`]" + type = "string" + default = "last_15m" +} + +variable "io_consumption_threshold_warning" { + description = "Postgresql IO consumption in percent (warning threshold)" + default = "80" +} + +variable "io_consumption_threshold_critical" { + description = "Postgresql IO consumption in percent (critical threshold)" + default = "90" +} + +variable "memory_usage_silenced" { + description = "Groups to mute for Postgresql memory monitor" + type = "map" + default = {} +} + +variable "memory_usage_message" { + description = "Custom message for Postgresql memory monitor" + type = "string" + default = "" +} + +variable "memory_usage_time_aggregator" { + description = "Monitor aggregator for Postgresql memory [available values: min, max or avg]" + type = "string" + default = "min" +} + +variable "memory_usage_timeframe" { + description = "Monitor timeframe for Postgresql memory [available values: `last_#m` (1, 5, 10, 15, or 30), `last_#h` (1, 2, or 4), or `last_1d`]" + type = "string" + default = "last_15m" +} + +variable "memory_usage_threshold_warning" { + description = "Postgresql memory usage in percent (warning threshold)" + default = "80" +} + +variable "memory_usage_threshold_critical" { + description = "Postgresql memory usage in percent (critical threshold)" + default = "90" +} + +variable "compute_consumption_silenced" { + description = "Groups to mute for Postgresql compute consumption monitor" + type = "map" + default = {} +} + +variable "compute_consumption_message" { + description = "Custom message for Postgresql compute consumption monitor" + type = "string" + default = "" +} + +variable "compute_consumption_time_aggregator" { + description = "Monitor aggregator for Postgresql compute consumption [available values: min, max or avg]" + type = "string" + default = "min" +} + +variable "compute_consumption_timeframe" { + description = "Monitor timeframe for Postgresql compute consumption [available values: `last_#m` (1, 5, 10, 15, or 30), `last_#h` (1, 2, or 4), or `last_1d`]" + type = "string" + default = "last_15m" +} + +variable "compute_consumption_threshold_warning" { + description = "Postgresql compute consumption in percent (warning threshold)" + default = "80" +} + +variable "compute_consumption_threshold_critical" { + description = "Postgresql compute consumption in percent (critical threshold)" + default = "90" +} diff --git a/cloud/azure/postgresql/modules.tf b/cloud/azure/postgresql/modules.tf new file mode 100644 index 0000000..7eed106 --- /dev/null +++ b/cloud/azure/postgresql/modules.tf @@ -0,0 +1,8 @@ +module "filter-tags" { + source = "../../../common/filter-tags" + + environment = "${var.environment}" + resource = "postgresql" + filter_tags_use_defaults = "${var.filter_tags_use_defaults}" + filter_tags_custom = "${var.filter_tags_custom}" +} diff --git a/cloud/azure/postgresql/monitors-postegresql.tf b/cloud/azure/postgresql/monitors-postegresql.tf new file mode 100644 index 0000000..0157907 --- /dev/null +++ b/cloud/azure/postgresql/monitors-postegresql.tf @@ -0,0 +1,194 @@ +data "template_file" "filter" { + template = "$${filter}" + + vars { + filter = "${var.filter_tags_use_defaults == "true" ? format("dd_monitoring:enabled,dd_azure_postgresql:enabled,env:%s", var.environment) : "${var.filter_tags_custom}"}" + } +} + +resource "datadog_monitor" "postgresql_cpu_usage" { + name = "[${var.environment}] Postgresql Server CPU usage is high {{#is_alert}}{{{comparator}}} {{threshold}}% ({{value}}%){{/is_alert}}{{#is_warning}}{{{comparator}}} {{warn_threshold}}% ({{value}}%){{/is_warning}}" + message = "${coalesce(var.cpu_usage_message, var.message)}" + + query = < ${var.cpu_usage_threshold_critical} + EOF + + type = "metric alert" + + thresholds { + critical = "${var.cpu_usage_threshold_critical}" + warning = "${var.cpu_usage_threshold_warning}" + } + + silenced = "${var.cpu_usage_silenced}" + + notify_no_data = true + evaluation_delay = "${var.delay}" + renotify_interval = 0 + notify_audit = false + timeout_h = 0 + include_tags = true + locked = false + require_full_window = false + new_host_delay = "${var.delay}" + + tags = ["env:${var.environment}", "resource:postgresql", "team:azure", "provider:azure"] +} + +resource "datadog_monitor" "postgresql_no_connection" { + name = "[${var.environment}] Postgresql Server has no connection" + message = "${coalesce(var.no_connection_message, var.message)}" + + query = < ${var.io_consumption_threshold_critical} + EOF + + type = "metric alert" + + thresholds { + critical = "${var.io_consumption_threshold_critical}" + warning = "${var.io_consumption_threshold_warning}" + } + + silenced = "${var.io_consumption_silenced}" + + notify_no_data = true + evaluation_delay = "${var.delay}" + renotify_interval = 0 + notify_audit = false + timeout_h = 0 + include_tags = true + locked = false + require_full_window = false + new_host_delay = "${var.delay}" + + tags = ["env:${var.environment}", "resource:postgresql", "team:azure", "provider:azure"] +} + +resource "datadog_monitor" "postgresql_memory_usage" { + name = "[${var.environment}] Postgresql Server memory usage is high {{#is_alert}}{{{comparator}}} {{threshold}}% ({{value}}%){{/is_alert}}{{#is_warning}}{{{comparator}}} {{warn_threshold}}% ({{value}}%){{/is_warning}}" + message = "${coalesce(var.memory_usage_message, var.message)}" + + query = < ${var.memory_usage_threshold_critical} + EOF + + type = "metric alert" + + thresholds { + critical = "${var.memory_usage_threshold_critical}" + warning = "${var.memory_usage_threshold_warning}" + } + + silenced = "${var.memory_usage_silenced}" + + notify_no_data = true + evaluation_delay = "${var.delay}" + renotify_interval = 0 + notify_audit = false + timeout_h = 0 + include_tags = true + locked = false + require_full_window = false + new_host_delay = "${var.delay}" + + tags = ["env:${var.environment}", "resource:postgresql", "team:azure", "provider:azure"] +} + +resource "datadog_monitor" "postgresql_compute_consumption" { + name = "[${var.environment}] Postgresql Server compute consumption is high {{#is_alert}}{{{comparator}}} {{threshold}}% ({{value}}%){{/is_alert}}{{#is_warning}}{{{comparator}}} {{warn_threshold}}% ({{value}}%){{/is_warning}}" + message = "${coalesce(var.compute_consumption_message, var.message)}" + + query = < ${var.compute_consumption_threshold_critical} + EOF + + type = "metric alert" + + thresholds { + critical = "${var.compute_consumption_threshold_critical}" + warning = "${var.compute_consumption_threshold_warning}" + } + + silenced = "${var.compute_consumption_silenced}" + + notify_no_data = true + evaluation_delay = "${var.delay}" + renotify_interval = 0 + notify_audit = false + timeout_h = 0 + include_tags = true + locked = false + require_full_window = false + new_host_delay = "${var.delay}" + + tags = ["env:${var.environment}", "resource:postgresql", "team:azure", "provider:azure"] +} diff --git a/cloud/azure/postgresql/outputs.tf b/cloud/azure/postgresql/outputs.tf new file mode 100644 index 0000000..b1eeb0a --- /dev/null +++ b/cloud/azure/postgresql/outputs.tf @@ -0,0 +1,29 @@ +output "postgresql_cpu_usage_id" { + description = "id for monitor postgresql_cpu_usage" + value = "${datadog_monitor.postgresql_cpu_usage.*.id}" +} + +output "postgresql_no_connection_id" { + description = "id for monitor postgresql_no_connection" + value = "${datadog_monitor.postgresql_no_connection.*.id}" +} + +output "postgresql_free_storage_id" { + description = "id for monitor postgresql_free_storage" + value = "${datadog_monitor.postgresql_free_storage.*.id}" +} + +output "postgresql_io_consumption_id" { + description = "id for monitor postgresql_io_consumption" + value = "${datadog_monitor.postgresql_io_consumption.*.id}" +} + +output "postgresql_memory_usage_id" { + description = "id for monitor postgresql_memory_usage" + value = "${datadog_monitor.postgresql_memory_usage.*.id}" +} + +output "postgresql_compute_consumption_id" { + description = "id for monitor postgresql_compute_consumption" + value = "${datadog_monitor.postgresql_compute_consumption.*.id}" +} From 0711c6a888eb508376a87aad2e7ec9d1e3e9e4f6 Mon Sep 17 00:00:00 2001 From: Alexandre Gaillet Date: Fri, 28 Sep 2018 14:52:03 +0200 Subject: [PATCH 2/2] MON-310 - Best practice applied --- cloud/azure/postgresql/README.md | 95 ++++---- cloud/azure/postgresql/inputs.tf | 213 ++++++++++++------ .../azure/postgresql/monitors-postegresql.tf | 82 ++++--- 3 files changed, 239 insertions(+), 151 deletions(-) diff --git a/cloud/azure/postgresql/README.md b/cloud/azure/postgresql/README.md index c042c55..1f5ad93 100644 --- a/cloud/azure/postgresql/README.md +++ b/cloud/azure/postgresql/README.md @@ -16,56 +16,69 @@ module "datadog-monitors-cloud-azure-postgresql" { Creates DataDog monitors with the following checks: -- Postgresql Server compute consumption is high -- Postgresql Server CPU usage is high +- Postgresql Server compute consumption +- Postgresql Server CPU usage - Postgresql Server has no connection -- Postgresql Server IO consumption is high -- Postgresql Server memory usage is high -- Postgresql Server storage is running low +- Postgresql Server IO consumption +- Postgresql Server memory usage +- Postgresql Server storage ## Inputs | Name | Description | Type | Default | Required | |------|-------------|:----:|:-----:|:-----:| -| compute_consumption_message | Custom message for Postgresql compute consumption monitor | string | `` | no | -| compute_consumption_silenced | Groups to mute for Postgresql compute consumption monitor | map | `{}` | no | -| compute_consumption_threshold_critical | Postgresql compute consumption in percent (critical threshold) | string | `90` | no | -| compute_consumption_threshold_warning | Postgresql compute consumption in percent (warning threshold) | string | `80` | no | -| compute_consumption_time_aggregator | Monitor aggregator for Postgresql compute consumption [available values: min, max or avg] | string | `min` | no | -| compute_consumption_timeframe | Monitor timeframe for Postgresql compute consumption [available values: `last_#m` (1, 5, 10, 15, or 30), `last_#h` (1, 2, or 4), or `last_1d`] | string | `last_15m` | no | -| cpu_usage_message | Custom message for Postgresql CPU monitor | string | `` | no | -| cpu_usage_silenced | Groups to mute for Postgresql CPU monitor | map | `{}` | no | -| cpu_usage_threshold_critical | Postgresql CPU usage in percent (critical threshold) | string | `90` | no | -| cpu_usage_threshold_warning | Postgresql CPU usage in percent (warning threshold) | string | `80` | no | -| cpu_usage_time_aggregator | Monitor aggregator for Postgresql CPU [available values: min, max or avg] | string | `min` | no | -| cpu_usage_timeframe | Monitor timeframe for Postgresql CPU [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 | +| compute_consumption_enabled | Flag to enable PostgreSQL status monitor | string | `true` | no | +| compute_consumption_extra_tags | Extra tags for PostgreSQL status monitor | list | `[]` | no | +| compute_consumption_message | Custom message for PostgreSQL compute consumption monitor | string | `` | no | +| compute_consumption_silenced | Groups to mute for PostgreSQL compute consumption monitor | map | `{}` | no | +| compute_consumption_threshold_critical | PostgreSQL compute consumption in percent (critical threshold) | string | `90` | no | +| compute_consumption_threshold_warning | PostgreSQL compute consumption in percent (warning threshold) | string | `80` | no | +| compute_consumption_time_aggregator | Monitor aggregator for PostgreSQL compute consumption [available values: min, max or avg] | string | `min` | no | +| compute_consumption_timeframe | Monitor timeframe for PostgreSQL compute consumption [available values: `last_#m` (1, 5, 10, 15, or 30), `last_#h` (1, 2, or 4), or `last_1d`] | string | `last_15m` | no | +| cpu_usage_enabled | Flag to enable PostgreSQL status monitor | string | `true` | no | +| cpu_usage_extra_tags | Extra tags for PostgreSQL status monitor | list | `[]` | no | +| cpu_usage_message | Custom message for PostgreSQL CPU monitor | string | `` | no | +| cpu_usage_silenced | Groups to mute for PostgreSQL CPU monitor | map | `{}` | no | +| cpu_usage_threshold_critical | PostgreSQL CPU usage in percent (critical threshold) | string | `90` | no | +| cpu_usage_threshold_warning | PostgreSQL CPU usage in percent (warning threshold) | string | `80` | no | +| cpu_usage_time_aggregator | Monitor aggregator for PostgreSQL CPU [available values: min, max or avg] | string | `min` | no | +| cpu_usage_timeframe | Monitor timeframe for PostgreSQL CPU [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 | -| free_storage_message | Custom message for Postgresql Free Storage monitor | string | `` | no | -| free_storage_silenced | Groups to mute for Postgresql Free Storage monitor | map | `{}` | no | -| free_storage_threshold_critical | Postgresql Free Storage remaining in percent (critical threshold) | string | `10` | no | -| free_storage_threshold_warning | Postgresql Free Storage remaining in percent (warning threshold) | string | `20` | no | -| free_storage_time_aggregator | Monitor aggregator for Postgresql Free Storage [available values: min, max or avg] | string | `min` | no | -| free_storage_timeframe | Monitor timeframe for Postgresql Free Storage [available values: `last_#m` (1, 5, 10, 15, or 30), `last_#h` (1, 2, or 4), or `last_1d`] | string | `last_15m` | no | -| io_consumption_message | Custom message for Postgresql IO consumption monitor | string | `` | no | -| io_consumption_silenced | Groups to mute for Postgresql IO consumption monitor | map | `{}` | no | -| io_consumption_threshold_critical | Postgresql IO consumption in percent (critical threshold) | string | `90` | no | -| io_consumption_threshold_warning | Postgresql IO consumption in percent (warning threshold) | string | `80` | no | -| io_consumption_time_aggregator | Monitor aggregator for Postgresql IO consumption [available values: min, max or avg] | string | `min` | no | -| io_consumption_timeframe | Monitor timeframe for Postgresql IO consumption [available values: `last_#m` (1, 5, 10, 15, or 30), `last_#h` (1, 2, or 4), or `last_1d`] | string | `last_15m` | no | -| memory_usage_message | Custom message for Postgresql memory monitor | string | `` | no | -| memory_usage_silenced | Groups to mute for Postgresql memory monitor | map | `{}` | no | -| memory_usage_threshold_critical | Postgresql memory usage in percent (critical threshold) | string | `90` | no | -| memory_usage_threshold_warning | Postgresql memory usage in percent (warning threshold) | string | `80` | no | -| memory_usage_time_aggregator | Monitor aggregator for Postgresql memory [available values: min, max or avg] | string | `min` | no | -| memory_usage_timeframe | Monitor timeframe for Postgresql memory [available values: `last_#m` (1, 5, 10, 15, or 30), `last_#h` (1, 2, or 4), or `last_1d`] | string | `last_15m` | no | -| message | Message sent when a Redis monitor is triggered | string | - | yes | -| no_connection_message | Custom message for Postgresql no connection monitor | string | `` | no | -| no_connection_silenced | Groups to mute for Postgresql no connection monitor | map | `{}` | no | -| no_connection_time_aggregator | Monitor aggregator for Postgresql no connection [available values: min, max or avg] | string | `min` | no | -| no_connection_timeframe | Monitor timeframe for Postgresql no connection [available values: `last_#m` (1, 5, 10, 15, or 30), `last_#h` (1, 2, or 4), or `last_1d`] | string | `last_5m` | no | +| free_storage_enabled | Flag to enable PostgreSQL status monitor | string | `true` | no | +| free_storage_extra_tags | Extra tags for PostgreSQL status monitor | list | `[]` | no | +| free_storage_message | Custom message for PostgreSQL Free Storage monitor | string | `` | no | +| free_storage_silenced | Groups to mute for PostgreSQL Free Storage monitor | map | `{}` | no | +| free_storage_threshold_critical | PostgreSQL Free Storage remaining in percent (critical threshold) | string | `10` | no | +| free_storage_threshold_warning | PostgreSQL Free Storage remaining in percent (warning threshold) | string | `20` | no | +| free_storage_time_aggregator | Monitor aggregator for PostgreSQL Free Storage [available values: min, max or avg] | string | `min` | no | +| free_storage_timeframe | Monitor timeframe for PostgreSQL Free Storage [available values: `last_#m` (1, 5, 10, 15, or 30), `last_#h` (1, 2, or 4), or `last_1d`] | string | `last_15m` | no | +| io_consumption_enabled | Flag to enable PostgreSQL status monitor | string | `true` | no | +| io_consumption_extra_tags | Extra tags for PostgreSQL status monitor | list | `[]` | no | +| io_consumption_message | Custom message for PostgreSQL IO consumption monitor | string | `` | no | +| io_consumption_silenced | Groups to mute for PostgreSQL IO consumption monitor | map | `{}` | no | +| io_consumption_threshold_critical | PostgreSQL IO consumption in percent (critical threshold) | string | `90` | no | +| io_consumption_threshold_warning | PostgreSQL IO consumption in percent (warning threshold) | string | `80` | no | +| io_consumption_time_aggregator | Monitor aggregator for PostgreSQL IO consumption [available values: min, max or avg] | string | `min` | no | +| io_consumption_timeframe | Monitor timeframe for PostgreSQL IO consumption [available values: `last_#m` (1, 5, 10, 15, or 30), `last_#h` (1, 2, or 4), or `last_1d`] | string | `last_15m` | no | +| memory_usage_enabled | Flag to enable PostgreSQL status monitor | string | `true` | no | +| memory_usage_extra_tags | Extra tags for PostgreSQL status monitor | list | `[]` | no | +| memory_usage_message | Custom message for PostgreSQL memory monitor | string | `` | no | +| memory_usage_silenced | Groups to mute for PostgreSQL memory monitor | map | `{}` | no | +| memory_usage_threshold_critical | PostgreSQL memory usage in percent (critical threshold) | string | `90` | no | +| memory_usage_threshold_warning | PostgreSQL memory usage in percent (warning threshold) | string | `80` | no | +| memory_usage_time_aggregator | Monitor aggregator for PostgreSQL memory [available values: min, max or avg] | string | `min` | no | +| memory_usage_timeframe | Monitor timeframe for PostgreSQL memory [available values: `last_#m` (1, 5, 10, 15, or 30), `last_#h` (1, 2, or 4), or `last_1d`] | string | `last_15m` | no | +| message | Message sent when an alert is triggered | string | - | yes | +| new_host_delay | Delay in seconds before monitor new resource | string | `300` | no | +| no_connection_enabled | Flag to enable PostgreSQL status monitor | string | `true` | no | +| no_connection_extra_tags | Extra tags for PostgreSQL status monitor | list | `[]` | no | +| no_connection_message | Custom message for PostgreSQL no connection monitor | string | `` | no | +| no_connection_silenced | Groups to mute for PostgreSQL no connection monitor | map | `{}` | no | +| no_connection_time_aggregator | Monitor aggregator for PostgreSQL no connection [available values: min, max or avg] | string | `min` | no | +| no_connection_timeframe | Monitor timeframe for PostgreSQL no connection [available values: `last_#m` (1, 5, 10, 15, or 30), `last_#h` (1, 2, or 4), or `last_1d`] | string | `last_5m` | no | ## Outputs diff --git a/cloud/azure/postgresql/inputs.tf b/cloud/azure/postgresql/inputs.tf index 47dfa44..fa3411a 100644 --- a/cloud/azure/postgresql/inputs.tf +++ b/cloud/azure/postgresql/inputs.tf @@ -5,15 +5,20 @@ variable "environment" { } # Global DataDog -variable "message" { - description = "Message sent when a Redis monitor is triggered" -} - -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" +} + variable "filter_tags_use_defaults" { description = "Use default filter tags convention" default = "true" @@ -24,197 +29,269 @@ variable "filter_tags_custom" { default = "*" } -# Azure Databases for Postgresql Servers specific variables +# Azure Databases for PostgreSQL Servers specific variables variable "cpu_usage_silenced" { - description = "Groups to mute for Postgresql CPU monitor" + description = "Groups to mute for PostgreSQL CPU monitor" type = "map" default = {} } +variable "cpu_usage_enabled" { + description = "Flag to enable PostgreSQL status monitor" + type = "string" + default = "true" +} + +variable "cpu_usage_extra_tags" { + description = "Extra tags for PostgreSQL status monitor" + type = "list" + default = [] +} + variable "cpu_usage_message" { - description = "Custom message for Postgresql CPU monitor" + description = "Custom message for PostgreSQL CPU monitor" type = "string" default = "" } variable "cpu_usage_time_aggregator" { - description = "Monitor aggregator for Postgresql CPU [available values: min, max or avg]" + description = "Monitor aggregator for PostgreSQL CPU [available values: min, max or avg]" type = "string" default = "min" } variable "cpu_usage_timeframe" { - description = "Monitor timeframe for Postgresql CPU [available values: `last_#m` (1, 5, 10, 15, or 30), `last_#h` (1, 2, or 4), or `last_1d`]" + description = "Monitor timeframe for PostgreSQL CPU [available values: `last_#m` (1, 5, 10, 15, or 30), `last_#h` (1, 2, or 4), or `last_1d`]" type = "string" default = "last_15m" } variable "cpu_usage_threshold_warning" { - description = "Postgresql CPU usage in percent (warning threshold)" + description = "PostgreSQL CPU usage in percent (warning threshold)" default = "80" } variable "cpu_usage_threshold_critical" { - description = "Postgresql CPU usage in percent (critical threshold)" + description = "PostgreSQL CPU usage in percent (critical threshold)" default = "90" } variable "no_connection_silenced" { - description = "Groups to mute for Postgresql no connection monitor" + description = "Groups to mute for PostgreSQL no connection monitor" type = "map" default = {} } +variable "no_connection_enabled" { + description = "Flag to enable PostgreSQL status monitor" + type = "string" + default = "true" +} + +variable "no_connection_extra_tags" { + description = "Extra tags for PostgreSQL status monitor" + type = "list" + default = [] +} + variable "no_connection_message" { - description = "Custom message for Postgresql no connection monitor" + description = "Custom message for PostgreSQL no connection monitor" type = "string" default = "" } variable "no_connection_time_aggregator" { - description = "Monitor aggregator for Postgresql no connection [available values: min, max or avg]" + description = "Monitor aggregator for PostgreSQL no connection [available values: min, max or avg]" type = "string" default = "min" } variable "no_connection_timeframe" { - description = "Monitor timeframe for Postgresql no connection [available values: `last_#m` (1, 5, 10, 15, or 30), `last_#h` (1, 2, or 4), or `last_1d`]" + description = "Monitor timeframe for PostgreSQL no connection [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 "free_storage_silenced" { - description = "Groups to mute for Postgresql Free Storage monitor" + description = "Groups to mute for PostgreSQL Free Storage monitor" type = "map" default = {} } +variable "free_storage_enabled" { + description = "Flag to enable PostgreSQL status monitor" + type = "string" + default = "true" +} + +variable "free_storage_extra_tags" { + description = "Extra tags for PostgreSQL status monitor" + type = "list" + default = [] +} + variable "free_storage_message" { - description = "Custom message for Postgresql Free Storage monitor" + description = "Custom message for PostgreSQL Free Storage monitor" type = "string" default = "" } variable "free_storage_time_aggregator" { - description = "Monitor aggregator for Postgresql Free Storage [available values: min, max or avg]" + description = "Monitor aggregator for PostgreSQL Free Storage [available values: min, max or avg]" type = "string" default = "min" } variable "free_storage_timeframe" { - description = "Monitor timeframe for Postgresql Free Storage [available values: `last_#m` (1, 5, 10, 15, or 30), `last_#h` (1, 2, or 4), or `last_1d`]" + description = "Monitor timeframe for PostgreSQL Free Storage [available values: `last_#m` (1, 5, 10, 15, or 30), `last_#h` (1, 2, or 4), or `last_1d`]" type = "string" default = "last_15m" } variable "free_storage_threshold_warning" { - description = "Postgresql Free Storage remaining in percent (warning threshold)" + description = "PostgreSQL Free Storage remaining in percent (warning threshold)" default = "20" } variable "free_storage_threshold_critical" { - description = "Postgresql Free Storage remaining in percent (critical threshold)" + description = "PostgreSQL Free Storage remaining in percent (critical threshold)" default = "10" } variable "io_consumption_silenced" { - description = "Groups to mute for Postgresql IO consumption monitor" + description = "Groups to mute for PostgreSQL IO consumption monitor" type = "map" default = {} } +variable "io_consumption_enabled" { + description = "Flag to enable PostgreSQL status monitor" + type = "string" + default = "true" +} + +variable "io_consumption_extra_tags" { + description = "Extra tags for PostgreSQL status monitor" + type = "list" + default = [] +} + variable "io_consumption_message" { - description = "Custom message for Postgresql IO consumption monitor" + description = "Custom message for PostgreSQL IO consumption monitor" type = "string" default = "" } variable "io_consumption_time_aggregator" { - description = "Monitor aggregator for Postgresql IO consumption [available values: min, max or avg]" + description = "Monitor aggregator for PostgreSQL IO consumption [available values: min, max or avg]" type = "string" default = "min" } variable "io_consumption_timeframe" { - description = "Monitor timeframe for Postgresql IO consumption [available values: `last_#m` (1, 5, 10, 15, or 30), `last_#h` (1, 2, or 4), or `last_1d`]" + description = "Monitor timeframe for PostgreSQL IO consumption [available values: `last_#m` (1, 5, 10, 15, or 30), `last_#h` (1, 2, or 4), or `last_1d`]" type = "string" default = "last_15m" } variable "io_consumption_threshold_warning" { - description = "Postgresql IO consumption in percent (warning threshold)" + description = "PostgreSQL IO consumption in percent (warning threshold)" default = "80" } variable "io_consumption_threshold_critical" { - description = "Postgresql IO consumption in percent (critical threshold)" - default = "90" -} - -variable "memory_usage_silenced" { - description = "Groups to mute for Postgresql memory monitor" - type = "map" - default = {} -} - -variable "memory_usage_message" { - description = "Custom message for Postgresql memory monitor" - type = "string" - default = "" -} - -variable "memory_usage_time_aggregator" { - description = "Monitor aggregator for Postgresql memory [available values: min, max or avg]" - type = "string" - default = "min" -} - -variable "memory_usage_timeframe" { - description = "Monitor timeframe for Postgresql memory [available values: `last_#m` (1, 5, 10, 15, or 30), `last_#h` (1, 2, or 4), or `last_1d`]" - type = "string" - default = "last_15m" -} - -variable "memory_usage_threshold_warning" { - description = "Postgresql memory usage in percent (warning threshold)" - default = "80" -} - -variable "memory_usage_threshold_critical" { - description = "Postgresql memory usage in percent (critical threshold)" + description = "PostgreSQL IO consumption in percent (critical threshold)" default = "90" } variable "compute_consumption_silenced" { - description = "Groups to mute for Postgresql compute consumption monitor" + description = "Groups to mute for PostgreSQL compute consumption monitor" type = "map" default = {} } +variable "compute_consumption_enabled" { + description = "Flag to enable PostgreSQL status monitor" + type = "string" + default = "true" +} + +variable "compute_consumption_extra_tags" { + description = "Extra tags for PostgreSQL status monitor" + type = "list" + default = [] +} + variable "compute_consumption_message" { - description = "Custom message for Postgresql compute consumption monitor" + description = "Custom message for PostgreSQL compute consumption monitor" type = "string" default = "" } variable "compute_consumption_time_aggregator" { - description = "Monitor aggregator for Postgresql compute consumption [available values: min, max or avg]" + description = "Monitor aggregator for PostgreSQL compute consumption [available values: min, max or avg]" type = "string" default = "min" } variable "compute_consumption_timeframe" { - description = "Monitor timeframe for Postgresql compute consumption [available values: `last_#m` (1, 5, 10, 15, or 30), `last_#h` (1, 2, or 4), or `last_1d`]" + description = "Monitor timeframe for PostgreSQL compute consumption [available values: `last_#m` (1, 5, 10, 15, or 30), `last_#h` (1, 2, or 4), or `last_1d`]" type = "string" default = "last_15m" } variable "compute_consumption_threshold_warning" { - description = "Postgresql compute consumption in percent (warning threshold)" + description = "PostgreSQL compute consumption in percent (warning threshold)" default = "80" } variable "compute_consumption_threshold_critical" { - description = "Postgresql compute consumption in percent (critical threshold)" + description = "PostgreSQL compute consumption in percent (critical threshold)" + default = "90" +} + +variable "memory_usage_silenced" { + description = "Groups to mute for PostgreSQL memory monitor" + type = "map" + default = {} +} + +variable "memory_usage_enabled" { + description = "Flag to enable PostgreSQL status monitor" + type = "string" + default = "true" +} + +variable "memory_usage_extra_tags" { + description = "Extra tags for PostgreSQL status monitor" + type = "list" + default = [] +} + +variable "memory_usage_message" { + description = "Custom message for PostgreSQL memory monitor" + type = "string" + default = "" +} + +variable "memory_usage_time_aggregator" { + description = "Monitor aggregator for PostgreSQL memory [available values: min, max or avg]" + type = "string" + default = "min" +} + +variable "memory_usage_timeframe" { + description = "Monitor timeframe for PostgreSQL memory [available values: `last_#m` (1, 5, 10, 15, or 30), `last_#h` (1, 2, or 4), or `last_1d`]" + type = "string" + default = "last_15m" +} + +variable "memory_usage_threshold_warning" { + description = "PostgreSQL memory usage in percent (warning threshold)" + default = "80" +} + +variable "memory_usage_threshold_critical" { + description = "PostgreSQL memory usage in percent (critical threshold)" default = "90" } diff --git a/cloud/azure/postgresql/monitors-postegresql.tf b/cloud/azure/postgresql/monitors-postegresql.tf index 0157907..9528fdd 100644 --- a/cloud/azure/postgresql/monitors-postegresql.tf +++ b/cloud/azure/postgresql/monitors-postegresql.tf @@ -1,18 +1,11 @@ -data "template_file" "filter" { - template = "$${filter}" - - vars { - filter = "${var.filter_tags_use_defaults == "true" ? format("dd_monitoring:enabled,dd_azure_postgresql:enabled,env:%s", var.environment) : "${var.filter_tags_custom}"}" - } -} - resource "datadog_monitor" "postgresql_cpu_usage" { - name = "[${var.environment}] Postgresql Server CPU usage is high {{#is_alert}}{{{comparator}}} {{threshold}}% ({{value}}%){{/is_alert}}{{#is_warning}}{{{comparator}}} {{warn_threshold}}% ({{value}}%){{/is_warning}}" + count = "${var.cpu_usage_enabled ? 1 : 0}" + name = "[${var.environment}] Postgresql Server CPU usage {{#is_alert}}{{{comparator}}} {{threshold}}% ({{value}}%){{/is_alert}}{{#is_warning}}{{{comparator}}} {{warn_threshold}}% ({{value}}%){{/is_warning}}" message = "${coalesce(var.cpu_usage_message, var.message)}" query = < ${var.cpu_usage_threshold_critical} EOF @@ -25,26 +18,27 @@ resource "datadog_monitor" "postgresql_cpu_usage" { silenced = "${var.cpu_usage_silenced}" - notify_no_data = true - evaluation_delay = "${var.delay}" + notify_no_data = false + evaluation_delay = "${var.evaluation_delay}" renotify_interval = 0 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}" - tags = ["env:${var.environment}", "resource:postgresql", "team:azure", "provider:azure"] + tags = ["env:${var.environment}", "type:cloud", "provider:azure", "resource:postgresql", "team:claranet", "created-by:terraform", "${var.cpu_usage_extra_tags}"] } resource "datadog_monitor" "postgresql_no_connection" { + count = "${var.no_connection_enabled ? 1 : 0}" name = "[${var.environment}] Postgresql Server has no connection" message = "${coalesce(var.no_connection_message, var.message)}" query = < ${var.io_consumption_threshold_critical} EOF @@ -116,26 +112,27 @@ resource "datadog_monitor" "postgresql_io_consumption" { silenced = "${var.io_consumption_silenced}" - notify_no_data = true - evaluation_delay = "${var.delay}" + notify_no_data = false + evaluation_delay = "${var.evaluation_delay}" renotify_interval = 0 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}" - tags = ["env:${var.environment}", "resource:postgresql", "team:azure", "provider:azure"] + tags = ["env:${var.environment}", "type:cloud", "provider:azure", "resource:postgresql", "team:claranet", "created-by:terraform", "${var.io_consumption_extra_tags}"] } resource "datadog_monitor" "postgresql_memory_usage" { - name = "[${var.environment}] Postgresql Server memory usage is high {{#is_alert}}{{{comparator}}} {{threshold}}% ({{value}}%){{/is_alert}}{{#is_warning}}{{{comparator}}} {{warn_threshold}}% ({{value}}%){{/is_warning}}" + count = "${var.memory_usage_enabled ? 1 : 0}" + name = "[${var.environment}] Postgresql Server memory usage {{#is_alert}}{{{comparator}}} {{threshold}}% ({{value}}%){{/is_alert}}{{#is_warning}}{{{comparator}}} {{warn_threshold}}% ({{value}}%){{/is_warning}}" message = "${coalesce(var.memory_usage_message, var.message)}" query = < ${var.memory_usage_threshold_critical} EOF @@ -148,26 +145,27 @@ resource "datadog_monitor" "postgresql_memory_usage" { silenced = "${var.memory_usage_silenced}" - notify_no_data = true - evaluation_delay = "${var.delay}" + notify_no_data = false + evaluation_delay = "${var.evaluation_delay}" renotify_interval = 0 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}" - tags = ["env:${var.environment}", "resource:postgresql", "team:azure", "provider:azure"] + tags = ["env:${var.environment}", "type:cloud", "provider:azure", "resource:postgresql", "team:claranet", "created-by:terraform", "${var.memory_usage_extra_tags}"] } resource "datadog_monitor" "postgresql_compute_consumption" { - name = "[${var.environment}] Postgresql Server compute consumption is high {{#is_alert}}{{{comparator}}} {{threshold}}% ({{value}}%){{/is_alert}}{{#is_warning}}{{{comparator}}} {{warn_threshold}}% ({{value}}%){{/is_warning}}" + count = "${var.compute_consumption_enabled ? 1 : 0}" + name = "[${var.environment}] Postgresql Server compute consumption {{#is_alert}}{{{comparator}}} {{threshold}}% ({{value}}%){{/is_alert}}{{#is_warning}}{{{comparator}}} {{warn_threshold}}% ({{value}}%){{/is_warning}}" message = "${coalesce(var.compute_consumption_message, var.message)}" query = < ${var.compute_consumption_threshold_critical} EOF @@ -180,15 +178,15 @@ resource "datadog_monitor" "postgresql_compute_consumption" { silenced = "${var.compute_consumption_silenced}" - notify_no_data = true - evaluation_delay = "${var.delay}" + notify_no_data = false + evaluation_delay = "${var.evaluation_delay}" renotify_interval = 0 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}" - tags = ["env:${var.environment}", "resource:postgresql", "team:azure", "provider:azure"] + tags = ["env:${var.environment}", "type:cloud", "provider:azure", "resource:postgresql", "team:claranet", "created-by:terraform", "${var.compute_consumption_extra_tags}"] }