From 50aede5330ed0a63924217d008aad473b7be946e Mon Sep 17 00:00:00 2001 From: Alexandre Gaillet Date: Wed, 21 Mar 2018 12:28:49 +0100 Subject: [PATCH] MON-140 - Added default function to ELB and Api Gateway monitors --- cloud/aws/apigateway/monitors-api.tf | 16 ++++++++------ cloud/aws/elb/monitors-elb.tf | 32 +++++++++++++++++----------- 2 files changed, 30 insertions(+), 18 deletions(-) diff --git a/cloud/aws/apigateway/monitors-api.tf b/cloud/aws/apigateway/monitors-api.tf index f6d2cd9..b25c3d2 100644 --- a/cloud/aws/apigateway/monitors-api.tf +++ b/cloud/aws/apigateway/monitors-api.tf @@ -37,9 +37,11 @@ resource "datadog_monitor" "API_http_5xx_errors_count" { query = < ${var.http_5xx_requests_threshold_critical} + default( + avg:aws.apigateway.5xxerror{${var.filter_tags}} by {region,apiname}.as_count() / + (avg:aws.apigateway.count{${var.filter_tags}} by {region,apiname}.as_count() + ${var.artificial_requests_count}), + 0) * 100 + ) > ${var.http_5xx_requests_threshold_critical} EOF evaluation_delay = "${var.delay}" @@ -69,9 +71,11 @@ resource "datadog_monitor" "API_http_4xx_errors_count" { query = < ${var.http_4xx_requests_threshold_critical} + default( + avg:aws.apigateway.4xxerror{${var.filter_tags}} by {region,apiname}.as_count() / + (avg:aws.apigateway.count{${var.filter_tags}} by {region,apiname}.as_count() + ${var.artificial_requests_count}), + 0) * 100 + ) > ${var.http_4xx_requests_threshold_critical} EOF evaluation_delay = "${var.delay}" diff --git a/cloud/aws/elb/monitors-elb.tf b/cloud/aws/elb/monitors-elb.tf index df8cf26..fc12fa5 100644 --- a/cloud/aws/elb/monitors-elb.tf +++ b/cloud/aws/elb/monitors-elb.tf @@ -40,9 +40,11 @@ resource "datadog_monitor" "ELB_too_much_4xx" { query = < ${var.elb_4xx_threshold_critical} + default( + avg:aws.elb.httpcode_elb_4xx{${data.template_file.filter.rendered}} by {region,loadbalancername} / + avg:aws.elb.request_count{${data.template_file.filter.rendered}} by {region,loadbalancername}, + 0) * 100 + ) > ${var.elb_4xx_threshold_critical} EOF type = "metric alert" @@ -74,9 +76,11 @@ resource "datadog_monitor" "ELB_too_much_5xx" { query = < ${var.elb_5xx_threshold_critical} + default( + avg:aws.elb.httpcode_elb_5xx{${data.template_file.filter.rendered}} by {region,loadbalancername} / + avg:aws.elb.request_count{${data.template_file.filter.rendered}} by {region,loadbalancername}, + 0) * 100 + ) > ${var.elb_5xx_threshold_critical} EOF type = "metric alert" @@ -108,9 +112,11 @@ resource "datadog_monitor" "ELB_too_much_4xx_backend" { query = < ${var.elb_backend_4xx_threshold_critical} + default( + avg:aws.elb.httpcode_backend_4xx{${data.template_file.filter.rendered}} by {region,loadbalancername} / + avg:aws.elb.request_count{${data.template_file.filter.rendered}} by {region,loadbalancername}, + 0) * 100 + ) > ${var.elb_backend_4xx_threshold_critical} EOF type = "metric alert" @@ -142,9 +148,11 @@ resource "datadog_monitor" "ELB_too_much_5xx_backend" { query = < ${var.elb_backend_5xx_threshold_critical} + default( + avg:aws.elb.httpcode_backend_5xx{${data.template_file.filter.rendered}} by {region,loadbalancername} / + avg:aws.elb.request_count{${data.template_file.filter.rendered}} by {region,loadbalancername}, + 0) * 100 + ) > ${var.elb_backend_5xx_threshold_critical} EOF type = "metric alert"