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

# --- CPU ---

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

# CPU credits are only available on burstable B-series VMs.
# NaN guard: remaining is NaN on non-burstable VM sizes.

 template: am_vm_cpu_credits_remaining
       on: azure_monitor.virtual_machines.cpu_credits
    class: Utilization
     type: System
component: Azure VM
   lookup: average -5m unaligned of remaining
    units: credits
    every: 1m
     warn: $this != nan AND $this < (($status >= $WARNING)  ? (30) : (20))
     crit: $this != nan AND $this < (($status == $CRITICAL) ? (20) : (10))
    delay: down 5m multiplier 1.5 max 1h
  summary: VM CPU credits low on ${label:resource_name}
     info: CPU credits remaining on burstable Azure VM ${label:resource_name} \
           in ${label:resource_group} (${label:region}). \
           When credits are exhausted, CPU performance is capped.
       to: sysadmin

# --- Memory ---
# Available Memory Percentage: low is bad.

 template: am_vm_memory_available
       on: azure_monitor.virtual_machines.memory_percentage
    class: Utilization
     type: System
component: Azure VM
   lookup: average -5m unaligned of available
    units: percentage
    every: 1m
     warn: $this < (($status >= $WARNING)  ? (15) : (10))
     crit: $this < (($status == $CRITICAL) ? (10) : (5))
    delay: down 5m multiplier 1.5 max 1h
  summary: VM available memory on ${label:resource_name}
     info: Available memory percentage on Azure VM ${label:resource_name} \
           in ${label:resource_group} (${label:region})
       to: sysadmin

# --- Availability ---
# VmAvailabilityMetric: 1 = available, < 1 = degraded/unavailable.

 template: am_vm_availability
       on: azure_monitor.virtual_machines.availability
    class: Availability
     type: System
component: Azure VM
   lookup: average -5m unaligned of average
    units: state
    every: 1m
     crit: $this < 1
    delay: down 5m multiplier 1.5 max 1h
  summary: VM unavailable ${label:resource_name}
     info: Azure VM ${label:resource_name} in ${label:resource_group} (${label:region}) \
           is reporting degraded or unavailable state
       to: sysadmin

# --- OS Disk Latency ---

 template: am_vm_os_disk_latency
       on: azure_monitor.virtual_machines.os_disk_latency
    class: Latency
     type: System
component: Azure VM
   lookup: average -5m unaligned of average
    units: milliseconds
    every: 1m
     warn: $this > (($status >= $WARNING)  ? (30) : (50))
     crit: $this > (($status == $CRITICAL) ? (50) : (100))
    delay: down 5m multiplier 1.5 max 1h
  summary: VM OS disk latency on ${label:resource_name}
     info: Average OS disk latency on Azure VM ${label:resource_name} \
           in ${label:resource_group} (${label:region}). \
           High latency indicates disk I/O bottleneck.
       to: sysadmin

# --- OS Disk Queue Depth ---

 template: am_vm_os_disk_queue_depth
       on: azure_monitor.virtual_machines.os_disk_queue_depth
    class: Utilization
     type: System
component: Azure VM
   lookup: average -5m unaligned of average
    units: operations
    every: 1m
     warn: $this > (($status >= $WARNING)  ? (16) : (32))
     crit: $this > (($status == $CRITICAL) ? (32) : (64))
    delay: down 5m multiplier 1.5 max 1h
  summary: VM OS disk queue depth on ${label:resource_name}
     info: Average OS disk queue depth on Azure VM ${label:resource_name} \
           in ${label:resource_group} (${label:region}). \
           High queue depth indicates I/O saturation.
       to: sysadmin

# --- OS Disk Throttling ---
# Bandwidth and IOPS consumed percentage. High values mean the disk
# is approaching its provisioned performance limit and may be throttled.

 template: am_vm_os_disk_bandwidth_throttling
       on: azure_monitor.virtual_machines.os_disk_throttling
    class: Utilization
     type: System
component: Azure VM
   lookup: average -5m unaligned of bandwidth
    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: VM OS disk bandwidth throttling on ${label:resource_name}
     info: OS disk bandwidth consumed percentage on Azure VM ${label:resource_name} \
           in ${label:resource_group} (${label:region}). \
           Approaching the provisioned bandwidth limit causes throttling.
       to: sysadmin

 template: am_vm_os_disk_iops_throttling
       on: azure_monitor.virtual_machines.os_disk_throttling
    class: Utilization
     type: System
component: Azure VM
   lookup: average -5m unaligned of iops
    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: VM OS disk IOPS throttling on ${label:resource_name}
     info: OS disk IOPS consumed percentage on Azure VM ${label:resource_name} \
           in ${label:resource_group} (${label:region}). \
           Approaching the provisioned IOPS limit causes throttling.
       to: sysadmin

