MON-446 Azure SQL Elastic Pool monitors

This commit is contained in:
Laurent Piroelle 2019-04-30 19:53:17 +02:00 committed by Quentin Manfroi
parent 4ae24a8a4e
commit 97b313f3db
9 changed files with 382 additions and 10 deletions

View File

@ -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/)

View File

@ -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)

View File

@ -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 = <<EOQ
${var.cpu_time_aggregator}(${var.cpu_timeframe}): (
avg:azure.sql_servers_databases.cpu_percent${module.filter-tags.query_alert} by {resource_group,region,name}
avg:azure.sql_servers_databases.cpu_percent${module.filter-tags.query_alert} by {resource_group,region,server_name,name}
) > ${var.cpu_threshold_critical}
EOQ
@ -67,7 +67,7 @@ resource "datadog_monitor" "sql-database_free_space_low" {
query = <<EOQ
${var.diskspace_time_aggregator}(${var.diskspace_timeframe}): (
avg:azure.sql_servers_databases.storage_percent${module.filter-tags.query_alert} by {resource_group,region,name}
avg:azure.sql_servers_databases.storage_percent${module.filter-tags.query_alert} by {resource_group,region,server_name,name}
) > ${var.diskspace_threshold_critical}
EOQ
@ -100,7 +100,7 @@ resource "datadog_monitor" "sql-database_dtu_consumption_high" {
query = <<EOQ
${var.dtu_time_aggregator}(${var.dtu_timeframe}): (
azure.sql_servers_databases.dtu_consumption_percent${module.filter-tags.query_alert} by {resource_group,region,name}
avg:azure.sql_servers_databases.dtu_consumption_percent${module.filter-tags.query_alert} by {resource_group,region,server_name,name}
) > ${var.dtu_threshold_critical}
EOQ
@ -133,7 +133,7 @@ resource "datadog_monitor" "sql-database_deadlocks_count" {
query = <<EOQ
sum(${var.deadlock_timeframe}): (
avg:azure.sql_servers_databases.deadlock${module.filter-tags.query_alert} by {resource_group,region,name}.as_count()
avg:azure.sql_servers_databases.deadlock${module.filter-tags.query_alert} by {resource_group,region,server_name,name}.as_count()
) > ${var.deadlock_threshold_critical}
EOQ

View File

@ -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" {

View File

@ -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)

View File

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

View File

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

View File

@ -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 = <<EOQ
${var.cpu_time_aggregator}(${var.cpu_timeframe}): (
avg:azure.sql_servers_elasticpools.cpu_percent${module.filter-tags.query_alert} by {resource_group,region,server_name,name}
) > ${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 = <<EOQ
${var.diskspace_time_aggregator}(${var.diskspace_timeframe}): (
avg:azure.sql_servers_elasticpools.storage_percent${module.filter-tags.query_alert} by {resource_group,region,server_name,name}
) > ${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 = <<EOQ
${var.dtu_time_aggregator}(${var.dtu_timeframe}): (
azure.sql_servers_elasticpools.dtu_consumption_percent${module.filter-tags.query_alert} by {resource_group,region,server_name,name}
) > ${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}"]
}

View File

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