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

# --- Capacity / Utilization ---

 template: am_api_management_capacity
       on: azure_monitor.api_management.capacity
    class: Utilization
     type: Web Server
component: API Management
   lookup: average -5m unaligned of capacity
    units: percentage
    every: 1m
     warn: $this > (($status >= $WARNING)  ? (70) : (80))
     crit: $this > (($status == $CRITICAL) ? (80) : (90))
    delay: down 5m multiplier 1.5 max 1h
  summary: APIM capacity on ${label:resource_name}
     info: Average capacity utilization of API Management service ${label:resource_name} \
           in ${label:resource_group} (${label:region}). \
           High capacity indicates the service is approaching its scaling limits
       to: sysadmin

 template: am_api_management_gateway_cpu
       on: azure_monitor.api_management.gateway_cpu
    class: Utilization
     type: Web Server
component: API Management
   lookup: average -5m unaligned of cpu
    units: percentage
    every: 1m
     warn: $this != nan AND $this > (($status >= $WARNING)  ? (70) : (80))
     crit: $this != nan AND $this > (($status == $CRITICAL) ? (85) : (95))
    delay: down 5m multiplier 1.5 max 1h
  summary: APIM gateway CPU on ${label:resource_name}
     info: Average gateway CPU utilization of API Management service ${label:resource_name} \
           in ${label:resource_group} (${label:region})
       to: sysadmin

 template: am_api_management_gateway_memory
       on: azure_monitor.api_management.gateway_memory
    class: Utilization
     type: Web Server
component: API Management
   lookup: average -5m unaligned of memory
    units: percentage
    every: 1m
     warn: $this != nan AND $this > (($status >= $WARNING)  ? (70) : (80))
     crit: $this != nan AND $this > (($status == $CRITICAL) ? (85) : (95))
    delay: down 5m multiplier 1.5 max 1h
  summary: APIM gateway memory on ${label:resource_name}
     info: Average gateway memory utilization of API Management service ${label:resource_name} \
           in ${label:resource_group} (${label:region})
       to: sysadmin

# --- Request Latency ---

 template: am_api_management_request_duration
       on: azure_monitor.api_management.request_duration
    class: Latency
     type: Web Server
component: API Management
   lookup: average -5m unaligned of overall
    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: APIM request duration on ${label:resource_name}
     info: Average overall request duration of API Management service ${label:resource_name} \
           in ${label:resource_group} (${label:region})
       to: sysadmin

 template: am_api_management_backend_duration
       on: azure_monitor.api_management.request_duration
    class: Latency
     type: Web Server
component: API Management
   lookup: average -5m unaligned of backend
    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: APIM backend duration on ${label:resource_name}
     info: Average backend request duration of API Management service ${label:resource_name} \
           in ${label:resource_group} (${label:region})
       to: sysadmin

# --- Network Connectivity ---

 template: am_api_management_network_connectivity
       on: azure_monitor.api_management.network_connectivity
    class: Availability
     type: Web Server
component: API Management
   lookup: average -5m unaligned of connectivity
    units: status
    every: 1m
     crit: $this < (($status == $CRITICAL) ? (1) : (0.5))
    delay: down 5m multiplier 1.5 max 1h
  summary: APIM network connectivity on ${label:resource_name}
     info: Network connectivity status of API Management service ${label:resource_name} \
           in ${label:resource_group} (${label:region}). \
           Values below 1 indicate connectivity problems to backend dependencies
       to: sysadmin

# --- EventHub Errors ---

 template: am_api_management_eventhub_failed_events
       on: azure_monitor.api_management.eventhub_events
    class: Errors
     type: Web Server
component: API Management
   lookup: average -5m unaligned of failed
    units: events/s
    every: 1m
     warn: $this != nan AND $this > (($status >= $WARNING) ? (0) : (5))
    delay: down 5m multiplier 1.5 max 1h
  summary: APIM EventHub failed events on ${label:resource_name}
     info: Rate of failed EventHub events for API Management service ${label:resource_name} \
           in ${label:resource_group} (${label:region})
       to: sysadmin

 template: am_api_management_eventhub_dropped_events
       on: azure_monitor.api_management.eventhub_events
    class: Errors
     type: Web Server
component: API Management
   lookup: average -5m unaligned of dropped
    units: events/s
    every: 1m
     warn: $this != nan AND $this > (($status >= $WARNING) ? (0) : (5))
    delay: down 5m multiplier 1.5 max 1h
  summary: APIM EventHub dropped events on ${label:resource_name}
     info: Rate of dropped EventHub events for API Management service ${label:resource_name} \
           in ${label:resource_group} (${label:region})
       to: sysadmin

 template: am_api_management_eventhub_rejected_events
       on: azure_monitor.api_management.eventhub_events
    class: Errors
     type: Web Server
component: API Management
   lookup: average -5m unaligned of rejected
    units: events/s
    every: 1m
     warn: $this != nan AND $this > (($status >= $WARNING) ? (0) : (5))
    delay: down 5m multiplier 1.5 max 1h
  summary: APIM EventHub rejected events on ${label:resource_name}
     info: Rate of rejected EventHub events for API Management service ${label:resource_name} \
           in ${label:resource_group} (${label:region})
       to: sysadmin

 template: am_api_management_eventhub_throttled_events
       on: azure_monitor.api_management.eventhub_events
    class: Errors
     type: Web Server
component: API Management
   lookup: average -5m unaligned of throttled
    units: events/s
    every: 1m
     warn: $this != nan AND $this > (($status >= $WARNING) ? (0) : (10))
    delay: down 5m multiplier 1.5 max 1h
  summary: APIM EventHub throttled events on ${label:resource_name}
     info: Rate of throttled EventHub events for API Management service ${label:resource_name} \
           in ${label:resource_group} (${label:region}). \
           Throttling indicates EventHub throughput limits are being reached
       to: sysadmin

 template: am_api_management_eventhub_timedout_events
       on: azure_monitor.api_management.eventhub_events
    class: Errors
     type: Web Server
component: API Management
   lookup: average -5m unaligned of timed_out
    units: events/s
    every: 1m
     warn: $this != nan AND $this > (($status >= $WARNING) ? (0) : (5))
    delay: down 5m multiplier 1.5 max 1h
  summary: APIM EventHub timed out events on ${label:resource_name}
     info: Rate of timed out EventHub events for API Management service ${label:resource_name} \
           in ${label:resource_group} (${label:region})
       to: sysadmin
