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

# --- Errors ---

 template: am_event_hubs_server_errors
       on: azure_monitor.event_hubs.errors
    class: Errors
     type: Messaging
component: Azure Event Hubs
   lookup: average -5m unaligned of server
    units: errors/s
    every: 1m
     warn: $this > (($status >= $WARNING)  ? (1) : (5))
     crit: $this > (($status == $CRITICAL) ? (5) : (10))
    delay: down 5m multiplier 1.5 max 1h
  summary: Event Hubs server errors on ${label:resource_name}
     info: Server-side errors on Event Hubs namespace ${label:resource_name} \
           in ${label:resource_group} (${label:region})
       to: sysadmin

 template: am_event_hubs_throttled_requests
       on: azure_monitor.event_hubs.errors
    class: Errors
     type: Messaging
component: Azure Event Hubs
   lookup: average -5m unaligned of throttled
    units: errors/s
    every: 1m
     warn: $this > (($status >= $WARNING)  ? (0) : (1))
     crit: $this > (($status == $CRITICAL) ? (5) : (10))
    delay: down 5m multiplier 1.5 max 1h
  summary: Event Hubs throttled requests on ${label:resource_name}
     info: Requests being throttled on Event Hubs namespace ${label:resource_name} \
           in ${label:resource_group} (${label:region})
       to: sysadmin

 template: am_event_hubs_quota_exceeded
       on: azure_monitor.event_hubs.errors
    class: Errors
     type: Messaging
component: Azure Event Hubs
   lookup: average -5m unaligned of quota_exceeded
    units: errors/s
    every: 1m
     warn: $this > (($status >= $WARNING)  ? (0) : (1))
     crit: $this > (($status == $CRITICAL) ? (1) : (5))
    delay: down 5m multiplier 1.5 max 1h
  summary: Event Hubs quota exceeded on ${label:resource_name}
     info: Quota exceeded errors on Event Hubs namespace ${label:resource_name} \
           in ${label:resource_group} (${label:region}). \
           Quota errors indicate the namespace has exceeded its throughput unit limits
       to: sysadmin

# User errors (400-class) at sustained high rate may indicate
# client misconfiguration or malformed messages.

 template: am_event_hubs_user_errors
       on: azure_monitor.event_hubs.errors
    class: Errors
     type: Messaging
component: Azure Event Hubs
   lookup: average -5m unaligned of user
    units: errors/s
    every: 1m
     warn: $this > (($status >= $WARNING) ? (10) : (25))
    delay: down 5m multiplier 1.5 max 1h
  summary: Event Hubs user errors on ${label:resource_name}
     info: Rate of user (client-side) errors on Event Hubs namespace ${label:resource_name} \
           in ${label:resource_group} (${label:region})
       to: sysadmin

# --- Request Success Rate ---

 template: am_event_hubs_incoming_requests
       on: azure_monitor.event_hubs.requests
    class: Workload
     type: Messaging
component: Azure Event Hubs
   lookup: sum -5m unaligned of incoming
    units: requests/s
    every: 1m
     info: Total incoming requests to Event Hubs namespace ${label:resource_name}

 template: am_event_hubs_success_rate
       on: azure_monitor.event_hubs.requests
    class: Errors
     type: Messaging
component: Azure Event Hubs
   lookup: sum -5m unaligned of successful
     calc: ($am_event_hubs_incoming_requests > 0) ? ($this * 100 / $am_event_hubs_incoming_requests) : (100)
    units: %
    every: 1m
     warn: ($am_event_hubs_incoming_requests > 120) ? ($this < (($status >= $WARNING) ? (99) : (95))) : (0)
     crit: ($am_event_hubs_incoming_requests > 120) ? ($this < (($status == $CRITICAL) ? (95) : (85))) : (0)
    delay: down 5m multiplier 1.5 max 1h
  summary: Event Hubs request success rate on ${label:resource_name}
     info: Percentage of successful requests on Event Hubs namespace ${label:resource_name} \
           in ${label:resource_group} (${label:region})
       to: sysadmin

# --- Utilization (Premium tier) ---

 template: am_event_hubs_namespace_cpu
       on: azure_monitor.event_hubs.namespace_resources
    class: Utilization
     type: Messaging
component: Azure Event Hubs
   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) ? (80) : (90))
    delay: down 5m multiplier 1.5 max 1h
  summary: Event Hubs namespace CPU on ${label:resource_name}
     info: CPU utilization of Event Hubs Premium namespace ${label:resource_name} \
           in ${label:resource_group} (${label:region})
       to: sysadmin

 template: am_event_hubs_namespace_memory
       on: azure_monitor.event_hubs.namespace_resources
    class: Utilization
     type: Messaging
component: Azure Event Hubs
   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) ? (80) : (90))
    delay: down 5m multiplier 1.5 max 1h
  summary: Event Hubs namespace memory on ${label:resource_name}
     info: Memory utilization of Event Hubs Premium namespace ${label:resource_name} \
           in ${label:resource_group} (${label:region})
       to: sysadmin

# --- Capture ---

 template: am_event_hubs_capture_backlog
       on: azure_monitor.event_hubs.capture_backlog
    class: Workload
     type: Messaging
component: Azure Event Hubs
   lookup: average -5m unaligned of backlog
    units: messages
    every: 1m
     warn: $this != nan AND $this > (($status >= $WARNING)  ? (500000) : (1000000))
     crit: $this != nan AND $this > (($status == $CRITICAL) ? (1000000) : (5000000))
    delay: down 5m multiplier 1.5 max 1h
  summary: Event Hubs capture backlog on ${label:resource_name}
     info: Messages waiting to be captured on Event Hubs namespace ${label:resource_name} \
           in ${label:resource_group} (${label:region})
       to: sysadmin

# --- Geo-Replication ---

 template: am_event_hubs_replication_lag
       on: azure_monitor.event_hubs.replication_lag
    class: Latency
     type: Messaging
component: Azure Event Hubs
   lookup: average -5m unaligned of messages
    units: messages
    every: 1m
     warn: $this != nan AND $this > (($status >= $WARNING)  ? (100) : (500))
     crit: $this != nan AND $this > (($status == $CRITICAL) ? (500) : (1000))
    delay: down 5m multiplier 1.5 max 1h
  summary: Event Hubs replication lag on ${label:resource_name}
     info: Geo-replication message lag on Event Hubs namespace ${label:resource_name} \
           in ${label:resource_group} (${label:region})
       to: sysadmin

 template: am_event_hubs_replication_lag_duration
       on: azure_monitor.event_hubs.replication_lag_duration
    class: Latency
     type: Messaging
component: Azure Event Hubs
   lookup: average -5m unaligned of duration
    units: seconds
    every: 1m
     warn: $this != nan AND $this > (($status >= $WARNING)  ? (30) : (60))
     crit: $this != nan AND $this > (($status == $CRITICAL) ? (60) : (120))
    delay: down 5m multiplier 1.5 max 1h
  summary: Event Hubs replication lag duration on ${label:resource_name}
     info: Geo-replication time lag on Event Hubs namespace ${label:resource_name} \
           in ${label:resource_group} (${label:region})
       to: sysadmin
