I’m having a problem creating metric alerts for a mysql instance using terraform. The error is referencing metric namespaces. I’m wondering if mysql and postgre are not supported with metric namespaces. Here’s an example (edited):
resource "azurerm_mysql_server" "mysql-server" {
location = module.resource-group.location
resource_group_name = module.resource-group.name
name = "test-mysql-monitor"
administrator_login = local.administrator_login
administrator_login_password = local.administrator_password
sku_name = var.mysql-sku-name
version = var.mysql-version
storage_mb = var.mysql-storage
auto_grow_enabled = true
backup_retention_days = 7
geo_redundant_backup_enabled = false
public_network_access_enabled = true
ssl_enforcement_enabled = true
ssl_minimal_tls_version_enforced = "TLS1_2"
}
# Create a MySQL database
resource "azurerm_mysql_database" "mysql-db" {
name = "pwtestmsql"
resource_group_name = module.resource-group.name
server_name = azurerm_mysql_server.mysql-server.name
charset = "utf8"
collation = "utf8_unicode_ci"
}
# Create an action group
resource "azurerm_monitor_action_group" "azuremag" {
name = var.action_group_name
resource_group_name = azurerm_mysql_database.mysql-db.resource_group_name
short_name = var.short_name
email_receiver {
name = var.receiver_name
email_address = var.email_address
use_common_alert_schema = var.alert_schema
}
}
resource "azurerm_monitor_metric_alert" "az_mysql_alert" {
name = "Failed Connections"
resource_group_name = azurerm_mysql_database.mysql-db.resource_group_name
scopes = [azurerm_mysql_database.mysql-db.id]
description = "An alert rule to watch for failed connections"
frequency = "PT5M"
criteria {
metric_name = "connections_failed"
operator = "GreaterThan"
threshold = 10
aggregation = "Average"
metric_namespace = "Microsoft.DBforMySQL/serversv2"
}
action {
action_group_id = azurerm_monitor_action_group.azuremag.id
}
}
I get the following error
Error: Error creating or updating metric alert “Failed Connections” (resource group “app-pwmysql-sandbox-useast2”): insights.MetricAlertsClient#CreateOrUpdate: Failure responding to request: StatusCode=400 – Original Error: autorest/azure: Service returned an error. Status=400 Code=“ResourceNotFound” Message="{“code”:“BadRequest”,“message”:“Detect invalid value: Microsoft.DBforMySQL/serversv2 for query parameter: ‘metricnamespace’, the value must be: Microsoft.DBforMySQL/servers/databases if the query parameter is provided, you can also skip this optional query parameter.”} Activity ID: 517d2151-3672-45cb-aeb7-dc42530aedb6."
I’ve tried using Microsoft.DBforMySQL/servers/databases but that returns an error as well. Here’s a link to the documentation: https://docs.microsoft.com/en-us/azure/azure-monitor/platform/alerts-metric-near-real-time
It looks like there is limited support for some of these resources with metric namespaces, and that might be the problem.