Database
ARM 模板 - Azure SQL 數據庫診斷和日誌分析工作區
使用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 工作區:
"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 } ] } } ] } ] }