# you can disable an alarm notification by setting the 'to' line to: silent

# --- Utilization ---

 template: am_mysql_flexible_cpu
       on: azure_monitor.mysql_flexible.cpu
    class: Utilization
     type: Database
component: Azure MySQL Flexible
   lookup: average -5m unaligned of average
    units: percentage
    every: 1m
     warn: $this > (($status >= $WARNING)  ? (75) : (85))
     crit: $this > (($status == $CRITICAL) ? (85) : (95))
    delay: down 5m multiplier 1.5 max 1h
  summary: MySQL Flexible CPU on ${label:resource_name}
     info: Average CPU utilization on Azure MySQL Flexible Server ${label:resource_name} \
           in ${label:resource_group} (${label:region})
       to: dba

 template: am_mysql_flexible_memory
       on: azure_monitor.mysql_flexible.memory
    class: Utilization
     type: Database
component: Azure MySQL Flexible
   lookup: average -5m unaligned of average
    units: percentage
    every: 1m
     warn: $this > (($status >= $WARNING)  ? (75) : (85))
     crit: $this > (($status == $CRITICAL) ? (85) : (95))
    delay: down 5m multiplier 1.5 max 1h
  summary: MySQL Flexible memory on ${label:resource_name}
     info: Average memory utilization on Azure MySQL Flexible Server ${label:resource_name} \
           in ${label:resource_group} (${label:region})
       to: dba

 template: am_mysql_flexible_io_utilization
       on: azure_monitor.mysql_flexible.io_utilization
    class: Utilization
     type: Database
component: Azure MySQL Flexible
   lookup: average -5m unaligned of average
    units: percentage
    every: 1m
     warn: $this > (($status >= $WARNING)  ? (80) : (90))
     crit: $this > (($status == $CRITICAL) ? (90) : (95))
    delay: down 5m multiplier 1.5 max 1h
  summary: MySQL Flexible I/O utilization on ${label:resource_name}
     info: Average storage I/O utilization on Azure MySQL Flexible Server ${label:resource_name} \
           in ${label:resource_group} (${label:region}). \
           Sustained high I/O can cause query performance degradation
       to: dba

 template: am_mysql_flexible_storage_utilization
       on: azure_monitor.mysql_flexible.storage_utilization
    class: Utilization
     type: Database
component: Azure MySQL Flexible
   lookup: average -5m unaligned of average
    units: percentage
    every: 1m
     warn: $this > (($status >= $WARNING)  ? (75) : (80))
     crit: $this > (($status == $CRITICAL) ? (85) : (90))
    delay: down 5m multiplier 1.5 max 1h
  summary: MySQL Flexible storage on ${label:resource_name}
     info: Storage utilization on Azure MySQL Flexible Server ${label:resource_name} \
           in ${label:resource_group} (${label:region}). \
           When storage reaches 100% the server becomes read-only
       to: dba

 template: am_mysql_flexible_serverlog_storage_utilization
       on: azure_monitor.mysql_flexible.serverlog_storage_utilization
    class: Utilization
     type: Database
component: Azure MySQL Flexible
   lookup: average -5m unaligned of average
    units: percentage
    every: 1m
     warn: $this > (($status >= $WARNING)  ? (75) : (85))
     crit: $this > (($status == $CRITICAL) ? (85) : (95))
    delay: down 5m multiplier 1.5 max 1h
  summary: MySQL Flexible server log storage on ${label:resource_name}
     info: Server log storage utilization on Azure MySQL Flexible Server ${label:resource_name} \
           in ${label:resource_group} (${label:region})
       to: dba

 template: am_mysql_flexible_cpu_credits_remaining
       on: azure_monitor.mysql_flexible.cpu_credits
    class: Utilization
     type: Database
component: Azure MySQL Flexible
   lookup: average -5m unaligned of remaining
    units: credits
    every: 1m
     warn: $this != nan AND $this < (($status >= $WARNING) ? (30) : (20))
    delay: down 5m multiplier 1.5 max 1h
  summary: MySQL Flexible CPU credits low on ${label:resource_name}
     info: Remaining CPU credits on Azure MySQL Flexible Server ${label:resource_name} \
           in ${label:resource_group} (${label:region}). \
           Only applicable to burstable tier; exhaustion causes CPU throttling
       to: dba

# --- Availability ---

 template: am_mysql_flexible_ha_io_status
       on: azure_monitor.mysql_flexible.ha_status
    class: Availability
     type: Database
