Merge branch 'MON-487_Datadog_monitors_Azure_VM_RAM_reserved' into 'master'

MON-487: Add Datadog monitor VM RAM used

Closes MON-487

See merge request claranet/pt-monitoring/projects/datadog/terraform/monitors!88
This commit is contained in:
Quentin Manfroi 2019-08-02 14:40:45 +02:00
commit 39eb1b5d39
4 changed files with 91 additions and 0 deletions

View File

@ -19,6 +19,7 @@ Creates DataDog monitors with the following checks:
- Virtual Machine CPU usage
- Virtual Machine credit CPU
- Virtual Machine is unreachable
- Virtual Machine RAM reserved
## Inputs
@ -46,6 +47,13 @@ Creates DataDog monitors with the following checks:
| message | Message sent when a Redis monitor is triggered | string | n/a | yes |
| new\_host\_delay | Delay in seconds before monitor new resource | string | `"300"` | no |
| prefix\_slug | Prefix string to prepend between brackets on every monitors names | string | `""` | no |
| ram\_reserved\_enabled | Flag to enable Virtual Machine RAM reserved monitor | string | `"true"` | no |
| ram\_reserved\_extra\_tags | Extra tags for Virtual Machine RAM reserved monitor | list(string) | `[]` | no |
| ram\_reserved\_message | Custom message for Virtual Machine RAM reserved monitor | string | `""` | no |
| ram\_reserved\_threshold\_critical | Virtual Machine RAM reserved limit (critical threshold) | string | `"95"` | no |
| ram\_reserved\_threshold\_warning | Virtual Machine RAM reserved limit (warning threshold) | string | `"90"` | no |
| ram\_reserved\_time\_aggregator | Monitor aggregator for Virtual Machine RAM reserved [available values: min, max, sum or avg] | string | `"min"` | no |
| ram\_reserved\_timeframe | Monitor timeframe for Virtual Machine RAM reserved [available values: `last_#m` (1, 5, 10, 15, or 30), `last_#h` (1, 2, or 4), or `last_1d`] | string | `"last_15m"` | no |
| status\_enabled | Flag to enable Virtual Machine status monitor | string | `"true"` | no |
| status\_extra\_tags | Extra tags for Virtual Machine status monitor | list(string) | `[]` | no |
| status\_message | Custom message for Virtual Machine status monitor | string | `""` | no |
@ -58,6 +66,7 @@ Creates DataDog monitors with the following checks:
|------|-------------|
| virtualmachine\_cpu\_usage\_id | id for monitor virtualmachine_cpu_usage |
| virtualmachine\_credit\_cpu\_remaining\_too\_low\_id | id for monitor virtualmachine_credit_cpu_remaining_too_low |
| virtualmachine\_ram\_reserved\_id | id for monitor virtualmachine_ram_reserved |
| virtualmachine\_status\_id | id for monitor virtualmachine_status |
## Related documentation

View File

@ -151,3 +151,44 @@ variable "cpu_remaining_rate_threshold_critical" {
default = 15
}
variable "ram_reserved_enabled" {
description = "Flag to enable Virtual Machine RAM reserved monitor"
type = string
default = "true"
}
variable "ram_reserved_message" {
description = "Custom message for Virtual Machine RAM reserved monitor"
type = string
default = ""
}
variable "ram_reserved_extra_tags" {
description = "Extra tags for Virtual Machine RAM reserved monitor"
type = list(string)
default = []
}
variable "ram_reserved_time_aggregator" {
description = "Monitor aggregator for Virtual Machine RAM reserved [available values: min, max, sum or avg]"
type = string
default = "min"
}
variable "ram_reserved_timeframe" {
description = "Monitor timeframe for Virtual Machine RAM reserved [available values: `last_#m` (1, 5, 10, 15, or 30), `last_#h` (1, 2, or 4), or `last_1d`]"
type = string
default = "last_15m"
}
variable "ram_reserved_threshold_warning" {
description = "Virtual Machine RAM reserved limit (warning threshold)"
default = 90
}
variable "ram_reserved_threshold_critical" {
description = "Virtual Machine RAM reserved limit (critical threshold)"
default = 95
}

View File

@ -98,3 +98,39 @@ EOQ
}
}
resource "datadog_monitor" "virtualmachine_ram_reserved" {
count = var.ram_reserved_enabled == "true" ? 1 : 0
name = "${var.prefix_slug == "" ? "" : "[${var.prefix_slug}]"}[${var.environment}] Virtual Machine RAM reserved {{#is_alert}}{{{comparator}}} {{threshold}}% ({{value}}%){{/is_alert}}{{#is_warning}}{{{comparator}}} {{warn_threshold}}% ({{value}}%){{/is_warning}}"
message = coalesce(var.ram_reserved_message, var.message)
type = "query alert"
query = <<EOQ
${var.ram_reserved_time_aggregator}(${var.ram_reserved_timeframe}):
avg:azure.vm.memory_committed_bytes${module.filter-tags.query_alert} by {resource_group,region,name} / (
avg:azure.vm.memory_committed_bytes${module.filter-tags.query_alert} by {resource_group,region,name} +
avg:azure.vm.memory_available_bytes${module.filter-tags.query_alert} by {resource_group,region,name}) * 100
> ${var.ram_reserved_threshold_critical}
EOQ
thresholds = {
critical = var.ram_reserved_threshold_critical
warning = var.ram_reserved_threshold_warning
}
evaluation_delay = var.evaluation_delay
new_host_delay = var.new_host_delay
notify_no_data = false
renotify_interval = 0
notify_audit = false
timeout_h = 0
include_tags = true
locked = false
require_full_window = false
tags = concat(["env:${var.environment}", "type:cloud", "provider:azure", "resource:virtualmachine", "team:claranet", "created-by:terraform"], var.ram_reserved_extra_tags)
lifecycle {
ignore_changes = ["silenced"]
}
}

View File

@ -13,3 +13,8 @@ output "virtualmachine_credit_cpu_remaining_too_low_id" {
value = datadog_monitor.virtualmachine_credit_cpu_remaining_too_low.*.id
}
output "virtualmachine_ram_reserved_id" {
description = "id for monitor virtualmachine_ram_reserved"
value = datadog_monitor.virtualmachine_ram_reserved.*.id
}