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

# --- Server Load ---

 template: am_redis_cache_server_load
       on: azure_monitor.redis_cache.server_load
    class: Utilization
     type: Database
component: Azure Redis
   lookup: average -5m unaligned of maximum
    units: percentage
    every: 1m
     warn: $this > (($status >= $WARNING)  ? (75) : (85))
     crit: $this > (($status == $CRITICAL) ? (85) : (95))
    delay: down 5m multiplier 1.5 max 1h
  summary: Redis server load on ${label:resource_name}
     info: Maximum server load on Azure Cache for Redis ${label:resource_name} \
           in ${label:resource_group} (${label:region}). \
           Sustained high server load causes timeouts and increased latency
       to: dba

# --- CPU ---

 template: am_redis_cache_cpu
       on: azure_monitor.redis_cache.cpu
    class: Utilization
     type: Database
component: Azure Redis
   lookup: average -5m unaligned of maximum
    units: percentage
    every: 1m
     warn: $this > (($status >= $WARNING)  ? (75) : (85))
     crit: $this > (($status == $CRITICAL) ? (85) : (95))
    delay: down 5m multiplier 1.5 max 1h
  summary: Redis CPU on ${label:resource_name}
     info: Maximum CPU utilization on Azure Cache for Redis ${label:resource_name} \
           in ${label:resource_group} (${label:region})
       to: dba

# --- Memory Utilization ---

 template: am_redis_cache_memory_utilization
       on: azure_monitor.redis_cache.memory_utilization
    class: Utilization
     type: Database
component: Azure Redis
   lookup: average -5m unaligned of maximum
    units: percentage
    every: 1m
     warn: $this > (($status >= $WARNING)  ? (75) : (85))
     crit: $this > (($status == $CRITICAL) ? (85) : (95))
    delay: down 5m multiplier 1.5 max 1h
  summary: Redis memory utilization on ${label:resource_name}
     info: Maximum memory utilization on Azure Cache for Redis ${label:resource_name} \
           in ${label:resource_group} (${label:region}). \
           High memory causes evictions and potential data loss
       to: dba

# --- Cache Miss Rate ---

 template: am_redis_cache_miss_rate
       on: azure_monitor.redis_cache.miss_rate
    class: Utilization
     type: Database
component: Azure Redis
   lookup: average -10m unaligned of miss_rate
    units: percentage
    every: 1m
     warn: $this > (($status >= $WARNING)  ? (40) : (50))
    delay: down 5m multiplier 1.5 max 1h
  summary: Redis cache miss rate on ${label:resource_name}
     info: Cache miss rate on Azure Cache for Redis ${label:resource_name} \
           in ${label:resource_group} (${label:region}). \
           High miss rates indicate the cache is not effectively serving requests
       to: dba

# --- Errors ---

 template: am_redis_cache_errors
       on: azure_monitor.redis_cache.errors
    class: Errors
     type: Database
component: Azure Redis
   lookup: average -5m unaligned of maximum
    units: errors
    every: 1m
     warn: $this > (($status >= $WARNING)  ? (0) : (5))
     crit: $this > (($status == $CRITICAL) ? (5) : (20))
    delay: down 5m multiplier 1.5 max 1h
  summary: Redis errors on ${label:resource_name}
     info: Errors on Azure Cache for Redis ${label:resource_name} \
           in ${label:resource_group} (${label:region}). \
           Includes authentication failures, maxmemory errors, and connection issues
       to: dba

# --- Latency (average) ---

 template: am_redis_cache_latency
       on: azure_monitor.redis_cache.latency
    class: Latency
     type: Database
component: Azure Redis
   lookup: average -5m unaligned of average
    units: microseconds
    every: 1m
     warn: $this > (($status >= $WARNING)  ? (5000) : (10000))
     crit: $this > (($status == $CRITICAL) ? (10000) : (30000))
    delay: down 5m multiplier 1.5 max 1h
  summary: Redis average latency on ${label:resource_name}
     info: Average cache latency on Azure Cache for Redis ${label:resource_name} \
           in ${label:resource_group} (${label:region})
       to: dba

