分享方式:


診斷記錄 - Azure 內容傳遞網路

透過 Azure 診斷記錄,您可以檢視核心分析,並將它們儲存到一或多個目的地,包括:

  • Azure 儲存體帳戶
  • Log Analytics 工作區
  • Azure 事件中樞

此功能適用於所有定價層的內容傳遞網路端點。

診斷記錄可讓您將基本使用計量從內容傳遞網路端點匯出至不同類型的來源,以便以自定義方式取用它們。 您可以執行下列幾種資料匯出作業:

  • 匯出資料至 Blob 儲存體、匯出至 CSV,以及在 Excel 中產生圖表。
  • 匯出資料至事件中樞,並將資料與其他 Azure 服務相互關聯。
  • 將資料匯出至 Azure 監視器記錄,並在您自己的 Log Analytics 工作區中檢視資料

下列步驟需要 Azure 內容傳遞網路 配置檔。 請先參閱建立 Azure 內容傳遞網路 配置檔和端點,再繼續。

使用 Azure 入口網站啟用記錄

請遵循下列步驟,為您的 Azure 內容傳遞網路 端點啟用記錄:

  1. 登入 Azure 入口網站

  2. 在 Azure 入口網站中,瀏覽至 [所有資源]>your-cdn-profile

  3. 選取您要啟用診斷記錄的內容傳遞網路端點:

    選取內容傳遞網路端點的螢幕快照。

  4. 在 [監視] 區段中,選取 [診斷記錄]

    [監視] 功能表下 [診斷記錄] 按鈕的螢幕快照。

使用 Azure 儲存體來啟用記錄功能

若要使用儲存體帳戶來儲存記錄,請遵循下列步驟:

注意

需要儲存體帳戶才能完成這些步驟。 如需詳細資訊,請參閱:建立 Azure 儲存體帳戶

  1. 針對 [診斷設定名稱],輸入診斷記錄設定的名稱。

  2. 選取 [封存至儲存體帳戶],然後選取 [CoreAnalytics]

  3. 針對 [保留期 (天數)],選擇保留天數。 保留天數為 0 會無限期地儲存記錄。

  4. 選取記錄的訂用帳戶和儲存體帳戶。

    診斷記錄 - 儲存體。

  5. 選取 [儲存]。

傳送至 Log Analytics

若要針對記錄使用 Log Analytics,請遵循下列步驟:

注意

需要 Log Analytics 工作區才能完成這些步驟。 如需詳細資訊,請參閱:在 Azure 入口網站中建立 Log Analytics 工作區

  1. 針對 [診斷設定名稱],輸入診斷記錄設定的名稱。

  2. 選取 [傳送至 Log Analytics],然後選取 [CoreAnalytics]

  3. 選取記錄的訂用帳戶和 Log Analytics 工作區。

    診斷記錄 - Log Analytics。

  4. 選取 [儲存]。

串流至事件中樞

若要針對記錄使用事件中樞,請遵循下列步驟:

注意

需要事件中樞才能完成這些步驟。 如需詳細資訊,請參閱:快速入門:使用 Azure 入口網站建立事件中樞

  1. 針對 [診斷設定名稱],輸入診斷記錄設定的名稱。

  2. 選取 [串流至事件中樞],然後選取 [CoreAnalytics]

  3. 選取記錄的訂用帳戶和事件中樞命名空間。

    診斷記錄 - 事件中樞。

  4. 選取 [儲存]。

使用 PowerShell 啟用記錄

下列範例說明如何透過 Azure PowerShell Cmdlet 啟用診斷記錄。

注意

建議您使用 Azure Az PowerShell 模組來與 Azure 互動。 若要開始使用,請參閱 安裝 Azure PowerShell。 若要了解如何移轉至 Az PowerShell 模組,請參閱將 Azure PowerShell 從 AzureRM 移轉至 Az

啟用儲存體帳戶中的診斷記錄

  1. 登入 Azure PowerShell:

    Connect-AzAccount 
    
  2. 若要啟用儲存體帳戶中的診斷記錄,請輸入此命令。 以您的值取代變數:

    $rsg = <your-resource-group-name>
    $cdnprofile = <your-cdn-profile-name>
    $cdnendpoint = <your-cdn-endpoint-name>
    $storageacct = <your-storage-account-name>
    $diagname = <your-diagnostic-setting-name>
    
    $cdn = Get-AzCdnEndpoint -ResourceGroupName $rsg -ProfileName $cdnprofile -EndpointName $cdnendpoint
    
    $storage = Get-AzStorageAccount -ResourceGroupName $rsg -Name $storageacct
    
    Set-AzDiagnosticSetting -Name $diagname -ResourceId $cdn.id -StorageAccountId $storage.id -Enabled $true -Categories CoreAnalytics
    

