MON-224 CloudSQL MySQL Network Connections monitor
This commit is contained in:
parent
d76ebfc1c4
commit
9557437195
49
cloud/gcp/cloud-sql/mysql/README.md
Normal file
49
cloud/gcp/cloud-sql/mysql/README.md
Normal file
@ -0,0 +1,49 @@
|
||||
GCP CloudSQL MySQL Monitors
|
||||
==============================
|
||||
|
||||
How to use this module
|
||||
----------------------
|
||||
|
||||
```
|
||||
module "datadog-monitors-gcp-cloudsql-mysql" {
|
||||
source = "git::ssh://git@bitbucket.org/morea/terraform.feature.datadog.git//cloud/gcp/clouds-sql/mysql?ref={revision}"
|
||||
|
||||
project_id = "${var.gcp_project_id}"
|
||||
environment = "${var.environment}"
|
||||
message = "${module.datadog-message-alerting.alerting-message}"
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
Purpose
|
||||
-------
|
||||
Creates DataDog monitors with the following checks :
|
||||
|
||||
* CloudSQL MySQL Network Connections
|
||||
* CloudSQL MySQL Replication Lag
|
||||
* CloudSQL MySQL Failover Lag
|
||||
|
||||
Useful links
|
||||
------------
|
||||
|
||||
* [GCP Metrics for CloudSQL](https://cloud.google.com/monitoring/api/metrics_gcp#gcp-cloudsql)
|
||||
* [Datadog Useful monitors for GCP CloudSQL](https://www.datadoghq.com/blog/monitor-google-cloud-sql/)
|
||||
* [Max connections depends on the type of the instance](https://cloud.google.com/sql/docs/quotas#fixed-limits)
|
||||
|
||||
Inputs
|
||||
------
|
||||
|
||||
| Name | Description | Type | Default | Required |
|
||||
|------|-------------|:----:|:-----:|:-----:|
|
||||
| delay | Delay in seconds for the metric evaluation | string | `900` | no |
|
||||
| environment | Architecture environment | string | - | yes |
|
||||
| filter_tags_custom | Tags used 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 | - | yes |
|
||||
| network_connections_hard_limit | Max number of connections for the CloudSQL Instance. Default value is the max value on https://cloud.google.com/sql/docs/quotas#fixed-limits for MySQL | string | `4000` | no |
|
||||
| network_connections_message | Custom message for the Network Connections monitor | string | `` | no |
|
||||
| network_connections_silenced | Groups to mute for GCP Cloud SQL Network Connections monitor | map | `<map>` | no |
|
||||
| network_connections_threshold_critical | Number of network connections (critical threshold) | string | `3600` | no |
|
||||
| network_connections_threshold_warning | Number of network connections (warning threshold) | string | `3200` | no |
|
||||
| network_connections_timeframe | Timeframe for the Network Connections monitor | string | `last_5m` | no |
|
||||
| project_id | ID of the GCP Project | string | - | yes |
|
||||
73
cloud/gcp/cloud-sql/mysql/inputs.tf
Normal file
73
cloud/gcp/cloud-sql/mysql/inputs.tf
Normal file
@ -0,0 +1,73 @@
|
||||
#
|
||||
# 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 "message" {
|
||||
description = "Message sent when a monitor is triggered"
|
||||
}
|
||||
|
||||
variable "delay" {
|
||||
description = "Delay in seconds for the metric evaluation"
|
||||
default = 900
|
||||
}
|
||||
|
||||
#
|
||||
# Filter variables
|
||||
#
|
||||
variable "project_id" {
|
||||
type = "string"
|
||||
description = "ID of the GCP Project"
|
||||
}
|
||||
|
||||
#
|
||||
# Network Connections
|
||||
#
|
||||
variable "network_connections_message" {
|
||||
description = "Custom message for the Network Connections monitor"
|
||||
type = "string"
|
||||
default = ""
|
||||
}
|
||||
|
||||
variable "network_connections_timeframe" {
|
||||
description = "Timeframe for the Network Connections monitor"
|
||||
type = "string"
|
||||
default = "last_5m"
|
||||
}
|
||||
|
||||
variable "network_connections_hard_limit" {
|
||||
description = "Max number of connections for the CloudSQL Instance. Default value is the max value on https://cloud.google.com/sql/docs/quotas#fixed-limits for MySQL"
|
||||
type = "string"
|
||||
default = 4000
|
||||
}
|
||||
|
||||
variable "network_connections_threshold_warning" {
|
||||
description = "Number of network connections (warning threshold)"
|
||||
type = "string"
|
||||
default = 3200
|
||||
}
|
||||
|
||||
variable "network_connections_threshold_critical" {
|
||||
description = "Number of network connections (critical threshold)"
|
||||
type = "string"
|
||||
default = 3600
|
||||
}
|
||||
|
||||
variable "network_connections_silenced" {
|
||||
description = "Groups to mute for GCP Cloud SQL Network Connections monitor"
|
||||
type = "map"
|
||||
default = {}
|
||||
}
|
||||
54
cloud/gcp/cloud-sql/mysql/monitors-cloudsql-mysql.tf
Normal file
54
cloud/gcp/cloud-sql/mysql/monitors-cloudsql-mysql.tf
Normal file
@ -0,0 +1,54 @@
|
||||
#
|
||||
# FILTERS
|
||||
#
|
||||
data "template_file" "filter" {
|
||||
template = "$${filter}"
|
||||
|
||||
vars {
|
||||
filter = "${var.filter_tags_use_defaults == "true" ?
|
||||
format("project_id:%s",var.project_id) :
|
||||
"${var.filter_tags_custom}"}"
|
||||
}
|
||||
}
|
||||
|
||||
#
|
||||
# MySQL Network Connections
|
||||
#
|
||||
resource "datadog_monitor" "network_connections" {
|
||||
name = "[${var.environment}] Cloud SQL MySQL Network Connections (hard limit: ${var.network_connections_hard_limit}) {{#is_alert}}{{{comparator}}} {{threshold}}% ({{value}}%){{/is_alert}}{{#is_warning}}{{{comparator}}} {{warn_threshold}}% ({{value}}%){{/is_warning}}"
|
||||
message = "${coalesce(var.network_connections_message, var.message)}"
|
||||
|
||||
type = "metric alert"
|
||||
|
||||
query = <<EOF
|
||||
avg(${var.network_connections_timeframe}):
|
||||
avg:gcp.cloudsql.database.network.connections{${data.template_file.filter.rendered}}
|
||||
by {database_id}
|
||||
> ${var.network_connections_threshold_critical}
|
||||
EOF
|
||||
|
||||
thresholds {
|
||||
warning = "${var.network_connections_threshold_warning}"
|
||||
critical = "${var.network_connections_threshold_critical}"
|
||||
}
|
||||
|
||||
include_tags = true
|
||||
notify_no_data = true
|
||||
require_full_window = false
|
||||
renotify_interval = 0
|
||||
notify_audit = false
|
||||
timeout_h = 0
|
||||
include_tags = true
|
||||
locked = false
|
||||
evaluation_delay = "${var.delay}"
|
||||
new_host_delay = "${var.delay}"
|
||||
silenced = "${var.network_connections_silenced}"
|
||||
|
||||
tags = [
|
||||
"team:gcp",
|
||||
"provider:gcp",
|
||||
"env:${var.environment}",
|
||||
"resource:cloud-sql",
|
||||
"engine:mysql",
|
||||
]
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user