Merged in MON-96-update-monitors-tags (pull request #35)

MON-96 Update legacy monitors to new best practices

Approved-by: Laurent Piroelle <laurent.piroelle@fr.clara.net>
Approved-by: Jérôme Respaut <shr3ps@gmail.com>
Approved-by: Alexandre Gaillet <alexandre.gaillet@fr.clara.net>
This commit is contained in:
Ahmed Fourti 2018-02-22 16:54:34 +00:00 committed by Quentin Manfroi
commit 55e0c50bf7
22 changed files with 674 additions and 388 deletions

View File

@ -33,7 +33,7 @@ EOF
timeout_h = 0
include_tags = true
locked = false
require_full_window = true
require_full_window = false
new_host_delay = "${var.evaluation_delay}"
no_data_timeframe = 20
@ -42,14 +42,15 @@ EOF
### Elasticsearch cluster free storage space monitor ###
resource "datadog_monitor" "es_free_space_low" {
name = "[${var.environment}] ElasticSearch cluster free storage space < ${var.diskspace_threshold_critical}%"
name = "[${var.environment}] ElasticSearch cluster free storage space {{comparator}} {{#is_alert}}{{threshold}}%{{/is_alert}}{{#is_warning}}{{warn_threshold}}%{{/is_warning}} ({{value}}%)"
message = "${var.message}"
type = "query alert"
query = <<EOF
avg(last_15m): (
avg:aws.es.free_storage_space{${data.template_file.filter.rendered}} by {region,name} / (${var.es_cluster_volume_size}*1000) * 100
avg:aws.es.free_storage_space{${data.template_file.filter.rendered}} by {region,name} /
(${var.es_cluster_volume_size}*1000) * 100
) < ${var.diskspace_threshold_critical}
EOF
@ -65,7 +66,7 @@ EOF
timeout_h = 0
include_tags = true
locked = false
require_full_window = true
require_full_window = false
new_host_delay = "${var.evaluation_delay}"
no_data_timeframe = 20
@ -74,7 +75,7 @@ EOF
### Elasticsearch cluster CPU monitor ###
resource "datadog_monitor" "es_cpu_90_15min" {
name = "[${var.environment}] ElasticSearch cluster CPU high > ${var.cpu_threshold_critical}%"
name = "[${var.environment}] ElasticSearch cluster CPU high {{comparator}} {{#is_alert}}{{threshold}}%{{/is_alert}}{{#is_warning}}{{warn_threshold}}%{{/is_warning}} ({{value}}%)"
message = "${var.message}"
type = "query alert"
@ -97,7 +98,7 @@ EOF
timeout_h = 0
include_tags = true
locked = false
require_full_window = true
require_full_window = false
new_host_delay = "${var.evaluation_delay}"
no_data_timeframe = 20

View File

@ -1 +0,0 @@
../../../inputs.tf

View File

@ -1,54 +0,0 @@
resource "datadog_monitor" "rds-mysql_cpu_80_15min" {
name = "[${var.env}] rds Cpu high > 90% for 15 min on {{host.identifier}}"
message = "{{#is_alert}}\n${var.hno_escalation_group} \n{{/is_alert}} \n{{#is_recovery}}\n${var.hno_escalation_group}\n{{/is_recovery}}\n{{#is_warning}}\n${var.ho_escalation_group} \n{{/is_warning}} \n{{#is_warning_recovery}}\n${var.ho_escalation_group}\n{{/is_warning_recovery}}"
count = "${var.dd_aws_rds == "enabled" ? 1 : 0 }"
query = "avg(last_15m):avg:aws.rds.cpuutilization{dd_monitoring:enabled,dd_aws_rds:enabled,env:${var.env}} by {region,name} > 90"
type = "query alert"
thresholds {
warning = "${var.rds_cpu_threshold["warning"]}"
critical = "${var.rds_cpu_threshold["critical"]}"
}
tags = ["*"]
notify_no_data = "${var.rds_config["notify_no_data"]}"
evaluation_delay = "${var.rds_config["delay"]}"
renotify_interval = 60
notify_audit = false
timeout_h = 0
include_tags = true
locked = false
require_full_window = true
new_host_delay = "${var.rds_config["delay"]}"
no_data_timeframe = 20
}
resource "datadog_monitor" "mysql_rds_free_space_low" {
name = "[${var.env}] rds free space low < 10 % on {{host.identifier}}"
message = "{{#is_alert}}\n${var.hno_escalation_group} \n{{/is_alert}} \n{{#is_recovery}}\n${var.hno_escalation_group}\n{{/is_recovery}}\n{{#is_warning}}\n${var.ho_escalation_group} \n{{/is_warning}} \n{{#is_warning_recovery}}\n${var.ho_escalation_group}\n{{/is_warning_recovery}}"
type = "query alert"
query = "avg(last_15m):avg:aws.rds.free_storage_space{dd_monitoring:enabled,dd_aws_rds:enabled,env:${var.env}} by {region,name} / avg:aws.rds.total_storage_space{dd_monitoring:enabled,dd_aws_rds:enabled,env:${var.env}} by {region,name} * 100 < 10"
count = "${var.dd_aws_rds == "enabled" ? 1 : 0 }"
thresholds {
warning = "${var.rds_mem_threshold["warning"]}"
critical = "${var.rds_mem_threshold["critical"]}"
}
tags = ["*"]
notify_no_data = "${var.rds_config["notify_no_data"]}"
evaluation_delay = "${var.rds_config["delay"]}"
renotify_interval = 60
notify_audit = false
timeout_h = 0
include_tags = true
locked = false
require_full_window = true
new_host_delay = "${var.rds_config["delay"]}"
no_data_timeframe = 20
}

43
cloud/aws/rds/README.md Normal file
View File

@ -0,0 +1,43 @@
AWS RDS Instance DataDog monitors
=================================
How to use this module
----------------------
```
module "datadog-monitors-aws-rds" {
source = "git::ssh://git@bitbucket.org/morea/terraform.feature.datadog.git//cloud/aws/rds?ref={revision}"
message = "${module.datadog-message-alerting.alerting-message}"
environment = "${var.environment}"
}
```
Purpose
-------
Creates a DataDog monitors with the following checks :
* CPU High
* Free disk space low
Inputs
------
| Name | Description | Type | Default | Required |
|------|-------------|:----:|:-----:|:-----:|
| cpu_threshold_critical | CPU usage in percent (critical threshold) | string | `90` | no |
| cpu_threshold_warning | CPU usage in percent (warning threshold) | string | `80` | no |
| diskspace_threshold_critical | Disk free space in percent (critical threshold) | string | `10` | no |
| diskspace_threshold_warning | Disk free space in percent (warning threshold) | string | `20` | no |
| environment | Architecture Environment | string | - | yes |
| evaluation_delay | Delay in seconds for the metric evaluation | string | `600` | no |
| 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 |
Related documentation
---------------------
DataDog documentation: [https://docs.datadoghq.com/integrations/amazon_rds/](https://docs.datadoghq.com/integrations/amazon_rds/)
AWS RDS Instance metrics documentation: [https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/rds-metricscollected.html](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/rds-metricscollected.html)

47
cloud/aws/rds/inputs.tf Normal file
View File

@ -0,0 +1,47 @@
# Global Terraform
variable "environment" {
description = "Architecture Environment"
type = "string"
}
# Global DataDog
variable "evaluation_delay" {
description = "Delay in seconds for the metric evaluation"
default = 600
}
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 = "*"
}
# AWS RDS instance specific
variable "cpu_threshold_warning" {
description = "CPU usage in percent (warning threshold)"
default = "80"
}
variable "cpu_threshold_critical" {
description = "CPU usage in percent (critical threshold)"
default = "90"
}
variable "diskspace_threshold_warning" {
description = "Disk free space in percent (warning threshold)"
default = "20"
}
variable "diskspace_threshold_critical" {
description = "Disk free space in percent (critical threshold)"
default = "10"
}

View File

@ -0,0 +1,70 @@
data "template_file" "filter" {
template = "$${filter}"
vars {
filter = "${var.filter_tags_use_defaults == "true" ? format("dd_monitoring:enabled,dd_aws_rds:enabled,env:%s", var.environment) : "${var.filter_tags_custom}"}"
}
}
### RDS instance CPU monitor ###
resource "datadog_monitor" "rds_cpu_90_15min" {
name = "[${var.environment}] RDS instance CPU high {{comparator}} {{#is_alert}}{{threshold}}%{{/is_alert}}{{#is_warning}}{{warn_threshold}}%{{/is_warning}} ({{value}}%)"
message = "${var.message}"
type = "metric alert"
query = <<EOF
avg(last_15m): (
avg:aws.rds.cpuutilization{${data.template_file.filter.rendered}} by {region,name}
) > ${var.cpu_threshold_critical}
EOF
thresholds {
warning = "${var.cpu_threshold_warning}"
critical = "${var.cpu_threshold_critical}"
}
notify_no_data = true
evaluation_delay = "${var.evaluation_delay}"
notify_audit = false
timeout_h = 0
include_tags = true
locked = false
require_full_window = false
new_host_delay = "${var.evaluation_delay}"
no_data_timeframe = 20
tags = ["env:${var.environment}", "resource:rds", "team:aws", "provider:aws"]
}
### RDS instance free space monitor ###
resource "datadog_monitor" "rds_free_space_low" {
name = "[${var.environment}] RDS instance free space {{comparator}} {{#is_alert}}{{threshold}}%{{/is_alert}}{{#is_warning}}{{warn_threshold}}%{{/is_warning}} ({{value}}%)"
message = "${var.message}"
type = "metric alert"
query = <<EOF
avg(last_15m): (
avg:aws.rds.free_storage_space{${data.template_file.filter.rendered}} by {region,name} /
avg:aws.rds.total_storage_space{${data.template_file.filter.rendered}} by {region,name} * 100
) < ${var.diskspace_threshold_critical}
EOF
thresholds {
warning = "${var.diskspace_threshold_warning}"
critical = "${var.diskspace_threshold_critical}"
}
notify_no_data = true
evaluation_delay = "${var.evaluation_delay}"
notify_audit = false
timeout_h = 0
include_tags = true
locked = false
require_full_window = false
new_host_delay = "${var.evaluation_delay}"
no_data_timeframe = 20
tags = ["env:${var.environment}", "resource:rds", "team:aws", "provider:aws"]
}

View File

@ -1,35 +1,47 @@
variable environment {}
variable region {}
variable "critical_escalation_group" {
default = "@pagerduty_HODummy"
}
variable "warning_escalation_group" {
default = "@pagerduty_HNODummy"
# Global Terraform
variable "environment" {
description = "Architecture Environment"
type = "string"
}
variable "datadog_api_key" {}
variable "datadog_app_key" {}
variable "dd_linux_basics" {
default = "enabled"
# Global DataDog
variable "evaluation_delay" {
description = "Delay in seconds for the metric evaluation"
default = 600
}
variable "dd_aws_rds" {
default = "enabled"
variable "message" {
description = "Message sent when an alert is triggered"
}
variable "dd_custom_cpu" {
type = "map"
default = {
status = "enabled"
name = "CPU High > 95% during 1 hour"
period = "last_1h"
critical_threshold = 95
warning_threshold = 90
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 = "*"
}
# instance specific
variable "cpu_threshold_warning" {
description = "CPU usage in percent (warning threshold)"
default = "80"
}
variable "cpu_threshold_critical" {
description = "CPU usage in percent (critical threshold)"
default = "90"
}
variable "diskspace_threshold_warning" {
description = "Disk free space in percent (warning threshold)"
default = "20"
}
variable "diskspace_threshold_critical" {
description = "Disk free space in percent (critical threshold)"
default = "10"
}

View File

@ -0,0 +1,29 @@
Apache Middleware DataDog monitors
==================================
How to use this module
----------------------
```
module "datadog-monitors-apache-middleware" {
source = "git::ssh://git@bitbucket.org/morea/terraform.feature.datadog.git//middleware/apache?ref={revision}"
message = "${module.datadog-message-alerting.alerting-message}"
environment = "${var.environment}"
}
```
Purpose
-------
Creates a DataDog monitors with the following checks :
* Apache process
Inputs
------
| Name | Description | Type | Default | Required |
|------|-------------|:----:|:-----:|:-----:|
| 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 |

View File

@ -1 +0,0 @@
../../inputs.tf

View File

@ -0,0 +1,18 @@
# Global Terraform
variable "environment" {
description = "Architecture Environment"
type = "string"
}
# Global DataDog
variable "evaluation_delay" {
description = "Delay in seconds for the metric evaluation"
default = 15
}
variable "message" {
description = "Message sent when an alert is triggered"
}
# Apache Middleware specific

View File

@ -1,10 +1,9 @@
resource "datadog_monitor" "Apache_process" {
name = "[${var.env}] Apache process is down on {{host.name}}"
message = "{{#is_alert}}\n${var.hno_escalation_group} \n{{/is_alert}} \n{{#is_recovery}}\n${var.hno_escalation_group}\n{{/is_recovery}}\n{{#is_warning}}\n${var.ho_escalation_group} \n{{/is_warning}} \n{{#is_warning_recovery}}\n${var.ho_escalation_group}\n{{/is_warning_recovery}}"
resource "datadog_monitor" "datadog_apache_process" {
name = "[${var.environment}] Can't connect to apache vhost status"
message = "${var.message}"
type = "service check"
query = "\"process.up\".over(\"dd_monitoring:enabled\",\"dd_apache:enabled\",\"process:apache\",\"env:${var.env}\").by(\"host\",\"process\", \"app\").last(4).count_by_status()"
count = "${var.dd_apache == "enabled" ? 1 : 0 }"
query = "\"apache.can_connect\".over(\"dd_monitoring:enabled\",\"dd_apache:enabled\",\"env:${var.environment}\").by(\"host\",\"port\").last(6).count_by_status()"
thresholds = {
ok = 1
@ -12,10 +11,10 @@ resource "datadog_monitor" "Apache_process" {
critical = 4
}
notify_no_data = "${var.apache_nginx_fpm_config["notify_no_data"]}"
evaluation_delay = "${var.apache_nginx_fpm_config["delay"]}"
new_host_delay = "${var.apache_nginx_fpm_config["delay"]}"
renotify_interval = 60
notify_no_data = true
evaluation_delay = "${var.evaluation_delay}"
new_host_delay = "${var.evaluation_delay}"
renotify_interval = 0
notify_audit = false
timeout_h = 0
include_tags = true
@ -23,5 +22,5 @@ resource "datadog_monitor" "Apache_process" {
require_full_window = true
no_data_timeframe = 20
tags = ["*"]
tags = ["env:${var.environment}", "resource:apache"]
}

View File

@ -0,0 +1,29 @@
Nginx Middleware DataDog monitors
=================================
How to use this module
----------------------
```
module "datadog-monitors-nginx-middleware" {
source = "git::ssh://git@bitbucket.org/morea/terraform.feature.datadog.git//middleware/nginx?ref={revision}"
message = "${module.datadog-message-alerting.alerting-message}"
environment = "${var.environment}"
}
```
Purpose
-------
Creates a DataDog monitors with the following checks :
* Nginx process
Inputs
------
| Name | Description | Type | Default | Required |
|------|-------------|:----:|:-----:|:-----:|
| 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 |

View File

@ -1 +0,0 @@
../../inputs.tf

View File

@ -0,0 +1,18 @@
# Global Terraform
variable "environment" {
description = "Architecture Environment"
type = "string"
}
# Global DataDog
variable "evaluation_delay" {
description = "Delay in seconds for the metric evaluation"
default = 15
}
variable "message" {
description = "Message sent when an alert is triggered"
}
# Nginx Middleware specific

View File

@ -1,10 +1,9 @@
resource "datadog_monitor" "Nginx_process" {
name = "[${var.env}] Nginx process is down on {{host.name}}"
message = "{{#is_alert}}\n${var.hno_escalation_group} \n{{/is_alert}} \n{{#is_recovery}}\n${var.hno_escalation_group}\n{{/is_recovery}}\n{{#is_warning}}\n${var.ho_escalation_group} \n{{/is_warning}} \n{{#is_warning_recovery}}\n${var.ho_escalation_group}\n{{/is_warning_recovery}}"
resource "datadog_monitor" "datadog_nginx_process" {
name = "[${var.environment}] Can't connect to nginx vhost status"
message = "${var.message}"
type = "service check"
query = "\"process.up\".over(\"dd_monitoring:enabled\",\"dd_nginx:enabled\",\"process:nginx\",\"env:${var.env}\").by(\"host\",\"process\", \"app\").last(4).count_by_status()"
count = "${var.dd_nginx == "enabled" ? 1 : 0 }"
query = "\"nginx.can_connect\".over(\"dd_monitoring:enabled\",\"dd_nginx:enabled\",\"env:${var.environment}\").by(\"host\",\"port\").last(6).count_by_status()"
thresholds = {
ok = 1
@ -12,10 +11,10 @@ resource "datadog_monitor" "Nginx_process" {
critical = 4
}
notify_no_data = "${var.apache_nginx_fpm_config["notify_no_data"]}"
evaluation_delay = "${var.apache_nginx_fpm_config["delay"]}"
new_host_delay = "${var.apache_nginx_fpm_config["delay"]}"
renotify_interval = 60
notify_no_data = true
evaluation_delay = "${var.evaluation_delay}"
new_host_delay = "${var.evaluation_delay}"
renotify_interval = 0
notify_audit = false
timeout_h = 0
include_tags = true
@ -23,5 +22,5 @@ resource "datadog_monitor" "Nginx_process" {
require_full_window = true
no_data_timeframe = 20
tags = ["*"]
tags = ["env:${var.environment}", "resource:nginx"]
}

View File

@ -0,0 +1,35 @@
PHP FPM Middleware DataDog monitors
===================================
How to use this module
----------------------
```
module "datadog-monitors-php-fpm-middleware" {
source = "git::ssh://git@bitbucket.org/morea/terraform.feature.datadog.git//middleware/php-fpm?ref={revision}"
message = "${module.datadog-message-alerting.alerting-message}"
environment = "${var.environment}"
}
```
Purpose
-------
Creates a DataDog monitors with the following checks :
* PHP FPM process
* PHP FPM load
Inputs
------
| Name | Description | Type | Default | Required |
|------|-------------|:----:|:-----:|:-----:|
| environment | Architecture Environment | string | - | yes |
| evaluation_delay_metric | Delay in seconds for the metric evaluation | string | `600` | no |
| evaluation_delay_service | Delay in seconds for the metric evaluation | string | `15` | no |
| 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 |
| 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 |

View File

@ -1 +0,0 @@
../../inputs.tf

View File

@ -0,0 +1,42 @@
# Global Terraform
variable "environment" {
description = "Architecture Environment"
type = "string"
}
# Global DataDog
variable "evaluation_delay_service" {
description = "Delay in seconds for the metric evaluation"
default = 15
}
variable "evaluation_delay_metric" {
description = "Delay in seconds for the metric evaluation"
default = 600
}
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 = "*"
}
# PHP FPM Middleware specific
variable "php_fpm_busy_threshold_warning" {
description = "php fpm busy warning threshold"
default = 0.8
}
variable "php_fpm_busy_threshold_critical" {
description = "php fpm busy critical threshold"
default = 0.9
}

View File

@ -1,38 +1,49 @@
resource "datadog_monitor" "php-fpm_process_idle" {
name = "[${var.env}] php_fpm busy worker > 90% on {{host.name}}"
message = "{{#is_alert}}\n${var.hno_escalation_group} \n{{/is_alert}} \n{{#is_recovery}}\n${var.hno_escalation_group}\n{{/is_recovery}}\n{{#is_warning}}\n${var.ho_escalation_group} \n{{/is_warning}} \n{{#is_warning_recovery}}\n${var.ho_escalation_group}\n{{/is_warning_recovery}}"
data "template_file" "filter" {
template = "$${filter}"
type = "query alert"
query = "avg(last_10m):avg:php_fpm.processes.active{dd_monitoring:enabled,dd_php_fpm:enabled,env:${var.env}} by {host,region} / ( avg:php_fpm.processes.idle{dd_monitoring:enabled,dd_php_fpm:enabled,env:${var.env}} by {host,region} + avg:php_fpm.processes.active{dd_monitoring:enabled,dd_php_fpm:enabled,env:${var.env}} by {host,region} ) > 0.9"
count = "${var.dd_php_fpm == "enabled" ? 1 : 0 }"
thresholds {
warning = "${var.php_fpm_busy_threshold["warning"]}"
critical = "${var.php_fpm_busy_threshold["critical"]}"
vars {
filter = "${var.filter_tags_use_defaults == "true" ? format("dd_monitoring:enabled,dd_php_fpm:enabled,env:%s", var.environment) : "${var.filter_tags_custom}"}"
}
}
notify_no_data = "${var.apache_nginx_fpm_config["notify_no_data"]}"
evaluation_delay = "${var.apache_nginx_fpm_config["delay"]}"
new_host_delay = "${var.apache_nginx_fpm_config["delay"]}"
renotify_interval = 60
resource "datadog_monitor" "datadog_php_fpm_process_idle" {
name = "[${var.environment}] php_fpm busy worker {{comparator}} {{#is_alert}}{{threshold}}%{{/is_alert}}{{#is_warning}}{{warn_threshold}}%{{/is_warning}} ({{value}}%)"
message = "${var.message}"
type = "metric alert"
query = <<EOF
avg(last_10m): (
avg:php_fpm.processes.active{${data.template_file.filter.rendered}} by {region, host} /
( avg:php_fpm.processes.idle{${data.template_file.filter.rendered}} by {region, host} +
avg:php_fpm.processes.active{${data.template_file.filter.rendered}} by {region, host} )
) > ${var.php_fpm_busy_threshold_critical}
EOF
thresholds {
warning = "${var.php_fpm_busy_threshold_warning}"
critical = "${var.php_fpm_busy_threshold_critical}"
}
notify_no_data = true
evaluation_delay = "${var.evaluation_delay_metric}"
new_host_delay = "${var.evaluation_delay_metric}"
notify_audit = false
timeout_h = 0
include_tags = true
locked = false
require_full_window = true
renotify_interval = 0
no_data_timeframe = 20
tags = ["*"]
tags = ["env:${var.environment}", "resource:php-fpm"]
}
resource "datadog_monitor" "FPM_process" {
name = "[${var.env}] FPM process is down on {{host.name}}"
message = "{{#is_alert}}\n${var.hno_escalation_group} \n{{/is_alert}} \n{{#is_recovery}}\n${var.hno_escalation_group}\n{{/is_recovery}}\n{{#is_warning}}\n${var.ho_escalation_group} \n{{/is_warning}} \n{{#is_warning_recovery}}\n${var.ho_escalation_group}\n{{/is_warning_recovery}}"
resource "datadog_monitor" "datadog_fpm_process" {
name = "[${var.environment}] Can't connect to php-fpm"
message = "${var.message}"
type = "service check"
query = "\"process.up\".over(\"dd_monitoring:enabled\",\"dd_php_fpm:enabled\",\"process:php_fpm\",\"env:${var.env}\").by(\"host\",\"process\", \"app\").last(4).count_by_status()"
count = "${var.dd_nginx == "enabled" ? 1 : 0 }"
query = "\"php_fpm.can_ping\".over(\"dd_monitoring:enabled\",\"dd_php_fpm:enabled\",\"env:${var.environment}\").by(\"host\",\"port\").last(6).count_by_status()"
thresholds = {
ok = 1
@ -40,10 +51,10 @@ resource "datadog_monitor" "FPM_process" {
critical = 4
}
notify_no_data = "${var.apache_nginx_fpm_config["notify_no_data"]}"
evaluation_delay = "${var.apache_nginx_fpm_config["delay"]}"
new_host_delay = "${var.apache_nginx_fpm_config["delay"]}"
renotify_interval = 60
notify_no_data = true
evaluation_delay = "${var.evaluation_delay_service}"
new_host_delay = "${var.evaluation_delay_service}"
renotify_interval = 0
notify_audit = false
timeout_h = 0
include_tags = true
@ -51,5 +62,5 @@ resource "datadog_monitor" "FPM_process" {
require_full_window = true
no_data_timeframe = 20
tags = ["*"]
tags = ["env:${var.environment}", "resource:php-fpm"]
}

40
system/generic/README.md Normal file
View File

@ -0,0 +1,40 @@
System Generic DataDog monitors
===============================
How to use this module
----------------------
```
module "datadog-monitors-system-generic" {
source = "git::ssh://git@bitbucket.org/morea/terraform.feature.datadog.git//system/generic?ref={revision}"
message = "${module.datadog-message-alerting.alerting-message}"
environment = "${var.environment}"
}
```
Purpose
-------
Creates a DataDog monitors with the following checks :
* System CPU High
Inputs
------
| Name | Description | Type | Default | Required |
|------|-------------|:----:|:-----:|:-----:|
| cpu_high_threshold_critical | CPU high critical threshold | string | `95` | no |
| cpu_high_threshold_warning | CPU high warning threshold | string | `80` | no |
| cpu_high_timeframe | CPU high timeframe | string | `last_5m` | no |
| environment | Architecture Environment | string | - | yes |
| evaluation_delay | Delay in seconds for the metric evaluation | string | `600` | no |
| 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 |
| free_disk_inodes_threshold_critical | Free disk space critical threshold | string | `5` | no |
| free_disk_inodes_threshold_warning | Free disk space warning threshold | string | `10` | no |
| free_disk_space_threshold_critical | Free disk space critical threshold | string | `5` | no |
| free_disk_space_threshold_warning | Free disk space warning threshold | string | `10` | no |
| free_memory_threshold_critical | Free disk space critical threshold | string | `5` | no |
| free_memory_threshold_warning | Free disk space warning threshold | string | `10` | no |
| message | Message sent when an alert is triggered | string | - | yes |

View File

@ -1 +0,0 @@
../../inputs.tf

72
system/generic/inputs.tf Normal file
View File

@ -0,0 +1,72 @@
# Global Terraform
variable "environment" {
description = "Architecture Environment"
type = "string"
}
# Global DataDog
variable "evaluation_delay" {
description = "Delay in seconds for the metric evaluation"
default = 600
}
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 = "*"
}
# Custom CPU instance specific
variable "cpu_high_timeframe" {
description = "CPU high timeframe"
default = "last_5m"
}
variable "cpu_high_threshold_warning" {
description = "CPU high warning threshold"
default = 80
}
variable "cpu_high_threshold_critical" {
description = "CPU high critical threshold"
default = 95
}
variable "free_disk_space_threshold_warning" {
description = "Free disk space warning threshold"
default = 10
}
variable "free_disk_space_threshold_critical" {
description = "Free disk space critical threshold"
default = 5
}
variable "free_disk_inodes_threshold_warning" {
description = "Free disk space warning threshold"
default = 10
}
variable "free_disk_inodes_threshold_critical" {
description = "Free disk space critical threshold"
default = 5
}
variable "free_memory_threshold_warning" {
description = "Free disk space warning threshold"
default = 10
}
variable "free_memory_threshold_critical" {
description = "Free disk space critical threshold"
default = 5
}

View File

@ -1,24 +0,0 @@
resource "datadog_monitor" "cpu_custom" {
name = "${var.dd_custom_cpu["name"]}"
message = "{{#is_alert}}\n${var.hno_escalation_group}\n{{/is_alert}}\n{{#is_recovery}}\n${var.hno_escalation_group}\n{{/is_recovery}}\n{{#is_warning}}\n${var.ho_escalation_group}\n{{/is_warning}}\n{{#is_warning_recovery}}\n${var.ho_escalation_group}\n{{/is_warning_recovery}}"
count = "${var.dd_custom_cpu["status"] == "enabled" ? 1 : 0}"
query = "min(${var.dd_custom_cpu["period"]}):avg:system.cpu.system{dd_monitoring:enabled,dd_linux_basics:enabled,!dd_custom_cpu.monitoring:enabled} by {host} + avg:system.cpu.user{dd_monitoring:enabled,dd_linux_basics:enabled,!dd_custom_cpu:enabled} by {host} > ${var.dd_custom_cpu["critical_threshold"]}"
type = "query alert"
thresholds = {
warning = "${var.dd_custom_cpu["warning_threshold"]}"
critical = "${var.dd_custom_cpu["critical_threshold"]}"
}
notify_no_data = "${var.linux_basics_config["notify_no_data"]}"
evaluation_delay = "${var.linux_basics_config["delay"]}"
new_host_delay = "${var.linux_basics_config["delay"]}"
renotify_interval = 60
notify_audit = false
timeout_h = 0
include_tags = true
locked = false
require_full_window = true
no_data_timeframe = 20
}

View File

@ -0,0 +1,131 @@
data "template_file" "filter" {
template = "$${filter}"
vars {
filter = "${var.filter_tags_use_defaults == "true" ? format("dd_monitoring:enabled,dd_system:enabled,env:%s", var.environment) : "${var.filter_tags_custom}"}"
}
}
resource "datadog_monitor" "datadog_cpu_too_high" {
name = "[${var.environment}] CPU usage {{comparator}} {{#is_alert}}{{threshold}}%{{/is_alert}}{{#is_warning}}{{warn_threshold}}%{{/is_warning}} ({{value}}%)"
message = "${var.message}"
query = <<EOF
min(${var.cpu_high_timeframe}): (
100 - avg:system.cpu.idle{${data.template_file.filter.rendered}} by {region,host}
) > ${var.cpu_high_threshold_critical}
EOF
type = "metric alert"
thresholds {
warning = "${var.cpu_high_threshold_warning}"
critical = "${var.cpu_high_threshold_critical}"
}
tags = ["env:${var.environment}", "type:system", "resource:cpu"]
notify_no_data = true
evaluation_delay = "${var.evaluation_delay}"
new_host_delay = "${var.evaluation_delay}"
notify_audit = false
timeout_h = 0
include_tags = true
locked = false
require_full_window = true
no_data_timeframe = 20
}
resource "datadog_monitor" "datadog_free_disk_space_too_low" {
name = "[${var.environment}] Free disk space {{comparator}} {{#is_alert}}{{threshold}}%{{/is_alert}}{{#is_warning}}{{warn_threshold}}%{{/is_warning}} ({{value}}%)"
message = "${var.message}"
query = <<EOF
min(last_5m): (
avg:system.disk.free{${data.template_file.filter.rendered}} by {region,host,device} /
avg:system.disk.total{${data.template_file.filter.rendered}} by {region,host,device} * 100
) < ${var.free_disk_space_threshold_critical}
EOF
type = "metric alert"
thresholds {
warning = "${var.free_disk_space_threshold_warning}"
critical = "${var.free_disk_space_threshold_critical}"
}
tags = ["env:${var.environment}", "type:system", "resource:disk"]
notify_no_data = true
evaluation_delay = "${var.evaluation_delay}"
new_host_delay = "${var.evaluation_delay}"
notify_audit = false
timeout_h = 0
include_tags = true
locked = false
require_full_window = true
no_data_timeframe = 20
}
resource "datadog_monitor" "datadog_free_disk_space_inodes_too_low" {
name = "[${var.environment}] Free disk inodes {{comparator}} {{#is_alert}}{{threshold}}%{{/is_alert}}{{#is_warning}}{{warn_threshold}}%{{/is_warning}} ({{value}}%)"
message = "${var.message}"
query = <<EOF
min(last_5m): (
avg:system.fs.inodes.free{${data.template_file.filter.rendered}} by {region,host,device} /
avg:system.fs.inodes.total{${data.template_file.filter.rendered}} by {region,host,device} * 100
) < ${var.free_disk_inodes_threshold_critical}
EOF
type = "metric alert"
thresholds {
warning = "${var.free_disk_inodes_threshold_warning}"
critical = "${var.free_disk_inodes_threshold_critical}"
}
tags = ["env:${var.environment}", "type:system", "resource:disk"]
notify_no_data = true
evaluation_delay = "${var.evaluation_delay}"
new_host_delay = "${var.evaluation_delay}"
notify_audit = false
timeout_h = 0
include_tags = true
locked = false
require_full_window = true
no_data_timeframe = 20
}
resource "datadog_monitor" "datadog_free_memory" {
name = "[${var.environment}] Free memory {{comparator}} {{#is_alert}}{{threshold}}%{{/is_alert}}{{#is_warning}}{{warn_threshold}}%{{/is_warning}} ({{value}}%)"
message = "${var.message}"
query = <<EOF
min(last_1m): (
avg:system.mem.free{${data.template_file.filter.rendered}} by {region,host} /
avg:system.mem.total{${data.template_file.filter.rendered}} by {region,host} * 100
) < ${var.free_memory_threshold_critical}
EOF
type = "metric alert"
thresholds {
warning = "${var.free_memory_threshold_warning}"
critical = "${var.free_memory_threshold_critical}"
}
tags = ["env:${var.environment}", "type:system", "resource:memory"]
notify_no_data = true
evaluation_delay = "${var.evaluation_delay}"
new_host_delay = "${var.evaluation_delay}"
renotify_interval = 0
notify_audit = false
timeout_h = 0
include_tags = true
locked = false
require_full_window = true
no_data_timeframe = 20
}

View File

@ -1 +0,0 @@
../../inputs.tf

View File

@ -1,226 +0,0 @@
resource "datadog_monitor" "cpu_80_15min" {
name = "[${var.env}] CPU High > ${var.cpu_15_critical} for 15 min on {{host.name}}"
message = "{{#is_alert}}\n${var.hno_escalation_group}\n{{/is_alert}}\n{{#is_recovery}}\n${var.hno_escalation_group}\n{{/is_recovery}}"
count = "${var.dd_linux_basics == "enabled" ? 1 : 0}"
query = "min(last_15m):avg:system.cpu.system{dd_monitoring:enabled,dd_linux_basics:enabled,env:${var.env},!dd_custom_cpu:enabled} by {host,region} + avg:system.cpu.user{dd_monitoring:enabled,dd_linux_basics:enabled,env:${var.env},!dd_custom_cpu:enabled} by {host,region} > ${var.cpu_15_critical}"
type = "query alert"
thresholds {
critical = "${var.cpu_15_critical}"
}
tags = ["*"]
notify_no_data = "${var.linux_basics_config["notify_no_data"]}"
evaluation_delay = "${var.linux_basics_config["delay"]}"
new_host_delay = "${var.linux_basics_config["delay"]}"
renotify_interval = 60
notify_audit = false
timeout_h = 0
include_tags = true
locked = false
require_full_window = true
no_data_timeframe = 20
}
resource "datadog_monitor" "cpu_95_5min" {
name = "[${var.env}] CPU High > ${var.cpu_5_critical} for 5 min on {{host.name}}"
message = "{{#is_alert}}\n${var.hno_escalation_group}\n{{/is_alert}}\n{{#is_recovery}}\n${var.hno_escalation_group}\n{{/is_recovery}}"
query = "min(last_5m):avg:system.cpu.system{dd_monitoring:enabled,dd_linux_basics:enabled,env:${var.env},!dd_custom_cpu:enabled} by {host,region} + avg:system.cpu.user{dd_monitoring:enabled,dd_linux_basics:enabled,env:${var.env},!dd_custom_cpu:enabled} by {host,region} > ${var.cpu_5_critical}"
type = "query alert"
count = "${var.dd_linux_basics == "enabled" ? 1 : 0}"
thresholds {
critical = "${var.cpu_5_critical}"
}
tags = ["*"]
notify_no_data = "${var.linux_basics_config["notify_no_data"]}"
evaluation_delay = "${var.linux_basics_config["delay"]}"
new_host_delay = "${var.linux_basics_config["delay"]}"
renotify_interval = 60
notify_audit = false
timeout_h = 0
include_tags = true
locked = false
require_full_window = true
no_data_timeframe = 20
}
resource "datadog_monitor" "datadog_free_disk_space_5" {
name = "[${var.env}] Free disk space < 5% on {{host.name}}"
message = "{{#is_alert}}\n${var.hno_escalation_group}\n{{/is_alert}}\n{{#is_recovery}}\n${var.hno_escalation_group}\n{{/is_recovery}}"
query = "sum(last_5m):avg:system.disk.free{dd_monitoring:enabled,dd_linux_basics:enabled,env:${var.env},!dd_custom_cpu:enabled} by {host,region,device} / avg:system.disk.total{dd_monitoring:enabled,dd_linux_basics:enabled,env:${var.env},!dd_custom_cpu:enabled} by {host,region,device} * 100 < 5"
type = "query alert"
count = "${var.dd_linux_basics == "enabled" ? 1 : 0}"
thresholds {
critical = 5
}
tags = ["*"]
notify_no_data = "${var.linux_basics_config["notify_no_data"]}"
evaluation_delay = "${var.linux_basics_config["delay"]}"
new_host_delay = "${var.linux_basics_config["delay"]}"
renotify_interval = 60
notify_audit = false
timeout_h = 0
include_tags = true
locked = false
require_full_window = true
no_data_timeframe = 20
}
resource "datadog_monitor" "datadog_free_disk_space_10" {
name = "[${var.env}] Free disk space < 10% on {{host.name}}"
message = "{{#is_alert}}\n${var.hno_escalation_group}\n{{/is_alert}}\n{{#is_recovery}}\n${var.hno_escalation_group}\n{{/is_recovery}}\n{{#is_warning}}\n${var.ho_escalation_group}\n{{/is_warning}}\n{{#is_warning_recovery}}\n${var.ho_escalation_group}\n{{/is_warning_recovery}}"
query = "sum(last_5m):avg:system.disk.free{dd_monitoring:enabled,dd_linux_basics:enabled,env:${var.env},!dd_custom_cpu:enabled} by {host,region,device} / avg:system.disk.total{dd_monitoring:enabled,dd_linux_basics:enabled,env:${var.env},!dd_custom_cpu:enabled} by {host,region,device} * 100 < 10"
type = "query alert"
count = "${var.dd_linux_basics == "enabled" ? 1 : 0}"
thresholds {
warning = 20
critical = 10
}
tags = ["*"]
notify_no_data = "${var.linux_basics_config["notify_no_data"]}"
evaluation_delay = "${var.linux_basics_config["delay"]}"
new_host_delay = "${var.linux_basics_config["delay"]}"
renotify_interval = 60
notify_audit = false
timeout_h = 0
include_tags = true
locked = false
require_full_window = true
no_data_timeframe = 20
}
resource "datadog_monitor" "datadog_free_disk_space_inodes_5" {
name = "[${var.env}] Free disk inodes < 5% on {{host.name}}"
message = "{{#is_alert}}\n${var.hno_escalation_group} \n{{/is_alert}} \n{{#is_recovery}}\n${var.hno_escalation_group} \n{{/is_recovery}}"
query = "sum(last_5m):avg:system.fs.inodes.free{dd_monitoring:enabled,dd_linux_basics:enabled,env:${var.env},!dd_custom_cpu:enabled} by {host,region,device} / avg:system.fs.inodes.total{dd_monitoring:enabled,dd_linux_basics:enabled,env:${var.env},!dd_custom_cpu:enabled} by {host,region,device} * 100 < 5"
type = "query alert"
count = "${var.dd_linux_basics == "enabled" ? 1 : 0}"
thresholds {
critical = 5
}
tags = ["*"]
notify_no_data = "${var.linux_basics_config["notify_no_data"]}"
evaluation_delay = "${var.linux_basics_config["delay"]}"
new_host_delay = "${var.linux_basics_config["delay"]}"
renotify_interval = 60
notify_audit = false
timeout_h = 0
include_tags = true
locked = false
require_full_window = true
no_data_timeframe = 20
}
resource "datadog_monitor" "datadog_free_disk_space_inodes_10" {
name = "[${var.env}] Free disk inodes < 10% on {{host.name}}"
message = "{{#is_alert}}\n${var.hno_escalation_group}\n{{/is_alert}}\n{{#is_recovery}}\n${var.hno_escalation_group}\n{{/is_recovery}}\n{{#is_warning}}\n${var.ho_escalation_group}\n{{/is_warning}}\n{{#is_warning_recovery}}\n${var.ho_escalation_group}\n{{/is_warning_recovery}}"
query = "max(last_5m):avg:system.fs.inodes.free{dd_monitoring:enabled,dd_linux_basics:enabled,env:${var.env},!dd_custom_cpu:enabled} by {host,device,region} / avg:system.fs.inodes.total{dd_monitoring:enabled,dd_linux_basics:enabled,env:${var.env},!dd_custom_cpu:enabled} by {host,device,region} * 100 < 10"
type = "query alert"
count = "${var.dd_linux_basics == "enabled" ? 1 : 0}"
thresholds {
warning = 20
critical = 10
}
tags = ["*"]
notify_no_data = "${var.linux_basics_config["notify_no_data"]}"
evaluation_delay = "${var.linux_basics_config["delay"]}"
new_host_delay = "${var.linux_basics_config["delay"]}"
renotify_interval = 60
notify_audit = false
timeout_h = 0
include_tags = true
locked = false
require_full_window = true
no_data_timeframe = 20
}
# resource "datadog_monitor" "datadog_cpu_load" {
# name = "CPU Load > 2"
# message = "Debugging alert - no escalation"
# query = "min(last_5m):avg:system.load.5{dd_monitoring:enabled,dd_linux_basics:enabled,!dd_custom_cpu:enabled} by {instance-id} / avg:gcp.gce.instance.cpu.reserved_cores{*} by {instance-id} > 2"
# type = "query alert"
# count = "${var.dd_linux_basics == "enabled" ? 1 : 0}"
# notify_no_data = "${var.linux_basics_config["notify_no_data"]}"
# evaluation_delay = "${var.linux_basics_config["delay"]}"
# new_host_delay = "${var.linux_basics_config["delay"]}"
# renotify_interval = 60
# notify_audit = false
# timeout_h = 0
# include_tags = true
# locked = false
# require_full_window = true
# no_data_timeframe = 20
# }
resource "datadog_monitor" "datadog_free_memory" {
name = "[${var.env}] Free memory < 5% on {{host.name}}"
message = "Debugging alert - no escalation"
query = "sum(last_1m):avg:system.mem.free{dd_monitoring:enabled,dd_linux_basics:enabled,env:${var.env},!dd_custom_memory:enabled} by {host,region} / avg:system.mem.total{dd_monitoring:enabled,dd_linux_basics:enabled,env:${var.env},!dd_custom_memory:enabled} by {host,region} * 100 < 5"
type = "query alert"
count = "${var.dd_linux_basics == "enabled" ? 1 : 0}"
thresholds {
critical = 5
}
tags = ["*"]
notify_no_data = "${var.linux_basics_config["notify_no_data"]}"
evaluation_delay = "${var.linux_basics_config["delay"]}"
new_host_delay = "${var.linux_basics_config["delay"]}"
renotify_interval = 60
notify_audit = false
timeout_h = 0
include_tags = true
locked = false
require_full_window = true
no_data_timeframe = 20
}
# resource "datadog_monitor" "datadog_host_unreachable" {
# name = "Host unreachable"
# message = "{{#is_alert}}\n${var.hno_escalation_group} \n{{/is_alert}} \n{{#is_recovery}}\n${var.hno_escalation_group} \n{{/is_recovery}}"
# query = "datadog.agent.up.over(dd_monitoring:enabled,dd_linux_basics:enabled,env:${var.env},!dd_custom_cpu:enabled).last(1).count_by_status()"
# type = "service check"
# count = "${var.dd_linux_basics == "enabled" ? 1 : 0}"
# notify_no_data = "${var.linux_basics_config["notify_no_data"]}"
# evaluation_delay = "${var.linux_basics_config["delay"]}"
# new_host_delay = "${var.linux_basics_config["delay"]}"
# renotify_interval = 60
# notify_audit = false
# timeout_h = 0
# include_tags = true
# locked = false
# require_full_window = true
# no_data_timeframe = 20
# }