From 45054fd835f43ee7779f85654245f342d13ecc27 Mon Sep 17 00:00:00 2001 From: Boris Rousseau Date: Tue, 20 Mar 2018 16:05:29 +0100 Subject: [PATCH] MON-142: Monitor for MySQL --- databases/mysql/README.md | 41 ++++++++++++++++++++++ databases/mysql/inputs.tf | 45 ++++++++++++++++++++++++ databases/mysql/mon-mysql.tf | 67 ++++++++++++++++++++++++++++++++++++ 3 files changed, 153 insertions(+) create mode 100644 databases/mysql/README.md create mode 100644 databases/mysql/inputs.tf create mode 100644 databases/mysql/mon-mysql.tf diff --git a/databases/mysql/README.md b/databases/mysql/README.md new file mode 100644 index 0000000..ab67fd3 --- /dev/null +++ b/databases/mysql/README.md @@ -0,0 +1,41 @@ +MySQL DataDog monitors +========================================== + +How to use this module +---------------------- + +``` +module "datadog-monitors-mysql" { + source = "git::ssh://git@bitbucket.org/morea/terraform.feature.datadog.git//databases/mysql?ref={revision}" + + environment = "${var.environment}" + message = "${module.datadog-message-alerting.alerting-message}" +} + +``` + +Purpose +------- +Creates DataDog monitors with the following checks : + +* MySQL Connections too high +* MySQL Number of threads too high + +Inputs +------ + +| Name | Description | Type | Default | Required | +|------|-------------|:----:|:-----:|:-----:| +| delay | Delay in seconds for the metric evaluation | string | `900` | no | +| environment | Environment | string | - | yes | +| 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 | +| message | Message sent when a monitor is triggered | string | - | yes | + +Related documentation +--------------------- + +DataDog documentation: [https://docs.datadoghq.com/integrations/mysql/](https://docs.datadoghq.com/integrations/mysql/) diff --git a/databases/mysql/inputs.tf b/databases/mysql/inputs.tf new file mode 100644 index 0000000..a751d76 --- /dev/null +++ b/databases/mysql/inputs.tf @@ -0,0 +1,45 @@ +variable "environment" { + description = "Environment" + type = "string" +} + +variable "filter_tags" { + description = "Tags used for filtering" + default = "*" +} + +variable "delay" { + default = 900 +} + +variable "message" { + description = "Message sent when a monitor is triggered" +} + +################################# +### MySQL connections ### +################################# + +variable "mysql_connection_threshold_critical" { + default = 80 + description = "Maximum critical acceptable percent of connections" +} + +variable "mysql_connection_threshold_warning" { + default = 70 + description = "Maximum warning acceptable percent of connections" +} + +################################# +### MySQL threads ### +################################# + +variable "mysql_thread_threshold_critical" { + default = 500 + description = "Maximum critical acceptable percent of threads" +} + +variable "mysql_thread_threshold_warning" { + default = 400 + description = "Maximum critical acceptable percent of threads" +} diff --git a/databases/mysql/mon-mysql.tf b/databases/mysql/mon-mysql.tf new file mode 100644 index 0000000..725272b --- /dev/null +++ b/databases/mysql/mon-mysql.tf @@ -0,0 +1,67 @@ +resource "datadog_monitor" "mysql_cpu_80_15min" { + name = "[${var.environment}] Mysql Connections > {{#is_alert}}{{threshold}}%{{/is_alert}}{{#is_warning}}{{warn_threshold}}%{{/is_warning}} ({{value}}%)" + message = "${var.message}" + type = "query alert" + + query = < ${var.mysql_connection_threshold_critical} + EOF + + evaluation_delay = "${var.delay}" + new_host_delay = "${var.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}" + renotify_interval = 60 + notify_audit = false + timeout_h = 0 + include_tags = true + locked = false + require_full_window = true + new_host_delay = "${var.delay}" + no_data_timeframe = 20 + + tags = ["env:${var.environment}", "resource:mysql"] +} + + +resource "datadog_monitor" "mysql_thread_5min" { + name = "[${var.environment}] Mysql threads > {{#is_alert}}{{threshold}}%{{/is_alert}}{{#is_warning}}{{warn_threshold}}%{{/is_warning}} ({{value}}%)" + message = "${var.message}" + type = "query alert" + + query = < ${var.mysql_thread_threshold_critical} + EOF + + evaluation_delay = "${var.delay}" + new_host_delay = "${var.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}" + renotify_interval = 60 + notify_audit = false + timeout_h = 0 + include_tags = true + locked = false + require_full_window = true + new_host_delay = "${var.delay}" + no_data_timeframe = 20 + + tags = ["env:${var.environment}", "resource:mysql"] +}