您现在访问的是微软AZURE全球版技术文档网站,若需要访问由世纪互联运营的MICROSOFT AZURE中国区技术文档网站,请访问 https://docs.azure.cn.

Azure CDN 的实时监视、指标和访问日志Real-time Monitoring, metrics, and access Logs for Azure CDN

利用 Microsoft 提供的 Azure CDN,你可以通过以下方式监视资源,以帮助你排查、跟踪和调试问题。With Azure CDN from Microsoft, you can monitor resources in the following ways to help you troubleshoot, track, and debug issues.

  • 原始日志提供有关 CDN 接收的每个请求的丰富信息。Raw logs provide rich information about every request that CDN receives. 原始日志不同于活动日志。Raw logs differ from activity logs. 活动日志让你能够了解对 Azure 资源执行的操作。Activity logs provide visibility into the operations done on Azure resources.
  • 度量值,它在 CDN 上显示四个关键指标,包括字节命中率、请求计数、响应大小和总滞后时间。Metrics, which display four key metrics on CDN, including Byte Hit Ratio, Request Count, Response Size and Total Latency. 它还提供不同的维度来细分指标。It also provides different dimensions to break down metrics.
  • 警报,允许客户设置关键指标的警报Alert, which allows customer to set up alert for key metrics
  • 其他指标,可让客户使用 Azure Log Analytics 来启用其他指标值。Additional metrics, which allow customers to use Azure Log Analytics to enable additional metrics of value. 我们还提供了 Azure Log Analytics 下几个其他指标的查询示例。We also provide query samples for a few other metrics under Azure Log Analytics.

重要

HTTP 原始日志功能适用于 Microsoft Azure CDN。The HTTP raw logs feature is available for Azure CDN from Microsoft.

如果没有 Azure 订阅,请在开始之前创建一个免费帐户If you don't have an Azure subscription, create a free account before you begin.

登录 AzureSign in to Azure

https://portal.azure.com 中登录 Azure 门户。Sign in to the Azure portal at https://portal.azure.com.

配置-Azure 门户Configuration - Azure portal

为 Microsoft 配置文件中的 Azure CDN 配置原始日志:To configure Raw logs for your Azure CDN from Microsoft profile:

  1. 从 "Azure 门户" 菜单中,选择 "所有资源" >> <your-CDN-profile>From the Azure portal menu, select All Resources >> <your-CDN-profile>.

  2. 在“监视”下,选择“诊断设置” 。Under Monitoring, select Diagnostics settings.

  3. 选择“+ 添加诊断设置”。Select + Add diagnostic setting.

    添加 CDN 配置文件的诊断设置。

    重要

    原始日志仅在配置文件级别提供,而聚合的 http 状态代码日志在终结点级别提供。Raw logs is only available in the profile level while aggregated http status code logs are available in the endpoint level.

  4. 在“诊断设置”下,在“诊断设置名称”下输入诊断设置的名称 。Under Diagnostic settings, enter a name for the diagnostic setting under Diagnostic settings name.

  5. 选择 AzureCdnAccessLog 并设置保留天数。Select the AzureCdnAccessLog and set the retention in days.

  6. 选择“目标详细信息”。Select the Destination details. 目标选项有:Destination options are:

    • 发送到 Log AnalyticsSend to Log Analytics
      • 选择“订阅”和“Log Analytics 工作区” 。Select the Subscription and Log Analytics workspace.
    • 存档到存储帐户Archive to a storage account
      • 选择“订阅”和“存储帐户” 。Select the Subscription and the Storage Account.
    • 流式传输到事件中心Stream to an event hub
      • 选择“订阅”、“事件中心命名空间”、“事件中心名称(可选)”和“事件中心策略名称” 。Select the Subscription, Event hub namespace, Event hub name (optional), and Event hub policy name.

    配置日志设置的目标。

  7. 选择“保存”。Select Save.

配置-Azure PowerShellConfiguration - Azure PowerShell

使用 AzDiagnosticSetting 配置原始日志的诊断设置。Use Set-AzDiagnosticSetting to configure the diagnostic setting for raw logs.

保留数据由命令中的 -RetentionInDays 选项定义。Retention data is defined by the -RetentionInDays option in the command.

备注

