From 97b313f3db983f135dfa4b83b2b0a9a906261864 Mon Sep 17 00:00:00 2001 From: Laurent Piroelle Date: Tue, 30 Apr 2019 19:53:17 +0200 Subject: [PATCH] MON-446 Azure SQL Elastic Pool monitors --- README.md | 1 + cloud/azure/sql-database/README.md | 4 +- ...ase-basics.tf => monitors-sql-database.tf} | 10 +- cloud/azure/sql-database/outputs.tf | 6 +- cloud/azure/sql-elasticpool/README.md | 72 +++++++ cloud/azure/sql-elasticpool/inputs.tf | 179 ++++++++++++++++++ cloud/azure/sql-elasticpool/modules.tf | 9 + .../monitors-sql-elasticpool.tf | 97 ++++++++++ cloud/azure/sql-elasticpool/outputs.tf | 14 ++ 9 files changed, 382 insertions(+), 10 deletions(-) rename cloud/azure/sql-database/{monitors-sql-database-basics.tf => monitors-sql-database.tf} (93%) create mode 100644 cloud/azure/sql-elasticpool/README.md create mode 100644 cloud/azure/sql-elasticpool/inputs.tf create mode 100644 cloud/azure/sql-elasticpool/modules.tf create mode 100644 cloud/azure/sql-elasticpool/monitors-sql-elasticpool.tf create mode 100644 cloud/azure/sql-elasticpool/outputs.tf diff --git a/README.md b/README.md index 1403e5b..faa5ba1 100644 --- a/README.md +++ b/README.md @@ -118,6 +118,7 @@ The `//` is very important, it's a terraform specific syntax used to separate gi - [serverfarms](https://git.fr.clara.net/claranet/pt-monitoring/projects/datadog/terraform/monitors/tree/master/cloud/azure/serverfarms/) - [servicebus](https://git.fr.clara.net/claranet/pt-monitoring/projects/datadog/terraform/monitors/tree/master/cloud/azure/servicebus/) - [sql-database](https://git.fr.clara.net/claranet/pt-monitoring/projects/datadog/terraform/monitors/tree/master/cloud/azure/sql-database/) + - [sql-elasticpool](https://git.fr.clara.net/claranet/pt-monitoring/projects/datadog/terraform/monitors/tree/master/cloud/azure/sql-elasticpool/) - [storage](https://git.fr.clara.net/claranet/pt-monitoring/projects/datadog/terraform/monitors/tree/master/cloud/azure/storage/) - [stream-analytics](https://git.fr.clara.net/claranet/pt-monitoring/projects/datadog/terraform/monitors/tree/master/cloud/azure/stream-analytics/) - [virtual-machine](https://git.fr.clara.net/claranet/pt-monitoring/projects/datadog/terraform/monitors/tree/master/cloud/azure/virtual-machine/) diff --git a/cloud/azure/sql-database/README.md b/cloud/azure/sql-database/README.md index 4d1e0df..ba77f2f 100644 --- a/cloud/azure/sql-database/README.md +++ b/cloud/azure/sql-database/README.md @@ -75,7 +75,7 @@ Creates DataDog monitors with the following checks: | Name | Description | |------|-------------| -| sql-database\_cpu\_90\_15min\_id | id for monitor sql-database_cpu_90_15min | +| sql-database\_cpu\_id | id for monitor sql-database_cpu | | sql-database\_deadlocks\_count\_id | id for monitor sql-database_deadlocks_count | | sql-database\_dtu\_consumption\_high\_id | id for monitor sql-database_dtu_consumption_high | | sql-database\_free\_space\_low\_id | id for monitor sql-database_free_space_low | @@ -85,5 +85,5 @@ Creates DataDog monitors with the following checks: DataDog documentation: [https://docs.datadoghq.com/integrations/azure_sql_database/](https://docs.datadoghq.com/integrations/azure_sql_database/) -Azure SQL Database metrics documentation: [https://docs.microsoft.com/en-us/azure/sql-database/saas-dbpertenant-log-analytics](https://docs.microsoft.com/en-us/azure/sql-database/saas-dbpertenant-log-analytics) +Azure SQL Database metrics documentation: [https://docs.microsoft.com/en-us/azure/azure-monitor/platform/metrics-supported#microsoftsqlserversdatabases](https://docs.microsoft.com/en-us/azure/azure-monitor/platform/metrics-supported#microsoftsqlserversdatabases) diff --git a/cloud/azure/sql-database/monitors-sql-database-basics.tf b/cloud/azure/sql-database/monitors-sql-database.tf similarity index 93% rename from cloud/azure/sql-database/monitors-sql-database-basics.tf rename to cloud/azure/sql-database/monitors-sql-database.tf index b075a72..40bdc05 100644 --- a/cloud/azure/sql-database/monitors-sql-database-basics.tf +++ b/cloud/azure/sql-database/monitors-sql-database.tf @@ -26,14 +26,14 @@ resource "datadog_monitor" "status" { tags = ["env:${var.environment}", "type:cloud", "provider:azure", "resource:sql-database", "team:claranet", "created-by:terraform", "${var.status_extra_tags}"] } -resource "datadog_monitor" "sql-database_cpu_90_15min" { +resource "datadog_monitor" "sql-database_cpu" { count = "${var.cpu_enabled == "true" ? 1 : 0}" name = "${var.prefix_slug == "" ? "" : "[${var.prefix_slug}]"}[${var.environment}] SQL Database CPU too high {{#is_alert}}{{{comparator}}} {{threshold}}% ({{value}}%){{/is_alert}}{{#is_warning}}{{{comparator}}} {{warn_threshold}}% ({{value}}%){{/is_warning}}" message = "${coalesce(var.cpu_message, var.message)}" query = < ${var.cpu_threshold_critical} EOQ @@ -67,7 +67,7 @@ resource "datadog_monitor" "sql-database_free_space_low" { query = < ${var.diskspace_threshold_critical} EOQ @@ -100,7 +100,7 @@ resource "datadog_monitor" "sql-database_dtu_consumption_high" { query = < ${var.dtu_threshold_critical} EOQ @@ -133,7 +133,7 @@ resource "datadog_monitor" "sql-database_deadlocks_count" { query = < ${var.deadlock_threshold_critical} EOQ diff --git a/cloud/azure/sql-database/outputs.tf b/cloud/azure/sql-database/outputs.tf index 0949567..d31edbf 100644 --- a/cloud/azure/sql-database/outputs.tf +++ b/cloud/azure/sql-database/outputs.tf @@ -3,9 +3,9 @@ output "status_id" { value = "${datadog_monitor.status.*.id}" } -output "sql-database_cpu_90_15min_id" { - description = "id for monitor sql-database_cpu_90_15min" - value = "${datadog_monitor.sql-database_cpu_90_15min.*.id}" +output "sql-database_cpu_id" { + description = "id for monitor sql-database_cpu" + value = "${datadog_monitor.sql-database_cpu.*.id}" } output "sql-database_free_space_low_id" { diff --git a/cloud/azure/sql-elasticpool/README.md b/cloud/azure/sql-elasticpool/README.md new file mode 100644 index 0000000..c6bf285 --- /dev/null +++ b/cloud/azure/sql-elasticpool/README.md @@ -0,0 +1,72 @@ +# CLOUD AZURE SQL-ELASTICPOOL DataDog monitors + +## How to use this module + +``` +module "datadog-monitors-cloud-azure-sql-elasticpool" { + source = "git::ssh://git@git.fr.clara.net/claranet/pt-monitoring/projects/datadog/terraform/monitors.git//cloud/azure/sql-elasticpool?ref={revision}" + + environment = "${var.environment}" + message = "${module.datadog-message-alerting.alerting-message}" +} + +``` + +## Purpose + +Creates DataDog monitors with the following checks: + +- SQL Elastic Pool CPU too high +- SQL Elastic Pool DTU Consumption too high +- SQL Elastic Pool low free space + +## Inputs + +| Name | Description | Type | Default | Required | +|------|-------------|:----:|:-----:|:-----:| +| cpu\_enabled | Flag to enable SQL Elastic Pool CPU monitor | string | `"true"` | no | +| cpu\_extra\_tags | Extra tags for SQL Elastic Pool CPU monitor | list | `[]` | no | +| cpu\_message | Custom message for SQL Elastic Pool CPU monitor | string | `""` | no | +| cpu\_silenced | Groups to mute for SQL Elastic Pool CPU 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 SQL Elastic Pool CPU [available values: min, max or avg] | string | `"min"` | no | +| cpu\_timeframe | Monitor timeframe for SQL Elastic Pool CPU [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 SQL Elastic Pool disk space monitor | string | `"true"` | no | +| diskspace\_extra\_tags | Extra tags for SQL Elastic Pool disk space monitor | list | `[]` | no | +| diskspace\_message | Custom message for SQL Elastic Pool disk space monitor | string | `""` | no | +| diskspace\_silenced | Groups to mute for SQL Elastic Pool disk space monitor | map | `{}` | no | +| diskspace\_threshold\_critical | Disk space used in percent (critical threshold) | string | `"90"` | no | +| diskspace\_threshold\_warning | Disk space used in percent (warning threshold) | string | `"80"` | no | +| diskspace\_time\_aggregator | Monitor aggregator for SQL Elastic Pool disk space [available values: min, max or avg] | string | `"max"` | no | +| diskspace\_timeframe | Monitor timeframe for SQL Elastic Pool disk space [available values: `last_#m` (1, 5, 10, 15, or 30), `last_#h` (1, 2, or 4), or `last_1d`] | string | `"last_15m"` | no | +| dtu\_enabled | Flag to enable SQL Elastic Pool DTU monitor | string | `"true"` | no | +| dtu\_extra\_tags | Extra tags for SQL Elastic Pool DTU monitor | list | `[]` | no | +| dtu\_message | Custom message for SQL Elastic Pool DTU monitor | string | `""` | no | +| dtu\_silenced | Groups to mute for SQL Elastic Pool DTU monitor | map | `{}` | no | +| dtu\_threshold\_critical | Amount of DTU used (critical threshold) | string | `"90"` | no | +| dtu\_threshold\_warning | Amount of DTU used (warning threshold) | string | `"85"` | no | +| dtu\_time\_aggregator | Monitor aggregator for SQL Elastic Pool DTU [available values: min, max or avg] | string | `"avg"` | no | +| dtu\_timeframe | Monitor timeframe for SQL Elastic Pool DTU [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 | n/a | 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\_excluded | Tags excluded 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 | n/a | yes | +| new\_host\_delay | Delay in seconds before monitor new resource | string | `"300"` | no | +| prefix\_slug | Prefix string to prepend between brackets on every monitors names | string | `""` | no | + +## Outputs + +| Name | Description | +|------|-------------| +| sql\_elasticpool\_cpu\_id | id for monitor sql_elasticpool_cpu | +| sql\_elasticpool\_dtu\_consumption\_high\_id | id for monitor sql_elasticpool_dtu_consumption_high | +| sql\_elasticpool\_free\_space\_low\_id | id for monitor sql_elasticpool_free_space_low | + +## Related documentation + +DataDog documentation: [https://docs.datadoghq.com/integrations/azure_sql_elastic_pool/](https://docs.datadoghq.com/integrations/azure_sql_elastic_pool/) + +Azure SQL Elastic Pool metrics documentation: [https://docs.microsoft.com/en-us/azure/azure-monitor/platform/metrics-supported#microsoftsqlserverselasticpools](https://docs.microsoft.com/en-us/azure/azure-monitor/platform/metrics-supported#microsoftsqlserverselasticpools) diff --git a/cloud/azure/sql-elasticpool/inputs.tf b/cloud/azure/sql-elasticpool/inputs.tf new file mode 100644 index 0000000..5f1d37b --- /dev/null +++ b/cloud/azure/sql-elasticpool/inputs.tf @@ -0,0 +1,179 @@ +# 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 "prefix_slug" { + description = "Prefix string to prepend between brackets on every monitors names" + default = "" +} + +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 = "*" +} + +variable "filter_tags_custom_excluded" { + description = "Tags excluded for custom filtering when filter_tags_use_defaults is false" + default = "" +} + +# Azure SQL Elastic Pool specific variables +variable "cpu_silenced" { + description = "Groups to mute for SQL Elastic Pool CPU monitor" + type = "map" + default = {} +} + +variable "cpu_enabled" { + description = "Flag to enable SQL Elastic Pool CPU monitor" + type = "string" + default = "true" +} + +variable "cpu_extra_tags" { + description = "Extra tags for SQL Elastic Pool CPU monitor" + type = "list" + default = [] +} + +variable "cpu_message" { + description = "Custom message for SQL Elastic Pool CPU monitor" + type = "string" + default = "" +} + +variable "cpu_time_aggregator" { + description = "Monitor aggregator for SQL Elastic Pool CPU [available values: min, max or avg]" + type = "string" + default = "min" +} + +variable "cpu_timeframe" { + description = "Monitor timeframe for SQL Elastic Pool 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_threshold_warning" { + description = "CPU usage in percent (warning threshold)" + default = "80" +} + +variable "cpu_threshold_critical" { + description = "CPU usage in percent (critical threshold)" + default = "90" +} + +variable "diskspace_silenced" { + description = "Groups to mute for SQL Elastic Pool disk space monitor" + type = "map" + default = {} +} + +variable "diskspace_enabled" { + description = "Flag to enable SQL Elastic Pool disk space monitor" + type = "string" + default = "true" +} + +variable "diskspace_extra_tags" { + description = "Extra tags for SQL Elastic Pool disk space monitor" + type = "list" + default = [] +} + +variable "diskspace_message" { + description = "Custom message for SQL Elastic Pool disk space monitor" + type = "string" + default = "" +} + +variable "diskspace_time_aggregator" { + description = "Monitor aggregator for SQL Elastic Pool disk space [available values: min, max or avg]" + type = "string" + default = "max" +} + +variable "diskspace_timeframe" { + description = "Monitor timeframe for SQL Elastic Pool disk space [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 "diskspace_threshold_warning" { + description = "Disk space used in percent (warning threshold)" + default = "80" +} + +variable "diskspace_threshold_critical" { + description = "Disk space used in percent (critical threshold)" + default = "90" +} + +variable "dtu_silenced" { + description = "Groups to mute for SQL Elastic Pool DTU monitor" + type = "map" + default = {} +} + +variable "dtu_enabled" { + description = "Flag to enable SQL Elastic Pool DTU monitor" + type = "string" + default = "true" +} + +variable "dtu_extra_tags" { + description = "Extra tags for SQL Elastic Pool DTU monitor" + type = "list" + default = [] +} + +variable "dtu_message" { + description = "Custom message for SQL Elastic Pool DTU monitor" + type = "string" + default = "" +} + +variable "dtu_time_aggregator" { + description = "Monitor aggregator for SQL Elastic Pool DTU [available values: min, max or avg]" + type = "string" + default = "avg" +} + +variable "dtu_timeframe" { + description = "Monitor timeframe for SQL Elastic Pool DTU [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 "dtu_threshold_warning" { + description = "Amount of DTU used (warning threshold)" + default = "85" +} + +variable "dtu_threshold_critical" { + description = "Amount of DTU used (critical threshold)" + default = "90" +} diff --git a/cloud/azure/sql-elasticpool/modules.tf b/cloud/azure/sql-elasticpool/modules.tf new file mode 100644 index 0000000..7e0411e --- /dev/null +++ b/cloud/azure/sql-elasticpool/modules.tf @@ -0,0 +1,9 @@ +module "filter-tags" { + source = "../../../common/filter-tags" + + environment = "${var.environment}" + resource = "azure_sql-elasticpool" + filter_tags_use_defaults = "${var.filter_tags_use_defaults}" + filter_tags_custom = "${var.filter_tags_custom}" + filter_tags_custom_excluded = "${var.filter_tags_custom_excluded}" +} diff --git a/cloud/azure/sql-elasticpool/monitors-sql-elasticpool.tf b/cloud/azure/sql-elasticpool/monitors-sql-elasticpool.tf new file mode 100644 index 0000000..d0b2a9b --- /dev/null +++ b/cloud/azure/sql-elasticpool/monitors-sql-elasticpool.tf @@ -0,0 +1,97 @@ +resource "datadog_monitor" "sql_elasticpool_cpu" { + count = "${var.cpu_enabled == "true" ? 1 : 0}" + name = "${var.prefix_slug == "" ? "" : "[${var.prefix_slug}]"}[${var.environment}] SQL Elastic Pool CPU too high {{#is_alert}}{{{comparator}}} {{threshold}}% ({{value}}%){{/is_alert}}{{#is_warning}}{{{comparator}}} {{warn_threshold}}% ({{value}}%){{/is_warning}}" + message = "${coalesce(var.cpu_message, var.message)}" + + query = < ${var.cpu_threshold_critical} + EOQ + + type = "metric alert" + + thresholds { + critical = "${var.cpu_threshold_critical}" + } + + silenced = "${var.cpu_silenced}" + + notify_no_data = true + 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.new_host_delay}" + + tags = ["env:${var.environment}", "type:cloud", "provider:azure", "resource:sql-elasticpool", "team:claranet", "created-by:terraform", "${var.cpu_extra_tags}"] +} + +resource "datadog_monitor" "sql_elasticpool_free_space_low" { + count = "${var.diskspace_enabled == "true" ? 1 : 0}" + name = "${var.prefix_slug == "" ? "" : "[${var.prefix_slug}]"}[${var.environment}] SQL Elastic Pool low 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.diskspace_threshold_critical} + EOQ + + thresholds { + warning = "${var.diskspace_threshold_warning}" + critical = "${var.diskspace_threshold_critical}" + } + + silenced = "${var.diskspace_silenced}" + + notify_no_data = true + 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.new_host_delay}" + + tags = ["env:${var.environment}", "type:cloud", "provider:azure", "resource:sql-elasticpool", "team:claranet", "created-by:terraform", "${var.diskspace_extra_tags}"] +} + +resource "datadog_monitor" "sql_elasticpool_dtu_consumption_high" { + count = "${var.dtu_enabled == "true" ? 1 : 0}" + name = "${var.prefix_slug == "" ? "" : "[${var.prefix_slug}]"}[${var.environment}] SQL Elastic Pool DTU Consumption too high {{#is_alert}}{{{comparator}}} {{threshold}}% ({{value}}%){{/is_alert}}{{#is_warning}}{{{comparator}}} {{warn_threshold}}% ({{value}}%){{/is_warning}}" + message = "${coalesce(var.dtu_message, var.message)}" + + type = "metric alert" + + query = < ${var.dtu_threshold_critical} + EOQ + + thresholds { + warning = "${var.dtu_threshold_warning}" + critical = "${var.dtu_threshold_critical}" + } + + silenced = "${var.dtu_silenced}" + + notify_no_data = true + 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.new_host_delay}" + + tags = ["env:${var.environment}", "type:cloud", "provider:azure", "resource:sql-elasticpool", "team:claranet", "created-by:terraform", "${var.dtu_extra_tags}"] +} diff --git a/cloud/azure/sql-elasticpool/outputs.tf b/cloud/azure/sql-elasticpool/outputs.tf new file mode 100644 index 0000000..f3c189d --- /dev/null +++ b/cloud/azure/sql-elasticpool/outputs.tf @@ -0,0 +1,14 @@ +output "sql_elasticpool_cpu_id" { + description = "id for monitor sql_elasticpool_cpu" + value = "${datadog_monitor.sql_elasticpool_cpu.*.id}" +} + +output "sql_elasticpool_free_space_low_id" { + description = "id for monitor sql_elasticpool_free_space_low" + value = "${datadog_monitor.sql_elasticpool_free_space_low.*.id}" +} + +output "sql_elasticpool_dtu_consumption_high_id" { + description = "id for monitor sql_elasticpool_dtu_consumption_high" + value = "${datadog_monitor.sql_elasticpool_dtu_consumption_high.*.id}" +}