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

# --- Availability ---

 template: am_cosmos_db_availability
       on: azure_monitor.cosmos_db.availability
    class: Availability
     type: Database
component: Cosmos DB
   lookup: average -10m unaligned of average
    units: percentage
    every: 1m
     warn: $this < (($status >= $WARNING)  ? (99.99) : (99.9))
     crit: $this < (($status == $CRITICAL) ? (99.9)  : (99))
    delay: down 5m multiplier 1.5 max 1h
  summary: Cosmos DB availability on ${label:resource_name}
     info: Service availability of Cosmos DB account ${label:resource_name} \
           in ${label:resource_group} (${label:region})
       to: dba

# --- Utilization ---

 template: am_cosmos_db_normalized_ru_consumption
       on: azure_monitor.cosmos_db.normalized_ru_consumption
    class: Utilization
     type: Database
component: Cosmos DB
   lookup: average -5m unaligned of maximum
    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: Cosmos DB RU consumption on ${label:resource_name}
     info: Normalized request unit consumption on Cosmos DB account ${label:resource_name} \
           in ${label:resource_group} (${label:region}). \
           High values indicate approaching provisioned throughput limit and risk of throttling
       to: dba

 template: am_cosmos_db_storage_utilization
       on: azure_monitor.cosmos_db.storage
    class: Utilization
     type: Database
component: Cosmos DB
     calc: ($quota > 0) ? (($data + $index) * 100 / $quota) : (0)
    units: %
    every: 5m
     warn: $this > (($status >= $WARNING)  ? (70) : (80))
     crit: $this > (($status == $CRITICAL) ? (80) : (90))
    delay: down 5m multiplier 1.5 max 1h
  summary: Cosmos DB storage utilization on ${label:resource_name}
     info: Data and index storage as a percentage of document quota on Cosmos DB account ${label:resource_name} \
           in ${label:resource_group} (${label:region})
       to: dba

# --- Latency ---

 template: am_cosmos_db_server_side_latency_direct
       on: azure_monitor.cosmos_db.server_side_latency
    class: Latency
     type: Database
component: Cosmos DB
   lookup: average -5m unaligned of direct
    units: milliseconds
    every: 1m
     warn: $this != nan AND $this > (($status >= $WARNING)  ? (8) : (10))
     crit: $this != nan AND $this > (($status == $CRITICAL) ? (10) : (15))
    delay: down 5m multiplier 1.5 max 1h
  summary: Cosmos DB direct latency on ${label:resource_name}
     info: Average server-side latency for direct connections on Cosmos DB account ${label:resource_name} \
           in ${label:resource_group} (${label:region})
       to: dba

 template: am_cosmos_db_server_side_latency_gateway
       on: azure_monitor.cosmos_db.server_side_latency
    class: Latency
     type: Database
component: Cosmos DB
   lookup: average -5m unaligned of gateway
    units: milliseconds
    every: 1m
     warn: $this != nan AND $this > (($status >= $WARNING)  ? (40) : (50))
     crit: $this != nan AND $this > (($status == $CRITICAL) ? (60) : (80))
    delay: down 5m multiplier 1.5 max 1h
  summary: Cosmos DB gateway latency on ${label:resource_name}
     info: Average server-side latency for gateway connections on Cosmos DB account ${label:resource_name} \
           in ${label:resource_group} (${label:region})
       to: dba

 template: am_cosmos_db_replication_latency
       on: azure_monitor.cosmos_db.replication_latency
    class: Latency
     type: Database
component: Cosmos DB
   lookup: average -5m unaligned of average
    units: milliseconds
    every: 1m
     warn: $this != nan AND $this > (($status >= $WARNING)  ? (100) : (200))
     crit: $this != nan AND $this > (($status == $CRITICAL) ? (200) : (500))
    delay: down 5m multiplier 1.5 max 1h
  summary: Cosmos DB replication latency on ${label:resource_name}
     info: Average geo-replication latency (P99) on Cosmos DB account ${label:resource_name} \
           in ${label:resource_group} (${label:region}). \
           Only relevant when multi-region writes are configured
       to: dba

# --- Dedicated Gateway ---

 template: am_cosmos_db_dedicated_gateway_cpu
       on: azure_monitor.cosmos_db.dedicated_gateway_cpu
    class: Utilization
     type: Database
component: Cosmos DB
   lookup: average -5m unaligned of average
    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: Cosmos DB dedicated gateway CPU on ${label:resource_name}
     info: CPU utilization of the dedicated gateway on Cosmos DB account ${label:resource_name} \
           in ${label:resource_group} (${label:region})
       to: dba

# --- Integrated Cache ---

 template: am_cosmos_db_integrated_cache_item_hit_rate
       on: azure_monitor.cosmos_db.integrated_cache_hit_rate
    class: Utilization
     type: Database
component: Cosmos DB
   lookup: average -10m unaligned of item
    units: percentage
    every: 5m
     warn: $this != nan AND $this < (($status >= $WARNING) ? (60) : (50))
    delay: down 5m multiplier 1.5 max 1h
  summary: Cosmos DB cache item hit rate on ${label:resource_name}
     info: Integrated cache item hit rate on Cosmos DB account ${label:resource_name} \
           in ${label:resource_group} (${label:region}). \
           Low hit rates indicate cache is not effectively reducing RU consumption
       to: dba

 template: am_cosmos_db_integrated_cache_query_hit_rate
       on: azure_monitor.cosmos_db.integrated_cache_hit_rate
    class: Utilization
     type: Database
component: Cosmos DB
   lookup: average -10m unaligned of query
    units: percentage
    every: 5m
     warn: $this != nan AND $this < (($status >= $WARNING) ? (60) : (50))
    delay: down 5m multiplier 1.5 max 1h
  summary: Cosmos DB cache query hit rate on ${label:resource_name}
     info: Integrated cache query hit rate on Cosmos DB account ${label:resource_name} \
           in ${label:resource_group} (${label:region}). \
           Low hit rates indicate cache is not effectively reducing RU consumption
       to: dba

# --- Cassandra API ---

 template: am_cosmos_db_cassandra_connection_closures
       on: azure_monitor.cosmos_db.cassandra_connections
    class: Errors
     type: Database
component: Cosmos DB
   lookup: average -5m unaligned of total
    units: connections/s
    every: 1m
     warn: $this != nan AND $this > (($status >= $WARNING) ? (5) : (10))
    delay: down 5m multiplier 1.5 max 1h
  summary: Cosmos DB Cassandra connection closures on ${label:resource_name}
     info: Rate of Cassandra connection closures on Cosmos DB account ${label:resource_name} \
           in ${label:resource_group} (${label:region}). \
           Only relevant for accounts using the Cassandra API
       to: dba
