Azure 監視器中 Log Analytics 工作區的 Resource Manager 範本範例

本文包含 Azure Resource Manager 範本範例,可用來在 Azure 監視器中建立和設定 Log Analytics 工作區。 每個範例都包含範本檔案和參數檔案,且附有要提供給範本的範例值。

注意

如需 Azure 監視器的可用範例清單,以及在 Azure 訂用帳戶中的部署指引,請參閱 Azure Resource Manager 範例

必要條件

請確認 Azure 訂閱允許您在在目標區域中建立 Log Analytics 工作區。

需要的權限

動作 需要的權限
部署 ARM 範本。 例如,Log Analytics 參與者的內建角色提供的 Microsoft.Resources/deployments/* 權限。
建立 Log Analytics 工作區。 例如,Log Analytics 參與者的內建角色提供的 Microsoft.OperationalInsights/workspaces/write 權限。
設定 Log Analytics 工作區的資料收集。 例如,Log Analytics 參與者的內建角色提供的 Microsoft.OperationalInsights/workspaces/writeMicrosoft.OperationalInsights/workspaces/dataSources/write 權限。

範本參考

建立 Log Analytics 工作區

下列範例會建立新的空白 Log Analytics 工作區。 工作區具有唯一的工作區識別碼和資源識別碼。 您可以在不同的資源群組中重複使用相同的工作區名稱。

備註

  • 如果您指定免費定價層,請移除 retentionInDays 元素。

範本檔案

@description('Specify the name of the workspace.')
param workspaceName string

@description('Specify the location for the workspace.')
param location string

@description('Specify the pricing tier: PerGB2018 or legacy tiers (Free, Standalone, PerNode, Standard or Premium) which are not available to all customers.')
@allowed([
  'CapacityReservation'
  'Free'
  'LACluster'
  'PerGB2018'
  'PerNode'
  'Premium'
  'Standalone'
  'Standard'
])
param sku string = 'PerGB2018'

@description('Specify the number of days to retain data.')
param retentionInDays int = 120

@description('Specify true to use resource or workspace permissions, or false to require workspace permissions.')
param resourcePermissions bool

@description('Specify the number of days to retain data in Heartbeat table.')
param heartbeatTableRetention int

resource workspace 'Microsoft.OperationalInsights/workspaces@2021-12-01-preview' = {
  name: workspaceName
  location: location
  properties: {
    sku: {
      name: sku
    }
    retentionInDays: retentionInDays
    features: {
      enableLogAccessUsingOnlyResourcePermissions: resourcePermissions
    }
  }
}

resource table 'Microsoft.OperationalInsights/workspaces/tables@2021-12-01-preview' = {
  parent: workspace
  name: 'Heartbeat'
  properties: {
    retentionInDays: heartbeatTableRetention
  }
}

參數檔案

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "workspaceName": {
      "value": "MyWorkspace"
    },
    "sku": {
      "value": "PerGB2018"
    },
    "location": {
      "value": "eastus"
    },
    "resourcePermissions": {
      "value": true
    },
    "heartbeatTableRetention": {
      "value": 30
    }
  }
}

部署範例範本

請參閱部署範例範本

下一步