啟用 Log Analytics 工作區的診斷記錄

  1. 登入 Azure PowerShell:

    Connect-AzAccount 
    
  2. 若要啟用 Log Analytics 工作區的診斷記錄,請輸入以下命令。 以您的值取代變數:

    $rsg = <your-resource-group-name>
    $cdnprofile = <your-cdn-profile-name>
    $cdnendpoint = <your-cdn-endpoint-name>
    $workspacename = <your-log-analytics-workspace-name>
    $diagname = <your-diagnostic-setting-name>
    
    $cdn = Get-AzCdnEndpoint -ResourceGroupName $rsg -ProfileName $cdnprofile -EndpointName $cdnendpoint
    
    $workspace = Get-AzOperationalInsightsWorkspace -ResourceGroupName $rsg -Name $workspacename
    
    Set-AzDiagnosticSetting -Name $diagname -ResourceId $cdn.id -WorkspaceId $workspace.ResourceId -Enabled $true -Categories CoreAnalytics
    

啟用事件中樞命名空間的診斷記錄

  1. 登入 Azure PowerShell:

    Connect-AzAccount 
    
  2. 若要啟用 Log Analytics 工作區的診斷記錄,請輸入以下命令。 以您的值取代變數:

    $rsg = <your-resource-group-name>
    $cdnprofile = <your-cdn-profile-name>
    $cdnendpoint = <your-cdn-endpoint-name>
    $eventhubname = <your-event-hub-namespace-name>
    $diagname = <your-diagnostic-setting-name>
    
    $cdn = Get-AzCdnEndpoint -ResourceGroupName $rsg -ProfileName $cdnprofile -EndpointName $cdnendpoint
    
    Set-AzDiagnosticSetting -Name $diagname -ResourceId $cdn.id -EventHubName $eventhubname -Enabled $true -Categories CoreAnalytics
    

從 Azure 儲存體取用診斷記錄

本節描述內容傳遞網路核心分析的架構、Azure 儲存體 帳戶中的組織,並提供範例程式代碼來下載 CSV 檔案中的記錄。

使用 Microsoft Azure 儲存體總管

若要下載此工具,請參閱 Azure 儲存體總管。 下載並安裝軟體之後,請將它設定為使用設定為內容傳遞網路診斷記錄目的地的相同 Azure 儲存體 帳戶。

  1. 開啟 [Microsoft Azure 儲存體總管]
  2. 找到儲存體帳戶
  3. 展開此儲存體帳戶下方的 [Blob 容器] 節點。
  4. 選取名為 insights-logs-coreanalytics 的容器。
  5. 結果會顯示在右側窗格,開頭的第一層會顯示 resourceId=。 繼續選取每個層級,直到您找到 PT1H.json 檔案為止。 如需路徑的說明,請參閱 Blob 路徑格式
  6. 每個 blob PT1H.json 檔案代表特定內容傳遞網路端點或其自定義網域一小時的分析記錄。
  7. 此 JSON 檔案內容的結構描述如<核心分析記錄結構描述>一節所述。

Blob 路徑格式

每個小時會產生 Core Analytics 記錄,且會收集資料並加以儲存在單一 Azure blob 作為 JSON 承載。 儲存體總管工具會將 '/' 解譯為目錄分隔符號,並顯示成階層。 Azure Blob 的路徑看起來就像有階層式結構,而且代表 Blob 名稱。 此 blob 名稱會遵循下列命名慣例:

resourceId=/SUBSCRIPTIONS/{Subscription Id}/RESOURCEGROUPS/{Resource Group Name}/PROVIDERS/MICROSOFT.CDN/PROFILES/{Profile Name}/ENDPOINTS/{Endpoint Name}/ y=/m=/d=/h=/m=/PT1H.json

欄位說明:

Description
訂用帳戶識別碼 全域唯一識別碼 (GUID) 格式的 Azure 訂用帳戶標識碼。
資源群組名稱 內容傳遞網路資源所屬的資源群組名稱。
設定檔名稱 內容傳遞網路配置檔的名稱
端點名稱 內容傳遞網路端點的名稱
Year 四位數的年份表示法,例如 2017
Month 兩位數的月份表示法。 01 = 一月...12 =十二月
Day 兩位數的當月日期表示法
PT1H.json 儲存分析資料的實際 JSON 檔案

