From bf327b6464322929b0b3d995825916b3d2246012 Mon Sep 17 00:00:00 2001 From: Boris Rousseau Date: Thu, 22 Mar 2018 09:54:06 +0100 Subject: [PATCH] MON-142: updated based on PR comments + best practices --- databases/mysql/README.md | 4 ++-- databases/mysql/inputs.tf | 28 ++++++++++++++++++---------- databases/mysql/mon-mysql.tf | 32 ++++++++++++++++++++------------ 3 files changed, 40 insertions(+), 24 deletions(-) diff --git a/databases/mysql/README.md b/databases/mysql/README.md index ab67fd3..5485210 100644 --- a/databases/mysql/README.md +++ b/databases/mysql/README.md @@ -31,8 +31,8 @@ Inputs | filter_tags | Tags used for custom filtering | string | `*` | no | | mysql_connection_threshold_critical | Maximum critical acceptable percent of connections | string | `80` | no | | mysql_connection_threshold_warning | Maximum warning acceptable percent of connections | string | `70` | no | -| mysql_thread_threshold_critical | Maximum critical acceptable percent of threads | string | `500` | no | -| mysql_thread_threshold_warning | Maximum warning acceptable percent of threads | string | `400` | no | +| mysql_thread_threshold_critical | Maximum critical acceptable number of threads | string | `500` | no | +| mysql_thread_threshold_warning | Maximum warning acceptable number of threads | string | `400` | no | | message | Message sent when a monitor is triggered | string | - | yes | Related documentation diff --git a/databases/mysql/inputs.tf b/databases/mysql/inputs.tf index a751d76..2c73edd 100644 --- a/databases/mysql/inputs.tf +++ b/databases/mysql/inputs.tf @@ -3,19 +3,27 @@ variable "environment" { type = "string" } -variable "filter_tags" { - description = "Tags used for filtering" - default = "*" -} - -variable "delay" { - default = 900 +# Global DataDog +variable "evaluation_delay" { + description = "Delay in seconds for the metric evaluation" + default = 900 } variable "message" { - description = "Message sent when a monitor is triggered" + 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 = "*" +} + +# MySQL specific ################################# ### MySQL connections ### ################################# @@ -36,10 +44,10 @@ variable "mysql_connection_threshold_warning" { variable "mysql_thread_threshold_critical" { default = 500 - description = "Maximum critical acceptable percent of threads" + description = "Maximum critical acceptable number of threads" } variable "mysql_thread_threshold_warning" { default = 400 - description = "Maximum critical acceptable percent of threads" + description = "Maximum critical acceptable number of threads" } diff --git a/databases/mysql/mon-mysql.tf b/databases/mysql/mon-mysql.tf index 957704a..67f9b3e 100644 --- a/databases/mysql/mon-mysql.tf +++ b/databases/mysql/mon-mysql.tf @@ -1,4 +1,12 @@ -resource "datadog_monitor" "mysql_cpu_80_15min" { +data "template_file" "filter" { + template = "$${filter}" + + vars { + filter = "${var.filter_tags_use_defaults == "true" ? format("dd_monitoring:enabled,dd_mysql:enabled,env:%s", var.environment) : "${var.filter_tags_custom}"}" + } +} + +resource "datadog_monitor" "mysql_connections_15min" { name = "[${var.environment}] Mysql Connections > {{#is_alert}}{{threshold}}%{{/is_alert}}{{#is_warning}}{{warn_threshold}}%{{/is_warning}} ({{value}}%)" message = "${var.message}" type = "query alert" @@ -10,23 +18,23 @@ resource "datadog_monitor" "mysql_cpu_80_15min" { ) * 100 > ${var.mysql_connection_threshold_critical} EOF - evaluation_delay = "${var.delay}" - new_host_delay = "${var.delay}" + evaluation_delay = "${var.evaluation_delay}" + new_host_delay = "${var.evaluation_delay}" thresholds { warning = "${var.mysql_connection_threshold_warning}" critical = "${var.mysql_connection_threshold_critical}" } - notify_no_data = false # Will NOT notify when no data is received - evaluation_delay = "${var.delay}" + notify_no_data = true + evaluation_delay = "${var.evaluation_delay}" renotify_interval = 60 notify_audit = false timeout_h = 0 include_tags = true - locked = false + locked = true require_full_window = true - new_host_delay = "${var.delay}" + new_host_delay = "${var.evaluation_delay}" no_data_timeframe = 20 tags = ["env:${var.environment}", "resource:mysql"] @@ -44,23 +52,23 @@ resource "datadog_monitor" "mysql_thread_5min" { ) > ${var.mysql_thread_threshold_critical} EOF - evaluation_delay = "${var.delay}" - new_host_delay = "${var.delay}" + evaluation_delay = "${var.evaluation_delay}" + new_host_delay = "${var.evaluation_delay}" thresholds { warning = "${var.mysql_thread_threshold_warning}" critical = "${var.mysql_thread_threshold_critical}" } - notify_no_data = false # Will NOT notify when no data is received - evaluation_delay = "${var.delay}" + notify_no_data = true + evaluation_delay = "${var.evaluation_delay}" renotify_interval = 60 notify_audit = false timeout_h = 0 include_tags = true locked = false require_full_window = true - new_host_delay = "${var.delay}" + new_host_delay = "${var.evaluation_delay}" no_data_timeframe = 20 tags = ["env:${var.environment}", "resource:mysql"]