resource "datadog_monitor" "amp_rds_cpu_usage_on_hostname" {
  name = "AOMA-DA-Prod - RDS - CPU usage on {{host.name}}"
  type = "query alert"
  query = <<EOT
avg(last_1h):avg:aws.rds.cpuutilization{hostname:amp-digital-archive-prod-rds-01.cpfm9cs4p5pq.us-east-1.rds.amazonaws.com,!name:amp-p2-rds-01} by {host} > 90
EOT
  message = <<EOT
{{#is_alert}}
### CPU usage is high on {{host.name}} **{{value}}%** > {{threshold}}% (threshold)
Engine - {{host.engine}}
PRIORITY=HIGH
{{/is_alert}}

{{#is_recovery}}
### CPU usage is normal on {{host.name}} **{{value}}%** < {{threshold}}% (threshold)
PRIORITY=HIGH
{{/is_recovery}}

${local.aoma_amp_del_data_notification_recipients}
EOT
  draft_status = "published"
  escalation_message = <<EOT
EOT
  tags = local.aoma_amp_del_data_monitor_tags
  priority = 1
  include_tags = false
  new_group_delay = 300
  on_missing_data = "default"
  require_full_window = false
  monitor_thresholds {
    critical = 90
  }
}
resource "datadog_monitor" "amp_rds_free_storage_space_on_namename" {
  name = "AOMA-DA-Prod - RDS - Free Storage Space on {{name.name}}"
  type = "query alert"
  query = <<EOT
avg(last_1h):( avg:aws.rds.free_storage_space{hostname:amp-digital-archive-prod-rds-01.cpfm9cs4p5pq.us-east-1.rds.amazonaws.com} by {name} / avg:aws.rds.total_storage_space{hostname:amp-digital-archive-prod-rds-01.cpfm9cs4p5pq.us-east-1.rds.amazonaws.com} by {name} ) * 100 <= 25
EOT
  message = <<EOT
{{#is_alert}}
### Free storage space available on del-rds-db-01 is **{{value}}%** <= {{threshold}}% (threshold)
PRIORITY=HIGH
{{/is_alert}}

{{#is_recovery}}
### Free storage space available on del-rds-db-01 is **{{value}}%** > {{threshold}}% (threshold)
PRIORITY=HIGH
{{/is_recovery}}

${local.aoma_amp_del_data_notification_recipients}
EOT
  draft_status = "published"
  escalation_message = <<EOT
EOT
  tags = local.aoma_amp_del_data_monitor_tags
  priority = 1
  include_tags = false
  new_group_delay = 0
  on_missing_data = "default"
  require_full_window = false
  monitor_thresholds {
    critical = 25
  }
}
resource "datadog_monitor" "amp_rds_number_of_db_connection_check_on_namename" {
  name = "AOMA-DA-Prod - RDS - Number of DB Connection Check on {{name.name}}"
  type = "query alert"
  query = <<EOT
avg(last_1h):avg:aws.rds.database_connections{hostname:amp-digital-archive-prod-rds-01.cpfm9cs4p5pq.us-east-1.rds.amazonaws.com} by {name} > 2000
EOT
  message = <<EOT
{{#is_alert}}
### Number of DB connections is {{value}}  > {{threshold}}  (threshold)
PRIORITY=HIGH
{{/is_alert}}

{{#is_recovery}}
### Number of DB connections are: {{value}}  < {{threshold}}  (threshold)
PRIORITY=HIGH
{{/is_recovery}}

${local.aoma_amp_del_data_notification_recipients}
EOT
  draft_status = "published"
  escalation_message = <<EOT
EOT
  tags = local.aoma_amp_del_data_monitor_tags
  priority = 1
  include_tags = false
  new_group_delay = 0
  on_missing_data = "default"
  require_full_window = false
  monitor_thresholds {
    critical = 2000
  }
}