# --- OS Disk Burst Credits ---
# Burst credit usage: high means credits are being depleted.
# NaN guard: burst credits are only available on eligible disk tiers.

 template: am_vm_os_disk_burst_bps_credits
       on: azure_monitor.virtual_machines.os_disk_burst_credits
    class: Utilization
     type: System
component: Azure VM
   lookup: average -5m unaligned of bandwidth
    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: VM OS disk burst bandwidth credits on ${label:resource_name}
     info: OS disk burst bandwidth credits consumed on Azure VM ${label:resource_name} \
           in ${label:resource_group} (${label:region}). \
           When credits are exhausted, disk throughput drops to baseline.
       to: sysadmin

 template: am_vm_os_disk_burst_io_credits
       on: azure_monitor.virtual_machines.os_disk_burst_credits
    class: Utilization
     type: System
component: Azure VM
   lookup: average -5m unaligned of io
    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: VM OS disk burst IO credits on ${label:resource_name}
     info: OS disk burst IO credits consumed on Azure VM ${label:resource_name} \
           in ${label:resource_group} (${label:region}). \
           When credits are exhausted, disk IOPS drops to baseline.
       to: sysadmin

# --- Data Disk Latency ---

 template: am_vm_data_disk_latency
       on: azure_monitor.virtual_machines.data_disk_latency
    class: Latency
     type: System
component: Azure VM
   lookup: average -5m unaligned of average
    units: milliseconds
    every: 1m
     warn: $this > (($status >= $WARNING)  ? (30) : (50))
     crit: $this > (($status == $CRITICAL) ? (50) : (100))
    delay: down 5m multiplier 1.5 max 1h
  summary: VM data disk latency on ${label:resource_name}
     info: Average data disk latency on Azure VM ${label:resource_name} \
           in ${label:resource_group} (${label:region}). \
           High latency indicates disk I/O bottleneck.
       to: sysadmin

# --- Data Disk Queue Depth ---

 template: am_vm_data_disk_queue_depth
       on: azure_monitor.virtual_machines.data_disk_queue_depth
    class: Utilization
     type: System
component: Azure VM
   lookup: average -5m unaligned of average
    units: operations
    every: 1m
     warn: $this > (($status >= $WARNING)  ? (16) : (32))
     crit: $this > (($status == $CRITICAL) ? (32) : (64))
    delay: down 5m multiplier 1.5 max 1h
  summary: VM data disk queue depth on ${label:resource_name}
     info: Average data disk queue depth on Azure VM ${label:resource_name} \
           in ${label:resource_group} (${label:region}). \
           High queue depth indicates I/O saturation.
       to: sysadmin

# --- Data Disk Throttling ---

 template: am_vm_data_disk_bandwidth_throttling
       on: azure_monitor.virtual_machines.data_disk_throttling
    class: Utilization
     type: System
component: Azure VM
   lookup: average -5m unaligned of bandwidth
    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: VM data disk bandwidth throttling on ${label:resource_name}
     info: Data disk bandwidth consumed percentage on Azure VM ${label:resource_name} \
           in ${label:resource_group} (${label:region}). \
           Approaching the provisioned bandwidth limit causes throttling.
       to: sysadmin

 template: am_vm_data_disk_iops_throttling
       on: azure_monitor.virtual_machines.data_disk_throttling
    class: Utilization
     type: System
component: Azure VM
   lookup: average -5m unaligned of iops
    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: VM data disk IOPS throttling on ${label:resource_name}
     info: Data disk IOPS consumed percentage on Azure VM ${label:resource_name} \
           in ${label:resource_group} (${label:region}). \
           Approaching the provisioned IOPS limit causes throttling.
       to: sysadmin

# --- Data Disk Burst Credits ---
# NaN guard: burst credits are only available on eligible disk tiers.

 template: am_vm_data_disk_burst_bps_credits
       on: azure_monitor.virtual_machines.data_disk_burst_credits
    class: Utilization
     type: System
component: Azure VM
   lookup: average -5m unaligned of bandwidth
    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: VM data disk burst bandwidth credits on ${label:resource_name}
     info: Data disk burst bandwidth credits consumed on Azure VM ${label:resource_name} \
           in ${label:resource_group} (${label:region}). \
           When credits are exhausted, disk throughput drops to baseline.
       to: sysadmin

 template: am_vm_data_disk_burst_io_credits
       on: azure_monitor.virtual_machines.data_disk_burst_credits
    class: Utilization
     type: System
