MON-48: monitoring for api gateway

This commit is contained in:
Boris Rousseau 2018-01-22 11:11:55 +01:00 committed by Alexandre Gaillet
parent e8548a226d
commit 980f9cbd7f
3 changed files with 193 additions and 0 deletions

View File

@ -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)

View File

@ -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"
}

View File

@ -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 = <<EOF
avg(last_5m): (
avg:aws.apigateway.latency{${var.filter_tags}} by {region,apiname}
) > ${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 = <<EOF
sum(last_5m): (
avg:aws.apigateway.5xxerror{${var.filter_tags}} by {region,apiname}.as_count() /
avg:aws.apigateway.count{${var.filter_tags}} by {region,apiname}.as_count()
) * 100 > ${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 = <<EOF
sum(last_5m): (
avg:aws.apigateway.4xxerror{${var.filter_tags}} by {region,apiname}.as_count() /
avg:aws.apigateway.count{${var.filter_tags}} by {region,apiname}.as_count()
) * 100 > ${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"]
}