Merge branch 'MON-221-Zookeeper' into 'master'

MON-221 "Zookeeper"

Closes MON-221

See merge request claranet/pt-monitoring/projects/datadog/terraform/monitors!167
This commit is contained in:
Quentin Manfroi 2020-03-30 14:09:28 +02:00
commit c422a414e0
6 changed files with 295 additions and 0 deletions

View File

@ -203,6 +203,7 @@ module "datadog-monitors-system-generic" {
- [redis](https://github.com/claranet/terraform-datadog-monitors/tree/master/database/redis/) - [redis](https://github.com/claranet/terraform-datadog-monitors/tree/master/database/redis/)
- [solr](https://github.com/claranet/terraform-datadog-monitors/tree/master/database/solr/) - [solr](https://github.com/claranet/terraform-datadog-monitors/tree/master/database/solr/)
- [sqlserver](https://github.com/claranet/terraform-datadog-monitors/tree/master/database/sqlserver/) - [sqlserver](https://github.com/claranet/terraform-datadog-monitors/tree/master/database/sqlserver/)
- [zookeeper](https://github.com/claranet/terraform-datadog-monitors/tree/master/database/zookeeper/)
- [middleware](https://github.com/claranet/terraform-datadog-monitors/tree/master/middleware/) - [middleware](https://github.com/claranet/terraform-datadog-monitors/tree/master/middleware/)
- [apache](https://github.com/claranet/terraform-datadog-monitors/tree/master/middleware/apache/) - [apache](https://github.com/claranet/terraform-datadog-monitors/tree/master/middleware/apache/)
- [kong](https://github.com/claranet/terraform-datadog-monitors/tree/master/middleware/kong/) - [kong](https://github.com/claranet/terraform-datadog-monitors/tree/master/middleware/kong/)

View File

@ -0,0 +1,62 @@
# DATABASE ZOOKEEPER DataDog monitors
## How to use this module
```hcl
module "datadog-monitors-database-zookeeper" {
source = "claranet/monitors/datadog//database/zookeeper"
version = "{revision}"
environment = var.environment
message = module.datadog-message-alerting.alerting-message
}
```
## Purpose
Creates DataDog monitors with the following checks:
- Zookeeper latency
- Zookeeper service does not respond
## Inputs
| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:-----:|
| environment | Architecture environment | `string` | n/a | yes |
| evaluation\_delay | Delay in seconds for the metric evaluation | `number` | `15` | no |
| filter\_tags\_custom | Tags used for custom filtering when filter\_tags\_use\_defaults is false | `string` | `"*"` | no |
| filter\_tags\_custom\_excluded | Tags excluded 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 monitor is triggered | `any` | n/a | yes |
| new\_host\_delay | Delay in seconds before begin to monitor new host | `number` | `300` | no |
| not\_responding\_group\_by | List of tags to use to group data | `list(string)` | <pre>[<br> "host",<br> "server"<br>]<br></pre> | no |
| not\_responding\_no\_data\_timeframe | Zookeeper monitor no\_data\_timeframe | `number` | `10` | no |
| not\_responding\_notify\_no\_data | Send notification if not\_responding monitor does not retrieve data | `bool` | `true` | no |
| not\_responding\_threshold\_warning | Zookeeper not responding limit (warning threshold) | `number` | `3` | no |
| prefix\_slug | Prefix string to prepend between brackets on every monitors names | `string` | `""` | no |
| zookeeper\_latency\_availability\_extra\_tags | Extra tags for zookeeper read latency monitor | `list(string)` | `[]` | no |
| zookeeper\_latency\_enabled | Flag to enable Zookeeper read latency monitor | `string` | `"true"` | no |
| zookeeper\_latency\_group\_by | Tags to use to group datas | `list(string)` | <pre>[<br> "host"<br>]<br></pre> | no |
| zookeeper\_latency\_status\_message | Custom message for Zookeeper read latency monitor | `string` | `""` | no |
| zookeeper\_latency\_threshold\_critical | Maximum critical acceptable ms of zookeeper latency monitor | `number` | `300000` | no |
| zookeeper\_latency\_threshold\_warning | Maximum warning acceptable ms of zookeeper latency monitor | `number` | `250000` | no |
| zookeeper\_latency\_time\_aggregator | Monitor time aggregator for Zookeeper read latency monitor [available values: min, max or avg] | `string` | `"avg"` | no |
| zookeeper\_latency\_timeframe | Monitor timeframe for Zookeeper read latency monitor [available values: `last_#m` (1, 5, 10, 15, or 30), `last_#h` (1, 2, or 4), or `last_1d`] | `string` | `"last_15m"` | no |
| zookeeper\_not\_responding\_enabled | Flag to enable Zookeeper does not respond monitor | `string` | `"true"` | no |
| zookeeper\_not\_responding\_extra\_tags | Extra tags for Zookeeper does not respond monitor | `list(string)` | `[]` | no |
| zookeeper\_not\_responding\_message | Custom message for Zookeeper does not respond monitor | `string` | `""` | no |
| zookeeper\_not\_responding\_time\_aggregator | Time aggregator for the Zookeeper does not respond monitor | `string` | `"avg"` | no |
| zookeeper\_not\_responding\_timeframe | Timeframe for the does not respond monitor | `string` | `"last_5m"` | no |
## Outputs
| Name | Description |
|------|-------------|
| datadog\_monitor\_zookeeper\_latency\_id | id for monitor datadog\_monitor\_zookeeper\_latency |
| not\_responding\_id | id for monitor not\_responding |
## Related documentation
DataDog documentation: [https://docs.datadoghq.com/integrations/zk/](https://docs.datadoghq.com/integrations/zk/)

View File

@ -0,0 +1,147 @@
#
# Datadog global variables
#
variable "environment" {
description = "Architecture environment"
type = string
}
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 = "*"
}
variable "filter_tags_custom_excluded" {
description = "Tags excluded for custom filtering when filter_tags_use_defaults is false"
default = ""
}
variable "message" {
description = "Message sent when a monitor is triggered"
}
variable "evaluation_delay" {
description = "Delay in seconds for the metric evaluation"
default = 15
}
variable "new_host_delay" {
description = "Delay in seconds before begin to monitor new host"
default = 300
}
variable "prefix_slug" {
description = "Prefix string to prepend between brackets on every monitors names"
default = ""
}
#
# Service Check
#
variable "not_responding_notify_no_data" {
default = true
type = bool
description = "Send notification if not_responding monitor does not retrieve data"
}
variable "not_responding_no_data_timeframe" {
default = 10
description = "Zookeeper monitor no_data_timeframe"
type = number
}
variable "not_responding_group_by" {
default = ["host", "server"]
type = list(string)
description = "List of tags to use to group data"
}
variable "zookeeper_not_responding_enabled" {
description = "Flag to enable Zookeeper does not respond monitor"
type = string
default = "true"
}
variable "zookeeper_not_responding_message" {
description = "Custom message for Zookeeper does not respond monitor"
type = string
default = ""
}
variable "zookeeper_not_responding_time_aggregator" {
description = "Time aggregator for the Zookeeper does not respond monitor"
type = string
default = "avg"
}
variable "zookeeper_not_responding_timeframe" {
description = "Timeframe for the does not respond monitor"
type = string
default = "last_5m"
}
variable "zookeeper_not_responding_extra_tags" {
description = "Extra tags for Zookeeper does not respond monitor"
type = list(string)
default = []
}
variable "not_responding_threshold_warning" {
default = 3
type = number
description = "Zookeeper not responding limit (warning threshold)"
}
#
# Check read latency monitor
#
variable "zookeeper_latency_enabled" {
description = "Flag to enable Zookeeper read latency monitor"
type = string
default = "true"
}
variable "zookeeper_latency_group_by" {
description = "Tags to use to group datas"
type = list(string)
default = ["host"]
}
variable "zookeeper_latency_status_message" {
description = "Custom message for Zookeeper read latency monitor"
type = string
default = ""
}
variable "zookeeper_latency_time_aggregator" {
description = "Monitor time aggregator for Zookeeper read latency monitor [available values: min, max or avg]"
type = string
default = "avg"
}
variable "zookeeper_latency_timeframe" {
description = "Monitor timeframe for Zookeeper read latency monitor [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 "zookeeper_latency_threshold_critical" {
description = "Maximum critical acceptable ms of zookeeper latency monitor"
default = 300000
}
variable "zookeeper_latency_threshold_warning" {
description = "Maximum warning acceptable ms of zookeeper latency monitor"
default = 250000
}
variable "zookeeper_latency_availability_extra_tags" {
description = "Extra tags for zookeeper read latency monitor"
type = list(string)
default = []
}

View File

@ -0,0 +1,10 @@
module "filter-tags" {
source = "../../common/filter-tags"
environment = var.environment
resource = "zookeeper"
filter_tags_use_defaults = var.filter_tags_use_defaults
filter_tags_custom = var.filter_tags_custom
filter_tags_custom_excluded = var.filter_tags_custom_excluded
}

View File

@ -0,0 +1,65 @@
resource "datadog_monitor" "not_responding" {
count = var.zookeeper_not_responding_enabled ? 1 : 0
name = "${var.prefix_slug == "" ? "" : "[${var.prefix_slug}]"}[${var.environment}] Zookeeper service does not respond {{#is_alert}}{{{comparator}}} {{threshold}} ({{value}}){{/is_alert}}{{#is_warning}}{{{comparator}}} {{warn_threshold}} ({{value}}){{/is_warning}}"
message = coalesce(var.zookeeper_not_responding_message, var.message)
type = "service check"
query = <<EOQ
"zookeeper.ruok"${module.filter-tags.service_check}.by(${join(",", formatlist("\"%s\"", var.not_responding_group_by))}).last(6).count_by_status()
EOQ
thresholds = {
warning = var.not_responding_threshold_warning
critical = 5
}
no_data_timeframe = var.not_responding_no_data_timeframe
new_host_delay = var.new_host_delay
notify_no_data = var.not_responding_notify_no_data
notify_audit = false
locked = false
timeout_h = 0
include_tags = true
require_full_window = true
renotify_interval = 0
tags = concat(["env:${var.environment}", "type:database", "provider:zookeeper", "resource:zookeeper", "team:claranet",
"created-by:terraform"], var.zookeeper_not_responding_extra_tags)
lifecycle {
ignore_changes = [silenced]
}
}
resource "datadog_monitor" "datadog_monitor_zookeeper_latency" {
count = var.zookeeper_latency_enabled ? 1 : 0
name = "${var.prefix_slug == "" ? "" : "[${var.prefix_slug}]"}[${var.environment}] Zookeeper latency {{#is_alert}}{{{comparator}}} {{threshold}}ms ({{value}}ms){{/is_alert}}{{#is_warning}}{{{comparator}}} {{warn_threshold}}ms ({{value}}ms){{/is_warning}}"
message = coalesce(var.zookeeper_latency_status_message, var.message)
type = "metric alert"
query = <<EOQ
${var.zookeeper_latency_time_aggregator}(${var.zookeeper_latency_timeframe}): (
zookeeper.avg_latency${module.filter-tags.query_alert} by {${join(",", var.zookeeper_latency_group_by)}}) > ${var.zookeeper_latency_threshold_critical}
EOQ
thresholds = {
warning = var.zookeeper_latency_threshold_warning
critical = var.zookeeper_latency_threshold_critical
}
notify_no_data = false
evaluation_delay = var.evaluation_delay
new_host_delay = var.new_host_delay
notify_audit = false
timeout_h = 0
include_tags = true
locked = false
require_full_window = true
tags = concat(["env:${var.environment}", "type:database", "provider:zookeeper", "resource:zookeeper", "team:claranet",
"created-by:terraform"], var.zookeeper_latency_availability_extra_tags)
lifecycle {
ignore_changes = [silenced]
}
}

View File

@ -0,0 +1,10 @@
output "datadog_monitor_zookeeper_latency_id" {
description = "id for monitor datadog_monitor_zookeeper_latency"
value = datadog_monitor.datadog_monitor_zookeeper_latency.*.id
}
output "not_responding_id" {
description = "id for monitor not_responding"
value = datadog_monitor.not_responding.*.id
}