MON-105: Add postgresql monitors
This commit is contained in:
parent
66af6f2267
commit
39ec9b1694
45
databases/postgresql/README.md
Normal file
45
databases/postgresql/README.md
Normal file
@ -0,0 +1,45 @@
|
||||
PostgreSQL DataDog monitors
|
||||
======================
|
||||
|
||||
How to use this module
|
||||
----------------------
|
||||
|
||||
```
|
||||
module "datadog-monitors-postgresql" {
|
||||
source = "git::ssh://git@bitbucket.org/morea/terraform.feature.datadog.git//databases/postgresql?ref={revision}"
|
||||
|
||||
environment = "${var.environment}"
|
||||
message = "${module.datadog-message-alerting.alerting-message}"
|
||||
}
|
||||
|
||||
```
|
||||
Purpose
|
||||
-------
|
||||
Creates DataDog monitors with the following checks :
|
||||
|
||||
* PostgreSQL not enough available connections
|
||||
* PostgreSQL too many locks
|
||||
|
||||
Inputs
|
||||
------
|
||||
|
||||
| Name | Description | Type | Default | Required |
|
||||
|------|-------------|:----:|:-----:|:-----:|
|
||||
| delay | Delay in seconds for the metric evaluation | string | `15` | no |
|
||||
| environment | Environment | string | - | yes |
|
||||
| filter_tags_use_defaults | Use default filter tags convention | string | `true` | no |
|
||||
| filter_tags_custom | Tags used for custom filtering when filter_tags_use_defaults is false | string | `*` | no |
|
||||
| postgresql_connection_threshold_critical | Maximum critical acceptable percent of connections | string | `80` | no |
|
||||
| postgresql_connection_threshold_warning | Maximum warning acceptable percent of connections | string | `70` | no |
|
||||
| postgresql_connection_silenced | Groups to mute PostgreSQL connection monitor | map | `<map>` | no |
|
||||
| postgresql_connection_message | Custom message for PostgreSQL connection monitor | string | `` | no |
|
||||
| postgresql_thread_threshold_critical | Maximum critical acceptable number of threads | string | `500` | no |
|
||||
| postgresql_thread_threshold_warning | Maximum warning acceptable number of threads | string | `400` | no |
|
||||
| postgresql_thread_silenced | Groups to mute PostgreSQL threads monitor | map | `<map>` | no |
|
||||
| postgresql_thread_message | Custom message for PostgreSQL thread monitor | string | `` | no |
|
||||
| message | Message sent when a monitor is triggered | string | - | yes |
|
||||
|
||||
Related documentation
|
||||
---------------------
|
||||
|
||||
DataDog documentation: [https://docs.datadoghq.com/integrations/postgres/](https://docs.datadoghq.com/integrations/postgres/)
|
||||
77
databases/postgresql/inputs.tf
Normal file
77
databases/postgresql/inputs.tf
Normal file
@ -0,0 +1,77 @@
|
||||
variable "environment" {
|
||||
description = "Environment"
|
||||
type = "string"
|
||||
}
|
||||
|
||||
# Global DataDog
|
||||
variable "delay" {
|
||||
description = "Delay in seconds for the metric evaluation"
|
||||
default = 15
|
||||
}
|
||||
|
||||
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 = "*"
|
||||
}
|
||||
|
||||
# PostgreSQL specific
|
||||
##################################
|
||||
### PostgreSQL connections ###
|
||||
##################################
|
||||
|
||||
variable "postgresql_connection_threshold_critical" {
|
||||
default = 80
|
||||
description = "Maximum critical acceptable percent of connections"
|
||||
}
|
||||
|
||||
variable "postgresql_connection_threshold_warning" {
|
||||
default = 70
|
||||
description = "Maximum warning acceptable percent of connections"
|
||||
}
|
||||
|
||||
variable "postgresql_connection_silenced" {
|
||||
description = "Groups to mute PostgreSQL connection monitor"
|
||||
type = "map"
|
||||
default = {}
|
||||
}
|
||||
|
||||
variable "postgresql_connection_message" {
|
||||
description = "Custom message for PostgreSQL connection monitor"
|
||||
type = "string"
|
||||
default = ""
|
||||
}
|
||||
|
||||
############################
|
||||
### PostgreSQL locks ###
|
||||
############################
|
||||
|
||||
variable "postgresql_lock_threshold_critical" {
|
||||
default = 99
|
||||
description = "Maximum critical acceptable number of locks"
|
||||
}
|
||||
|
||||
variable "postgresql_lock_threshold_warning" {
|
||||
default = 70
|
||||
description = "Maximum warning acceptable number of locks"
|
||||
}
|
||||
|
||||
variable "posgresql_lock_silenced" {
|
||||
description = "Groups to mute PostgreSQL lock monitor"
|
||||
type = "map"
|
||||
default = {}
|
||||
}
|
||||
|
||||
variable "postgresql_lock_message" {
|
||||
description = "Custom message for PostgreSQL lock monitor"
|
||||
type = "string"
|
||||
default = ""
|
||||
}
|
||||
67
databases/postgresql/mon-postgresql.tf
Normal file
67
databases/postgresql/mon-postgresql.tf
Normal file
@ -0,0 +1,67 @@
|
||||
data "template_file" "filter" {
|
||||
template = "$${filter}"
|
||||
|
||||
vars {
|
||||
filter = "${var.filter_tags_use_defaults == "true" ? format("dd_monitoring:enabled,dd_postgres:enabled,db_env:%s", var.environment) : "${var.filter_tags_custom}"}"
|
||||
}
|
||||
}
|
||||
|
||||
resource "datadog_monitor" "postgresql_connection_too_high" {
|
||||
name = "[${var.environment}] PostgreSQL Connections {{#is_alert}}{{{comparator}}} {{threshold}}% ({{value}}%){{/is_alert}}{{#is_warning}}{{{comparator}}} {{warn_threshold}}% ({{value}}%){{/is_warning}}"
|
||||
message = "${coalesce(var.postgresql_connection_message, var.message)}"
|
||||
type = "metric alert"
|
||||
|
||||
query = <<EOF
|
||||
avg(last_15m): (
|
||||
avg:postgresql.percent_usage_connections{${data.template_file.filter.rendered}} by {db_host}
|
||||
) * 100 > ${var.postgresql_connection_threshold_critical}
|
||||
EOF
|
||||
|
||||
evaluation_delay = "${var.delay}"
|
||||
new_host_delay = "${var.delay}"
|
||||
|
||||
thresholds {
|
||||
warning = "${var.postgresql_connection_threshold_warning}"
|
||||
critical = "${var.postgresql_connection_threshold_critical}"
|
||||
}
|
||||
|
||||
notify_no_data = true
|
||||
renotify_interval = 0
|
||||
require_full_window = true
|
||||
timeout_h = 0
|
||||
include_tags = true
|
||||
|
||||
silenced = "${var.postgresql_connection_silenced}"
|
||||
|
||||
tags = ["env:${var.environment}", "resource:postgresql"]
|
||||
}
|
||||
|
||||
resource "datadog_monitor" "postgresql_too_many_locks" {
|
||||
name = "[${var.environment}] PostgreSQL too many locks {{#is_alert}}{{{comparator}}} {{threshold}} ({{value}}){{/is_alert}}{{#is_warning}}{{{comparator}}} {{warn_threshold}} ({{value}}){{/is_warning}}"
|
||||
message = "${coalesce(var.postgresql_lock_message, var.message)}"
|
||||
type = "metric alert"
|
||||
|
||||
query = <<EOF
|
||||
avg(last_5m): (
|
||||
avg:postgresql.locks{${data.template_file.filter.rendered}} by {db_host}
|
||||
) > ${var.postgresql_lock_threshold_critical}
|
||||
EOF
|
||||
|
||||
evaluation_delay = "${var.delay}"
|
||||
new_host_delay = "${var.delay}"
|
||||
|
||||
thresholds {
|
||||
warning = "${var.postgresql_lock_threshold_warning}"
|
||||
critical = "${var.postgresql_lock_threshold_critical}"
|
||||
}
|
||||
|
||||
notify_no_data = true
|
||||
renotify_interval = 0
|
||||
require_full_window = true
|
||||
timeout_h = 0
|
||||
include_tags = true
|
||||
|
||||
silenced = "${var.posgresql_lock_silenced}"
|
||||
|
||||
tags = ["env:${var.environment}", "resource:postgresql"]
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user