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

# --- Origin Health ---

 template: am_front_door_origin_health
       on: azure_monitor.front_door.origin_health
    class: Availability
     type: Web Server
component: Azure Front Door
   lookup: average -5m unaligned of health
    units: percentage
    every: 1m
     warn: $this < (($status >= $WARNING)  ? (99) : (95))
     crit: $this < (($status == $CRITICAL) ? (95) : (90))
    delay: down 5m multiplier 1.5 max 1h
  summary: Front Door origin health on ${label:resource_name}
     info: Origin health percentage for Azure Front Door ${label:resource_name} \
           in ${label:resource_group} (${label:region}). \
           Low origin health indicates backends are failing health probes
       to: sysadmin

# --- Latency ---

 template: am_front_door_total_latency
       on: azure_monitor.front_door.latency
    class: Latency
     type: Web Server
component: Azure Front Door
   lookup: average -5m unaligned of total
    units: milliseconds
    every: 1m
     warn: $this > (($status >= $WARNING)  ? (3000) : (4000))
     crit: $this > (($status == $CRITICAL) ? (5000) : (8000))
    delay: down 5m multiplier 1.5 max 1h
  summary: Front Door total latency on ${label:resource_name}
     info: Average total request latency (client to Front Door to origin and back) \
           for Azure Front Door ${label:resource_name} \
           in ${label:resource_group} (${label:region})
       to: sysadmin

 template: am_front_door_origin_latency
       on: azure_monitor.front_door.latency
    class: Latency
     type: Web Server
component: Azure Front Door
   lookup: average -5m unaligned of origin
    units: milliseconds
    every: 1m
     warn: $this > (($status >= $WARNING)  ? (3000) : (5000))
     crit: $this > (($status == $CRITICAL) ? (5000) : (10000))
    delay: down 5m multiplier 1.5 max 1h
  summary: Front Door origin latency on ${label:resource_name}
     info: Average origin response latency for Azure Front Door ${label:resource_name} \
           in ${label:resource_group} (${label:region}). \
           High origin latency indicates slow backends
       to: sysadmin

# --- Error Rates ---

 template: am_front_door_5xx_error_rate
       on: azure_monitor.front_door.error_rate
    class: Errors
     type: Web Server
component: Azure Front Door
   lookup: average -5m unaligned of 5xx
    units: percentage
    every: 1m
     warn: $this > (($status >= $WARNING)  ? (3) : (5))
     crit: $this > (($status == $CRITICAL) ? (5) : (10))
    delay: down 5m multiplier 1.5 max 1h
  summary: Front Door 5xx error rate on ${label:resource_name}
     info: Percentage of requests resulting in 5xx server errors \
           for Azure Front Door ${label:resource_name} \
           in ${label:resource_group} (${label:region})
       to: sysadmin

 template: am_front_door_4xx_error_rate
       on: azure_monitor.front_door.error_rate
    class: Errors
     type: Web Server
component: Azure Front Door
   lookup: average -5m unaligned of 4xx
    units: percentage
    every: 1m
     warn: $this > (($status >= $WARNING)  ? (15) : (25))
    delay: down 5m multiplier 1.5 max 1h
  summary: Front Door 4xx error rate on ${label:resource_name}
     info: Percentage of requests resulting in 4xx client errors \
           for Azure Front Door ${label:resource_name} \
           in ${label:resource_group} (${label:region}). \
           Sustained high 4xx rates may indicate misconfigured routing or abusive clients
       to: sysadmin

# --- Cache Performance ---

 template: am_front_door_byte_hit_ratio
       on: azure_monitor.front_door.byte_hit_ratio
    class: Utilization
     type: Web Server
component: Azure Front Door
   lookup: average -10m unaligned of hit_ratio
    units: percentage
    every: 1m
     warn: $this != nan AND $this < (($status >= $WARNING) ? (50) : (40))
    delay: down 15m multiplier 1.5 max 1h
  summary: Front Door cache hit ratio on ${label:resource_name}
     info: Byte hit ratio (percentage of bytes served from cache) \
           for Azure Front Door ${label:resource_name} \
           in ${label:resource_group} (${label:region}). \
           Low cache hit ratio means most traffic goes to origin, increasing latency and origin load
       to: sysadmin

# --- WAF ---

 template: am_front_door_waf_rate_limited
       on: azure_monitor.front_door.origin_shield_requests
    class: Errors
     type: Web Server
component: Azure Front Door
   lookup: average -5m unaligned of rate_limited
    units: requests/s
    every: 1m
     warn: $this != nan AND $this > (($status >= $WARNING) ? (50) : (100))
    delay: down 5m multiplier 1.5 max 1h
  summary: Front Door origin shield rate limiting on ${label:resource_name}
     info: Rate of origin shield requests being rate limited \
           for Azure Front Door ${label:resource_name} \
           in ${label:resource_group} (${label:region})
       to: sysadmin