本文已经过更新,以便使用 Azure Az PowerShell 模块。This article has been updated to use the Azure Az PowerShell module. 若要与 Azure 交互,建议使用的 PowerShell 模块是 Az PowerShell 模块。The Az PowerShell module is the recommended PowerShell module for interacting with Azure. 若要开始使用 Az PowerShell 模块,请参阅安装 Azure PowerShellTo get started with the Az PowerShell module, see Install Azure PowerShell. 若要了解如何迁移到 Az PowerShell 模块,请参阅 将 Azure PowerShell 从 AzureRM 迁移到 AzTo learn how to migrate to the Az PowerShell module, see Migrate Azure PowerShell from AzureRM to Az.

在存储帐户中启用诊断日志Enable diagnostic logs in a storage account

  1. 登录到 Azure PowerShell:Sign in to Azure PowerShell:

    Connect-AzAccount 
    
  2. 若要在存储帐户中启用诊断日志,请输入以下命令。To enable Diagnostic Logs in a storage account, enter these commands. 将变量替换为值:Replace the variables with your values:

    ## Variables for the commands ##
    $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>
    $days = '30'
    
    $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 -Category AzureCdnAccessLog -RetentionEnabled 1 -RetentionInDays $days
    

为 Log Analytics 工作区启用诊断日志Enable diagnostics logs for Log Analytics workspace

  1. 登录到 Azure PowerShell:Sign in to Azure PowerShell:

    Connect-AzAccount 
    
  2. 若要为 Log Analytics 工作区启用诊断日志,请输入以下命令。To enable Diagnostic Logs for a Log Analytics workspace, enter these commands. 将变量替换为值:Replace the variables with your values:

    ## Variables for the commands ##
    $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>
    $days = '30'
    
    $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 -Category AzureCdnAccessLog -RetentionEnabled 1 -RetentionInDays $days
    

为事件中心命名空间启用诊断日志Enable diagnostics logs for event hub namespace

  1. 登录到 Azure PowerShell:Sign in to Azure PowerShell:

    Connect-AzAccount 
    
  2. 若要为事件中心命名空间启用诊断日志,请输入以下命令。To enable Diagnostic Logs for an event hub namespace, enter these commands. 将变量替换为值:Replace the variables with your values:

    ## Variables for the commands ##
    $rsg = <your-resource-group-name>
    $cdnprofile = <your-cdn-profile-name>
    $cdnendpoint = <your-cdn-endpoint-name>
    $evthubnamespace = <your-event-hub-namespace-name>
    $diagname = <your-diagnostic-setting-name>
    
    $cdn = Get-AzCdnEndpoint -ResourceGroupName $rsg -ProfileName $cdnprofile -EndpointName $cdnendpoint
    
    $eventhub = Get-AzEventHubNamespace -ResourceGroupName $rsg -Name $eventhubname
    
    Set-AzDiagnosticSetting -Name $diagname -ResourceId $cdn.id -EventHubName $eventhub.id -Enabled $true -Category AzureCdnAccessLog -RetentionEnabled 1 -RetentionInDays $days
    

原始日志属性Raw logs properties

Microsoft 服务中的 Azure CDN 当前提供原始日志。Azure CDN from Microsoft Service currently provides Raw logs. 原始日志提供单个 API 请求,其中每个条目具有以下架构:Raw logs provide individual API requests with each entry having the following schema:

