From 84f4e8d5ba3496a0de6e7fcaf756b445b3ee7779 Mon Sep 17 00:00:00 2001 From: Alexandre Gaillet Date: Fri, 23 Mar 2018 14:53:39 +0100 Subject: [PATCH] MON-96 - Update middleware monitors with EOF best practice --- middleware/apache/README.md | 8 +++++--- middleware/apache/inputs.tf | 10 ++++++++++ middleware/apache/monitors-apache.tf | 15 +++++++++++++-- middleware/nginx/README.md | 6 ++++-- middleware/nginx/inputs.tf | 10 ++++++++++ middleware/nginx/monitors-nginx.tf | 15 +++++++++++++-- middleware/php-fpm/README.md | 4 ++-- middleware/php-fpm/monitors-fpm.tf | 7 +++++-- 8 files changed, 62 insertions(+), 13 deletions(-) diff --git a/middleware/apache/README.md b/middleware/apache/README.md index e4da4f0..d3f5010 100644 --- a/middleware/apache/README.md +++ b/middleware/apache/README.md @@ -24,8 +24,10 @@ Inputs | Name | Description | Type | Default | Required | |------|-------------|:----:|:-----:|:-----:| -| apache_process_message | Custom message for Apache process monitor | string | `` | no | -| apache_process_silenced | Groups to mute for Apache process monitor | map | `` | no | +| apache_connect_message | Custom message for Apache process monitor | string | `` | no | +| apache_connect_silenced | Groups to mute for Apache process monitor | map | `` | no | | environment | Architecture Environment | string | - | yes | | evaluation_delay | Delay in seconds for the metric evaluation | string | `15` | no | -| message | Message sent when an alert is triggered | string | - | yes | +| filter_tags_custom | Tags used for custom filtering when filter_tags_use_defaults is false | string | `*` | no | +| filter_tags_use_defaults | Use default filter tags convention | string | `true` | no | +| message | Message sent when an alert is triggered | string | - | yes | \ No newline at end of file diff --git a/middleware/apache/inputs.tf b/middleware/apache/inputs.tf index 36beec8..d300534 100644 --- a/middleware/apache/inputs.tf +++ b/middleware/apache/inputs.tf @@ -14,6 +14,16 @@ variable "message" { 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 = "*" +} + # Apache Middleware specific variable "apache_connect_silenced" { diff --git a/middleware/apache/monitors-apache.tf b/middleware/apache/monitors-apache.tf index 139a052..3406d3b 100644 --- a/middleware/apache/monitors-apache.tf +++ b/middleware/apache/monitors-apache.tf @@ -1,9 +1,20 @@ +data "template_file" "filter" { + template = "$${filter}" + + vars { + filter = "${var.filter_tags_use_defaults == "true" ? format("dd_monitoring:enabled,dd_apache:enabled,env:%s", var.environment) : "${var.filter_tags_custom}"}" + } +} + resource "datadog_monitor" "datadog_apache_process" { name = "[${var.environment}] Can't connect to apache vhost status" message = "${coalesce(var.apache_connect_message, var.message)}" - type = "service check" - query = "\"apache.can_connect\".over(\"dd_monitoring:enabled\",\"dd_apache:enabled\",\"env:${var.environment}\").by(\"host\",\"port\").last(6).count_by_status()" + type = "service check" + + query = <` | no | +| nginx_connect_message | Custom message for Nginx process monitor | string | `` | no | +| nginx_connect_silenced | Groups to mute for Nginx process monitor | map | `` | no | \ No newline at end of file diff --git a/middleware/nginx/inputs.tf b/middleware/nginx/inputs.tf index 8ab7f01..b4ca2f7 100644 --- a/middleware/nginx/inputs.tf +++ b/middleware/nginx/inputs.tf @@ -14,6 +14,16 @@ variable "message" { 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 = "*" +} + # Nginx Middleware specific variable "nginx_connect_silenced" { diff --git a/middleware/nginx/monitors-nginx.tf b/middleware/nginx/monitors-nginx.tf index 9ab5daf..b578fca 100644 --- a/middleware/nginx/monitors-nginx.tf +++ b/middleware/nginx/monitors-nginx.tf @@ -1,9 +1,20 @@ +data "template_file" "filter" { + template = "$${filter}" + + vars { + filter = "${var.filter_tags_use_defaults == "true" ? format("dd_monitoring:enabled,dd_nginx:enabled,env:%s", var.environment) : "${var.filter_tags_custom}"}" + } +} + resource "datadog_monitor" "datadog_nginx_process" { name = "[${var.environment}] Can't connect to nginx vhost status" message = "${coalesce(var.nginx_connect_message, var.message)}" - type = "service check" - query = "\"nginx.can_connect\".over(\"dd_monitoring:enabled\",\"dd_nginx:enabled\",\"env:${var.environment}\").by(\"host\",\"port\").last(6).count_by_status()" + type = "service check" + + query = <` | no | | php_fpm_busy_threshold_critical | php fpm busy critical threshold | string | `0.9` | no | | php_fpm_busy_threshold_warning | php fpm busy warning threshold | string | `0.8` | no | -| php_fpm_process_message | Custom message for PHP FPM process monitor | string | `` | no | -| php_fpm_process_silenced | Groups to mute for PHP FPM process monitor | map | `` | no | \ No newline at end of file +| php_fpm_connect_message | Custom message for PHP FPM process monitor | string | `` | no | +| php_fpm_connect_silenced | Groups to mute for PHP FPM process monitor | map | `` | no | \ No newline at end of file diff --git a/middleware/php-fpm/monitors-fpm.tf b/middleware/php-fpm/monitors-fpm.tf index 52b4a92..16a944d 100644 --- a/middleware/php-fpm/monitors-fpm.tf +++ b/middleware/php-fpm/monitors-fpm.tf @@ -44,8 +44,11 @@ resource "datadog_monitor" "datadog_fpm_process" { name = "[${var.environment}] Can't connect to php-fpm" message = "${coalesce(var.php_fpm_connect_message, var.message)}" - type = "service check" - query = "\"php_fpm.can_ping\".over(\"dd_monitoring:enabled\",\"dd_php_fpm:enabled\",\"env:${var.environment}\").by(\"host\",\"port\").last(6).count_by_status()" + type = "service check" + + query = <