所以我定义了以下 Terraform 资源。我不太确定窗口大小到底是多少。 % 连续 30 分钟?
resource "azurerm_monitor_metric_alert" "cpu_percent" {
name = "alert-${azurerm_postgresql_flexible_server.pgsql_server.name}-cpupercent"
resource_group_name = data.azurerm_resource_group.resource_group.name
scopes = [azurerm_postgresql_flexible_server.pgsql_server.id]
description = "Action will be triggered Whenever the maximum cpu percent is greater than 100% for 30 minutes."
window_size = "PT30M"
frequency = "PT15M"
severity = 0
criteria {
metric_namespace = "Microsoft.DBforPostgreSQL/flexibleServers"
metric_name = "cpu_percent"
aggregation = "Maximum"
operator = "Equals"
threshold = 100
}
我是否正确地假设这意味着 Azure 每 15 分钟检查一次数据库,并在最大 CPU 为 100 时发出警报?
使用 terraform 设置 Azure 监控警报 100% CPU 30 分钟
Terraform 配置,为 Azure PostgreSQL 灵活服务器上的 CPU 使用情况设置指标警报。如果 CPU 使用率在过去 30 分钟内的任何时候达到 100%,此警报应每 15 分钟检查一次,就像我在下面提到的那样。
我的 Terraform 配置:
provider "azurerm" {
features {}
}
resource "azurerm_resource_group" "resource_group" {
name = "vksb-resources"
location = "East US"
}
resource "azurerm_postgresql_flexible_server" "pgsql_server" {
name = "vksbepgserver"
resource_group_name = azurerm_resource_group.resource_group.name
location = azurerm_resource_group.resource_group.location
sku_name = "GP_Standard_D4s_v3"
administrator_login = "adminuser"
administrator_password = "H@Sh1CoR3!"
storage_mb = 32768
version = "12"
}
data "azurerm_resource_group" "resource_group" {
name = azurerm_resource_group.resource_group.name
}
resource "azurerm_monitor_metric_alert" "cpu_percent" {
name = "alert-${azurerm_postgresql_flexible_server.pgsql_server.name}-cpupercent"
resource_group_name = data.azurerm_resource_group.resource_group.name
scopes = [azurerm_postgresql_flexible_server.pgsql_server.id]
description = "Action will be triggered whenever the maximum CPU percent is greater than 100% for 30 minutes."
window_size = "PT30M"
frequency = "PT15M"
severity = 0
criteria {
metric_namespace = "Microsoft.DBforPostgreSQL/flexibleServers"
metric_name = "cpu_percent"
aggregation = "Maximum"
operator = "Equals"
threshold = 100
}
}
部署成功: