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

# ── Availability ─────────────────────────────────────────────────────────────

 template: am_appinsights_availability
       on: azure_monitor.application_insights.availability_percentage
    class: Availability
     type: Other
component: Application Insights
   lookup: average -5m unaligned of average
    units: percentage
    every: 1m
     warn: $this < (($status >= $WARNING)  ? (99.9) : (99))
     crit: $this < (($status == $CRITICAL) ? (99)   : (90))
    delay: down 5m multiplier 1.5 max 1h
  summary: App Insights availability on ${label:resource_name}
     info: Availability test success rate for Application Insights resource ${label:resource_name} \
           in ${label:resource_group} (${label:region})
       to: sysadmin

 template: am_appinsights_availability_duration
       on: azure_monitor.application_insights.availability_duration
    class: Latency
     type: Other
component: Application Insights
   lookup: average -5m unaligned of average
    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: App Insights availability test duration on ${label:resource_name}
     info: Average availability test duration for Application Insights resource ${label:resource_name} \
           in ${label:resource_group} (${label:region})
       to: sysadmin

# ── Server Requests ──────────────────────────────────────────────────────────

# Helper: total request rate over 5 minutes (used for minimum-data guard)
 template: am_appinsights_request_rate
       on: azure_monitor.application_insights.server_requests
    class: Workload
     type: Other
component: Application Insights
   lookup: average -5m unaligned of total
    units: requests/s
    every: 1m
  summary: App Insights request rate on ${label:resource_name}
     info: Average server request rate for Application Insights resource ${label:resource_name} \
           in ${label:resource_group} (${label:region})
       to: silent

 template: am_appinsights_failed_requests
       on: azure_monitor.application_insights.server_requests
    class: Errors
     type: Other
component: Application Insights
   lookup: average -5m unaligned percentage of failed
    units: %
    every: 1m
     warn: ($am_appinsights_request_rate > 0.5) ? ($this > (($status >= $WARNING) ? (3) : (5))) : (0)
     crit: ($am_appinsights_request_rate > 0.5) ? ($this > (($status == $CRITICAL) ? (10) : (15))) : (0)
    delay: down 5m multiplier 1.5 max 1h
  summary: App Insights failed requests on ${label:resource_name}
     info: Percentage of failed server requests for Application Insights resource ${label:resource_name} \
           in ${label:resource_group} (${label:region})
       to: sysadmin

 template: am_appinsights_response_time
       on: azure_monitor.application_insights.server_response_time
    class: Latency
     type: Other
component: Application Insights
   lookup: average -5m unaligned of average
    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: App Insights server response time on ${label:resource_name}
     info: Average server response time for Application Insights resource ${label:resource_name} \
           in ${label:resource_group} (${label:region})
       to: sysadmin

# ── Dependencies ─────────────────────────────────────────────────────────────

# Helper: total dependency call rate over 5 minutes
 template: am_appinsights_dependency_rate
       on: azure_monitor.application_insights.dependency_calls
    class: Workload
     type: Other
component: Application Insights
   lookup: average -5m unaligned of total
    units: calls/s
    every: 1m
  summary: App Insights dependency call rate on ${label:resource_name}
     info: Average dependency call rate for Application Insights resource ${label:resource_name} \
           in ${label:resource_group} (${label:region})
       to: silent

 template: am_appinsights_failed_dependencies
       on: azure_monitor.application_insights.dependency_calls
    class: Errors
     type: Other
component: Application Insights
   lookup: average -5m unaligned percentage of failed
    units: %
    every: 1m
     warn: ($am_appinsights_dependency_rate > 0.5) ? ($this > (($status >= $WARNING) ? (5) : (10))) : (0)
     crit: ($am_appinsights_dependency_rate > 0.5) ? ($this > (($status == $CRITICAL) ? (15) : (25))) : (0)
    delay: down 5m multiplier 1.5 max 1h
  summary: App Insights failed dependencies on ${label:resource_name}
     info: Percentage of failed dependency calls for Application Insights resource ${label:resource_name} \
           in ${label:resource_group} (${label:region})
       to: sysadmin

 template: am_appinsights_dependency_duration
       on: azure_monitor.application_insights.dependency_duration
    class: Latency
     type: Other
component: Application Insights
   lookup: average -5m unaligned of average
    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: App Insights dependency duration on ${label:resource_name}
     info: Average dependency call duration for Application Insights resource ${label:resource_name} \
           in ${label:resource_group} (${label:region})
       to: sysadmin

# ── Exceptions ───────────────────────────────────────────────────────────────

 template: am_appinsights_exception_rate
       on: azure_monitor.application_insights.exception_rate
    class: Errors
     type: Other
component: Application Insights
   lookup: average -5m unaligned of average
    units: exceptions/s
    every: 1m
     warn: $this != nan AND $this > (($status >= $WARNING)  ? (5) : (10))
     crit: $this != nan AND $this > (($status == $CRITICAL) ? (25) : (50))
    delay: down 5m multiplier 1.5 max 1h
  summary: App Insights exception rate on ${label:resource_name}
     info: Server exception rate for Application Insights resource ${label:resource_name} \
           in ${label:resource_group} (${label:region})
       to: sysadmin

 template: am_appinsights_server_exceptions
       on: azure_monitor.application_insights.exceptions
    class: Errors
     type: Other
