使用ARM 模板,我想为我的Azure SQL 数据库启用诊断设置,并将该数据存储在我创建的Log Analytics 工作区中。我想启用错误、超时、阻塞和等待统计日志以及基本指标选项。我能够使用 Web 应用程序来实现此功能,因此我采用了类似的方法,但我的模板失败并抛出错误,指出我引用的指标或诊断类别不存在或不受支持。这是我的模板的一些资源部分:
我不确定是否需要在模板中启用或引用其他设置才能使其正常工作,但我将不胜感激,谢谢!
"resources": [
{
"type": "databases",
"apiVersion": "2019-06-01-preview",
"name": "[parameters('sqlDatabase')]",
"location": "[parameters('location')]",
"tags": {},
"dependsOn": [
"[parameters('sqlServer')]"
],
"sku": {
"name": "GP_Gen5_4",
"tier": "GeneralPurpose"
},
"properties": {
"startIpAddress": "0.0.0.0",
"endIpAddress": "0.0.0.0"
}
},
{
"type": "providers/diagnosticSettings",
"name": "[concat('Microsoft.Insights/', parameters('diagnostics-name'))]",
"dependsOn": [
"[resourceId('Microsoft.Sql/servers', parameters('sqlServer'))]",
"[resourceId('Microsoft.Sql/servers/databases', parameters('sqlServer'), parameters('sqlDatabase'))]"
],
"apiVersion": "2017-05-01-preview",
"properties": {
"name": "[parameters('diagnostics-name')]",
"workspaceId": "[concat('subscriptions/', subscription().subscriptionId, '/resourceGroups/', parameters('loganalytics-rg'), '/providers/Microsoft.OperationalInsights/workspaces/', parameters('workspacename'))]",
"logs": [
{
"category": "Errors",
"enabled": "true",
"retentionPolicy": {
"enabled": "true",
"days": 7
}
},
{
"category": "DatabaseWaitStatistics",
"enabled": "true",
"retentionPolicy": {
"enabled": "true",
"days": 7
}
},
{
"category": "Timeouts",
"enabled": "true",
"retentionPolicy": {
"enabled": "true",
"days": 7
}
},
{
"category": "Blocks",
"enabled": "true",
"retentionPolicy": {
"enabled": "true",
"days": 7
}
}
]
}
}
]
}
]
}
在对我的 ARM 模板进行以下更改后,我能够部署一个 azure sql 服务器和数据库,并在数据库上启用了诊断,从而将诊断日志定向到现有的 Log Analytics 工作区: