diff --git a/README.md b/README.md index 9c91a51..ca132ec 100644 --- a/README.md +++ b/README.md @@ -96,6 +96,7 @@ The `//` is very important, it's a terraform specific syntax used to separate gi - [filter-tags](https://bitbucket.org/morea/terraform.feature.datadog/src/master/common/filter-tags/) - [database](https://bitbucket.org/morea/terraform.feature.datadog/src/master/database/) - [mongodb](https://bitbucket.org/morea/terraform.feature.datadog/src/master/database/mongodb/) + - [redis](https://bitbucket.org/morea/terraform.feature.datadog/src/master/database/redis/) - [middleware](https://bitbucket.org/morea/terraform.feature.datadog/src/master/middleware/) - [apache](https://bitbucket.org/morea/terraform.feature.datadog/src/master/middleware/apache/) - [nginx](https://bitbucket.org/morea/terraform.feature.datadog/src/master/middleware/nginx/) diff --git a/database/mongodb/monitors-mongo.tf b/database/mongodb/monitors-mongo.tf index e51394a..8f52da0 100644 --- a/database/mongodb/monitors-mongo.tf +++ b/database/mongodb/monitors-mongo.tf @@ -20,7 +20,7 @@ resource "datadog_monitor" "mongodb_primary" { silenced = "${var.mongodb_primary_silenced}" - tags = ["env:${var.environment}", "type:database", "provider:mongodb", "resource:mongodb", "team:claranet", "created-by:terraform", "${var.mongodb_primary_extra_tags}"] + tags = ["env:${var.environment}", "type:database", "provider:mongo", "resource:mongodb", "team:claranet", "created-by:terraform", "${var.mongodb_primary_extra_tags}"] } resource "datadog_monitor" "mongodb_secondary" { @@ -52,7 +52,7 @@ resource "datadog_monitor" "mongodb_secondary" { silenced = "${var.mongodb_secondary_silenced}" - tags = ["env:${var.environment}", "type:database", "provider:mongodb", "resource:mongodb", "team:claranet", "created-by:terraform", "${var.mongodb_secondary_extra_tags}"] + tags = ["env:${var.environment}", "type:database", "provider:mongo", "resource:mongodb", "team:claranet", "created-by:terraform", "${var.mongodb_secondary_extra_tags}"] } resource "datadog_monitor" "mongodb_server_count" { @@ -83,7 +83,7 @@ resource "datadog_monitor" "mongodb_server_count" { silenced = "${var.mongodb_secondary_silenced}" - tags = ["env:${var.environment}", "type:database", "provider:mongodb", "resource:mongodb", "team:claranet", "created-by:terraform", "${var.mongodb_secondary_extra_tags}"] + tags = ["env:${var.environment}", "type:database", "provider:mongo", "resource:mongodb", "team:claranet", "created-by:terraform", "${var.mongodb_secondary_extra_tags}"] } resource "datadog_monitor" "mongodb_replication" { @@ -113,5 +113,5 @@ resource "datadog_monitor" "mongodb_replication" { silenced = "${var.mongodb_replication_silenced}" - tags = ["env:${var.environment}", "type:database", "provider:mongodb", "resource:mongodb", "team:claranet", "created-by:terraform", "${var.mongodb_replication_extra_tags}"] + tags = ["env:${var.environment}", "type:database", "provider:mongo", "resource:mongodb", "team:claranet", "created-by:terraform", "${var.mongodb_replication_extra_tags}"] } diff --git a/database/redis/README.md b/database/redis/README.md new file mode 100644 index 0000000..e162a51 --- /dev/null +++ b/database/redis/README.md @@ -0,0 +1,127 @@ +# DATABASE REDIS DataDog monitors + +## How to use this module + +``` +module "datadog-monitors-database-redis" { + source = "git::ssh://git@bitbucket.org/morea/terraform.feature.datadog.git//database/redis?ref={revision}" + + environment = "${var.environment}" + message = "${module.datadog-message-alerting.alerting-message}" +} + +``` + +## Purpose + +Creates DataDog monitors with the following checks: + +- Redis evicted keys +- Redis expired keys +- Redis blocked clients +- Redis keyspace seems full (no changes since ${var.keyspace_timeframe}) +- Redis memory used +- Redis memory fragmented +- Redis rejected connections +- Redis latency +- Redis hitrate +- Redis does not respond + +## Inputs + +| Name | Description | Type | Default | Required | +|------|-------------|:----:|:-----:|:-----:| +| blocked_clients_extra_tags | Extra tags for Redis Blocked clients monitor | list | `` | no | +| blocked_clients_message | Custom message for Redis Blocked clients monitor | string | `` | no | +| blocked_clients_silenced | Groups to mute for Redis Blocked clients monitor | map | `` | no | +| blocked_clients_threshold_critical | Blocked clients rate (critical threshold) | string | `30` | no | +| blocked_clients_threshold_warning | Blocked clients rate (warning threshold) | string | `10` | no | +| blocked_clients_time_aggregator | Monitor aggregator for Redis Blocked clients [available values: min, max or avg] | string | `min` | no | +| blocked_clients_timeframe | Monitor timeframe for Redis Blocked clients [available values: `last_#m` (1, 5, 10, 15, or 30), `last_#h` (1, 2, or 4), or `last_1d`] | string | `last_5m` | no | +| environment | Architecture environment | string | - | yes | +| evaluation_delay | Delay in seconds for the metric evaluation | string | `15` | no | +| evictedkeys_change_extra_tags | Extra tags for Redis evicted keys monitor | list | `` | no | +| evictedkeys_change_message | Custom message for Redis evicted keys monitor | string | `` | no | +| evictedkeys_change_silenced | Groups to mute for Redis evicted keys monitor | map | `` | no | +| evictedkeys_change_threshold_critical | Evicted keys change (critical threshold) | string | `100` | no | +| evictedkeys_change_threshold_warning | Evicted keys change (warning threshold) | string | `20` | no | +| evictedkeys_change_time_aggregator | Monitor aggregator for Redis evicted keys [available values: min, max or avg] | string | `avg` | no | +| evictedkeys_change_timeframe | Monitor timeframe for Redis evicted keys [available values: `last_#m` (1, 5, 10, 15, or 30), `last_#h` (1, 2, or 4), or `last_1d`] | string | `last_5m` | no | +| expirations_rate_extra_tags | Extra tags for Redis keys expirations monitor | list | `` | no | +| expirations_rate_message | Custom message for Redis keys expirations monitor | string | `` | no | +| expirations_rate_silenced | Groups to mute for Redis keys expirations monitor | map | `` | no | +| expirations_rate_threshold_critical | Expirations percent (critical threshold) | string | `80` | no | +| expirations_rate_threshold_warning | Expirations percent (warning threshold) | string | `60` | no | +| expirations_rate_time_aggregator | Monitor aggregator for Redis keys expirations [available values: min, max or avg] | string | `min` | no | +| expirations_rate_timeframe | Monitor timeframe for Redis keys expirations [available values: `last_#m` (1, 5, 10, 15, or 30), `last_#h` (1, 2, or 4), or `last_1d`] | string | `last_5m` | 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 | +| hitrate_extra_tags | Extra tags for Redis hitrate monitor | list | `` | no | +| hitrate_message | Custom message for Redis hitrate monitor | string | `` | no | +| hitrate_silenced | Groups to mute for Redis hitrate monitor | map | `` | no | +| hitrate_threshold_critical | hitrate limit (critical threshold) | string | `10` | no | +| hitrate_threshold_warning | hitrate limit (warning threshold) | string | `30` | no | +| hitrate_time_aggregator | Monitor aggregator for Redis hitrate [available values: min, max or avg] | string | `max` | no | +| hitrate_timeframe | Monitor timeframe for Redis hitrate [available values: `last_#m` (1, 5, 10, 15, or 30), `last_#h` (1, 2, or 4), or `last_1d`] | string | `last_5m` | no | +| keyspace_extra_tags | Extra tags for Redis keyspace monitor | list | `` | no | +| keyspace_message | Custom message for Redis keyspace monitor | string | `` | no | +| keyspace_silenced | Groups to mute for Redis keyspace monitor | map | `` | no | +| keyspace_threshold_critical | Keyspace no changement (critical threshold) | string | `0` | no | +| keyspace_threshold_warning | Keyspace no changement (warning threshold) | string | `1` | no | +| keyspace_time_aggregator | Monitor aggregator for Redis keyspace [available values: min, max or avg] | string | `min` | no | +| keyspace_timeframe | Monitor timeframe for Redis keyspace [available values: `last_#m` (1, 5, 10, 15, or 30), `last_#h` (1, 2, or 4), or `last_1d`] | string | `last_5m` | no | +| latency_extra_tags | Extra tags for Redis latency monitor | list | `` | no | +| latency_message | Custom message for Redis latency monitor | string | `` | no | +| latency_silenced | Groups to mute for Redis latency monitor | map | `` | no | +| latency_threshold_critical | latency limit (critical threshold) | string | `100` | no | +| latency_threshold_warning | latency limit (warning threshold) | string | `50` | no | +| latency_time_aggregator | Monitor aggregator for Redis latency [available values: min, max or avg] | string | `min` | no | +| latency_timeframe | Monitor timeframe for Redis latency [available values: `last_#m` (1, 5, 10, 15, or 30), `last_#h` (1, 2, or 4), or `last_1d`] | string | `last_5m` | no | +| mem_frag_extra_tags | Extra tags for Redis memory RAM fragmentation monitor | list | `` | no | +| mem_frag_message | Custom message for Redis memory RAM fragmentation monitor | string | `` | no | +| mem_frag_silenced | Groups to mute for Redis memory RAM fragmentation monitor | map | `` | no | +| mem_frag_threshold_critical | memory RAM fragmentation limit (critical threshold) | string | `150` | no | +| mem_frag_threshold_warning | memory RAM fragmentation limit (warning threshold) | string | `130` | no | +| mem_frag_time_aggregator | Monitor aggregator for Redis memory RAM fragmentation [available values: min, max or avg] | string | `min` | no | +| mem_frag_timeframe | Monitor timeframe for Redis memory RAM fragmentation [available values: `last_#m` (1, 5, 10, 15, or 30), `last_#h` (1, 2, or 4), or `last_1d`] | string | `last_5m` | no | +| mem_used_extra_tags | Extra tags for Redis RAM memory used monitor | list | `` | no | +| mem_used_message | Custom message for Redis RAM memory used monitor | string | `` | no | +| mem_used_silenced | Groups to mute for Redis RAM memory used monitor | map | `` | no | +| mem_used_threshold_critical | RAM memory used limit (critical threshold) | string | `95` | no | +| mem_used_threshold_warning | RAM memory used limit (warning threshold) | string | `85` | no | +| mem_used_time_aggregator | Monitor aggregator for Redis RAM memory used [available values: min, max or avg] | string | `min` | no | +| mem_used_timeframe | Monitor timeframe for Redis RAM memory used [available values: `last_#m` (1, 5, 10, 15, or 30), `last_#h` (1, 2, or 4), or `last_1d`] | string | `last_5m` | no | +| message | Message sent when a Redis monitor is triggered | string | - | yes | +| new_host_delay | Delay in seconds for the metric evaluation | string | `300` | no | +| not_responding_extra_tags | Extra tags for Redis does not respond monitor | list | `` | no | +| not_responding_message | Custom message for Redis does not respond monitor | string | `` | no | +| not_responding_silenced | Groups to mute for Redis does not respond monitor | map | `` | no | +| redis_silenced | Groups to mute for Redis monitors | map | `` | no | +| rejected_con_extra_tags | Extra tags for Redis rejected connections errors monitor | list | `` | no | +| rejected_con_message | Custom message for Redis rejected connections errors monitor | string | `` | no | +| rejected_con_silenced | Groups to mute for Redis rejected connections errors monitor | map | `` | no | +| rejected_con_threshold_critical | rejected connections errors limit (critical threshold) | string | `50` | no | +| rejected_con_threshold_warning | rejected connections errors limit (warning threshold) | string | `10` | no | +| rejected_con_time_aggregator | Monitor aggregator for Redis rejected connections errors [available values: min, max or avg] | string | `min` | no | +| rejected_con_timeframe | Monitor timeframe for Redis rejected connections errors [available values: `last_#m` (1, 5, 10, 15, or 30), `last_#h` (1, 2, or 4), or `last_1d`] | string | `last_5m` | no | + +## Outputs + +| Name | Description | +|------|-------------| +| blocked_clients_id | id for monitor blocked_clients | +| evicted_keys_id | id for monitor evicted_keys | +| expirations_id | id for monitor expirations | +| hitrate_id | id for monitor hitrate | +| keyspace_full_id | id for monitor keyspace_full | +| latency_id | id for monitor latency | +| memory_frag_id | id for monitor memory_frag | +| memory_used_id | id for monitor memory_used | +| not_responding_id | id for monitor not_responding | +| rejected_connections_id | id for monitor rejected_connections | + +## Related documentation + +[Datadog blog: How to monitor Redis](https://www.datadoghq.com/blog/how-to-monitor-redis-performance-metrics/) + +[Datadog Redis integration doc](https://docs.datadoghq.com/integrations/redisdb/) diff --git a/database/redis/inputs.tf b/database/redis/inputs.tf new file mode 100644 index 0000000..e651acf --- /dev/null +++ b/database/redis/inputs.tf @@ -0,0 +1,421 @@ +# Global Terraform +variable "environment" { + description = "Architecture environment" + type = "string" +} + +# Global DataDog +variable "message" { + description = "Message sent when a Redis monitor is triggered" +} + +variable "evaluation_delay" { + description = "Delay in seconds for the metric evaluation" + default = 15 +} + +variable "new_host_delay" { + description = "Delay in seconds for the metric evaluation" + default = 300 +} + +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 = "*" +} + +# Redis specific variables +variable "redis_silenced" { + description = "Groups to mute for Redis monitors" + type = "map" + default = {} +} + +variable "evictedkeys_change_silenced" { + description = "Groups to mute for Redis evicted keys monitor" + type = "map" + default = {} +} + +variable "evictedkeys_change_message" { + description = "Custom message for Redis evicted keys monitor" + type = "string" + default = "" +} + +variable "evictedkeys_change_extra_tags" { + description = "Extra tags for Redis evicted keys monitor" + type = "list" + default = [] +} + +variable "evictedkeys_change_time_aggregator" { + description = "Monitor aggregator for Redis evicted keys [available values: min, max or avg]" + type = "string" + default = "avg" +} + +variable "evictedkeys_change_timeframe" { + description = "Monitor timeframe for Redis evicted keys [available values: `last_#m` (1, 5, 10, 15, or 30), `last_#h` (1, 2, or 4), or `last_1d`]" + type = "string" + default = "last_5m" +} + +variable "evictedkeys_change_threshold_warning" { + description = "Evicted keys change (warning threshold)" + default = 20 +} + +variable "evictedkeys_change_threshold_critical" { + description = "Evicted keys change (critical threshold)" + default = 100 +} + +variable "expirations_rate_silenced" { + description = "Groups to mute for Redis keys expirations monitor" + type = "map" + default = {} +} + +variable "expirations_rate_message" { + description = "Custom message for Redis keys expirations monitor" + type = "string" + default = "" +} + +variable "expirations_rate_extra_tags" { + description = "Extra tags for Redis keys expirations monitor" + type = "list" + default = [] +} + +variable "expirations_rate_time_aggregator" { + description = "Monitor aggregator for Redis keys expirations [available values: min, max or avg]" + type = "string" + default = "min" +} + +variable "expirations_rate_timeframe" { + description = "Monitor timeframe for Redis keys expirations [available values: `last_#m` (1, 5, 10, 15, or 30), `last_#h` (1, 2, or 4), or `last_1d`]" + type = "string" + default = "last_5m" +} + +variable "expirations_rate_threshold_critical" { + description = "Expirations percent (critical threshold)" + default = 80 +} + +variable "expirations_rate_threshold_warning" { + description = "Expirations percent (warning threshold)" + default = 60 +} + +variable "blocked_clients_silenced" { + description = "Groups to mute for Redis Blocked clients monitor" + type = "map" + default = {} +} + +variable "blocked_clients_message" { + description = "Custom message for Redis Blocked clients monitor" + type = "string" + default = "" +} + +variable "blocked_clients_extra_tags" { + description = "Extra tags for Redis Blocked clients monitor" + type = "list" + default = [] +} + +variable "blocked_clients_time_aggregator" { + description = "Monitor aggregator for Redis Blocked clients [available values: min, max or avg]" + type = "string" + default = "min" +} + +variable "blocked_clients_timeframe" { + description = "Monitor timeframe for Redis Blocked clients [available values: `last_#m` (1, 5, 10, 15, or 30), `last_#h` (1, 2, or 4), or `last_1d`]" + type = "string" + default = "last_5m" +} + +variable "blocked_clients_threshold_critical" { + description = "Blocked clients rate (critical threshold)" + default = 30 +} + +variable "blocked_clients_threshold_warning" { + description = "Blocked clients rate (warning threshold)" + default = 10 +} + +variable "keyspace_silenced" { + description = "Groups to mute for Redis keyspace monitor" + type = "map" + + default = { + "*" = 0 # Mute all for now by default + } +} + +variable "keyspace_message" { + description = "Custom message for Redis keyspace monitor" + type = "string" + default = "" +} + +variable "keyspace_extra_tags" { + description = "Extra tags for Redis keyspace monitor" + type = "list" + default = [] +} + +variable "keyspace_time_aggregator" { + description = "Monitor aggregator for Redis keyspace [available values: min, max or avg]" + type = "string" + default = "min" +} + +variable "keyspace_timeframe" { + description = "Monitor timeframe for Redis keyspace [available values: `last_#m` (1, 5, 10, 15, or 30), `last_#h` (1, 2, or 4), or `last_1d`]" + type = "string" + default = "last_5m" +} + +variable "keyspace_threshold_critical" { + description = "Keyspace no changement (critical threshold)" + default = 0 +} + +variable "keyspace_threshold_warning" { + description = "Keyspace no changement (warning threshold)" + default = 1 +} + +variable "mem_used_silenced" { + description = "Groups to mute for Redis RAM memory used monitor" + type = "map" + default = {} +} + +variable "mem_used_message" { + description = "Custom message for Redis RAM memory used monitor" + type = "string" + default = "" +} + +variable "mem_used_extra_tags" { + description = "Extra tags for Redis RAM memory used monitor" + type = "list" + default = [] +} + +variable "mem_used_time_aggregator" { + description = "Monitor aggregator for Redis RAM memory used [available values: min, max or avg]" + type = "string" + default = "min" +} + +variable "mem_used_timeframe" { + description = "Monitor timeframe for Redis RAM memory used [available values: `last_#m` (1, 5, 10, 15, or 30), `last_#h` (1, 2, or 4), or `last_1d`]" + type = "string" + default = "last_5m" +} + +variable "mem_used_threshold_critical" { + description = "RAM memory used limit (critical threshold)" + default = 95 +} + +variable "mem_used_threshold_warning" { + description = "RAM memory used limit (warning threshold)" + default = 85 +} + +variable "mem_frag_silenced" { + description = "Groups to mute for Redis memory RAM fragmentation monitor" + type = "map" + default = {} +} + +variable "mem_frag_message" { + description = "Custom message for Redis memory RAM fragmentation monitor" + type = "string" + default = "" +} + +variable "mem_frag_extra_tags" { + description = "Extra tags for Redis memory RAM fragmentation monitor" + type = "list" + default = [] +} + +variable "mem_frag_time_aggregator" { + description = "Monitor aggregator for Redis memory RAM fragmentation [available values: min, max or avg]" + type = "string" + default = "min" +} + +variable "mem_frag_timeframe" { + description = "Monitor timeframe for Redis memory RAM fragmentation [available values: `last_#m` (1, 5, 10, 15, or 30), `last_#h` (1, 2, or 4), or `last_1d`]" + type = "string" + default = "last_5m" +} + +variable "mem_frag_threshold_critical" { + description = "memory RAM fragmentation limit (critical threshold)" + default = 150 +} + +variable "mem_frag_threshold_warning" { + description = "memory RAM fragmentation limit (warning threshold)" + default = 130 +} + +variable "rejected_con_silenced" { + description = "Groups to mute for Redis rejected connections errors monitor" + type = "map" + default = {} +} + +variable "rejected_con_message" { + description = "Custom message for Redis rejected connections errors monitor" + type = "string" + default = "" +} + +variable "rejected_con_extra_tags" { + description = "Extra tags for Redis rejected connections errors monitor" + type = "list" + default = [] +} + +variable "rejected_con_time_aggregator" { + description = "Monitor aggregator for Redis rejected connections errors [available values: min, max or avg]" + type = "string" + default = "min" +} + +variable "rejected_con_timeframe" { + description = "Monitor timeframe for Redis rejected connections errors [available values: `last_#m` (1, 5, 10, 15, or 30), `last_#h` (1, 2, or 4), or `last_1d`]" + type = "string" + default = "last_5m" +} + +variable "rejected_con_threshold_critical" { + description = "rejected connections errors limit (critical threshold)" + default = 50 +} + +variable "rejected_con_threshold_warning" { + description = "rejected connections errors limit (warning threshold)" + default = 10 +} + +variable "latency_silenced" { + description = "Groups to mute for Redis latency monitor" + type = "map" + default = {} +} + +variable "latency_message" { + description = "Custom message for Redis latency monitor" + type = "string" + default = "" +} + +variable "latency_extra_tags" { + description = "Extra tags for Redis latency monitor" + type = "list" + default = [] +} + +variable "latency_time_aggregator" { + description = "Monitor aggregator for Redis latency [available values: min, max or avg]" + type = "string" + default = "min" +} + +variable "latency_timeframe" { + description = "Monitor timeframe for Redis latency [available values: `last_#m` (1, 5, 10, 15, or 30), `last_#h` (1, 2, or 4), or `last_1d`]" + type = "string" + default = "last_5m" +} + +variable "latency_threshold_critical" { + description = "latency limit (critical threshold)" + default = 100 +} + +variable "latency_threshold_warning" { + description = "latency limit (warning threshold)" + default = 50 +} + +variable "hitrate_silenced" { + description = "Groups to mute for Redis hitrate monitor" + type = "map" + default = {} +} + +variable "hitrate_message" { + description = "Custom message for Redis hitrate monitor" + type = "string" + default = "" +} + +variable "hitrate_extra_tags" { + description = "Extra tags for Redis hitrate monitor" + type = "list" + default = [] +} + +variable "hitrate_time_aggregator" { + description = "Monitor aggregator for Redis hitrate [available values: min, max or avg]" + type = "string" + default = "max" +} + +variable "hitrate_timeframe" { + description = "Monitor timeframe for Redis hitrate [available values: `last_#m` (1, 5, 10, 15, or 30), `last_#h` (1, 2, or 4), or `last_1d`]" + type = "string" + default = "last_5m" +} + +variable "hitrate_threshold_critical" { + description = "hitrate limit (critical threshold)" + default = 10 +} + +variable "hitrate_threshold_warning" { + description = "hitrate limit (warning threshold)" + default = 30 +} + +# +# Connection Down +# +variable "not_responding_silenced" { + description = "Groups to mute for Redis does not respond monitor" + type = "map" + default = {} +} + +variable "not_responding_message" { + description = "Custom message for Redis does not respond monitor" + type = "string" + default = "" +} + +variable "not_responding_extra_tags" { + description = "Extra tags for Redis does not respond monitor" + type = "list" + default = [] +} diff --git a/database/redis/modules.tf b/database/redis/modules.tf new file mode 100644 index 0000000..48011c6 --- /dev/null +++ b/database/redis/modules.tf @@ -0,0 +1,8 @@ +module "filter-tags" { + source = "../../common/filter-tags" + + environment = "${var.environment}" + resource = "redis" + filter_tags_use_defaults = "${var.filter_tags_use_defaults}" + filter_tags_custom = "${var.filter_tags_custom}" +} diff --git a/database/redis/monitors-redis.tf b/database/redis/monitors-redis.tf new file mode 100644 index 0000000..a5a1339 --- /dev/null +++ b/database/redis/monitors-redis.tf @@ -0,0 +1,360 @@ +resource "datadog_monitor" "evicted_keys" { + name = "[${var.environment}] Redis evicted keys {{#is_alert}}{{{comparator}}} {{threshold}}% (+{{value}}%){{/is_alert}}{{#is_warning}}{{{comparator}}} {{warn_threshold}}% (+{{value}}%){{/is_warning}}" + message = "${coalesce(var.evictedkeys_change_message, var.message)}" + + query = < ${var.evictedkeys_change_threshold_critical} +EOL + + type = "metric alert" + + lifecycle { + ignore_changes = ["type"] + } + + thresholds { + warning = "${var.evictedkeys_change_threshold_warning}" + critical = "${var.evictedkeys_change_threshold_critical}" + } + + silenced = "${var.evictedkeys_change_silenced}" + + notify_no_data = false + evaluation_delay = "${var.evaluation_delay}" + renotify_interval = 0 + notify_audit = false + timeout_h = 0 + include_tags = true + locked = false + require_full_window = true + new_host_delay = "${var.new_host_delay}" + + tags = ["env:${var.environment}", "type:database", "provider:redisdb", "resource:redis", "team:claranet", "created-by:terraform", "${var.evictedkeys_change_extra_tags}"] +} + +resource "datadog_monitor" "expirations" { + name = "[${var.environment}] Redis expired keys {{#is_alert}}{{{comparator}}} {{threshold}}% ({{value}}%){{/is_alert}}{{#is_warning}}{{{comparator}}} {{warn_threshold}}% ({{value}}%){{/is_warning}}" + message = "${coalesce(var.expirations_rate_message, var.message)}" + + query = < ${var.expirations_rate_threshold_critical} +EOL + + type = "metric alert" + + lifecycle { + ignore_changes = ["type"] + } + + thresholds { + warning = "${var.expirations_rate_threshold_warning}" + critical = "${var.expirations_rate_threshold_critical}" + } + + silenced = "${var.expirations_rate_silenced}" + + notify_no_data = false + evaluation_delay = "${var.evaluation_delay}" + renotify_interval = 0 + notify_audit = false + timeout_h = 0 + include_tags = true + locked = false + require_full_window = false + new_host_delay = "${var.new_host_delay}" + + tags = ["env:${var.environment}", "type:database", "provider:redisdb", "resource:redis", "team:claranet", "created-by:terraform", "${var.expirations_rate_extra_tags}"] +} + +resource "datadog_monitor" "blocked_clients" { + name = "[${var.environment}] Redis blocked clients {{#is_alert}}{{{comparator}}} {{threshold}}% ({{value}}%){{/is_alert}}{{#is_warning}}{{{comparator}}} {{warn_threshold}}% ({{value}}%){{/is_warning}}" + message = "${coalesce(var.blocked_clients_message, var.message)}" + + query = < ${var.blocked_clients_threshold_critical} +EOL + + type = "metric alert" + + lifecycle { + ignore_changes = ["type"] + } + + thresholds { + warning = "${var.blocked_clients_threshold_warning}" + critical = "${var.blocked_clients_threshold_critical}" + } + + silenced = "${var.blocked_clients_silenced}" + + notify_no_data = false + evaluation_delay = "${var.evaluation_delay}" + renotify_interval = 0 + notify_audit = false + timeout_h = 0 + include_tags = true + locked = false + require_full_window = false + new_host_delay = "${var.new_host_delay}" + + tags = ["env:${var.environment}", "type:database", "provider:redisdb", "resource:redis", "team:claranet", "created-by:terraform", "${var.blocked_clients_extra_tags}"] +} + +resource "datadog_monitor" "keyspace_full" { + name = "[${var.environment}] Redis keyspace seems full (no changes since ${var.keyspace_timeframe})" + message = "${coalesce(var.keyspace_message, var.message)}" + + query = < ${var.mem_used_threshold_critical} +EOL + + type = "metric alert" + + lifecycle { + ignore_changes = ["type"] + } + + thresholds { + warning = "${var.mem_used_threshold_warning}" + critical = "${var.mem_used_threshold_critical}" + } + + silenced = "${var.mem_used_silenced}" + + notify_no_data = false + evaluation_delay = "${var.evaluation_delay}" + renotify_interval = 0 + notify_audit = false + timeout_h = 0 + include_tags = true + locked = false + require_full_window = false + new_host_delay = "${var.new_host_delay}" + + tags = ["env:${var.environment}", "type:database", "provider:redisdb", "resource:redis", "team:claranet", "created-by:terraform", "${var.mem_used_extra_tags}"] +} + +resource "datadog_monitor" "memory_frag" { + name = "[${var.environment}] Redis memory fragmented {{#is_alert}}{{{comparator}}} {{threshold}}% ({{value}}%){{/is_alert}}{{#is_warning}}{{{comparator}}} {{warn_threshold}}% ({{value}}%){{/is_warning}}" + message = "${coalesce(var.mem_frag_message, var.message)}" + + query = < ${var.mem_frag_threshold_critical} +EOL + + type = "metric alert" + + lifecycle { + ignore_changes = ["type"] + } + + thresholds { + warning = "${var.mem_frag_threshold_warning}" + critical = "${var.mem_frag_threshold_critical}" + } + + silenced = "${var.mem_frag_silenced}" + + notify_no_data = false + evaluation_delay = "${var.evaluation_delay}" + renotify_interval = 0 + notify_audit = false + timeout_h = 0 + include_tags = true + locked = false + require_full_window = false + new_host_delay = "${var.new_host_delay}" + + tags = ["env:${var.environment}", "type:database", "provider:redisdb", "resource:redis", "team:claranet", "created-by:terraform", "${var.mem_frag_extra_tags}"] +} + +resource "datadog_monitor" "rejected_connections" { + name = "[${var.environment}] Redis rejected connections {{#is_alert}}{{{comparator}}} {{threshold}} ({{value}}){{/is_alert}}{{#is_warning}}{{{comparator}}} {{warn_threshold}} ({{value}}){{/is_warning}}" + message = "${coalesce(var.rejected_con_message, var.message)}" + + query = < ${var.rejected_con_threshold_critical} +EOL + + type = "metric alert" + + lifecycle { + ignore_changes = ["type"] + } + + thresholds { + warning = "${var.rejected_con_threshold_warning}" + critical = "${var.rejected_con_threshold_critical}" + } + + silenced = "${var.rejected_con_silenced}" + + notify_no_data = false + evaluation_delay = "${var.evaluation_delay}" + renotify_interval = 0 + notify_audit = false + timeout_h = 0 + include_tags = true + locked = false + require_full_window = false + new_host_delay = "${var.new_host_delay}" + + tags = ["env:${var.environment}", "type:database", "provider:redisdb", "resource:redis", "team:claranet", "created-by:terraform", "${var.rejected_con_extra_tags}"] +} + +resource "datadog_monitor" "latency" { + name = "[${var.environment}] Redis latency {{#is_alert}}{{{comparator}}} {{threshold}}ms ({{value}}){{/is_alert}}{{#is_warning}}{{{comparator}}} {{warn_threshold}}ms ({{value}}){{/is_warning}}" + message = "${coalesce(var.latency_message, var.message)}" + + query = < ${var.latency_threshold_critical} +EOL + + type = "metric alert" + + lifecycle { + ignore_changes = ["type"] + } + + thresholds { + warning = "${var.latency_threshold_warning}" + critical = "${var.latency_threshold_critical}" + } + + silenced = "${var.latency_silenced}" + + notify_no_data = false + evaluation_delay = "${var.evaluation_delay}" + renotify_interval = 0 + notify_audit = false + timeout_h = 0 + include_tags = true + locked = false + require_full_window = false + new_host_delay = "${var.new_host_delay}" + + tags = ["env:${var.environment}", "type:database", "provider:redisdb", "resource:redis", "team:claranet", "created-by:terraform", "${var.latency_extra_tags}"] +} + +resource "datadog_monitor" "hitrate" { + name = "[${var.environment}] Redis hitrate {{#is_alert}}{{{comparator}}} {{threshold}}% ({{value}}%){{/is_alert}}{{#is_warning}}{{{comparator}}} {{warn_threshold}}% ({{value}}%){{/is_warning}}" + message = "${coalesce(var.hitrate_message, var.message)}" + + query = <