![ARM 模板 - Azure SQL 数据库诊断和日志分析工作区](https://linux22.com/image/760287/ARM%20%E6%A8%A1%E6%9D%BF%20-%20Azure%20SQL%20%E6%95%B0%E6%8D%AE%E5%BA%93%E8%AF%8A%E6%96%AD%E5%92%8C%E6%97%A5%E5%BF%97%E5%88%86%E6%9E%90%E5%B7%A5%E4%BD%9C%E5%8C%BA.png)
使用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
}
}
]
}
}
]
}
]
}
答案1
对我的 ARM 模板进行以下更改后,我能够部署一个 Azure SQL 服务器和数据库,并在 DB 上启用诊断功能,将诊断日志定向到现有的 Log Analytics 工作区:
"resources": [
{
"type": "Microsoft.Sql/servers",
"apiVersion": "2019-06-01-preview",
"name": "[parameters('sqlServer')]",
"location": "[parameters('location')]",
"properties": {
"administratorLogin": "[parameters('adminLogin')]",
"administratorLoginPassword": "[parameters('adminPassword')]",
"version": "12.0"
},
"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": "microsoft.sql/servers/databases/providers/diagnosticSettings",
"name": "[concat(parameters('sqlServer'),'/',parameters('sqlDatabase'),'/microsoft.insights/', parameters('diagnostics-name'))]",
"dependsOn": [
"[parameters('sqlServer')]",
"[parameters('sqlDatabase')]"
],
"apiVersion": "2017-05-01-preview",
"properties": {
"workspaceId": "[concat('subscriptions/',subscription().subscriptionId,'/resourceGroups/',parameters('loganalytics-rg'),'/providers/Microsoft.OperationalInsights/workspaces/',parameters('workspacename'))]",
"logs": [
{
"category": "Errors",
"enabled": true
},
{
"category": "Timeouts",
"enabled": true
},
{
"category": "Blocks",
"enabled": true
},
{
"category": "Deadlocks",
"enabled": true
},
{
"category": "SQLInsights",
"enabled": true
},
{
"category": "DatabaseWaitStatistics",
"enabled": true
}
],
"metrics":[
{
"category": "Basic",
"enabled": true
},
{
"category": "InstanceAndAppAdvanced",
"enabled": true
}
]
}
}
]
}
]
}