將 Core Analytics 資料匯出至 CSV 檔案

為了存取核心分析,我們提供一種工具的範例程式碼。 此工具可讓您將 JSON 檔案下載至以逗號分隔的一般檔案格式,用來建立圖表或其他彙總。

以下為使用此工具的方式:

  1. 瀏覽 GitHub 連結:https://github.com/Azure-Samples/azure-cdn-samples/tree/master/CoreAnalytics-ExportToCsv
  2. 下載程式碼。
  3. 依照指示編譯與設定。
  4. 執行該工具。
  5. 產生的 CSV 檔案會以簡單的平面階層顯示分析資料。

記錄資料延遲

下表顯示來自 Microsoft 的 Azure CDN 標準版來自 Edgio 的 Azure CDN 標準版/進階版的記錄資料延遲。

Microsoft 記錄資料延遲 Edgio 記錄資料延遲
延遲 1 小時。 延遲 1 小時,而且在端點傳播完成後需花費最多 2 小時才會開始出現。

內容傳遞網路核心分析的診斷記錄類型

Microsoft 目前僅提供核心分析記錄,其中包含顯示 HTTP 回應統計數據和輸出統計數據的計量,如內容傳遞網路 POP/邊緣所見。

Core Analytics 計量詳細資料

下表說明核心分析記錄中可用計量的清單:

  • 來自 Microsoft 的 Azure CDN 標準
  • 來自 Edgio 的 Azure CDN 標準版/進階版

並非所有提供者的所有計量皆可用,雖然這樣的差異極少。 下表也顯示提供者是否提供指定的計量。 計量僅適用於具有流量的那些內容傳遞網路端點。

計量 描述 Microsoft Edgio
RequestCountTotal 這段期間要求命中總數。 Yes Yes
RequestCountHttpStatus2xx 產生 2xx HTTP 代碼 (例如 200、202) 的所有要求計數。 Yes Yes
RequestCountHttpStatus3xx 產生 3xx HTTP 代碼 (例如 300、302) 的所有要求計數。 Yes Yes
RequestCountHttpStatus4xx 產生 4xx HTTP 代碼 (例如 400、404) 的所有要求計數。 Yes Yes
RequestCountHttpStatus5xx 產生 5xx HTTP 代碼 (例如 500、504) 的所有要求計數。 Yes Yes
RequestCountHttpStatusOthers 所有其他 HTTP 代碼 (2xx-5xx 以外) 的計數。 Yes Yes
RequestCountHttpStatus200 產生 200 HTTP 代碼回應的所有要求計數。 No
RequestCountHttpStatus206 產生 206 HTTP 代碼回應的所有要求計數。 No
RequestCountHttpStatus302 產生 302 HTTP 代碼回應的所有要求計數。 No
RequestCountHttpStatus304 產生 304 HTTP 代碼回應的所有要求計數。 No
RequestCountHttpStatus404 產生 404 HTTP 代碼回應的所有要求計數。 No
RequestCountCacheHit 產生快取命中之所有要求的計數。 資產是從 POP 直接提供給用戶端。 Yes Yes
RequestCountCacheMiss 產生快取遺漏之所有要求的計數。 快取遺漏表示在最靠近用戶端的 POP 上找不到資產,因此會從來源擷取。 Yes Yes
RequestCountCacheNoCache 因為邊緣上的使用者組態之故,而無法予以快取的所有資產要求計數。 Yes Yes
RequestCountCacheUncacheable 無法由資產的 Cache-Control 和 Expires 標頭快取的資產所有要求計數。 此計數表示應該不會在 POP 上加以快取或由 HTTP 用戶端進行快取。 Yes Yes
RequestCountCacheOthers 先前所列計量未涵蓋快取狀態的所有要求計數。 No Yes
EgressTotal 輸出資料傳輸 (單位 GB) Yes Yes
EgressHttpStatus2xx 狀態代碼為 2xx HTTP 之回應的輸出資料傳輸* (單位為 GB)。 Yes Yes
EgressHttpStatus3xx 狀態代碼為 3xx HTTP 之回應的輸出資料傳輸 (單位為 GB)。 Yes Yes
EgressHttpStatus4xx 狀態代碼為 4xx HTTP 之回應的輸出資料傳輸 (單位為 GB)。 Yes Yes
EgressHttpStatus5xx 狀態代碼為 5xx HTTP 之回應的輸出資料傳輸 (單位為 GB)。 Yes Yes
EgressHttpStatusOthers 狀態代碼為其他 HTTP 之回應的輸出資料傳輸 (單位為 GB)。 Yes Yes
EgressCacheHit 直接從內容傳遞網路 POP/Edges 上的內容傳遞網路快取所傳遞之回應的輸出數據傳輸。 Yes Yes
EgressCacheMiss。 在最靠近的 POP 伺服器上找不到和從原始伺服器擷取之回應的輸出資料傳輸。 Yes Yes
EgressCacheNoCache 因為邊緣上使用者組態之故而無法予以快取的資產輸出資料傳輸。 Yes Yes
EgressCacheUncacheable 無法由資產的 Cache-Control 和 Expires 標頭快取的資產輸出資料傳輸。 表示應該不會在 POP 上加以快取或由 HTTP 用戶端進行快取。 Yes Yes
EgressCacheOthers 其他快取案例的輸出資料傳輸。 No Yes