component: Application Insights
   lookup: average -5m unaligned of server
    units: exceptions/s
    every: 1m
     warn: $this != nan AND $this > (($status >= $WARNING)  ? (5) : (10))
     crit: $this != nan AND $this > (($status == $CRITICAL) ? (25) : (50))
    delay: down 5m multiplier 1.5 max 1h
  summary: App Insights server exceptions on ${label:resource_name}
     info: Server-side exception rate for Application Insights resource ${label:resource_name} \
           in ${label:resource_group} (${label:region})
       to: sysadmin

# ── Browser Performance ──────────────────────────────────────────────────────

 template: am_appinsights_browser_page_load_time
       on: azure_monitor.application_insights.browser_page_load_time
    class: Latency
     type: Other
component: Application Insights
   lookup: average -5m unaligned of total
    units: milliseconds
    every: 1m
     warn: $this != nan AND $this > (($status >= $WARNING)  ? (5000)  : (10000))
     crit: $this != nan AND $this > (($status == $CRITICAL) ? (10000) : (20000))
    delay: down 5m multiplier 1.5 max 1h
  summary: App Insights browser page load time on ${label:resource_name}
     info: Average browser page load time for Application Insights resource ${label:resource_name} \
           in ${label:resource_group} (${label:region})
       to: sysadmin

# ── Performance - CPU ────────────────────────────────────────────────────────

 template: am_appinsights_process_cpu
       on: azure_monitor.application_insights.cpu_utilization
    class: Utilization
     type: Other
component: Application Insights
   lookup: average -5m unaligned of process
    units: percentage
    every: 1m
     warn: $this != nan AND $this > (($status >= $WARNING)  ? (75) : (85))
     crit: $this != nan AND $this > (($status == $CRITICAL) ? (85) : (95))
    delay: down 5m multiplier 1.5 max 1h
  summary: App Insights process CPU on ${label:resource_name}
     info: Application process CPU utilization for Application Insights resource ${label:resource_name} \
           in ${label:resource_group} (${label:region})
       to: sysadmin

 template: am_appinsights_processor_cpu
       on: azure_monitor.application_insights.cpu_utilization
    class: Utilization
     type: Other
component: Application Insights
   lookup: average -5m unaligned of processor
    units: percentage
    every: 1m
     warn: $this != nan AND $this > (($status >= $WARNING)  ? (80) : (90))
     crit: $this != nan AND $this > (($status == $CRITICAL) ? (90) : (95))
    delay: down 5m multiplier 1.5 max 1h
  summary: App Insights processor CPU on ${label:resource_name}
     info: Host processor CPU utilization for Application Insights resource ${label:resource_name} \
           in ${label:resource_group} (${label:region})
       to: sysadmin

# ── Performance - HTTP Pipeline ──────────────────────────────────────────────

 template: am_appinsights_http_execution_time
       on: azure_monitor.application_insights.http_request_execution_time
    class: Latency
     type: Other
component: Application Insights
   lookup: average -5m unaligned of average
    units: milliseconds
    every: 1m
     warn: $this != nan AND $this > (($status >= $WARNING)  ? (3000) : (5000))
     crit: $this != nan AND $this > (($status == $CRITICAL) ? (5000) : (10000))
    delay: down 5m multiplier 1.5 max 1h
  summary: App Insights HTTP execution time on ${label:resource_name}
     info: Average HTTP request execution time for Application Insights resource ${label:resource_name} \
           in ${label:resource_group} (${label:region})
       to: sysadmin

 template: am_appinsights_http_queue_length
       on: azure_monitor.application_insights.http_request_queue
    class: Utilization
     type: Other
component: Application Insights
   lookup: average -5m unaligned of queued
    units: requests
    every: 1m
     warn: $this != nan AND $this > (($status >= $WARNING)  ? (50)  : (100))
     crit: $this != nan AND $this > (($status == $CRITICAL) ? (100) : (250))
    delay: down 5m multiplier 1.5 max 1h
  summary: App Insights HTTP request queue on ${label:resource_name}
     info: Number of HTTP requests waiting in the application queue for Application Insights resource \
           ${label:resource_name} in ${label:resource_group} (${label:region})
       to: sysadmin

# ── Usage - Page Views ───────────────────────────────────────────────────────

 template: am_appinsights_page_view_load_time
       on: azure_monitor.application_insights.page_view_load_time
    class: Latency
     type: Other
component: Application Insights
   lookup: average -5m unaligned of average
    units: milliseconds
    every: 1m
     warn: $this != nan AND $this > (($status >= $WARNING)  ? (5000)  : (10000))
     crit: $this != nan AND $this > (($status == $CRITICAL) ? (10000) : (20000))
    delay: down 5m multiplier 1.5 max 1h
  summary: App Insights page view load time on ${label:resource_name}
     info: Average page view load time for Application Insights resource ${label:resource_name} \
           in ${label:resource_group} (${label:region})
       to: sysadmin