component: Azure MySQL Flexible
   lookup: average -5m unaligned of io
    units: status
    every: 1m
     crit: $this != nan AND $this < 1
    delay: down 5m multiplier 1.5 max 1h
  summary: MySQL Flexible HA IO thread down on ${label:resource_name}
     info: HA replication IO thread is not running on Azure MySQL Flexible Server ${label:resource_name} \
           in ${label:resource_group} (${label:region}). \
           Only relevant when high availability is configured
       to: dba

 template: am_mysql_flexible_ha_sql_status
       on: azure_monitor.mysql_flexible.ha_status
    class: Availability
     type: Database
component: Azure MySQL Flexible
   lookup: average -5m unaligned of sql
    units: status
    every: 1m
     crit: $this != nan AND $this < 1
    delay: down 5m multiplier 1.5 max 1h
  summary: MySQL Flexible HA SQL thread down on ${label:resource_name}
     info: HA replication SQL thread is not running on Azure MySQL Flexible Server ${label:resource_name} \
           in ${label:resource_group} (${label:region}). \
           Only relevant when high availability is configured
       to: dba

 template: am_mysql_flexible_replica_io_status
       on: azure_monitor.mysql_flexible.replica_status
    class: Availability
     type: Database
component: Azure MySQL Flexible
   lookup: average -5m unaligned of io
    units: status
    every: 1m
     crit: $this != nan AND $this < 1
    delay: down 5m multiplier 1.5 max 1h
  summary: MySQL Flexible replica IO thread down on ${label:resource_name}
     info: Read replica IO thread is not running on Azure MySQL Flexible Server ${label:resource_name} \
           in ${label:resource_group} (${label:region}). \
           Only relevant when read replicas are configured
       to: dba

 template: am_mysql_flexible_replica_sql_status
       on: azure_monitor.mysql_flexible.replica_status
    class: Availability
     type: Database
component: Azure MySQL Flexible
   lookup: average -5m unaligned of sql
    units: status
    every: 1m
     crit: $this != nan AND $this < 1
    delay: down 5m multiplier 1.5 max 1h
  summary: MySQL Flexible replica SQL thread down on ${label:resource_name}
     info: Read replica SQL thread is not running on Azure MySQL Flexible Server ${label:resource_name} \
           in ${label:resource_group} (${label:region}). \
           Only relevant when read replicas are configured
       to: dba

# --- Replication ---

 template: am_mysql_flexible_replication_lag
       on: azure_monitor.mysql_flexible.replication_lag
    class: Latency
     type: Database
component: Azure MySQL Flexible
   lookup: average -5m unaligned of replica
    units: seconds
    every: 1m
     warn: $this != nan AND $this > (($status >= $WARNING)  ? (20) : (30))
     crit: $this != nan AND $this > (($status == $CRITICAL) ? (30) : (60))
    delay: down 5m multiplier 1.5 max 1h
  summary: MySQL Flexible replica lag on ${label:resource_name}
     info: Read replica replication lag on Azure MySQL Flexible Server ${label:resource_name} \
           in ${label:resource_group} (${label:region}). \
           Only relevant when read replicas are configured
       to: dba

 template: am_mysql_flexible_ha_replication_lag
       on: azure_monitor.mysql_flexible.replication_lag
    class: Latency
     type: Database
component: Azure MySQL Flexible
   lookup: average -5m unaligned of ha
    units: seconds
    every: 1m
     warn: $this != nan AND $this > (($status >= $WARNING)  ? (10) : (20))
     crit: $this != nan AND $this > (($status == $CRITICAL) ? (20) : (30))
    delay: down 5m multiplier 1.5 max 1h
  summary: MySQL Flexible HA replication lag on ${label:resource_name}
     info: HA standby replication lag on Azure MySQL Flexible Server ${label:resource_name} \
           in ${label:resource_group} (${label:region}). \
           High lag increases data loss risk during failover. \
           Only relevant when high availability is configured
       to: dba

# --- Latency / Contention ---

 template: am_mysql_flexible_innodb_row_lock_time
       on: azure_monitor.mysql_flexible.innodb_row_lock_time
    class: Latency
     type: Database
component: Azure MySQL Flexible
   lookup: average -5m unaligned of average
    units: milliseconds
    every: 1m
     warn: $this > (($status >= $WARNING)  ? (200) : (500))
     crit: $this > (($status == $CRITICAL) ? (500) : (1000))
    delay: down 5m multiplier 1.5 max 1h
  summary: MySQL Flexible row lock wait time on ${label:resource_name}
     info: Average InnoDB row lock wait time on Azure MySQL Flexible Server ${label:resource_name} \
           in ${label:resource_group} (${label:region}). \
           High values indicate significant lock contention between transactions
       to: dba

 template: am_mysql_flexible_lock_deadlocks
       on: azure_monitor.mysql_flexible.lock_deadlocks
    class: Errors
     type: Database
