MON-90 Azure API Management monitors
This commit is contained in:
parent
8a2679e08a
commit
25c07babea
43
cloud/azure/apimanagement/README.md
Normal file
43
cloud/azure/apimanagement/README.md
Normal file
@ -0,0 +1,43 @@
|
||||
Azure API Management Datadog monitors
|
||||
=====================================
|
||||
|
||||
How to use this module
|
||||
----------------------
|
||||
```
|
||||
module "datadog-monitors-azure-apimanagement" {
|
||||
source = "git::ssh://git@bitbucket.org/morea/terraform.feature.datadog.git//cloud/azure/apimanagement?ref={revision}"
|
||||
|
||||
message = "${module.datadog-message-alerting.alerting-message}"
|
||||
environment = "${var.environment}"
|
||||
}
|
||||
```
|
||||
|
||||
Purpose
|
||||
-------
|
||||
Creates Datadog monitors with the following checks :
|
||||
|
||||
* Service status
|
||||
* Failed requests ratio
|
||||
* Other requests ratio
|
||||
* Unauthorized requests ratio
|
||||
* Successful requests ratio
|
||||
|
||||
Inputs
|
||||
------
|
||||
|
||||
| Name | Description | Type | Default | Required |
|
||||
|------|-------------|:----:|:-----:|:-----:|
|
||||
| delay | Delay in seconds for the metric evaluation | string | `600` | no |
|
||||
| environment | Architecture environment | string | - | yes |
|
||||
| failed_requests_threshold_critical | Maximum acceptable percent of failed requests | string | `5` | 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 |
|
||||
| message | Message sent when a Redis monitor is triggered | string | - | yes |
|
||||
| other_requests_threshold_critical | Maximum acceptable percent of other requests | string | `5` | no |
|
||||
| successful_requests_threshold_critical | Minimum acceptable percent of successful requests | string | `90` | no |
|
||||
| unauthorized_requests_threshold_critical | Maximum acceptable percent of unauthorized requests | string | `5` | no |
|
||||
|
||||
Related documentation
|
||||
---------------------
|
||||
|
||||
Azure API Management metrics documentation: [https://docs.microsoft.com/en-us/azure/api-management/api-management-howto-use-azure-monitor](https://docs.microsoft.com/en-us/azure/api-management/api-management-howto-use-azure-monitor)
|
||||
46
cloud/azure/apimanagement/inputs.tf
Normal file
46
cloud/azure/apimanagement/inputs.tf
Normal file
@ -0,0 +1,46 @@
|
||||
# Global Terraform
|
||||
variable "environment" {
|
||||
description = "Architecture environment"
|
||||
type = "string"
|
||||
}
|
||||
|
||||
# Global DataDog
|
||||
variable "message" {
|
||||
description = "Message sent when a Redis monitor is triggered"
|
||||
}
|
||||
|
||||
variable "delay" {
|
||||
description = "Delay in seconds for the metric evaluation"
|
||||
default = 600
|
||||
}
|
||||
|
||||
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 API Management specific
|
||||
variable "failed_requests_threshold_critical" {
|
||||
description = "Maximum acceptable percent of failed requests"
|
||||
default = 5
|
||||
}
|
||||
|
||||
variable "other_requests_threshold_critical" {
|
||||
description = "Maximum acceptable percent of other requests"
|
||||
default = 5
|
||||
}
|
||||
|
||||
variable "unauthorized_requests_threshold_critical" {
|
||||
description = "Maximum acceptable percent of unauthorized requests"
|
||||
default = 5
|
||||
}
|
||||
|
||||
variable "successful_requests_threshold_critical" {
|
||||
description = "Minimum acceptable percent of successful requests"
|
||||
default = 90
|
||||
}
|
||||
160
cloud/azure/apimanagement/monitors-azure-apimanagement.tf
Normal file
160
cloud/azure/apimanagement/monitors-azure-apimanagement.tf
Normal file
@ -0,0 +1,160 @@
|
||||
data "template_file" "filter" {
|
||||
template = "$${filter}"
|
||||
|
||||
vars {
|
||||
filter = "${var.filter_tags_use_defaults == "true" ?
|
||||
format("dd_monitoring:enabled,dd_azure_apimanagement:enabled,env:%s", var.environment) :
|
||||
"${var.filter_tags_custom}"}"
|
||||
}
|
||||
}
|
||||
|
||||
resource "datadog_monitor" "apimgt_status" {
|
||||
name = "[${var.environment}] API Management status is not ok on {{name}}"
|
||||
message = "${var.message}"
|
||||
|
||||
query = <<EOF
|
||||
avg(last_5m):avg:azure.apimanagement_service.status{${data.template_file.filter.rendered}} by {name,resource_group,region} < 1
|
||||
EOF
|
||||
type = "metric alert"
|
||||
|
||||
thresholds {
|
||||
critical = 1
|
||||
}
|
||||
|
||||
notify_no_data = true
|
||||
evaluation_delay = "${var.delay}"
|
||||
renotify_interval = 0
|
||||
notify_audit = false
|
||||
timeout_h = 0
|
||||
include_tags = true
|
||||
locked = false
|
||||
require_full_window = true
|
||||
new_host_delay = "${var.delay}"
|
||||
no_data_timeframe = 20
|
||||
|
||||
tags = ["env:${var.environment}", "resource:apimanagement", "team:azure", "provider:azure"]
|
||||
}
|
||||
|
||||
resource "datadog_monitor" "apimgt_failed_requests" {
|
||||
name = "[${var.environment}] API Management {{name}} too much failed requests"
|
||||
message = "${var.message}"
|
||||
|
||||
query = <<EOF
|
||||
avg(last_5m): (
|
||||
avg:azure.apimanagement_service.failed_requests{${data.template_file.filter.rendered}} * 100 /
|
||||
avg:azure.apimanagement_service.total_requests{${data.template_file.filter.rendered}}
|
||||
by {name,resource_group,region}
|
||||
) > ${var.failed_requests_threshold_critical}
|
||||
EOF
|
||||
|
||||
thresholds {
|
||||
critical = "${var.failed_requests_threshold_critical}"
|
||||
}
|
||||
|
||||
type = "metric alert"
|
||||
notify_no_data = false
|
||||
notify_audit = false
|
||||
timeout_h = 0
|
||||
include_tags = true
|
||||
locked = false
|
||||
require_full_window = true
|
||||
new_host_delay = "${var.delay}"
|
||||
evaluation_delay = "${var.delay}"
|
||||
renotify_interval = 0
|
||||
no_data_timeframe = 20
|
||||
|
||||
tags = ["env:${var.environment}", "resource:apimanagement", "team:azure", "provider:azure"]
|
||||
}
|
||||
|
||||
resource "datadog_monitor" "apimgt_other_requests" {
|
||||
name = "[${var.environment}] API Management {{name}} too much other requests"
|
||||
message = "${var.message}"
|
||||
|
||||
query = <<EOF
|
||||
avg(last_5m): (
|
||||
avg:azure.apimanagement_service.other_requests{${data.template_file.filter.rendered}} * 100 /
|
||||
avg:azure.apimanagement_service.total_requests{${data.template_file.filter.rendered}}
|
||||
by {name,resource_group,region}
|
||||
) > ${var.other_requests_threshold_critical}
|
||||
EOF
|
||||
|
||||
thresholds {
|
||||
critical = "${var.other_requests_threshold_critical}"
|
||||
}
|
||||
|
||||
type = "metric alert"
|
||||
notify_no_data = false
|
||||
notify_audit = false
|
||||
timeout_h = 0
|
||||
include_tags = true
|
||||
locked = false
|
||||
require_full_window = true
|
||||
new_host_delay = "${var.delay}"
|
||||
evaluation_delay = "${var.delay}"
|
||||
renotify_interval = 0
|
||||
no_data_timeframe = 20
|
||||
|
||||
tags = ["env:${var.environment}", "resource:apimanagement", "team:azure", "provider:azure"]
|
||||
}
|
||||
|
||||
resource "datadog_monitor" "apimgt_unauthorized_requests" {
|
||||
name = "[${var.environment}] API Management {{name}} too much unauthorized requests"
|
||||
message = "${var.message}"
|
||||
|
||||
query = <<EOF
|
||||
avg(last_5m): (
|
||||
avg:azure.apimanagement_service.failed_requests{${data.template_file.filter.rendered}} * 100 /
|
||||
avg:azure.apimanagement_service.total_requests{${data.template_file.filter.rendered}}
|
||||
by {name,resource_group,region}
|
||||
) > ${var.unauthorized_requests_threshold_critical}
|
||||
EOF
|
||||
|
||||
thresholds {
|
||||
critical = "${var.unauthorized_requests_threshold_critical}"
|
||||
}
|
||||
|
||||
type = "metric alert"
|
||||
notify_no_data = false
|
||||
notify_audit = false
|
||||
timeout_h = 0
|
||||
include_tags = true
|
||||
locked = false
|
||||
require_full_window = true
|
||||
new_host_delay = "${var.delay}"
|
||||
evaluation_delay = "${var.delay}"
|
||||
renotify_interval = 0
|
||||
no_data_timeframe = 20
|
||||
|
||||
tags = ["env:${var.environment}", "resource:apimanagement", "team:azure", "provider:azure"]
|
||||
}
|
||||
|
||||
resource "datadog_monitor" "apimgt_successful_requests" {
|
||||
name = "[${var.environment}] API Management {{name}} successful requests rate too low"
|
||||
message = "${var.message}"
|
||||
|
||||
query = <<EOF
|
||||
avg(last_5m): (
|
||||
avg:azure.apimanagement_service.successful_requests{${data.template_file.filter.rendered}} * 100 /
|
||||
avg:azure.apimanagement_service.total_requests{${data.template_file.filter.rendered}}
|
||||
by {name,resource_group,region}
|
||||
) < ${var.successful_requests_threshold_critical}
|
||||
EOF
|
||||
|
||||
thresholds {
|
||||
critical = "${var.successful_requests_threshold_critical}"
|
||||
}
|
||||
|
||||
type = "metric alert"
|
||||
notify_no_data = true
|
||||
notify_audit = false
|
||||
timeout_h = 0
|
||||
include_tags = true
|
||||
locked = false
|
||||
require_full_window = true
|
||||
new_host_delay = "${var.delay}"
|
||||
evaluation_delay = "${var.delay}"
|
||||
renotify_interval = 0
|
||||
no_data_timeframe = 20
|
||||
|
||||
tags = ["env:${var.environment}", "resource:apimanagement", "team:azure", "provider:azure"]
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user