MON-521 add fargate monitors
This commit is contained in:
parent
76e87e76ff
commit
ebfa547cff
@ -141,6 +141,7 @@ module "datadog-monitors-system-generic" {
|
||||
- [ecs](https://github.com/claranet/terraform-datadog-monitors/tree/master/cloud/aws/ecs/)
|
||||
- [common](https://github.com/claranet/terraform-datadog-monitors/tree/master/cloud/aws/ecs/common/)
|
||||
- [ec2-cluster](https://github.com/claranet/terraform-datadog-monitors/tree/master/cloud/aws/ecs/ec2-cluster/)
|
||||
- [fargate](https://github.com/claranet/terraform-datadog-monitors/tree/master/cloud/aws/ecs/fargate/)
|
||||
- [elasticache](https://github.com/claranet/terraform-datadog-monitors/tree/master/cloud/aws/elasticache/)
|
||||
- [common](https://github.com/claranet/terraform-datadog-monitors/tree/master/cloud/aws/elasticache/common/)
|
||||
- [memcached](https://github.com/claranet/terraform-datadog-monitors/tree/master/cloud/aws/elasticache/memcached/)
|
||||
|
||||
1
cloud/aws/ecs/fargate/MANIFEST.txt
Normal file
1
cloud/aws/ecs/fargate/MANIFEST.txt
Normal file
@ -0,0 +1 @@
|
||||
cloud-aws
|
||||
73
cloud/aws/ecs/fargate/README.md
Normal file
73
cloud/aws/ecs/fargate/README.md
Normal file
@ -0,0 +1,73 @@
|
||||
# CLOUD AWS ECS FARGATE DataDog monitors
|
||||
|
||||
## How to use this module
|
||||
|
||||
```hcl
|
||||
module "datadog-monitors-cloud-aws-ecs-fargate" {
|
||||
source = "claranet/monitors/datadog//cloud/aws/ecs/fargate"
|
||||
version = "{revision}"
|
||||
|
||||
environment = var.environment
|
||||
message = module.datadog-message-alerting.alerting-message
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
## Purpose
|
||||
|
||||
Creates DataDog monitors with the following checks:
|
||||
|
||||
- Fargate CPU Utilization High (disabled by default)
|
||||
- Fargate memory Utilization High (disabled by default)
|
||||
- Fargate service does not respond.
|
||||
|
||||
## Inputs
|
||||
|
||||
| Name | Description | Type | Default | Required |
|
||||
|------|-------------|------|---------|:-----:|
|
||||
| cpu\_utilization\_enabled | Flag to enable monitor | `string` | `"false"` | no |
|
||||
| cpu\_utilization\_extra\_tags | Extra tags for the monitor | `list(string)` | `[]` | no |
|
||||
| cpu\_utilization\_message | Custom message for the monitor | `string` | `""` | no |
|
||||
| cpu\_utilization\_threshold\_critical | Critical threshold for the monitor | `string` | `90` | no |
|
||||
| cpu\_utilization\_threshold\_warning | Warning threshold for the monitor | `string` | `85` | no |
|
||||
| cpu\_utilization\_time\_aggregator | Monitor aggregator (min, max or avg) | `string` | `"min"` | no |
|
||||
| cpu\_utilization\_timeframe | Timeframe for the monitor | `string` | `"last_5m"` | no |
|
||||
| environment | Architecture environment | `string` | n/a | yes |
|
||||
| evaluation\_delay | Delay in seconds for the metric evaluation | `number` | `15` | no |
|
||||
| filter\_tags\_custom | Tags used for custom filtering when filter\_tags\_use\_defaults is false | `string` | `"*"` | no |
|
||||
| filter\_tags\_custom\_excluded | Tags excluded for custom filtering when filter\_tags\_use\_defaults is false | `string` | `""` | no |
|
||||
| filter\_tags\_use\_defaults | Use default filter tags convention | `bool` | `true` | no |
|
||||
| memory\_utilization\_enabled | Flag to enable Fargate Memory utilization monitor | `string` | `"false"` | no |
|
||||
| memory\_utilization\_extra\_tags | Extra tags for Fargate Memory utilization monitor | `list(string)` | `[]` | no |
|
||||
| memory\_utilization\_message | Custom message for the Fargate Memory Utilization monitor | `string` | `""` | no |
|
||||
| memory\_utilization\_threshold\_critical | Critical threshold for the Fargate Memory Utilization monitor | `string` | `90` | no |
|
||||
| memory\_utilization\_threshold\_warning | Warning threshold for the Fargate Memory Utilization monitor | `string` | `85` | no |
|
||||
| memory\_utilization\_time\_aggregator | Monitor aggregator for Fargate Memory Utilization [available values: min, max or avg] | `string` | `"min"` | no |
|
||||
| memory\_utilization\_timeframe | Timeframe for the Fargate Memory Utilization monitor | `string` | `"last_5m"` | no |
|
||||
| message | Message sent when a monitor is triggered | `string` | n/a | yes |
|
||||
| new\_host\_delay | Delay in seconds before monitor new resource | `number` | `300` | no |
|
||||
| notify\_no\_data | Will raise no data alert if set to true | `bool` | `true` | no |
|
||||
| prefix\_slug | Prefix string to prepend between brackets on every monitors names | `string` | `""` | no |
|
||||
| service\_check\_enabled | Flag to enable monitor | `bool` | `true` | no |
|
||||
| service\_check\_extra\_tags | Extra tags for the monitor | `list(string)` | `[]` | no |
|
||||
| service\_check\_message | Custom message for the monitor | `string` | `""` | no |
|
||||
| service\_check\_no\_data\_timeframe | No data timeframe in minutes | `number` | `10` | no |
|
||||
| service\_check\_threshold\_warning | Warning threshold | `number` | `3` | no |
|
||||
|
||||
## Outputs
|
||||
|
||||
| Name | Description |
|
||||
|------|-------------|
|
||||
| cpu\_utilization\_id | id for monitor cpu\_utilization |
|
||||
| memory\_utilization\_id | id for monitor memory\_utilization |
|
||||
| service\_check\_id | id for monitor service\_check |
|
||||
|
||||
## Related documentation
|
||||
|
||||
[Official DataDog documentation on ECS Fargate](https://docs.datadoghq.com/integrations/ecs_fargate/)
|
||||
|
||||
### Specific configuration due to agent limitations
|
||||
|
||||
CPU & memory monitors will be usable only when deploying datadog agent as a sidecar in task definitions.
|
||||
|
||||
In order to avoid clutter on monitors, datadog agent & ECS internal containers are always excluded from filtering to be on par with Kubernetes way of work. A bug is [currently opened](https://github.com/DataDog/datadog-agent/issues/2722) on agent repository on this matter.
|
||||
169
cloud/aws/ecs/fargate/inputs.tf
Normal file
169
cloud/aws/ecs/fargate/inputs.tf
Normal file
@ -0,0 +1,169 @@
|
||||
# Generics
|
||||
|
||||
variable "environment" {
|
||||
description = "Architecture environment"
|
||||
type = string
|
||||
}
|
||||
|
||||
variable "message" {
|
||||
type = string
|
||||
description = "Message sent when a monitor is triggered"
|
||||
}
|
||||
|
||||
variable "evaluation_delay" {
|
||||
description = "Delay in seconds for the metric evaluation"
|
||||
type = number
|
||||
default = 15
|
||||
}
|
||||
|
||||
variable "new_host_delay" {
|
||||
description = "Delay in seconds before monitor new resource"
|
||||
type = number
|
||||
default = 300
|
||||
}
|
||||
|
||||
variable "notify_no_data" {
|
||||
description = "Will raise no data alert if set to true"
|
||||
type = bool
|
||||
default = true
|
||||
}
|
||||
|
||||
variable "prefix_slug" {
|
||||
description = "Prefix string to prepend between brackets on every monitors names"
|
||||
default = ""
|
||||
}
|
||||
|
||||
variable "filter_tags_use_defaults" {
|
||||
description = "Use default filter tags convention"
|
||||
type = bool
|
||||
default = true
|
||||
}
|
||||
|
||||
variable "filter_tags_custom" {
|
||||
description = "Tags used for custom filtering when filter_tags_use_defaults is false"
|
||||
type = string
|
||||
default = "*"
|
||||
}
|
||||
|
||||
variable "filter_tags_custom_excluded" {
|
||||
description = "Tags excluded for custom filtering when filter_tags_use_defaults is false"
|
||||
type = string
|
||||
default = ""
|
||||
}
|
||||
|
||||
# Service checks
|
||||
variable "service_check_enabled" {
|
||||
type = bool
|
||||
description = "Flag to enable monitor "
|
||||
default = true
|
||||
}
|
||||
|
||||
variable "service_check_message" {
|
||||
type = string
|
||||
description = "Custom message for the monitor"
|
||||
default = ""
|
||||
}
|
||||
|
||||
variable "service_check_extra_tags" {
|
||||
type = list(string)
|
||||
description = "Extra tags for the monitor"
|
||||
default = []
|
||||
}
|
||||
|
||||
variable "service_check_threshold_warning" {
|
||||
type = number
|
||||
description = "Warning threshold"
|
||||
default = 3
|
||||
}
|
||||
|
||||
variable "service_check_no_data_timeframe" {
|
||||
type = number
|
||||
description = "No data timeframe in minutes"
|
||||
default = 10
|
||||
}
|
||||
|
||||
# CPU utilization
|
||||
variable "cpu_utilization_enabled" {
|
||||
description = "Flag to enable monitor"
|
||||
type = string
|
||||
default = "false"
|
||||
}
|
||||
|
||||
variable "cpu_utilization_message" {
|
||||
description = "Custom message for the monitor"
|
||||
type = string
|
||||
default = ""
|
||||
}
|
||||
|
||||
variable "cpu_utilization_time_aggregator" {
|
||||
description = "Monitor aggregator (min, max or avg)"
|
||||
type = string
|
||||
default = "min"
|
||||
}
|
||||
|
||||
variable "cpu_utilization_timeframe" {
|
||||
description = "Timeframe for the monitor"
|
||||
type = string
|
||||
default = "last_5m"
|
||||
}
|
||||
|
||||
variable "cpu_utilization_threshold_critical" {
|
||||
description = "Critical threshold for the monitor"
|
||||
type = string
|
||||
default = 90
|
||||
}
|
||||
|
||||
variable "cpu_utilization_threshold_warning" {
|
||||
description = "Warning threshold for the monitor"
|
||||
type = string
|
||||
default = 85
|
||||
}
|
||||
|
||||
variable "cpu_utilization_extra_tags" {
|
||||
description = "Extra tags for the monitor"
|
||||
type = list(string)
|
||||
default = []
|
||||
}
|
||||
|
||||
# Memory usage
|
||||
variable "memory_utilization_enabled" {
|
||||
description = "Flag to enable Fargate Memory utilization monitor"
|
||||
type = string
|
||||
default = "false"
|
||||
}
|
||||
|
||||
variable "memory_utilization_extra_tags" {
|
||||
description = "Extra tags for Fargate Memory utilization monitor"
|
||||
type = list(string)
|
||||
default = []
|
||||
}
|
||||
|
||||
variable "memory_utilization_message" {
|
||||
description = "Custom message for the Fargate Memory Utilization monitor"
|
||||
type = string
|
||||
default = ""
|
||||
}
|
||||
|
||||
variable "memory_utilization_time_aggregator" {
|
||||
description = "Monitor aggregator for Fargate Memory Utilization [available values: min, max or avg]"
|
||||
type = string
|
||||
default = "min"
|
||||
}
|
||||
|
||||
variable "memory_utilization_timeframe" {
|
||||
description = "Timeframe for the Fargate Memory Utilization monitor"
|
||||
type = string
|
||||
default = "last_5m"
|
||||
}
|
||||
|
||||
variable "memory_utilization_threshold_critical" {
|
||||
description = "Critical threshold for the Fargate Memory Utilization monitor"
|
||||
type = string
|
||||
default = 90
|
||||
}
|
||||
|
||||
variable "memory_utilization_threshold_warning" {
|
||||
description = "Warning threshold for the Fargate Memory Utilization monitor"
|
||||
type = string
|
||||
default = 85
|
||||
}
|
||||
14
cloud/aws/ecs/fargate/modules.tf
Normal file
14
cloud/aws/ecs/fargate/modules.tf
Normal file
@ -0,0 +1,14 @@
|
||||
module "filter-tags" {
|
||||
|
||||
source = "../../../../common/filter-tags"
|
||||
|
||||
environment = var.environment
|
||||
resource = "aws_ecs"
|
||||
extra_tags_excluded = [
|
||||
"ecs_container_name:datadog-agent",
|
||||
"ecs_container_name:_internal_ecs_pause"
|
||||
]
|
||||
filter_tags_use_defaults = var.filter_tags_use_defaults
|
||||
filter_tags_custom = var.filter_tags_custom
|
||||
filter_tags_custom_excluded = var.filter_tags_custom_excluded
|
||||
}
|
||||
110
cloud/aws/ecs/fargate/monitors-ecs-fargate.tf
Normal file
110
cloud/aws/ecs/fargate/monitors-ecs-fargate.tf
Normal file
@ -0,0 +1,110 @@
|
||||
# Service check
|
||||
|
||||
resource "datadog_monitor" "service_check" {
|
||||
count = var.service_check_enabled ? 1 : 0
|
||||
name = "${var.prefix_slug == "" ? "" : "[${var.prefix_slug}]"}[${var.environment}] Fargate service does not respond."
|
||||
message = coalesce(var.service_check_message, var.message)
|
||||
type = "service check"
|
||||
|
||||
query = <<EOQ
|
||||
"fargate_check"${module.filter-tags.service_check}.last(6).count_by_status()
|
||||
EOQ
|
||||
|
||||
thresholds = {
|
||||
warning = var.service_check_threshold_warning
|
||||
critical = 5
|
||||
}
|
||||
|
||||
notify_audit = false
|
||||
locked = false
|
||||
timeout_h = 0
|
||||
|
||||
evaluation_delay = var.evaluation_delay
|
||||
new_host_delay = var.new_host_delay
|
||||
notify_no_data = var.notify_no_data
|
||||
no_data_timeframe = var.service_check_no_data_timeframe
|
||||
renotify_interval = 0
|
||||
|
||||
|
||||
include_tags = true
|
||||
|
||||
tags = concat(["env:${var.environment}", "type:cloud", "provider:aws", "resource:ecs_fargate", "team:claranet", "created-by:terraform", "category:service"], var.service_check_extra_tags)
|
||||
|
||||
lifecycle {
|
||||
ignore_changes = [silenced]
|
||||
}
|
||||
}
|
||||
|
||||
resource "datadog_monitor" "cpu_utilization" {
|
||||
count = var.cpu_utilization_enabled ? 1 : 0
|
||||
name = "${var.prefix_slug == "" ? "" : "[${var.prefix_slug}]"}[${var.environment}] Fargate CPU Utilization High {{#is_alert}}{{{comparator}}} {{threshold}}% ({{value}}%){{/is_alert}}{{#is_warning}}{{{comparator}}} {{warn_threshold}}% ({{value}}%){{/is_warning}}"
|
||||
message = coalesce(var.cpu_utilization_message, var.message)
|
||||
type = "metric alert"
|
||||
|
||||
query = <<EOQ
|
||||
${var.cpu_utilization_time_aggregator}(${var.cpu_utilization_timeframe}):
|
||||
avg:ecs.fargate.cpu.percent${module.filter-tags.query_alert} by {task_family, ecs_container_name}
|
||||
> ${var.cpu_utilization_threshold_critical}
|
||||
EOQ
|
||||
|
||||
|
||||
thresholds = {
|
||||
critical = var.cpu_utilization_threshold_critical
|
||||
warning = var.cpu_utilization_threshold_warning
|
||||
}
|
||||
|
||||
evaluation_delay = var.evaluation_delay
|
||||
new_host_delay = var.new_host_delay
|
||||
notify_no_data = false
|
||||
require_full_window = true
|
||||
renotify_interval = 0
|
||||
notify_audit = false
|
||||
timeout_h = 0
|
||||
include_tags = true
|
||||
locked = false
|
||||
|
||||
tags = concat(["env:${var.environment}", "type:cloud", "provider:aws", "resource:ecs_fargate", "team:claranet", "created-by:terraform"], var.cpu_utilization_extra_tags)
|
||||
|
||||
lifecycle {
|
||||
ignore_changes = [silenced]
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
resource "datadog_monitor" "memory_utilization" {
|
||||
count = var.memory_utilization_enabled == "true" ? 1 : 0
|
||||
name = "${var.prefix_slug == "" ? "" : "[${var.prefix_slug}]"}[${var.environment}] Fargate memory Utilization High {{#is_alert}}{{{comparator}}} {{threshold}}% ({{value}}%){{/is_alert}}{{#is_warning}}{{{comparator}}} {{warn_threshold}}% ({{value}}%){{/is_warning}}"
|
||||
message = coalesce(var.memory_utilization_message, var.message)
|
||||
type = "metric alert"
|
||||
|
||||
query = <<EOQ
|
||||
${var.memory_utilization_time_aggregator}(${var.memory_utilization_timeframe}):
|
||||
avg:ecs.fargate.mem.usage${module.filter-tags.query_alert} by {task_family, ecs_container_name} /
|
||||
avg:ecs.fargate.mem.limit${module.filter-tags.query_alert} by {task_family, ecs_container_name}
|
||||
* 100
|
||||
> ${var.memory_utilization_threshold_critical}
|
||||
EOQ
|
||||
|
||||
|
||||
thresholds = {
|
||||
critical = var.memory_utilization_threshold_critical
|
||||
warning = var.memory_utilization_threshold_warning
|
||||
}
|
||||
|
||||
evaluation_delay = var.evaluation_delay
|
||||
new_host_delay = var.new_host_delay
|
||||
notify_no_data = false
|
||||
require_full_window = true
|
||||
renotify_interval = 0
|
||||
notify_audit = false
|
||||
timeout_h = 0
|
||||
include_tags = true
|
||||
locked = false
|
||||
|
||||
tags = concat(["env:${var.environment}", "type:cloud", "provider:aws", "resource:ecs_fargate", "team:claranet", "created-by:terraform"], var.memory_utilization_extra_tags)
|
||||
|
||||
lifecycle {
|
||||
ignore_changes = [silenced]
|
||||
}
|
||||
|
||||
}
|
||||
15
cloud/aws/ecs/fargate/outputs.tf
Normal file
15
cloud/aws/ecs/fargate/outputs.tf
Normal file
@ -0,0 +1,15 @@
|
||||
output "cpu_utilization_id" {
|
||||
description = "id for monitor cpu_utilization"
|
||||
value = datadog_monitor.cpu_utilization.*.id
|
||||
}
|
||||
|
||||
output "memory_utilization_id" {
|
||||
description = "id for monitor memory_utilization"
|
||||
value = datadog_monitor.memory_utilization.*.id
|
||||
}
|
||||
|
||||
output "service_check_id" {
|
||||
description = "id for monitor service_check"
|
||||
value = datadog_monitor.service_check.*.id
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user