*輸出數據傳輸是指從內容傳遞網路 POP 伺服器傳送至用戶端的流量。

Core Analytics 記錄結構描述

所有記錄都以 JSON 格式儲存,且每個項目都有根據下列結構描述的字串欄位:

    "records": [
        {
            "time": "2017-04-27T01:00:00",
            "resourceId": "<ARM Resource Id of the CDN Endpoint>",
            "operationName": "Microsoft.Cdn/profiles/endpoints/contentDelivery",
            "category": "CoreAnalytics",
            "properties": {
                "DomainName": "<Name of the domain for which the statistics is reported>",
                "RequestCountTotal": integer value,
                "RequestCountHttpStatus2xx": integer value,
                "RequestCountHttpStatus3xx": integer value,
                "RequestCountHttpStatus4xx": integer value,
                "RequestCountHttpStatus5xx": integer value,
                "RequestCountHttpStatusOthers": integer value,
                "RequestCountHttpStatus200": integer value,
                "RequestCountHttpStatus206": integer value,
                "RequestCountHttpStatus302": integer value,
                "RequestCountHttpStatus304": integer value,
                "RequestCountHttpStatus404": integer value,
                "RequestCountCacheHit": integer value,
                "RequestCountCacheMiss": integer value,
                "RequestCountCacheNoCache": integer value,
                "RequestCountCacheUncacheable": integer value,
                "RequestCountCacheOthers": integer value,
                "EgressTotal": double value,
                "EgressHttpStatus2xx": double value,
                "EgressHttpStatus3xx": double value,
                "EgressHttpStatus4xx": double value,
                "EgressHttpStatus5xx": double value,
                "EgressHttpStatusOthers": double value,
                "EgressCacheHit": double value,
                "EgressCacheMiss": double value,
                "EgressCacheNoCache": double value,
                "EgressCacheUncacheable": double value,
                "EgressCacheOthers": double value,
            }
        }

    ]
}

其中 time 代表報告某段時間統計資料時該時間範圍的開始時間。 內容傳遞網路提供者不支援的計量,而不是雙精度浮點數或整數值,會產生 Null 值。 此 null 值表示沒有計量,且與 0 值不同。 各網域會在端點上有一組這類計量設定。

範例屬性︰

{
     "DomainName": "azurecdntest.azureedge.net",
     "RequestCountTotal": 480,
     "RequestCountHttpStatus2xx": 480,
     "RequestCountHttpStatus3xx": 0,
     "RequestCountHttpStatus4xx": 0,
     "RequestCountHttpStatus5xx": 0,
     "RequestCountHttpStatusOthers": 0,
     "RequestCountHttpStatus200": 480,
     "RequestCountHttpStatus206": 0,
     "RequestCountHttpStatus302": 0,
     "RequestCountHttpStatus304": 0,
     "RequestCountHttpStatus404": 0,
     "RequestCountCacheHit": null,
     "RequestCountCacheMiss": null,
     "RequestCountCacheNoCache": null,
     "RequestCountCacheUncacheable": null,
     "RequestCountCacheOthers": null,
     "EgressTotal": 0.09,
     "EgressHttpStatus2xx": null,
     "EgressHttpStatus3xx": null,
     "EgressHttpStatus4xx": null,
     "EgressHttpStatus5xx": null,
     "EgressHttpStatusOthers": null,
     "EgressCacheHit": null,
     "EgressCacheMiss": null,
     "EgressCacheNoCache": null,
     "EgressCacheUncacheable": null,
     "EgressCacheOthers": null
}

更多資源