Azure 标准负载均衡器的 Azure Monitor 日志Azure Monitor logs for Azure Standard Load Balancer

你可以使用不同类型的 Azure Monitor 日志对 Azure 标准负载均衡器进行管理和故障排除。You can use different types of Azure Monitor logs to manage and troubleshoot Azure Standard Load Balancer. 可以将日志流式传输到事件中心或 Log Analytics 工作区。Logs can be streamed to an event hub or a Log Analytics workspace. 你可以从 Azure Blob 存储中提取所有日志并在 Excel 和 Power BI 等工具中查看它们。You can extract all logs from Azure Blob Storage and view them in tools like Excel and Power BI.

日志类型有:The types of logs are:

  • 活动日志: 你可以查看提交到 Azure 订阅的所有活动及其状态。Activity logs: You can view all activity being submitted to your Azure subscriptions, along with their status. 有关详细信息,请参阅查看活动日志以监视对资源的操作For more information, see View activity logs to monitor actions on resources. 活动日志是默认启用的,可以在 Azure 门户中查看。Activity logs are enabled by default and can be viewed in the Azure portal. 针对 Azure 基本负载均衡器和标准负载均衡器都提供了这些日志。These logs are available for both Azure Basic Load Balancer and Standard Load Balancer.
  • 标准负载均衡器指标:你可以使用此日志来查询指标,这些指标导出为标准负载均衡器的日志。Standard Load Balancer metrics: You can use this log to query the metrics exported as logs for Standard Load Balancer. 这些日志仅针对标准负载均衡器提供。These logs are available only for Standard Load Balancer.


运行状况探测和负载均衡器警报事件日志当前不起作用,已在 Azure 负载均衡器已知问题中列出。Health probe and Load Balancer alert event logs are not currently functional and are listed in the known issues for Azure Load Balancer.


日志仅适用于在 Azure 资源管理器部署模型中部署的 Azure 资源。Logs are available only for resources deployed in the Azure Resource Manager deployment model. 你不能将日志用于经典部署模型中的资源。You can't use logs for resources in the classic deployment model. 有关部署模型的详细信息,请参阅了解 Resource Manager 部署和经典部署For more information about the deployment models, see Understanding Resource Manager deployment and classic deployment.

启用日志记录Enable logging

