在 Azure 流量管理員中啟用資源記錄Enable resource logging in Azure Traffic Manager

本文說明如何啟用收集流量管理員設定檔的診斷資源記錄和存取記錄檔資料。This article describes how to enable collection of diagnostic resource logs and access log data for a Traffic Manager profile.

Azure 流量管理員資源記錄可讓您深入瞭解流量管理員設定檔資源的行為。Azure Traffic Manager resource logs can provide insight into the behavior of the Traffic Manager profile resource. 例如,您可以使用設定檔的記錄資料判斷為何針對某個端點進行的個別探查已經逾時。For example, you can use the profile's log data to determine why individual probes have timed out against an endpoint.

啟用資源記錄Enable resource logging

注意

本文已更新為使用新的 Azure PowerShell Az 模組。This article has been updated to use the new Azure PowerShell Az module. AzureRM 模組在至少 2020 年 12 月之前都還會持續收到錯誤 (Bug) 修正,因此您仍然可以持續使用。You can still use the AzureRM module, which will continue to receive bug fixes until at least December 2020. 若要深入了解新的 Az 模組和 AzureRM 的相容性,請參閱新的 Azure PowerShell Az 模組簡介To learn more about the new Az module and AzureRM compatibility, see Introducing the new Azure PowerShell Az module. 如需 Az 模組安裝指示,請參閱安裝 Azure PowerShellFor Az module installation instructions, see Install Azure PowerShell.

您可以執行 Azure Cloud Shell 中採用的命令,或從您的電腦執行 PowerShell。You can run the commands that follow in the Azure Cloud Shell, or by running PowerShell from your computer. Azure Cloud Shell 是免費的互動式殼層。The Azure Cloud Shell is a free interactive shell. 它具有預先安裝和設定的共用 Azure 工具,可與您的帳戶搭配使用。It has common Azure tools preinstalled and configured to use with your account. 如果您從電腦執行 PowerShell,就需要 Azure PowerShell 模組 1.0.0 或更新版本。If you run PowerShell from your computer, you need the Azure PowerShell module, 1.0.0 or later. 您可以執行 Get-Module -ListAvailable Az 來了解安裝的版本。You can run Get-Module -ListAvailable Az to find the installed version. 如果您需要安裝或升級,請參閱安裝 Azure PowerShell 模組If you need to install or upgrade, see Install Azure PowerShell module. 如果您在本機執行 PowerShell,也需要執行 Login-AzAccount 來登入 Azure。If you are running PowerShell locally, you also need to run Login-AzAccount to sign in to Azure.

  1. 擷取流量管理員設定檔:Retrieve the Traffic Manager profile:

    若要啟用資源記錄,您需要流量管理員設定檔的識別碼。To enable resource logging, you need the ID of a Traffic Manager profile. 取得您想要使用get-aztrafficmanagerprofile啟用資源記錄功能的流量管理員設定檔。Retrieve the Traffic Manager profile that you want to enable resource logging for with Get-AzTrafficManagerProfile. 輸出會包含流量管理員設定檔的識別碼資訊。The output includes the Traffic Manager profile's ID information.

    Get-AzTrafficManagerProfile -Name <TrafficManagerprofilename> -ResourceGroupName <resourcegroupname>
    
  2. 啟用流量管理員設定檔的資源記錄:Enable resource logging for the Traffic Manager profile:

    使用在上一個步驟中取得的識別碼,為流量管理員設定檔啟用資源記錄,並使用set-azdiagnosticsettingEnable resource logging for the Traffic Manager profile using the ID obtained in the previous step with Set-AzDiagnosticSetting. 以下命令會將流量管理員設定檔的詳細資訊記錄儲存至指定的 Azure 儲存體帳戶。The following command stores verbose logs for the Traffic Manager profile to a specified Azure Storage account.

    Set-AzDiagnosticSetting -ResourceId <TrafficManagerprofileResourceId> -StorageAccountId <storageAccountId> -Enabled $true
    
  3. 確認診斷設定Verify diagnostic settings:

    使用 Get-AzDiagnosticSetting (英文),來確認流量管理員設定檔的診斷設定。Verify diagnostic settings for the Traffic Manager profile using Get-AzDiagnosticSetting. 以下命令會顯示記錄的資源類別。The following command displays the categories that are logged for a resource.

    Get-AzDiagnosticSetting -ResourceId <TrafficManagerprofileResourceId>
    

    請確定與流量管理員設定檔資源關聯的所有記錄類別都顯示為已啟用。Ensure that all log categories associated with the Traffic Manager profile resource display as enabled. 也請您確認儲存體帳戶已正確設定。Also, verify that the storage account is correctly set.

存取記錄檔Access log files

  1. 登入 Azure 入口網站Sign in to the Azure portal.

  2. 在入口網站中瀏覽至您的 Azure 儲存體帳戶。Navigate to your Azure Storage account in the portal.

  3. 在 Azure 儲存體帳戶的 [概觀]**** 頁面中,於選取 [服務]**** 底下選取 [Blob]****。On the Overview page of your Azure storage account, under Services select Blobs.

  4. 針對 [容器]****,選取 insights-logs-probehealthstatusevents,並向下瀏覽至 PT1H.json 檔案,然後按一下 [下載]**** 以下載並儲存一份此記錄。For Containers, select insights-logs-probehealthstatusevents, and navigate down to the PT1H.json file and click Download to download and save a copy of this log file.

    從 blob 儲存體存取您流量管理員設定檔記錄檔

流量管理員記錄結構描述Traffic Manager log schema

透過 Azure 監視器所提供的所有資源記錄都會共用通用的最上層架構,而且每個服務都可以彈性地為自己的事件發出唯一的屬性。All resource logs available through Azure Monitor share a common top-level schema, with flexibility for each service to emit unique properties for their own events. 如需最上層資源記錄架構,請參閱Azure 資源記錄的支援服務、架構和類別For top-level resource logs schema, see Supported services, schemas, and categories for Azure Resource Logs.

下表包含 Azure 流量管理員設定檔資源特定的記錄結構描述。The following table includes logs schema specific to the Azure Traffic Manager profile resource.

欄位名稱Field Name 欄位類型Field Type 定義Definition 範例Example
EndpointNameEndpointName 字串String 正在記錄其健全狀況狀態的流量管理員端點的名稱。The name of the Traffic Manager endpoint whose health status is being recorded. myPrimaryEndpointmyPrimaryEndpoint
狀態Status 字串String 所探查流量管理員端點的健全狀況狀態。The health status of the Traffic Manager endpoint that was probed. 狀態可以是 UpdownThe status can either be Up or Down. UpUp

後續步驟Next steps