MON-142: updated based on PR comments + best practices

This commit is contained in:
Boris Rousseau 2018-03-22 09:54:06 +01:00 committed by Quentin Manfroi
parent 87d5075363
commit bf327b6464
3 changed files with 40 additions and 24 deletions

View File

@ -31,8 +31,8 @@ Inputs
| filter_tags | Tags used for custom filtering | string | `*` | no | | 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_critical | Maximum critical acceptable percent of connections | string | `80` | no |
| mysql_connection_threshold_warning | Maximum warning acceptable percent of connections | string | `70` | 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_critical | Maximum critical acceptable number of threads | string | `500` | no |
| mysql_thread_threshold_warning | Maximum warning acceptable percent of threads | string | `400` | no | | mysql_thread_threshold_warning | Maximum warning acceptable number of threads | string | `400` | no |
| message | Message sent when a monitor is triggered | string | - | yes | | message | Message sent when a monitor is triggered | string | - | yes |
Related documentation Related documentation

View File

@ -3,19 +3,27 @@ variable "environment" {
type = "string" type = "string"
} }
variable "filter_tags" { # Global DataDog
description = "Tags used for filtering" variable "evaluation_delay" {
default = "*" description = "Delay in seconds for the metric evaluation"
} default = 900
variable "delay" {
default = 900
} }
variable "message" { 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 ### ### MySQL connections ###
################################# #################################
@ -36,10 +44,10 @@ variable "mysql_connection_threshold_warning" {
variable "mysql_thread_threshold_critical" { variable "mysql_thread_threshold_critical" {
default = 500 default = 500
description = "Maximum critical acceptable percent of threads" description = "Maximum critical acceptable number of threads"
} }
variable "mysql_thread_threshold_warning" { variable "mysql_thread_threshold_warning" {
default = 400 default = 400
description = "Maximum critical acceptable percent of threads" description = "Maximum critical acceptable number of threads"
} }

View File

@ -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}}%)" name = "[${var.environment}] Mysql Connections > {{#is_alert}}{{threshold}}%{{/is_alert}}{{#is_warning}}{{warn_threshold}}%{{/is_warning}} ({{value}}%)"
message = "${var.message}" message = "${var.message}"
type = "query alert" type = "query alert"
@ -10,23 +18,23 @@ resource "datadog_monitor" "mysql_cpu_80_15min" {
) * 100 > ${var.mysql_connection_threshold_critical} ) * 100 > ${var.mysql_connection_threshold_critical}
EOF EOF
evaluation_delay = "${var.delay}" evaluation_delay = "${var.evaluation_delay}"
new_host_delay = "${var.delay}" new_host_delay = "${var.evaluation_delay}"
thresholds { thresholds {
warning = "${var.mysql_connection_threshold_warning}" warning = "${var.mysql_connection_threshold_warning}"
critical = "${var.mysql_connection_threshold_critical}" critical = "${var.mysql_connection_threshold_critical}"
} }
notify_no_data = false # Will NOT notify when no data is received notify_no_data = true
evaluation_delay = "${var.delay}" evaluation_delay = "${var.evaluation_delay}"
renotify_interval = 60 renotify_interval = 60
notify_audit = false notify_audit = false
timeout_h = 0 timeout_h = 0
include_tags = true include_tags = true
locked = false locked = true
require_full_window = true require_full_window = true
new_host_delay = "${var.delay}" new_host_delay = "${var.evaluation_delay}"
no_data_timeframe = 20 no_data_timeframe = 20
tags = ["env:${var.environment}", "resource:mysql"] tags = ["env:${var.environment}", "resource:mysql"]
@ -44,23 +52,23 @@ resource "datadog_monitor" "mysql_thread_5min" {
) > ${var.mysql_thread_threshold_critical} ) > ${var.mysql_thread_threshold_critical}
EOF EOF
evaluation_delay = "${var.delay}" evaluation_delay = "${var.evaluation_delay}"
new_host_delay = "${var.delay}" new_host_delay = "${var.evaluation_delay}"
thresholds { thresholds {
warning = "${var.mysql_thread_threshold_warning}" warning = "${var.mysql_thread_threshold_warning}"
critical = "${var.mysql_thread_threshold_critical}" critical = "${var.mysql_thread_threshold_critical}"
} }
notify_no_data = false # Will NOT notify when no data is received notify_no_data = true
evaluation_delay = "${var.delay}" evaluation_delay = "${var.evaluation_delay}"
renotify_interval = 60 renotify_interval = 60
notify_audit = false notify_audit = false
timeout_h = 0 timeout_h = 0
include_tags = true include_tags = true
locked = false locked = false
require_full_window = true require_full_window = true
new_host_delay = "${var.delay}" new_host_delay = "${var.evaluation_delay}"
no_data_timeframe = 20 no_data_timeframe = 20
tags = ["env:${var.environment}", "resource:mysql"] tags = ["env:${var.environment}", "resource:mysql"]