component: Azure VM
   lookup: average -5m unaligned of io
    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: VM data disk burst IO credits on ${label:resource_name}
     info: Data disk burst IO credits consumed on Azure VM ${label:resource_name} \
           in ${label:resource_group} (${label:region}). \
           When credits are exhausted, disk IOPS drops to baseline.
       to: sysadmin

# --- VM-Level Cached IO Throttling ---
# VM-level limits are separate from individual disk limits.
# The VM can be throttled even when individual disks are not.

 template: am_vm_cached_bandwidth_throttling
       on: azure_monitor.virtual_machines.vm_cached_throttling
    class: Utilization
     type: System
component: Azure VM
   lookup: average -5m unaligned of bandwidth
    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: VM cached bandwidth throttling on ${label:resource_name}
     info: VM-level cached bandwidth consumed percentage on Azure VM ${label:resource_name} \
           in ${label:resource_group} (${label:region}). \
           VM-level throttling affects all disks on the VM.
       to: sysadmin

 template: am_vm_cached_iops_throttling
       on: azure_monitor.virtual_machines.vm_cached_throttling
    class: Utilization
     type: System
component: Azure VM
   lookup: average -5m unaligned of iops
    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: VM cached IOPS throttling on ${label:resource_name}
     info: VM-level cached IOPS consumed percentage on Azure VM ${label:resource_name} \
           in ${label:resource_group} (${label:region}). \
           VM-level throttling affects all disks on the VM.
       to: sysadmin

# --- VM-Level Uncached IO Throttling ---

 template: am_vm_uncached_bandwidth_throttling
       on: azure_monitor.virtual_machines.vm_uncached_throttling
    class: Utilization
     type: System
component: Azure VM
   lookup: average -5m unaligned of bandwidth
    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: VM uncached bandwidth throttling on ${label:resource_name}
     info: VM-level uncached bandwidth consumed percentage on Azure VM ${label:resource_name} \
           in ${label:resource_group} (${label:region}). \
           VM-level throttling affects all disks on the VM.
       to: sysadmin

 template: am_vm_uncached_iops_throttling
       on: azure_monitor.virtual_machines.vm_uncached_throttling
    class: Utilization
     type: System
component: Azure VM
   lookup: average -5m unaligned of iops
    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: VM uncached IOPS throttling on ${label:resource_name}
     info: VM-level uncached IOPS consumed percentage on Azure VM ${label:resource_name} \
           in ${label:resource_group} (${label:region}). \
           VM-level throttling affects all disks on the VM.
       to: sysadmin

# --- VM-Level Burst Credits ---
# NaN guard: burst credits are only available on burstable VM sizes.

 template: am_vm_cached_burst_bps_credits
       on: azure_monitor.virtual_machines.vm_cached_burst_credits
    class: Utilization
     type: System
component: Azure VM
   lookup: average -5m unaligned of bandwidth
    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: VM cached burst bandwidth credits on ${label:resource_name}
     info: VM-level cached burst bandwidth credits consumed on Azure VM ${label:resource_name} \
           in ${label:resource_group} (${label:region}). \
           When credits are exhausted, cached I/O throughput drops to baseline.
       to: sysadmin

 template: am_vm_cached_burst_io_credits
       on: azure_monitor.virtual_machines.vm_cached_burst_credits
    class: Utilization
     type: System
component: Azure VM
   lookup: average -5m unaligned of io
    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: VM cached burst IO credits on ${label:resource_name}
     info: VM-level cached burst IO credits consumed on Azure VM ${label:resource_name} \
           in ${label:resource_group} (${label:region}). \
           When credits are exhausted, cached IOPS drops to baseline.
       to: sysadmin

 template: am_vm_uncached_burst_bps_credits
       on: azure_monitor.virtual_machines.vm_uncached_burst_credits
    class: Utilization
     type: System
component: Azure VM
   lookup: average -5m unaligned of bandwidth
    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: VM uncached burst bandwidth credits on ${label:resource_name}
     info: VM-level uncached burst bandwidth credits consumed on Azure VM ${label:resource_name} \
           in ${label:resource_group} (${label:region}). \
           When credits are exhausted, uncached I/O throughput drops to baseline.
       to: sysadmin

 template: am_vm_uncached_burst_io_credits
       on: azure_monitor.virtual_machines.vm_uncached_burst_credits
    class: Utilization
     type: System
component: Azure VM
   lookup: average -5m unaligned of io
    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: VM uncached burst IO credits on ${label:resource_name}
     info: VM-level uncached burst IO credits consumed on Azure VM ${label:resource_name} \
           in ${label:resource_group} (${label:region}). \
           When credits are exhausted, uncached IOPS drops to baseline.
       to: sysadmin
