Skip to content

massdriver-cloud/terraform-massdriver-azure-metric-alarm

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Azure Metric Alarm Terraform module

Terraform module that creates a Massdriver-integrated Azure Monitor metric alert. Supports both static threshold alarms and dynamic threshold alarms (Azure ML-based) in a single module.

This module is designed to be used alongside terraform-massdriver-azure-alarm-channel, which creates the Action Group that alarm notifications are published to.

Features

  • Creates an Azure Monitor metric alert with Action Group integration for alarm notifications
  • Supports static threshold alarms (metric_name, metric_namespace, aggregation, operator, threshold)
  • Supports dynamic threshold alarms (dynamic_criteria) where Azure ML determines thresholds based on historical metric patterns
  • Validates inputs at plan time to enforce mutual exclusivity between the two modes
  • Registers the alarm with Massdriver for UI visibility via massdriver_package_alarm

Usage

Static threshold alarm

module "alarm_channel" {
  source = "massdriver-cloud/azure-alarm-channel/massdriver"

  md_metadata = var.md_metadata
}

module "cpu_alarm" {
  source = "massdriver-cloud/azure-metric-alarm/massdriver"

  alarm_name   = "${var.md_metadata.name_prefix}-cpu-high"
  display_name = "CPU High"
  message      = "CPU utilization exceeded threshold"

  monitor_action_group_id = module.alarm_channel.id
  md_metadata             = var.md_metadata
  resource_group_name     = azurerm_resource_group.main.name
  scopes                  = [azurerm_linux_virtual_machine.main.id]

  severity    = 2
  frequency   = "PT5M"
  window_size = "PT15M"

  metric_namespace = "Microsoft.Compute/virtualMachines"
  metric_name      = "Percentage CPU"
  aggregation      = "Average"
  operator         = "GreaterThanOrEqual"
  threshold        = 80
}

Dynamic threshold alarm

module "latency_alarm" {
  source = "massdriver-cloud/azure-metric-alarm/massdriver"

  alarm_name   = "${var.md_metadata.name_prefix}-latency-anomaly"
  display_name = "Latency Anomaly"
  message      = "Request latency is outside normal range"

  monitor_action_group_id = module.alarm_channel.id
  md_metadata             = var.md_metadata
  resource_group_name     = azurerm_resource_group.main.name
  scopes                  = [azurerm_app_service.main.id]

  severity    = 2
  frequency   = "PT5M"
  window_size = "PT15M"

  dynamic_criteria = {
    metric_namespace         = "Microsoft.Web/sites"
    metric_name              = "HttpResponseTime"
    aggregation              = "Average"
    operator                 = "GreaterThan"
    alert_sensitivity        = "Medium"
    evaluation_total_count   = 4
    evaluation_failure_count = 4
  }
}

Requirements

Name Version
terraform >= 1.0
azurerm >= 3.0
massdriver >= 1.0

Providers

Name Version
azurerm 4.68.0
massdriver 1.3.4

Modules

No modules.

Resources

Name Type
azurerm_monitor_metric_alert.main resource
massdriver_package_alarm.package_alarm resource

Inputs

Name Description Type Default Required
aggregation The statistic that runs over the metric values. Possible values are Average, Count, Minimum, Maximum, and Total. Required when metric_name is set. string null no
alarm_name The name of the metric alert. Must be unique within the resource group. string n/a yes
dimensions Dimensions for the static metric criteria. The dimension operator accepts Include, Exclude, or StartsWith.
set(object({
name = string
operator = string
values = list(string)
}))
[] no
display_name Short name to display in the Massdriver UI. string n/a yes
dynamic_criteria Dynamic threshold criteria configuration. Uses Azure ML to determine thresholds automatically based on historical metric patterns. Set alert_sensitivity to High, Medium, or Low. The operator must be LessThan, GreaterThan, or GreaterOrLessThan (differs from static criteria). Conflicts with static criteria variables (metric_name, metric_namespace, etc.).
object({
metric_namespace = string
metric_name = string
aggregation = string
operator = string
alert_sensitivity = string
evaluation_total_count = optional(number)
evaluation_failure_count = optional(number)
ignore_data_before = optional(string)
dimensions = optional(set(object({
name = string
operator = string
values = list(string)
})), [])
})
null no
frequency The evaluation frequency represented in ISO 8601 duration format. Possible values are PT1M, PT5M, PT15M, PT30M, and PT1H. string n/a yes
md_metadata Massdriver metadata object, must include name_prefix. any n/a yes
message Message to include in the alarm description. string n/a yes
metric_name The metric name to monitor. Required for static criteria alarms, conflicts with dynamic_criteria. string null no
metric_namespace The metric namespace to monitor. Required for static criteria alarms, conflicts with dynamic_criteria. string null no
monitor_action_group_id Massdriver alarm channel Action Group ID. string n/a yes
operator The criteria operator. Possible values are Equals, GreaterThan, GreaterThanOrEqual, LessThan, and LessThanOrEqual. Required when metric_name is set. string null no
resource_group_name The name of the resource group for the metric alert. string n/a yes
scopes A set of resource IDs at which the metric criteria should be applied. set(string) n/a yes
severity The severity of the metric alert. Possible values are 0, 1, 2, 3, and 4. number n/a yes
threshold The criteria threshold value that activates the alert. Required when metric_name is set. number null no
window_size The period of time used to monitor alert activity, represented in ISO 8601 duration format. Must be greater than frequency. Possible values are PT1M, PT5M, PT15M, PT30M, PT1H, PT6H, PT12H, and P1D. string n/a yes

Outputs

Name Description
id The ID of the Azure Monitor metric alert.

Authors

Module is maintained by Massdriver, Inc.

License

Apache 2 Licensed. See LICENSE for full details.

Packages

 
 
 

Contributors

Languages