# --- Latency P99 ---

 template: am_redis_cache_latency_p99
       on: azure_monitor.redis_cache.latency_p99
    class: Latency
     type: Database
component: Azure Redis
   lookup: average -5m unaligned of p99
    units: microseconds
    every: 1m
     warn: $this > (($status >= $WARNING)  ? (10000) : (20000))
     crit: $this > (($status == $CRITICAL) ? (20000) : (50000))
    delay: down 5m multiplier 1.5 max 1h
  summary: Redis P99 latency on ${label:resource_name}
     info: P99 latency on Azure Cache for Redis ${label:resource_name} \
           in ${label:resource_group} (${label:region}). \
           Tail latency spikes indicate resource pressure or network issues
       to: dba

# --- Key Evictions ---

 template: am_redis_cache_evicted_keys
       on: azure_monitor.redis_cache.key_events
    class: Errors
     type: Database
component: Azure Redis
   lookup: average -5m unaligned of evicted
    units: keys/s
    every: 1m
     warn: $this > (($status >= $WARNING)  ? (50) : (100))
     crit: $this > (($status == $CRITICAL) ? (100) : (500))
    delay: down 5m multiplier 1.5 max 1h
  summary: Redis key evictions on ${label:resource_name}
     info: Rate of evicted keys on Azure Cache for Redis ${label:resource_name} \
           in ${label:resource_group} (${label:region}). \
           Key evictions indicate the cache is running out of memory
       to: dba

# --- Geo-Replication Health (optional — only present when geo-replication is configured) ---

 template: am_redis_cache_geo_replication_health
       on: azure_monitor.redis_cache.geo_replication_health
    class: Availability
     type: Database
component: Azure Redis
   lookup: average -5m unaligned of average
    units: status
    every: 1m
     crit: $this != nan AND $this < 1
    delay: down 5m multiplier 1.5 max 1h
  summary: Redis geo-replication health on ${label:resource_name}
     info: Geo-replication link health on Azure Cache for Redis ${label:resource_name} \
           in ${label:resource_group} (${label:region}). \
           A value below 1 indicates the replication link is unhealthy
       to: dba

# --- Geo-Replication Lag (optional — only present when geo-replication is configured) ---

 template: am_redis_cache_geo_replication_lag
       on: azure_monitor.redis_cache.geo_replication_lag
    class: Latency
     type: Database
component: Azure Redis
   lookup: average -5m unaligned of average
    units: seconds
    every: 1m
     warn: $this != nan AND $this > (($status >= $WARNING)  ? (5) : (10))
     crit: $this != nan AND $this > (($status == $CRITICAL) ? (10) : (30))
    delay: down 5m multiplier 1.5 max 1h
  summary: Redis geo-replication lag on ${label:resource_name}
     info: Geo-replication connectivity lag on Azure Cache for Redis ${label:resource_name} \
           in ${label:resource_group} (${label:region}). \
           High lag indicates network issues between primary and secondary regions
       to: dba

# --- Geo-Replication Sync Offset (optional — only present when geo-replication is configured) ---

 template: am_redis_cache_geo_replication_sync_offset
       on: azure_monitor.redis_cache.geo_replication_sync_offset
    class: Latency
     type: Database
component: Azure Redis
   lookup: average -5m unaligned of average
    units: bytes
    every: 1m
     warn: $this != nan AND $this > (($status >= $WARNING)  ? (1048576) : (5242880))
     crit: $this != nan AND $this > (($status == $CRITICAL) ? (5242880) : (52428800))
    delay: down 5m multiplier 1.5 max 1h
  summary: Redis geo-replication sync offset on ${label:resource_name}
     info: Geo-replication data sync offset on Azure Cache for Redis ${label:resource_name} \
           in ${label:resource_group} (${label:region}). \
           Large offset indicates the secondary is falling behind the primary
       to: dba
