Merged in MON-316-monitors-for-server-farms (pull request #166)

MON-316 monitors for server farms

Approved-by: jeremy.nancel@fr.clara.net <jeremy.nancel@fr.clara.net>
Approved-by: Quentin Manfroi <quentin.manfroi@yahoo.fr>
This commit is contained in:
jeremy.nancel@fr.clara.net 2018-10-03 16:07:46 +00:00 committed by Quentin Manfroi
commit 9c3afce524
6 changed files with 344 additions and 0 deletions

View File

@ -103,6 +103,7 @@ The `//` is very important, it's a terraform specific syntax used to separate gi
- [keyvault](https://bitbucket.org/morea/terraform.feature.datadog/src/master/cloud/azure/keyvault/)
- [postgresql](https://bitbucket.org/morea/terraform.feature.datadog/src/master/cloud/azure/postgresql/)
- [redis](https://bitbucket.org/morea/terraform.feature.datadog/src/master/cloud/azure/redis/)
- [serverfarms](https://bitbucket.org/morea/terraform.feature.datadog/src/master/cloud/azure/serverfarms/)
- [servicebus](https://bitbucket.org/morea/terraform.feature.datadog/src/master/cloud/azure/servicebus/)
- [sql-database](https://bitbucket.org/morea/terraform.feature.datadog/src/master/cloud/azure/sql-database/)
- [storage](https://bitbucket.org/morea/terraform.feature.datadog/src/master/cloud/azure/storage/)

View File

@ -0,0 +1,65 @@
# CLOUD AZURE SERVERFARMS DataDog monitors
## How to use this module
```
module "datadog-monitors-cloud-azure-serverfarms" {
source = "git::ssh://git@bitbucket.org/morea/terraform.feature.datadog.git//cloud/azure/serverfarms?ref={revision}"
environment = "${var.environment}"
message = "${module.datadog-message-alerting.alerting-message}"
}
```
## Purpose
Creates DataDog monitors with the following checks:
- Serverfarm CPU percentage is too high
- Serverfarm is down
- Serverfarm memory percentage is too high
## Inputs
| Name | Description | Type | Default | Required |
|------|-------------|:----:|:-----:|:-----:|
| cpu_percentage_enabled | Flag to enable the serverfarms cpu_percentage monitor | string | `true` | no |
| cpu_percentage_extra_tags | Extra tags for serverfarms cpu_percentage monitor | list | `[]` | no |
| cpu_percentage_message | Custom message for serverfarm cpu_percentage monitor | string | `` | no |
| cpu_percentage_silenced | Groups to mute for serverfarm cpu_percentage monitor | map | `{}` | no |
| cpu_percentage_threshold_critical | CPU percentage (critical threshold) | string | `95` | no |
| cpu_percentage_threshold_warning | CPU percentage (warning threshold) | string | `90` | no |
| cpu_percentage_time_aggregator | Monitor aggregator for serverfarms cpu_percentage [available values: min, max or avg] | string | `min` | no |
| cpu_percentage_timeframe | Monitor timeframe for serverfarms cpu_percentage [available values: `last_#m` (1, 5, 10, 15, or 30), `last_#h` (1, 2, or 4), or `last_1d`] | string | `last_10m` | no |
| environment | Architecture environment | string | - | yes |
| evaluation_delay | Delay in seconds for the metric evaluation | string | `900` | 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 |
| memory_percentage_enabled | Flag to enable the serverfarms memory_percentage monitor | string | `true` | no |
| memory_percentage_extra_tags | Extra tags for serverfarms memory_percentage monitor | list | `[]` | no |
| memory_percentage_message | Custom message for serverfarm memory_percentage monitor | string | `` | no |
| memory_percentage_silenced | Groups to mute for serverfarm memory_percentage monitor | map | `{}` | no |
| memory_percentage_threshold_critical | Memory percentage (critical threshold) | string | `95` | no |
| memory_percentage_threshold_warning | Memory percentage (warning threshold) | string | `90` | no |
| memory_percentage_time_aggregator | Monitor aggregator for serverfarms memory_percentage [available values: min, max or avg] | string | `min` | no |
| memory_percentage_timeframe | Monitor timeframe for serverfarms memory_percentage [available values: `last_#m` (1, 5, 10, 15, or 30), `last_#h` (1, 2, or 4), or `last_1d`] | string | `last_5m` | no |
| message | Message sent when a serverfarms monitor is triggered | string | - | yes |
| new_host_delay | Delay in seconds before monitor new resource | string | `300` | no |
| status_enabled | Flag to enable the serverfarms status monitor | string | `true` | no |
| status_extra_tags | Extra tags for serverfarms status monitor | list | `[]` | no |
| status_message | Custom message for serverfarm status monitor | string | `` | no |
| status_silenced | Groups to mute for serverfarm status monitor | map | `{}` | no |
| status_time_aggregator | Monitor aggregator for serverfarms status [available values: min, max or avg] | string | `min` | no |
| status_timeframe | Monitor timeframe for serverfarms status [available values: `last_#m` (1, 5, 10, 15, or 30), `last_#h` (1, 2, or 4), or `last_1d`] | string | `last_5m` | no |
## Outputs
| Name | Description |
|------|-------------|
| cpu_percentage_id | id for monitor cpu_percentage |
| memory_percentage_id | id for monitor memory_percentage |
| status_id | id for monitor status |
## Related documentation

View File

@ -0,0 +1,163 @@
# Global Terraform
variable "environment" {
description = "Architecture environment"
type = "string"
}
# Global DataDog
variable "message" {
description = "Message sent when a serverfarms monitor is triggered"
}
variable "evaluation_delay" {
description = "Delay in seconds for the metric evaluation"
default = 900
}
variable "new_host_delay" {
description = "Delay in seconds before monitor new resource"
default = 300
}
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 = "*"
}
# Azure serverfarms specific variables
# Status
variable "status_enabled" {
description = "Flag to enable the serverfarms status monitor"
type = "string"
default = "true"
}
variable "status_message" {
description = "Custom message for serverfarm status monitor"
type = "string"
default = ""
}
variable "status_silenced" {
type = "map"
description = "Groups to mute for serverfarm status monitor"
default = {}
}
variable "status_extra_tags" {
description = "Extra tags for serverfarms status monitor"
type = "list"
default = []
}
variable "status_time_aggregator" {
description = "Monitor aggregator for serverfarms status [available values: min, max or avg]"
type = "string"
default = "min"
}
variable "status_timeframe" {
description = "Monitor timeframe for serverfarms status [available values: `last_#m` (1, 5, 10, 15, or 30), `last_#h` (1, 2, or 4), or `last_1d`]"
type = "string"
default = "last_5m"
}
# CPU percentage
variable "cpu_percentage_enabled" {
description = "Flag to enable the serverfarms cpu_percentage monitor"
type = "string"
default = "true"
}
variable "cpu_percentage_message" {
description = "Custom message for serverfarm cpu_percentage monitor"
type = "string"
default = ""
}
variable "cpu_percentage_silenced" {
type = "map"
description = "Groups to mute for serverfarm cpu_percentage monitor"
default = {}
}
variable "cpu_percentage_extra_tags" {
description = "Extra tags for serverfarms cpu_percentage monitor"
type = "list"
default = []
}
variable "cpu_percentage_time_aggregator" {
description = "Monitor aggregator for serverfarms cpu_percentage [available values: min, max or avg]"
type = "string"
default = "min"
}
variable "cpu_percentage_timeframe" {
description = "Monitor timeframe for serverfarms cpu_percentage [available values: `last_#m` (1, 5, 10, 15, or 30), `last_#h` (1, 2, or 4), or `last_1d`]"
type = "string"
default = "last_10m"
}
variable "cpu_percentage_threshold_critical" {
description = "CPU percentage (critical threshold)"
default = 95
}
variable "cpu_percentage_threshold_warning" {
description = "CPU percentage (warning threshold)"
default = 90
}
# Memory percentage
variable "memory_percentage_enabled" {
description = "Flag to enable the serverfarms memory_percentage monitor"
type = "string"
default = "true"
}
variable "memory_percentage_message" {
description = "Custom message for serverfarm memory_percentage monitor"
type = "string"
default = ""
}
variable "memory_percentage_silenced" {
type = "map"
description = "Groups to mute for serverfarm memory_percentage monitor"
default = {}
}
variable "memory_percentage_extra_tags" {
description = "Extra tags for serverfarms memory_percentage monitor"
type = "list"
default = []
}
variable "memory_percentage_time_aggregator" {
description = "Monitor aggregator for serverfarms memory_percentage [available values: min, max or avg]"
type = "string"
default = "min"
}
variable "memory_percentage_timeframe" {
description = "Monitor timeframe for serverfarms memory_percentage [available values: `last_#m` (1, 5, 10, 15, or 30), `last_#h` (1, 2, or 4), or `last_1d`]"
type = "string"
default = "last_5m"
}
variable "memory_percentage_threshold_critical" {
description = "Memory percentage (critical threshold)"
default = 95
}
variable "memory_percentage_threshold_warning" {
description = "Memory percentage (warning threshold)"
default = 90
}

View File

@ -0,0 +1,8 @@
module "filter-tags" {
source = "../../../common/filter-tags"
environment = "${var.environment}"
resource = "serverfarms"
filter_tags_use_defaults = "${var.filter_tags_use_defaults}"
filter_tags_custom = "${var.filter_tags_custom}"
}

View File

@ -0,0 +1,93 @@
resource "datadog_monitor" "status" {
count = "${var.status_enabled ? 1 : 0}"
name = "[${var.environment}] Serverfarm is down"
message = "${coalesce(var.status_message, var.message)}"
query = <<EOF
${var.status_time_aggregator}(${var.status_timeframe}): (
avg:azure.web_serverfarms.status${module.filter-tags.query_alert} by {resource_group,region,name}
) != 1
EOF
type = "metric alert"
silenced = "${var.status_silenced}"
notify_no_data = true
evaluation_delay = "${var.evaluation_delay}"
renotify_interval = 0
notify_audit = false
timeout_h = 0
include_tags = true
locked = false
require_full_window = false
new_host_delay = "${var.new_host_delay}"
tags = ["env:${var.environment}", "type:cloud", "provider:azure", "resource:serverfarms", "team:claranet", "created-by:terraform", "${var.status_extra_tags}"]
}
resource "datadog_monitor" "cpu_percentage" {
count = "${var.cpu_percentage_enabled ? 1 : 0}"
name = "[${var.environment}] Serverfarm CPU percentage is too high {{#is_alert}}{{{comparator}}} {{threshold}}% ({{value}}%){{/is_alert}}{{#is_warning}}{{{comparator}}} {{warn_threshold}}% ({{value}}%){{/is_warning}}"
message = "${coalesce(var.cpu_percentage_message, var.message)}"
query = <<EOF
${var.cpu_percentage_time_aggregator}(${var.cpu_percentage_timeframe}): (
avg:azure.web_serverfarms.cpu_percentage${module.filter-tags.query_alert} by {resource_group,region,name}
) > ${var.cpu_percentage_threshold_critical}
EOF
type = "metric alert"
thresholds {
warning = "${var.cpu_percentage_threshold_warning}"
critical = "${var.cpu_percentage_threshold_critical}"
}
silenced = "${var.cpu_percentage_silenced}"
notify_no_data = false
evaluation_delay = "${var.evaluation_delay}"
renotify_interval = 0
notify_audit = false
timeout_h = 0
include_tags = true
locked = false
require_full_window = false
new_host_delay = "${var.new_host_delay}"
tags = ["env:${var.environment}", "type:cloud", "provider:azure", "resource:serverfarms", "team:claranet", "created-by:terraform", "${var.cpu_percentage_extra_tags}"]
}
resource "datadog_monitor" "memory_percentage" {
count = "${var.memory_percentage_enabled ? 1 : 0}"
name = "[${var.environment}] Serverfarm memory percentage is too high {{#is_alert}}{{{comparator}}} {{threshold}}% ({{value}}%){{/is_alert}}{{#is_warning}}{{{comparator}}} {{warn_threshold}}% ({{value}}%){{/is_warning}}"
message = "${coalesce(var.memory_percentage_message, var.message)}"
query = <<EOF
${var.memory_percentage_time_aggregator}(${var.memory_percentage_timeframe}): (
avg:azure.web_serverfarms.memory_percentage${module.filter-tags.query_alert} by {resource_group,region,name}
) > ${var.memory_percentage_threshold_critical}
EOF
type = "metric alert"
thresholds {
warning = "${var.memory_percentage_threshold_warning}"
critical = "${var.memory_percentage_threshold_critical}"
}
silenced = "${var.memory_percentage_silenced}"
notify_no_data = false
evaluation_delay = "${var.evaluation_delay}"
renotify_interval = 0
notify_audit = false
timeout_h = 0
include_tags = true
locked = false
require_full_window = false
new_host_delay = "${var.new_host_delay}"
tags = ["env:${var.environment}", "type:cloud", "provider:azure", "resource:serverfarms", "team:claranet", "created-by:terraform", "${var.memory_percentage_extra_tags}"]
}

View File

@ -0,0 +1,14 @@
output "status_id" {
description = "id for monitor status"
value = "${datadog_monitor.status.*.id}"
}
output "cpu_percentage_id" {
description = "id for monitor cpu_percentage"
value = "${datadog_monitor.cpu_percentage.*.id}"
}
output "memory_percentage_id" {
description = "id for monitor memory_percentage"
value = "${datadog_monitor.memory_percentage.*.id}"
}