每个 Resource Manager 资源都会自动启用活动日志记录。Activity logging is automatically enabled for every Resource Manager resource. 需启用事件和运行状况探测日志记录才能开始收集通过这些日志提供的数据。Enable event and health probe logging to start collecting the data available through those logs. 请使用以下步骤:Use the following steps:

  1. 登录到 Azure 门户Sign in to the Azure portal. 如果用户还没有负载均衡器,请先 创建负载均衡器 ,并继续。If you don't already have a load balancer, create a load balancer before you continue.

  2. 在门户中,选择“资源组”。In the portal, select Resource groups.

  3. 选择负载均衡器所在的 <resource-group-name>Select <resource-group-name> where your load balancer is.

  4. 选择负载均衡器。Select your load balancer.

  5. 选择“活动日志” > “诊断设置”。 Select Activity log > Diagnostic settings.

  6. 在“诊断设置”窗格中,在“诊断设置”下选择“添加诊断设置”。 In the Diagnostics settings pane, under Diagnostics settings, select + Add diagnostic setting.

  7. 在“诊断设置”创建窗格的“名称”框中输入“myLBDiagnostics” 。In the Diagnostics settings creation pane, enter myLBDiagnostics in the Name box.

  8. “诊断设置”有三个选项。You have three options for the Diagnostics settings. 你可以选择一个、两个或全部三个,并根据要求对各选项进行配置:You can choose one, two, or all three and configure each for your requirements:

    • 存档到存储帐户Archive to a storage account. 此进程需要已创建好的存储帐户。You'll need a storage account already created for this process. 若要创建存储帐户,请参阅创建存储帐户To create a storage account, see Create a storage account.

      1. 选中“存档到存储帐户”复选框。Select the Archive to a storage account check box.
      2. 选择“配置”,打开“选择存储帐户”窗格 。Select Configure to open the Select a storage account pane.
      3. 在“订阅”下拉列表中,选择在其中创建了你的存储帐户的订阅。In the Subscription drop-down list, select the subscription where your storage account was created.
      4. 在“存储帐户”下拉列表中,选择你的存储帐户的名称。In the Storage account drop-down list, select the name of your storage account.
      5. 选择“确定” 。Select OK.
    • 流式传输到事件中心Stream to an event hub. 此进程需要已创建好的事件中心。You'll need an event hub already created for this process. 若要创建事件中心,请参阅快速入门:使用 Azure 门户创建事件中心To create an event hub, see Quickstart: Create an event hub by using the Azure portal.

      1. 选择“流式传输到事件中心”复选框。Select the Stream to an event hub check box.
      2. 选择“配置”,打开“选择事件中心”窗格 。Select Configure to open the Select event hub pane.
      3. 在“订阅”下拉列表中,选择在其中创建了你的事件中心的订阅。In the Subscription drop-down list, select the subscription where your event hub was created.
      4. 在“选择事件中心命名空间”下拉列表中,选择命名空间。In the Select event hub namespace drop-down list, select the namespace.
      5. 在“选择事件中心策略名称”下拉列表中,选择名称。In the Select event hub policy name drop-down list, select the name.
      6. 选择“确定” 。Select OK.
    • 发送到 Log AnalyticsSend to Log Analytics. 此进程需要已创建并配置好的 Log Analytics 工作区。You'll need to already have a log analytics workspace created and configured for this process. 若要创建 Log Analytics 工作区,请参阅在 Azure 门户中创建 Log Analytics 工作区To create a Log Analytics workspace, see Create a Log Analytics workspace in the Azure portal.

      1. 选中“发送到 Log Analytics”复选框。Select the Send to Log Analytics check box.
      2. 在“订阅”下拉列表中,选择你的 Log Analytics 工作区所在的订阅。In the Subscription drop-down list, select the subscription where your Log Analytics workspace is.
      3. 在“Log Analytics 工作区”下拉列表中,选择工作区。In the Log Analytics Workspace drop-down list, select the workspace.
  9. 在“诊断设置”窗格的“指标”部分 ,选中“AllMetrics”复选框。In the METRIC section of the Diagnostics settings pane, select the AllMetrics check box.

  10. 验证是否所有内容都正确,然后选择“诊断设置”创建窗格顶部的“保存” 。Verify that everything looks correct, and then select Save at the top of the Diagnostic settings creation pane.

查看和分析活动日志View and analyze the activity log

默认生成活动日志。The activity log is generated by default. 可以按照此文中的说明将活动日志配置为在订阅级别导出。You can configure it to be exported on a subscription level by following instructions in this article. 若要了解这些日志的详细信息,请阅读查看活动日志以监视对资源的操作一文。Learn more about these logs by reading the View activity logs to monitor actions on resources article.

可以使用以下任一方法查看和分析活动日志数据:You can view and analyze activity log data by using either of the following methods:

  • Azure 工具: 通过 Azure PowerShell、Azure CLI、Azure REST API 或 Azure 门户检索活动日志中的信息。Azure tools: Retrieve information from the activity log through Azure PowerShell, the Azure CLI, the Azure REST API, or the Azure portal. 使用资源管理器审核操作一文提供了每种方法的分步说明。The Audit operations with Resource Manager article provides step-by-step instructions for each method.
  • Power BI: 如果还没有 Power BI 帐户,可以免费试用。Power BI: If you don't already have a Power BI account, you can try it for free. 通过使用 Power BI 的 Azure 审核日志集成,你可以使用预配置的仪表板来分析数据。By using the Azure Audit Logs integration for Power BI, you can analyze your data with preconfigured dashboards. 另外,还可以自定义视图来满足你的要求。Or you can customize views to suit your requirements.

以日志形式查看和分析指标View and analyze metrics as logs

