Initial Commit
This commit is contained in:
commit
94ba287166
8
.gitignore
vendored
Normal file
8
.gitignore
vendored
Normal file
@ -0,0 +1,8 @@
|
||||
# Compiled files
|
||||
*.tfstate
|
||||
*.tfstate.backup
|
||||
.terraform.tfstate.lock.info
|
||||
terraform.tfvars
|
||||
# Module directory
|
||||
.terraform/
|
||||
jq
|
||||
23
.terraform.lock.hcl
generated
Normal file
23
.terraform.lock.hcl
generated
Normal file
@ -0,0 +1,23 @@
|
||||
# This file is maintained automatically by "terraform init".
|
||||
# Manual edits may be lost in future updates.
|
||||
|
||||
provider "registry.terraform.io/datadog/datadog" {
|
||||
version = "3.2.0"
|
||||
constraints = "3.2.0"
|
||||
hashes = [
|
||||
"h1:nfbkvIrUHhsI0cx7IfYDdwdn+C7nBaDvqp3lsZ2BcQw=",
|
||||
"zh:0973526974954263941cc4bc4a4bbd5a56726c09ebd118a513b0106d2164863d",
|
||||
"zh:0e89a0254f65951da832f73822592c46758e168a1ea3f7fa7eb6c79fe1e13a5d",
|
||||
"zh:35145207a6b585e51775079eb6c114d7d555c4f8a928361915374cb28b2cbe46",
|
||||
"zh:3fdf4e1d184fbad0aed31e851cd8465d9be9e7481fcfcd1b5c0da7a1eb582048",
|
||||
"zh:42dfbf4ecd8779346fa4764ce9db99b993fe3c8aefb6eea32d293f9a0bc5cab0",
|
||||
"zh:4e172436bdcbfb2e41fa43a58bc89a1d1e47178e7011d99ff87885c65ef3966c",
|
||||
"zh:72d77a750399ec7ff51c38894d54e54c178f16aab726b36caf0094501124f918",
|
||||
"zh:72e112c8d008418f40677533e855a8b79061892fb42b8296ea69e8246d6205f9",
|
||||
"zh:753d154fb6fb32f064469d3a2e2c657b7d8d19c674189480dae2d2f3b93d524b",
|
||||
"zh:b8dfdcc4402856c043a08e4befe39b042203d616ffb370b54c64a7b3def6ca55",
|
||||
"zh:be523a10cb95220cb52375ac71e03d8f0f48b0d8f3534075aa22d37b5d335d86",
|
||||
"zh:eb9f11a30d9303b422eea27b5d11a716a290c81b8c09e5457292fb378386f66c",
|
||||
"zh:fce91b84c90ce97b7acc6e4ec2cb6f9f4518ae070e00d7ca8973edd585d0ea14",
|
||||
]
|
||||
}
|
||||
69
main.tf
Normal file
69
main.tf
Normal file
@ -0,0 +1,69 @@
|
||||
# Monitor for the the disk usage.
|
||||
resource "datadog_monitor" "disk_usage" {
|
||||
name = "Disk usage high"
|
||||
query = "avg(last_5m):${var.disk_usage["query"]}{*} by ${var.trigger_by} * 100 > ${var.disk_usage["threshold"]}"
|
||||
type = "metric alert"
|
||||
notify_no_data = true
|
||||
include_tags = true
|
||||
|
||||
message = <<EOM
|
||||
Disk usage high: {{value}}
|
||||
${var.datadog_alert_footer}
|
||||
EOM
|
||||
}
|
||||
|
||||
# Monitor for the the CPU usage.
|
||||
resource "datadog_monitor" "cpu_usage" {
|
||||
name = "CPU usage high"
|
||||
query = "avg(last_5m):${var.cpu_usage["query"]}{*} by ${var.trigger_by} > ${var.cpu_usage["threshold"]}"
|
||||
type = "query alert"
|
||||
notify_no_data = true
|
||||
include_tags = true
|
||||
|
||||
message = <<EOM
|
||||
CPU usage high: {{value}}
|
||||
${var.datadog_alert_footer}
|
||||
EOM
|
||||
}
|
||||
|
||||
# Timeboard including graphs of the disk and CPU usage, each graph includes a marker incidicating the metric's monitor alert threshold.
|
||||
resource "datadog_timeboard" "host_metrics" {
|
||||
title = "Host metrics"
|
||||
description = "Host level metrics: CPU, memory, disk, etc."
|
||||
read_only = true
|
||||
|
||||
graph {
|
||||
title = "CPU usage"
|
||||
viz = "timeseries"
|
||||
autoscale = true
|
||||
|
||||
request {
|
||||
q = "${var.cpu_usage["query"]}{*} by ${var.trigger_by}"
|
||||
aggregator = "avg"
|
||||
type = "line"
|
||||
}
|
||||
|
||||
marker {
|
||||
value = "y > ${var.cpu_usage["threshold"]}"
|
||||
type = "error dashed"
|
||||
}
|
||||
}
|
||||
|
||||
graph {
|
||||
title = "Disk usage"
|
||||
viz = "timeseries"
|
||||
autoscale = true
|
||||
|
||||
request {
|
||||
q = "${var.disk_usage["query"]}{*} by ${var.trigger_by}"
|
||||
aggregator = "avg"
|
||||
type = "line"
|
||||
}
|
||||
|
||||
marker {
|
||||
value = "y > ${var.disk_usage["threshold"]}"
|
||||
type = "error dashed"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
15
provider.tf
Normal file
15
provider.tf
Normal file
@ -0,0 +1,15 @@
|
||||
terraform {
|
||||
required_providers {
|
||||
datadog = {
|
||||
source = "DataDog/datadog"
|
||||
version = "3.2.0"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
# Configure the Datadog provider
|
||||
provider "datadog" {
|
||||
api_key = var.datadog_api_key
|
||||
app_key = var.datadog_app_key
|
||||
}
|
||||
|
||||
72
variables.tf
Normal file
72
variables.tf
Normal file
@ -0,0 +1,72 @@
|
||||
###### Datadog Provider configuration ######
|
||||
variable "datadog_api_key" {
|
||||
description = "The datadog API key"
|
||||
type = string
|
||||
}
|
||||
|
||||
variable "datadog_app_key" {
|
||||
description = "The datadog APP key"
|
||||
type = string
|
||||
}
|
||||
|
||||
variable "api_url" {
|
||||
description = "Which API to Connect to, we are using the EU one for GDPR compliance"
|
||||
type = string
|
||||
default = "https://api.datadoghq.eu"
|
||||
}
|
||||
|
||||
variable "http_client_retry_enabled" {
|
||||
description = "Enables Request retries on HTTP status codes 429 and 5xx"
|
||||
type = bool
|
||||
default = true
|
||||
}
|
||||
|
||||
variable "http_client_retry_timeout" {
|
||||
description = "Sets the number of HTTP request retry timeout period"
|
||||
type = string
|
||||
default = ""
|
||||
}
|
||||
|
||||
variable "validate" {
|
||||
description = "Validates the provided APP and API keys during provider initialization"
|
||||
type = bool
|
||||
default = true
|
||||
}
|
||||
|
||||
###### Datadog Monitors Configuration ######
|
||||
|
||||
# Variable defining the query and threshold shared by a monitor and graph for the disk usage.
|
||||
variable "disk_usage" {
|
||||
type = map
|
||||
|
||||
default = {
|
||||
query = "max:system.disk.in_use"
|
||||
threshold = "85"
|
||||
}
|
||||
}
|
||||
|
||||
# Variable defining the query and threshold shared by a monitor and graph for the CPU usage.
|
||||
variable "cpu_usage" {
|
||||
type = map
|
||||
|
||||
default = {
|
||||
query = "avg:aws.ec2.cpuutilization"
|
||||
threshold = "85"
|
||||
}
|
||||
}
|
||||
|
||||
# Footer added to each monitor alert.
|
||||
variable "datadog_alert_footer" {
|
||||
default = <<EOF
|
||||
{{#is_no_data}}Not receiving data{{/is_no_data}}
|
||||
{{#is_alert}}@pagerduty{{/is_alert}}
|
||||
{{#is_recovery}}@pagerduty-resolve{{/is_recovery}}
|
||||
@slack-alerts
|
||||
EOF
|
||||
}
|
||||
|
||||
# Trigger a separate alert for each host and env.
|
||||
variable "trigger_by" {
|
||||
default = "{host,env}"
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user