ARM 模板 - Azure SQL 数据库诊断和日志分析工作区

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
                                }
                            }

                        ]
                    }
                }
            ]
        }
    ]
}

答案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
                            }
                        ]
                    }
                }
            ]
        }
    ]
}

相关内容