MON-114 add kubernetes cluster monitors

This commit is contained in:
Quentin Manfroi 2019-04-19 20:53:20 +02:00
parent 2df9ff2706
commit c2c98581fa
6 changed files with 157 additions and 0 deletions

View File

@ -77,6 +77,7 @@ The `//` is very important, it's a terraform specific syntax used to separate gi
- [caas](https://git.fr.clara.net/claranet/pt-monitoring/projects/datadog/terraform/monitors/tree/master/caas/)
- [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/)
- [ingress](https://git.fr.clara.net/claranet/pt-monitoring/projects/datadog/terraform/monitors/tree/master/caas/kubernetes/ingress/)
- [vts](https://git.fr.clara.net/claranet/pt-monitoring/projects/datadog/terraform/monitors/tree/master/caas/kubernetes/ingress/vts/)
- [cloud](https://git.fr.clara.net/claranet/pt-monitoring/projects/datadog/terraform/monitors/tree/master/cloud/)

View File

@ -0,0 +1,48 @@
# CAAS KUBERNETES CLUSTER DataDog monitors
## How to use this module
```
module "datadog-monitors-caas-kubernetes-cluster" {
source = "git::ssh://git@git.fr.clara.net/claranet/pt-monitoring/projects/datadog/terraform/monitors.git//caas/kubernetes/cluster?ref={revision}"
environment = "${var.environment}"
message = "${module.datadog-message-alerting.alerting-message}"
}
```
## Purpose
Creates DataDog monitors with the following checks:
- Kubernetes API server does not respond
## Inputs
| Name | Description | Type | Default | Required |
|------|-------------|:----:|:-----:|:-----:|
| apiserver\_enabled | Flag to enable API server monitor | string | `"true"` | no |
| apiserver\_extra\_tags | Extra tags for API server monitor | list | `[]` | no |
| apiserver\_message | Custom message for API server monitor | string | `""` | no |
| apiserver\_silenced | Groups to mute for API server monitor | map | `{}` | no |
| apiserver\_threshold\_warning | API server monitor (warning threshold) | string | `"3"` | no |
| environment | Architecture environment | string | n/a | yes |
| evaluation\_delay | Delay in seconds for the metric evaluation | string | `"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 | string | n/a | yes |
| new\_host\_delay | Delay in seconds before monitor new resource | string | `"300"` | no |
## Outputs
| Name | Description |
|------|-------------|
| apiserver\_id | id for monitor apiserver |
## Related documentation
* [Datadog metrics](https://docs.datadoghq.com/agent/kubernetes/metrics/)
* [Datadog documentation](https://docs.datadoghq.com/integrations/kubernetes/)
* [Datadog Blog](https://www.datadoghq.com/blog/monitor-kubernetes-docker/)

View File

@ -0,0 +1,66 @@
# Datadog global variables
variable "environment" {
description = "Architecture environment"
}
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 monitor new resource"
default = 300
}
# Datadog monitors variables
variable "apiserver_silenced" {
description = "Groups to mute for API server monitor"
type = "map"
default = {}
}
variable "apiserver_enabled" {
description = "Flag to enable API server monitor"
type = "string"
default = "true"
}
variable "apiserver_extra_tags" {
description = "Extra tags for API server monitor"
type = "list"
default = []
}
variable "apiserver_message" {
description = "Custom message for API server monitor"
type = "string"
default = ""
}
variable "apiserver_threshold_warning" {
description = "API server monitor (warning threshold)"
type = "string"
default = 3
}

View File

@ -0,0 +1,9 @@
module "filter-tags" {
source = "../../../common/filter-tags"
environment = "${var.environment}"
resource = "kubernetes"
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,29 @@
resource "datadog_monitor" "apiserver" {
count = "${var.apiserver_enabled == "true" ? 1 : 0}"
name = "[${var.environment}] Kubernetes API server does not respond"
message = "${coalesce(var.apiserver_message, var.message)}"
type = "service check"
query = <<EOQ
"kube_apiserver_controlplane.up"${module.filter-tags.service_check}.by("apiserver_name").last(6).count_by_status()
EOQ
thresholds = {
warning = "${var.apiserver_threshold_warning}"
critical = 5
}
new_host_delay = "${var.new_host_delay}"
notify_no_data = true
renotify_interval = 0
notify_audit = false
timeout_h = 0
include_tags = true
locked = false
require_full_window = true
silenced = "${var.apiserver_silenced}"
tags = ["env:${var.environment}", "type:caas", "provider:kubernetes", "resource:kubernetes-node", "team:claranet", "created-by:terraform", "${var.apiserver_extra_tags}"]
}

View File

@ -0,0 +1,4 @@
output "apiserver_id" {
description = "id for monitor apiserver"
value = "${datadog_monitor.apiserver.*.id}"
}