diff --git a/cloud/aws/apigateway/README.md b/cloud/aws/apigateway/README.md new file mode 100644 index 0000000..1dab021 --- /dev/null +++ b/cloud/aws/apigateway/README.md @@ -0,0 +1,46 @@ +AWS API Gateway DataDog monitors +========================================== + +How to use this module +---------------------- + +``` +module "datadog-monitors-aws-api-gateway" { + source = "git::ssh://git@bitbucket.org/morea/terraform.feature.datadog.git//cloud/aws/apigateway?ref={revision}" + + environment = "${var.environment}" + message = "${module.datadog-message-alerting.alerting-message}" +} + +``` + +Purpose +------- +Creates DataDog monitors with the following checks : + +* API Gateway too much 5xx errors +* API Gateway too much 4xx errors +* API Gateway latency to high + +Inputs +------ + +| Name | Description | Type | Default | Required | +|------|-------------|:----:|:-----:|:-----:| +| delay | Delay in seconds for the metric evaluation | string | `900` | no | +| environment | Architecture environment | string | - | yes | +| filter_tags | Tags used for custom filtering | string | `*` | no | +| http_4xx_requests_threshold_critical | Maximum critical acceptable percent of 4xx errors | string | `30` | no | +| http_4xx_requests_threshold_warning | Maximum warning acceptable percent of 4xx errors | string | `15` | no | +| http_5xx_requests_threshold_critical | Maximum critical acceptable percent of 5xx errors | string | `20` | no | +| http_5xx_requests_threshold_warning | Maximum warning acceptable percent of 5xx errors | string | `10` | no | +| message | Message sent when a monitor is triggered | string | - | yes | +| latency_threshold_critical | Alerting threshold in miliseconds | string | `800` | no | +| latency_threshold_warning | Warning threshold in miliseconds | string | `400` | no | + +Related documentation +--------------------- + +DataDog documentation: [https://docs.datadoghq.com/integrations/amazon_api_gateway/](https://docs.datadoghq.com/integrations/amazon_api_gateway/) + +AWS API Gateway metrics documentation: [https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/api-gateway-metrics-dimensions.html](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/api-gateway-metrics-dimensions.html) diff --git a/cloud/aws/apigateway/inputs.tf b/cloud/aws/apigateway/inputs.tf new file mode 100644 index 0000000..98b5067 --- /dev/null +++ b/cloud/aws/apigateway/inputs.tf @@ -0,0 +1,60 @@ +variable "environment" { + description = "Architecture environment" + type = "string" +} + +variable "filter_tags" { + description = "Tags used for filtering" + default = "*" +} + +variable "message" { + description = "Message sent when a monitor is triggered" +} + +variable "delay" { + description = "Delay in seconds for the metric evaluation" + default = 900 +} + +################################### +### LATENCY VARIABLES ### +################################### + +variable "latency_threshold_critical" { + default = 800 + description = "Alerting threshold in milliseconds" +} + +variable "latency_threshold_warning" { + default = 400 + description = "Warning threshold in milliseconds" +} + +################################# +### HTTP 5xx status pages ### +################################# + +variable "http_5xx_requests_threshold_critical" { + default = 20 + description = "Maximum critical acceptable percent of 5xx errors" +} + +variable "http_5xx_requests_threshold_warning" { + default = 10 + description = "Maximum warning acceptable percent of 5xx errors" +} + +################################# +### HTTP 4xx status pages ### +################################# + +variable "http_4xx_requests_threshold_critical" { + default = 30 + description = "Maximum critical acceptable percent of 4xx errors" +} + +variable "http_4xx_requests_threshold_warning" { + default = 15 + description = "Maximum warning acceptable percent of 4xx errors" +} diff --git a/cloud/aws/apigateway/monitors-api.tf b/cloud/aws/apigateway/monitors-api.tf new file mode 100644 index 0000000..c0cfc79 --- /dev/null +++ b/cloud/aws/apigateway/monitors-api.tf @@ -0,0 +1,87 @@ +# Monitoring Api Gateway latency +resource "datadog_monitor" "API_Gateway_latency" { + name = "[${var.environment}] API Gateway latency > ${var.latency_threshold_critical}" + type = "metric alert" + message = "${var.message}" + query = < ${var.latency_threshold_critical} + EOF + + evaluation_delay = "${var.delay}" + new_host_delay = "${var.delay}" + + thresholds { + warning = "${var.latency_threshold_warning}" + critical = "${var.latency_threshold_critical}" + } + + notify_no_data = true # Will notify when no data is received + renotify_interval = 0 + require_full_window = false + timeout_h = 0 + include_tags = true + + tags = ["env:${var.environment}", "resource:apigateway", "team:aws", "provider:aws"] +} + +# Monitoring API Gateway 5xx errors percent +resource "datadog_monitor" "API_http_5xx_errors_count" { + name = "[${var.environment}] API Gateway HTTP 5xx errors > ${var.http_5xx_requests_threshold_critical}%" + type = "metric alert" + message = "${var.message}" + + query = < ${var.http_5xx_requests_threshold_critical} + EOF + + evaluation_delay = "${var.delay}" + new_host_delay = "${var.delay}" + + thresholds { + warning = "${var.http_5xx_requests_threshold_warning}" + critical = "${var.http_5xx_requests_threshold_critical}" + } + + notify_no_data = false # Will NOT notify when no data is received + renotify_interval = 0 + require_full_window = false + timeout_h = 1 + include_tags = true + + tags = ["env:${var.environment}", "resource:apigateway", "team:aws", "provider:aws"] +} + +# Monitoring API Gateway 4xx errors percent +resource "datadog_monitor" "API_http_4xx_errors_count" { + name = "[${var.environment}] API Gateway HTTP 4xx errors > ${var.http_4xx_requests_threshold_critical}%" + type = "metric alert" + message = "${var.message}" + + query = < ${var.http_4xx_requests_threshold_critical} + EOF + + evaluation_delay = "${var.delay}" + new_host_delay = "${var.delay}" + + thresholds { + warning = "${var.http_4xx_requests_threshold_warning}" + critical = "${var.http_4xx_requests_threshold_critical}" + } + + notify_no_data = false # Will NOT notify when no data is received + renotify_interval = 0 + require_full_window = false + timeout_h = 1 + include_tags = true + + tags = ["env:${var.environment}", "resource:apigateway", "team:aws", "provider:aws"] +}