propertiesProperty 说明Description
BackendHostnameBackendHostname 如果将请求转发到后端,此字段表示后端的主机名。If the request is being forwarded to a backend, this field represents the hostname of the backend. 如果在为路由规则) 启用缓存时,请求将被重定向或转发到区域 (缓存,则此字段将为空。This field will be blank if the request gets redirected or forwarded to a regional cache (when caching gets enabled for the routing rule).
CacheStatusCacheStatus 对于缓存方案,此字段定义了弹出窗口中的缓存命中/未命中For caching scenarios, this field defines the cache hit/miss at the POP
ClientIpClientIp 发出请求的客户端的 IP 地址。The IP address of the client that made the request. 如果请求中有一个 X 转发的标头,则从同一获取客户端 IP。If there was an X-Forwarded-For header in the request, then the Client IP is picked from the same.
ClientPortClientPort 发出请求的客户端的 IP 端口。The IP port of the client that made the request.
HttpMethodHttpMethod 请求使用的 HTTP 方法。HTTP method used by the request.
HttpStatusCodeHttpStatusCode 从代理返回的 HTTP 状态代码。The HTTP status code returned from the proxy.
HttpStatusDetailsHttpStatusDetails 请求的结果状态。Resulting status on the request. 此字符串值的含义可以在状态引用表中找到。Meaning of this string value can be found at a Status reference table.
HttpVersionHttpVersion 请求或连接的类型。Type of the request or connection.
POPPOP 请求着陆的边缘的短名称。Short name of the edge where the request landed.
RequestBytesRequestBytes HTTP 请求消息的大小(以字节为单位),包括请求标头和请求正文。The size of the HTTP request message in bytes, including the request headers and the request body.
RequestUriRequestUri 已收到请求的 URI。URI of the received request.
ResponseBytesResponseBytes 后端服务器作为响应发送的字节数。Bytes sent by the backend server as the response.
RoutingRuleNameRoutingRuleName 请求匹配的路由规则的名称。The name of the routing rule that the request matched.
RulesEngineMatchNamesRulesEngineMatchNames 请求匹配的规则的名称。The names of the rules that the request matched.
SecurityProtocolSecurityProtocol 请求所使用的 TLS/SSL 协议版本,如果没有加密,则为 null。The TLS/SSL protocol version used by the request or null if no encryption.
SentToOriginShieldSentToOriginShield
(弃用)\ * 请参阅以下部分中的弃用说明:(deprecated) * See notes on deprecation in the following section.
如果为 true,则表示请求是从源防护缓存(而不是边缘 pop)响应的。If true, it means that request was answered from origin shield cache instead of the edge pop. 源防护是用于提高缓存命中率的父缓存。Origin shield is a parent cache used to improve cache hit ratio.
isReceivedFromClientisReceivedFromClient 如果为 true,则表示请求来自客户端。If true, it means that the request came from the client. 如果为 false,则请求在边缘 (子 POP) ,并从源盾牌 (父 POP) 中进行响应。If false, the request is a miss in the edge (child POP) and is responded from origin shield (parent POP).
TimeTakenTimeTaken 从请求的第一个字节到响应的最后一个字节的时间长度(以秒为单位)。The length of time from first byte of request into Front Door to last byte of response out, in seconds.
TrackingReferenceTrackingReference 标识由 Front Door 提供的请求的唯一引用字符串,该请求还会以 X-Azure-Ref 标头的形式发送到客户端。The unique reference string that identifies a request served by Front Door, also sent as X-Azure-Ref header to the client. 是搜索特定请求访问日志中的详细信息必需的。Required for searching details in the access logs for a specific request.
UserAgentUserAgent 客户端使用的浏览器类型。The browser type that the client used.
ErrorInfoErrorInfo 此字段包含特定类型的错误以缩小疑难解答区域。This field contains the specific type of error to narrow down troubleshooting area.
可能的值包括:Possible values include:
NoError:指示未发现任何错误。NoError: Indicates no errors were found.
CertificateError:通用 SSL 证书错误。CertificateError: Generic SSL certificate error.
CertificateNameCheckFailed: SSL 证书中的主机名无效或不匹配。CertificateNameCheckFailed: The host name in the SSL certificate is invalid or doesn't match.
ClientDisconnected:由于客户端网络连接而导致请求失败。ClientDisconnected: Request failure because of client network connection.
UnspecifiedClientError:泛型客户端错误。UnspecifiedClientError: Generic client error.
InvalidRequest:请求无效。InvalidRequest: Invalid request. 由于标头、正文和 URL 格式不正确,可能会发生这种情况。It might occur because of malformed header, body, and URL.
DNSFailure: DNS 故障。DNSFailure: DNS Failure.
DNSNameNotResolved:无法解析服务器名称或地址。DNSNameNotResolved: The server name or address couldn't be resolved.
OriginConnectionAborted:与源的连接突然停止。OriginConnectionAborted: The connection with the origin was stopped abruptly.
OriginConnectionError:泛型源连接错误。OriginConnectionError: Generic origin connection error.
OriginConnectionRefused:无法建立与源的连接。OriginConnectionRefused: The connection with the origin wasn't able to established.
OriginError:泛型源错误。OriginError: Generic origin error.
OriginInvalidResponse:源返回的响应无效或无法识别。OriginInvalidResponse: Origin returned an invalid or unrecognized response.
OriginTimeout:源请求的超时期限已过期。OriginTimeout: The timeout period for origin request expired.
ResponseHeaderTooBig:原点返回了太大的响应标头。ResponseHeaderTooBig: The origin returned too large of a response header.
RestrictedIP:由于限制了 IP,请求被阻止。RestrictedIP: The request was blocked because of restricted IP.
SSLHandshakeError:由于 SSL 错误,无法建立与源的连接。SSLHandshakeError: Unable to establish connection with origin because of SSL hand shake failure.
UnspecifiedError:出现错误,因为表中的任何错误都不适合。UnspecifiedError: An error occurred that didn’t fit in any of the errors in the table.
TimeToFirstByteTimeToFirstByte Microsoft CDN 接收向客户端发送第一个字节的时间之后的时间长度(以毫秒为单位)。The length of time in milliseconds from when Microsoft CDN receives the request to the time the first byte gets sent to the client. 仅从 Microsoft 端度量该时间。The time is measured only from the Microsoft side. 不测量客户端数据。Client-side data isn't measured.

备注

可以通过运行查询来查看 Log Analytics 配置文件下的日志。The logs can be viewed under your Log Analytics profile by running a query. 示例查询如下所示:A sample query would look like: AzureDiagnostics | where Category == "AzureCdnAccessLog"

已发送到源防护板弃用Sent to origin shield deprecation

原始日志属性 isSentToOriginShield 已弃用,并已替换为新的字段 isReceivedFromClientThe raw log property isSentToOriginShield has been deprecated and replaced by a new field isReceivedFromClient. 如果已在使用已弃用的字段,请使用新字段。Use the new field if you're already using the deprecated field.

原始日志包括从 CDN 边缘 (子 POP) 和源盾牌生成的日志。Raw logs include logs generated from both CDN edge (child POP) and origin shield. 源盾牌是指在全球上战略定位的父节点。Origin shield refers to parent nodes that are strategically located across the globe. 这些节点与源服务器通信,并减少源上的流量负载。These nodes communicate with origin servers and reduce the traffic load on origin.

对于进入源盾牌的每个请求,都有2个日志条目:For every request that goes to origin shield, there are 2-log entries:

  • 一个用于边缘节点One for edge nodes
  • 一个用于源盾牌。One for origin shield.

若要区分来自边缘节点与源盾牌的出口或响应,可以使用字段 isReceivedFromClient 来获取正确的数据。To differentiate the egress or responses from the edge nodes vs. origin shield, you can use the field isReceivedFromClient to get the correct data.

如果该值为 false,则表示该请求将从源盾牌响应到边缘节点。If the value is false, then it means the request is responded from origin shield to edge nodes. 此方法可用于将原始日志与计费数据进行比较。This approach is effective to compare raw logs with billing data. 从来源盾牌出口到边缘节点不会产生费用。Charges aren't incurred for egress from origin shield to the edge nodes. 从边缘节点向客户端出口会产生费用。Charges are incurred for egress from the edge nodes to clients.

Kusto 查询示例,排除在 Log Analytics 中的源盾牌上生成的日志。Kusto query sample to exclude logs generated on origin shield in Log Analytics.

AzureDiagnostics 
| where OperationName == "Microsoft.Cdn/Profiles/AccessLog/Write" and Category == "AzureCdnAccessLog"  
| where isReceivedFromClient == true

重要

2020 年 2 月 25 日之后创建或更新的任何配置文件可自动使用 HTTP 原始日志功能。The HTTP Raw logs feature is available automatically for any profiles created or updated after 25th February 2020. 对于之前创建的 CDN 配置文件,应在设置日志记录后更新 CDN 终结点。For CDN profiles created earlier, one should update the CDN endpoint after setting up logging. 例如,可以导航到 CDN 终结点下的地区筛选,并阻止任何与工作负荷无关的国家/地区,并按保存。For example, one can navigate to geo filtering under CDN endpoints and block any country/region not relevant to their workload and hit save.

指标Metrics

Microsoft Azure CDN 与 Azure Monitor 集成,并发布四个 CDN 指标来帮助跟踪、排查和调试问题。Azure CDN from Microsoft is integrated with Azure Monitor and publishes four CDN metrics to help track, troubleshoot, and debug issues.

度量值显示在图表中,并可通过 PowerShell、CLI 和 API 进行访问。The Metrics are displayed in charts and accessible via PowerShell, CLI, and API. CDN 指标是免费的。The CDN metrics are free of charge.

从 Microsoft 度量值 Azure CDN,并以60秒为间隔发送指标。Azure CDN from Microsoft measures and sends its metrics in 60-second intervals. 此指标最多可能需要3分钟才能在门户中显示。The metrics can take up to 3 mins to appear in the portal.

有关详细信息,请参阅 Azure Monitor 指标For more information, see Azure Monitor metrics.

Microsoft Azure CDN 支持的指标Metrics supported by Azure CDN from Microsoft

指标Metrics 说明Description 维度Dimensions
字节命中率 *Bytes Hit ratio* 针对传出总数计算的 CDN 缓存中的出口百分比。The percentage of egress from CDN cache, computed against the total egress. 终结点Endpoint
RequestCountRequestCount CDN 提供的客户端请求数。The number of client requests served by CDN. 终结点Endpoint
客户端国家/地区。Client country.
客户端区域。Client region.
HTTP 状态。HTTP status.
HTTP 状态组。HTTP status group.
ResponseSizeResponseSize 从 CDN 边缘到客户端的响应发送的字节数。The number of bytes sent as responses from CDN edge to clients. 终结点Endpoint
客户端国家/地区。Client country.
客户端区域。Client region.
HTTP 状态。HTTP status.
HTTP 状态组。HTTP status group.
TotalLatencyTotalLatency CDN 从 cdn 发送到客户端之前,CDN 收到的客户端请求的总时间。The total time from the client request received by CDN until the last response byte send from CDN to client. 终结点Endpoint
客户端国家/地区。Client country.
客户端区域。Client region.
HTTP 状态。HTTP status.
HTTP 状态组。HTTP status group.

*Bytes r = 从起源) /egress 的边缘出口 (出口*Bytes Hit Ration = (egress from edge - egress from origin)/egress from edge

排除的方案数(按字节数计算):Scenarios excluded in bytes hit ratio calculation:

  • 不通过规则引擎或查询字符串缓存行为显式配置缓存。You explicitly configure no cache either through Rules Engine or Query String caching behavior.
  • 显式配置缓存控制指令和无存储或专用缓存。You explicitly configure cache-control directive with no-store or private cache.

指标配置Metrics configuration

  1. 从 "Azure 门户" 菜单中,选择 "所有资源" >> <your-CDN-profile>From the Azure portal menu, select All Resources >> <your-CDN-profile>.

  2. 在 " 监视" 下,选择 " 指标":Under Monitoring, select Metrics:

    CDN 配置文件的指标。

  3. 选择 " 添加度量 值",然后选择要添加的度量值:Select Add metric, select the metric to add:

    添加并选择 CDN 配置文件的指标。

  4. 选择 " 添加筛选 器" 以添加筛选器:Select Add filter to add a filter:

    将筛选器应用于指标。

  5. 选择 " 应用 拆分" 以查看不同维度的趋势:Select Apply splitting to see trend by different dimensions:

    对指标应用拆分。

  6. 选择 " 新建图表 " 以添加新图表:Select New chart to add a new chart:

    将新图表添加到指标视图。

警报Alerts

可以通过选择 "监视 警报" 在 Microsoft CDN 上设置警报 >> 。You can setup alerts on Microsoft CDN by selecting Monitoring >> Alerts.

为 "度量值" 部分中列出的指标选择 新的警报规则Select New alert rule for metrics listed in Metrics section:

为 CDN 终结点配置警报。

将根据 Azure Monitor 对警报进行收费。Alert will be charged based on Azure Monitor. 有关警报的详细信息,请参阅 Azure Monitor 警报For more information about alerts, see Azure Monitor alerts.

其他指标Additional Metrics

可以使用 Azure Log Analytics 和原始日志启用其他度量值,以实现额外的费用。You can enable additional metrics using Azure Log Analytics and raw logs for an additional cost.

  1. 按照上述步骤启用诊断,将原始日志发送到 log analytics。Follow steps above in enabling diagnostics to send raw log to log analytics.

  2. 选择创建的 Log Analytics 工作区:Select the Log Analytics workspace you created:

    选择 log analytics 工作区

  3. 在 log analytics 工作区中,选择 "常规" 下的 "日志"。Select Logs under General in the log analytics workspace. 然后选择 " 开始":Then select Get Started:

    Log analytics 资源工作区。

  4. 选择 " CDN 配置文件"。Select CDN Profiles. 选择一个示例查询以运行或关闭示例屏幕以输入自定义查询:Select an example query to RUN or close the example screen to enter a custom query:

    示例查询屏幕。

    查询执行。

  5. 若要按图表查看数据,请选择 " 图表"。To view data by chart, select Chart. 选择 " 固定到仪表板 ",将图表固定到 Azure 仪表板:Select Pin to dashboard to pin the chart to the Azure dashboard:

    将图表固定到仪表板。

后续步骤Next Steps

本文介绍了如何为 Microsoft CDN 服务启用 HTTP 原始日志。In this article, you enabled HTTP raw logs for the Microsoft CDN service.

有关 Azure CDN 和本文中所述的其他 Azure 服务的详细信息,请参阅:For more information on Azure CDN and the other Azure services mentioned in this article, see: