MON-497 Docker monitors: service check and memory used

This commit is contained in:
Rafael Romero Carmona 2019-08-20 09:16:04 +01:00
parent e567752f2c
commit e019c90563
6 changed files with 241 additions and 0 deletions

View File

@ -127,6 +127,7 @@ The `//` is very important, it's a terraform specific syntax used to separate gi
### Monitors summary ###
- [caas](https://git.fr.clara.net/claranet/pt-monitoring/projects/datadog/terraform/monitors/tree/master/caas/)
- [docker](https://git.fr.clara.net/claranet/pt-monitoring/projects/datadog/terraform/monitors/tree/master/caas/docker/)
- [kubernetes](https://git.fr.clara.net/claranet/pt-monitoring/projects/datadog/terraform/monitors/tree/master/caas/kubernetes/)
- [ark](https://git.fr.clara.net/claranet/pt-monitoring/projects/datadog/terraform/monitors/tree/master/caas/kubernetes/ark/)
- [cluster](https://git.fr.clara.net/claranet/pt-monitoring/projects/datadog/terraform/monitors/tree/master/caas/kubernetes/cluster/)

22
caas/docker/README.md Normal file
View File

@ -0,0 +1,22 @@
# CAAS DOCKER DataDog monitors
## How to use this module
```
module "datadog-monitors-caas-docker" {
source = "git::ssh://git@git.fr.clara.net/claranet/pt-monitoring/projects/datadog/terraform/monitors.git//caas/docker?ref={revision}"
environment = var.environment
message = module.datadog-message-alerting.alerting-message
}
```
## Purpose
Creates DataDog monitors with the following checks:
- Docker Container Memory Used (disabled by default)
- Service Docker does not respond

130
caas/docker/inputs.tf Normal file
View File

@ -0,0 +1,130 @@
# Global Terraform
variable "environment" {
description = "Architecture Environment"
type = string
}
# Global DataDog
variable "evaluation_delay" {
description = "Delay in seconds for the metric evaluation"
default = 15
}
variable "new_host_delay" {
description = "Delay in seconds before monitor new resource"
default = 300
}
variable "prefix_slug" {
description = "Prefix string to prepend between brackets on every monitors names"
default = ""
}
variable "message" {
description = "Message sent when an alert is triggered"
}
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 = ""
}
#
# Not Responding
#
variable "not_responding_enabled" {
description = "Flag to enable Docker does not respond monitor"
type = string
default = "true"
}
variable "not_responding_message" {
description = "Custom message for Docker does not respond monitor"
type = string
default = ""
}
variable "not_responding_last" {
description = "Parameter 'last' for the service check"
type = string
default = 6
}
variable "not_responding_threshold_warning" {
description = "Docker does not respond monitor (warning threshold)"
type = string
default = 3
}
variable "not_responding_threshold_critical" {
description = "Docker does not respond monitor (warning threshold)"
type = string
default = 5
}
variable "not_responding_no_data_timeframe" {
description = "Docker does not respond monitor no data timeframe"
type = string
default = 10
}
variable "not_responding_extra_tags" {
description = "Extra tags for Docker does not respond monitor"
type = list(string)
default = []
}
#
# Container Memory Usage
#
variable "memory_used_enabled" {
description = "Flag to enable Container Memory Usage monitor"
type = string
default = "false"
}
variable "memory_used_message" {
description = "Custom message for the Container Memory Usage monitor"
type = string
default = ""
}
variable "memory_used_time_aggregator" {
description = "Time aggregator for the Container Memory Usage monitor"
type = string
default = "min"
}
variable "memory_used_timeframe" {
description = "Timeframe for the Container Memory Usage monitor"
type = string
default = "last_5m"
}
variable "memory_used_threshold_warning" {
description = "Container Memory Usage warning threshold"
type = string
default = 80
}
variable "memory_used_threshold_critical" {
description = "Container Memory Usage critical threshold"
type = string
default = 90
}
variable "memory_used_extra_tags" {
description = "Extra tags for Container Memory Usage monitor"
type = list(string)
default = []
}

9
caas/docker/modules.tf Normal file
View File

@ -0,0 +1,9 @@
module "filter-tags" {
source = "../../common/filter-tags"
environment = var.environment
resource = "docker"
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,69 @@
#
# Service Check
#
resource "datadog_monitor" "not_responding" {
count = var.not_responding_enabled == "true" ? 1 : 0
name = "${var.prefix_slug == "" ? "" : "[${var.prefix_slug}]"}[${var.environment}] Service Docker does not respond"
message = coalesce(var.not_responding_message, var.message)
type = "service check"
query = <<EOQ
"docker.service_up"${module.filter-tags.service_check}.by("host").last(${var.not_responding_last}).count_by_status()
EOQ
thresholds = {
warning = var.not_responding_threshold_warning
critical = var.not_responding_threshold_critical
}
new_host_delay = var.new_host_delay
no_data_timeframe = var.not_responding_no_data_timeframe
notify_no_data = true
notify_audit = false
locked = false
timeout_h = 0
include_tags = true
require_full_window = true
renotify_interval = 0
tags = concat(["env:${var.environment}", "type:docker", "provider:docker", "resource:docker", "team:claranet", "created-by:terraform"], var.not_responding_extra_tags)
lifecycle {
ignore_changes = ["silenced"]
}
}
resource "datadog_monitor" "memory_used" {
count = var.memory_used_enabled == "true" ? 1 : 0
name = "${var.prefix_slug == "" ? "" : "[${var.prefix_slug}]"}[${var.environment}] Docker Container Memory Used {{#is_alert}}{{{comparator}}} {{threshold}}% ({{value}}%){{/is_alert}}{{#is_warning}}{{{comparator}}} {{warn_threshold}}% ({{value}}%){{/is_warning}}"
message = coalesce(var.memory_used_message, var.message)
type = "query alert"
query = <<EOQ
${var.memory_used_time_aggregator}(${var.memory_used_timeframe}):
avg:docker.mem.in_use${module.filter-tags.query_alert} by {container_name} * 100
> ${var.memory_used_threshold_critical}
EOQ
thresholds = {
warning = var.memory_used_threshold_warning
critical = var.memory_used_threshold_critical
}
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 = true
tags = concat(["env:${var.environment}", "type:docker", "provider:docker", "resource:docker", "team:claranet", "created-by:terraform"], var.memory_used_extra_tags)
lifecycle {
ignore_changes = ["silenced"]
}
}

10
caas/docker/outputs.tf Normal file
View File

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