resource "datadog_monitor" "amp_prod_tusd_disk_space_usage_on_hostnamedevicename_is_va" {
  name = "AMP-P | TUSD | Disk space usage on {{host.name}}:{{device.name}} is {{value}}%"
  type = "query alert"
  query = <<EOT
avg(last_15m):avg:system.disk.in_use{host:ampaasp-tusd01.smeampaasp.net} by {device,host} * 100 > 90
EOT
  message = <<EOT
{{#is_alert}}
### Disk space usage on {{host.name}}: **{{device.name}}** is {{value}}%  > {{threshold}}% (threshold)
PRIORITY=LOW
{{/is_alert}}

{{#is_recovery}}
### Disk space usage on {{host.name}}:**{{device.name}}** is {{value}}%  < {{threshold}}% (threshold)
PRIORITY=LOW
{{/is_recovery}}

@pagerduty-AMP
@amp-microservices@sonymusic.com

EOT
  draft_status = "published"
  escalation_message = <<EOT
EOT
  tags = ["team:amp-team","managed_by:amp-terraform"]
  include_tags = false
  new_group_delay = 300
  on_missing_data = "default"
  require_full_window = false
  monitor_thresholds {
    critical = 90
  }
}
resource "datadog_monitor" "amp_prod_tusd_ec2_host_status_check_failed_for_hostname" {
  name = "AMP-P |TUSD | EC2 Host Status Check failed for {{host.name}}"
  type = "query alert"
  query = <<EOT
max(last_1h):avg:aws.ec2.status_check_failed{host:ampaasp-tusd01.smeampaasp.net} by {host} >= 1
EOT
  message = <<EOT
{{#is_alert}}
### Host ** {{host.name}}  ** status check failed
#### Verify the host ** {{host.name}} ** in AWS console and confirm it is reachable by logging into the host.
PRIORITY=HIGH
{{/is_alert}}

{{#is_recovery}}
### Host ** {{host.name}} ** is reachable
PRIORITY=HIGH
{{/is_recovery}}

@pagerduty-AMP
@amp-microservices@sonymusic.com

EOT
  draft_status = "published"
  escalation_message = <<EOT
EOT
  tags = ["team:amp-team","managed_by:amp-terraform"]
  include_tags = false
  new_group_delay = 300
  on_missing_data = "default"
  require_full_window = false
  monitor_thresholds {
    critical = 1
  }
}
resource "datadog_monitor" "amp_prod_tusd_memory_utilization_on_hostname" {
  name = "AMP-P | Prod | TUSD - Memory Utilization on {{host.name}}"
  type = "query alert"
  query = <<EOT
avg(last_15m):avg:system.mem.pct_usable{host:ampaasp-tusd01.smeampaasp.net} by {host} * 100 < 15
EOT
  message = <<EOT
{{#is_alert}}
{{host.name}} - High Memory Utilization - Free Memory available on {{host.name}} is {{value}}%  < 10%
PRIORITY=HIGH
{{/is_alert}}

{{#is_recovery}}
{{host.name}} - Memory Utilization is Normal - Free Memory available on {{host.name}} is {{value}}%  >= 10%
PRIORITY=HIGH
{{/is_recovery}}

@pagerduty-AMP
@amp-microservices@sonymusic.com

EOT
  draft_status = "published"
  escalation_message = <<EOT
EOT
  tags = ["team:amp-team","managed_by:amp-terraform"]
  include_tags = false
  new_group_delay = 300
  on_missing_data = "show_and_notify_no_data"
  require_full_window = false
  monitor_thresholds {
    critical = 15
  }
}
