MON-142: Monitor for MySQL

This commit is contained in:
Boris Rousseau 2018-03-20 16:05:29 +01:00 committed by Quentin Manfroi
parent a82a626e28
commit 45054fd835
3 changed files with 153 additions and 0 deletions

41
databases/mysql/README.md Normal file
View File

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

45
databases/mysql/inputs.tf Normal file
View File

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

View File

@ -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 = <<EOF
avg(last_15m): (
avg:mysql.net.connections{db_env:${var.environment},dd_monitoring:enabled,dd_mysql:enabled} /
avg:mysql.net.max_connections{db_env:${var.environment},dd_monitoring:enabled,dd_mysql:enabled}
) * 100 > ${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 = <<EOF
avg(last_5m): (
avg:mysql.performance.threads_running{db_env:${var.environment},dd_monitoring:enabled,dd_mysql:enabled}
) > ${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"]
}