通过使用 Azure Monitor 中的导出功能,可以导出负载均衡器指标。By using the export functionality in Azure Monitor, you can export your Load Balancer metrics. 这些指标会为每个一分钟的采样间隔生成一个日志条目。These metrics will generate a log entry for each one-minute sampling interval.

指标转日志导出在每资源级别启用。Metrics-to-logs export is enabled on a per-resource level. 若要启用这些日志,请执行以下操作:To enable these logs:

  1. 转到“诊断设置”窗格。Go to the Diagnostic Settings pane.
  2. 按资源组进行筛选,然后选择要为其启用指标导出的负载均衡器实例。Filter by resource group, and then select the Load Balancer instance that you want to enable metrics export for.
  3. 当负载均衡器的诊断设置页显示后,选择“AllMetrics”以将符合条件的指标作为日志导出。When the diagnostic settings page for Load Balancer is up, select AllMetrics to export eligible metrics as logs.

有关指标导出限制,请参阅本文的限制部分。For metric export limitations, see the Limitations section of this article.

在标准负载均衡器的诊断设置中启用“AllMetrics”后,如果你使用的是事件中心或 Log Analytics 工作区,则这些日志会填充在 AzureMonitor 表中。After you enable AllMetrics in the diagnostic settings of Standard Load Balancer, if you're using an event hub or Log Analytics workspace, these logs will be populated in the AzureMonitor table.

如果导出到存储,请连接到你的存储帐户并检索事件和运行状况探测日志的 JSON 日志条目。If you're exporting to storage, connect to your storage account and retrieve the JSON log entries for event and health probe logs. 下载 JSON 文件后,可以将其转换为 CSV 并在 Excel、Power BI 或任何其他数据可视化效果工具中查看。After you download the JSON files, you can convert them to CSV and view them in Excel, Power BI, or any other data visualization tool.


如果你熟悉 Visual Studio 和更改 C# 中的常量和变量值的基本概念,则可以使用 GitHub 提供的日志转换器工具If you're familiar with Visual Studio and basic concepts of changing values for constants and variables in C#, you can use the log converter tools available from GitHub.

流式传输到事件中心Stream to an event hub

将诊断信息流式传输到事件中心后,可以使用该信息在集成了 Azure Monitor 的合作伙伴 SIEM 工具中进行集中的日志分析。When diagnostic information is streamed to an event hub, you can use it for centralized log analysis in a partner SIEM tool with Azure Monitor integration. 有关详细信息,请参阅将 Azure 监视数据流式传输到事件中心For more information, see Stream Azure monitoring data to an event hub.

发送到 Log AnalyticsSend to Log Analytics

可以将 Azure 中资源的诊断信息直接发送到 Log Analytics 工作区。You can send diagnostic information for resources in Azure directly to a Log Analytics workspace. 在该工作区中,可以对信息运行复杂的查询,以便进行故障排除和分析。In that workspace, you can run complex queries against the information for troubleshooting and analysis. 有关详细信息,请参阅在 Azure Monitor 的 Log Analytics 工作区中收集 Azure 资源日志For more information, see Collect Azure resource logs in a Log Analytics workspace in Azure Monitor.


Azure 负载均衡器的指标转日志导出功能具有以下限制:The metrics-to-logs export feature for Azure Load Balancer has the following limitations:

  • 作为日志导出时,指标当前通过内部名称显示。Metrics are currently displayed through internal names when exported as logs. 可以在下表中找到映射。You can find the mapping in the below table.
  • 不会保留指标的维数。The dimensionality of metrics is not preserved. 例如,对于 DipAvailability(运行状况探测状态)等指标,无法按后端 IP 地址进行拆分或查看。For example, with metrics such as DipAvailability (health probe status), you won't be able to split or view by back-end IP address.
  • 使用的 SNAT 端口和分配的 SNAT 端口的指标目前无法作为日志导出。Metrics for used SNAT ports and allocated SNAT ports aren't currently available for export as logs.

后续步骤Next steps