MON-75 SQL DB monitors init

This commit is contained in:
Kevin Pecquet 2017-10-30 15:48:26 +01:00 committed by Laurent Piroelle
parent 22e7021681
commit 71d78bacde
3 changed files with 202 additions and 0 deletions

View File

@ -0,0 +1,44 @@
Azure SQL Database DataDog monitors
============================
How to use this module
----------------------
```
module "datadog-monitors-azure-storage" {
source = "git::ssh://git@bitbucket.org/morea/terraform.feature.datadog.git//cloud/azure/sql-database?ref={revision}"
message = "${module.datadog-message-alerting.alerting-message}"
environment = "${var.environment}"
client_name = "${var.client_name}"
}
```
Purpose
-------
Creates a DataDog monitors with the following checks :
* CPU High
* Free disk space low
* DTU Consumption high
* SQL deadlocks
Inputs
------
| Name | Type | Default | Required |
|------|:----:|:-------:|:--------:|
| client_name | Client name | string | - | yes |
| delay | Delay in seconds for the metric evaluation | string | `600` | no |
| environment | Architecture environment | string | - | yes |
| message | Message sent when a monitor is triggered | string | - | yes |
| use_filter_tags | Filter the data with service tags if true | string | `false` | no |
| dd_azure_sqldb | string | `disabled` | yes |
| cpu_threshold_warning | string | `85` | no |
| cpu_threshold_critical | string | `90` | no |
| diskspace_threshold_warning | string | `80` | no |
| diskspace_threshold_critical | string | `90` | no |
| dtu_threshold_warning | string | `85` | no |
| dtu_threshold_critical | string | `90` | no |
| deadlock_threshold_critical | string | `1` | no |

View File

@ -0,0 +1,49 @@
variable "subscription_id" {
default = ""
}
variable "message" {
description = "Message sent when a SQL DB monitor is triggered"
}
variable "environment" {}
variable "use_filter_tags" {
default = "false"
}
variable "cpu_threshold_warning" {
default = ""
}
variable "cpu_threshold_critical" {
default = "90"
}
variable "diskspace_threshold_warning" {
default = "80"
}
variable "diskspace_threshold_critical" {
default = "90"
}
variable "dtu_threshold_warning" {
default = "85"
}
variable "dtu_threshold_critical" {
default = "90"
}
variable "deadlock_threshold_critical" {
default = "1"
}
variable "delay" {
default = "600"
}
variable "dd_azure_sqldb" {
default = "disabled"
}

View File

@ -0,0 +1,109 @@
data "template_file" "filter" {
template = "$${filter}"
vars {
filter = "${var.use_filter_tags == "true" ? format("dd_monitoring:enabled,dd_azure_sqldb:enabled,env:%s",var.environment) : "*"}"
}
}
resource "datadog_monitor" "sql-database_cpu_90_15min" {
name = "[${var.environment}] SQL Database CPU high > 90% for 15 min on {{name}}"
message = "${message}"
count = "${var.dd_azure_sqldb == "enabled" ? 1 : 0 }"
query = "avg(last_15m):avg:azure.sql_servers_databases.cpu_percent{${data.template_file.filter.rendered}} by {name,resource_group} > ${var.cpu_threshold_critical}"
type = "query alert"
thresholds {
critical = "${var.cpu_threshold_critical}"
}
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 = true
new_host_delay = "${var.delay}"
no_data_timeframe = 20
}
resource "datadog_monitor" "sql-database_free_space_low" {
name = "[${var.environment}] SQL Database free space < 10 % on {{name}}"
message = "${message}"
type = "query alert"
query = "avg(last_15m):avg:azure.sql_servers_databases.storage_percent{${data.template_file.filter.rendered}} by {name,resource_group} > 90"
count = "${var.dd_azure_sqldb == "enabled" ? 1 : 0 }"
thresholds {
warning = "${var.diskspace_threshold_warning}"
critical = "${var.diskspace_threshold_critical}"
}
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 = true
new_host_delay = "${var.delay}"
no_data_timeframe = 20
}
resource "datadog_monitor" "sql-database_dtu_consumption_high" {
name = "[${var.environment}] DTU Consumption on {{name}} > 90"
message = "${message}"
type = "query alert"
query = "avg(last_15m):azure.sql_servers_databases.dtu_consumption_percent{${data.template_file.filter.rendered}} by {name,resource_group} > 90"
count = "${var.dd_azure_sqldb == "enabled" ? 1 : 0 }"
thresholds {
warning = "${var.dtu_threshold_warning}"
critical = "${var.dtu_threshold_critical}"
}
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 = true
new_host_delay = "${var.delay}"
no_data_timeframe = 20
}
resource "datadog_monitor" "sql-database_deadlocks_count" {
name = "[${var.environment}] SQL Deadlocks too high on {{name}}"
message = "${message}"
type = "query alert"
query = "sum(last_5m):avg:azure.sql_servers_databases.deadlock{${data.template_file.filter.rendered}} by {name,resource_group}.as_count() > ${var.deadlock_threshold_critical}"
count = "${var.dd_azure_sqldb == "enabled" ? 1 : 0 }"
thresholds {
critical = "${var.deadlock_threshold_critical}"
}
notify_no_data = false
evaluation_delay = "${var.delay}"
renotify_interval = 0
notify_audit = false
timeout_h = 0
include_tags = true
locked = false
require_full_window = true
new_host_delay = "${var.delay}"
no_data_timeframe = 20
}