component: Azure MySQL Flexible
   lookup: average -5m unaligned of total
    units: deadlocks/s
    every: 1m
     warn: $this > (($status >= $WARNING)  ? (0) : (1))
     crit: $this > (($status == $CRITICAL) ? (1) : (5))
    delay: down 5m multiplier 1.5 max 1h
  summary: MySQL Flexible deadlocks on ${label:resource_name}
     info: Rate of InnoDB deadlocks on Azure MySQL Flexible Server ${label:resource_name} \
           in ${label:resource_group} (${label:region}). \
           Deadlocks cause transactions to be rolled back
       to: dba

 template: am_mysql_flexible_lock_timeouts
       on: azure_monitor.mysql_flexible.lock_timeouts
    class: Errors
     type: Database
component: Azure MySQL Flexible
   lookup: average -5m unaligned of total
    units: timeouts/s
    every: 1m
     warn: $this > (($status >= $WARNING)  ? (0) : (1))
     crit: $this > (($status == $CRITICAL) ? (1) : (5))
    delay: down 5m multiplier 1.5 max 1h
  summary: MySQL Flexible lock timeouts on ${label:resource_name}
     info: Rate of lock wait timeouts on Azure MySQL Flexible Server ${label:resource_name} \
           in ${label:resource_group} (${label:region}). \
           Timeouts indicate long-held locks blocking other transactions
       to: dba

# --- Errors ---

 template: am_mysql_flexible_aborted_connections
       on: azure_monitor.mysql_flexible.aborted_connections
    class: Errors
     type: Database
component: Azure MySQL Flexible
   lookup: average -5m unaligned of total
    units: connections/s
    every: 1m
     warn: $this > (($status >= $WARNING)  ? (3) : (5))
     crit: $this > (($status == $CRITICAL) ? (10) : (20))
    delay: down 5m multiplier 1.5 max 1h
  summary: MySQL Flexible aborted connections on ${label:resource_name}
     info: Rate of aborted connections on Azure MySQL Flexible Server ${label:resource_name} \
           in ${label:resource_group} (${label:region}). \
           Common causes include authentication failures, connection timeouts, and client errors
       to: dba

# --- Performance ---

 template: am_mysql_flexible_slow_queries
       on: azure_monitor.mysql_flexible.queries
    class: Workload
     type: Database
component: Azure MySQL Flexible
   lookup: average -5m unaligned of slow
    units: queries/s
    every: 1m
     warn: $this > (($status >= $WARNING)  ? (5) : (10))
     crit: $this > (($status == $CRITICAL) ? (10) : (25))
    delay: down 5m multiplier 1.5 max 1h
  summary: MySQL Flexible slow queries on ${label:resource_name}
     info: Rate of slow queries on Azure MySQL Flexible Server ${label:resource_name} \
           in ${label:resource_group} (${label:region}). \
           Review slow query log for optimization opportunities
       to: dba

 template: am_mysql_flexible_innodb_row_lock_waits
       on: azure_monitor.mysql_flexible.innodb_row_lock_waits
    class: Latency
     type: Database
component: Azure MySQL Flexible
   lookup: average -5m unaligned of total
    units: waits/s
    every: 1m
     warn: $this > (($status >= $WARNING)  ? (50) : (100))
     crit: $this > (($status == $CRITICAL) ? (100) : (200))
    delay: down 5m multiplier 1.5 max 1h
  summary: MySQL Flexible row lock waits on ${label:resource_name}
     info: Rate of InnoDB row lock waits on Azure MySQL Flexible Server ${label:resource_name} \
           in ${label:resource_group} (${label:region}). \
           High lock waits degrade query throughput and increase response times
       to: dba

 template: am_mysql_flexible_history_list_length
       on: azure_monitor.mysql_flexible.history_list_length
    class: Utilization
     type: Database
component: Azure MySQL Flexible
   lookup: average -5m unaligned of maximum
    units: entries
    every: 1m
     warn: $this > (($status >= $WARNING)  ? (50000) : (100000))
     crit: $this > (($status == $CRITICAL) ? (100000) : (1000000))
    delay: down 5m multiplier 1.5 max 1h
  summary: MySQL Flexible history list length on ${label:resource_name}
     info: InnoDB history list length (undo log entries) on Azure MySQL Flexible Server ${label:resource_name} \
           in ${label:resource_group} (${label:region}). \
           A growing history list indicates long-running transactions preventing purge
       to: dba
