使用 Azure Monitor 日志进行性能监视Performance Monitoring with Azure Monitor logs

本文介绍如何逐步将 Log Analytics 代理作为虚拟机规模集扩展添加到群集并将其连接到现有的 Azure Log Analytics 工作区。This article covers the steps to add the Log Analytics agent as a virtual machine scale set extension to your cluster, and connect it to your existing Azure Log Analytics workspace. 这可收集关于容器、应用程序和性能监视的诊断数据。This enables collecting diagnostics data about containers, applications, and performance monitoring. 通过将其作为扩展添加到虚拟机规模集资源,Azure 资源管理器可确保它安装在每个节点上,即使在缩放群集时也是如此。By adding it as an extension to the virtual machine scale set resource, Azure Resource Manager ensures that it gets installed on every node, even when scaling the cluster.

备注

本文假定已设置了 Azure Log Analytics 工作区。This article assumes that you have an Azure Log Analytics workspace already set up. 如果尚未设置,请转到设置 Azure Monitor 日志If you do not, head over to Set up Azure Monitor logs

备注

本文最近已更新,从使用术语“Log Analytics”改为使用术语“Azure Monitor 日志”。This article was recently updated to use the term Azure Monitor logs instead of Log Analytics. 日志数据仍然存储在 Log Analytics 工作区中,并仍然由同一 Log Analytics 服务收集并分析。Log data is still stored in a Log Analytics workspace and is still collected and analyzed by the same Log Analytics service. 我们正在更新术语,以便更好地反映 Azure Monitor 中日志的角色。We are updating the terminology to better reflect the role of logs in Azure Monitor. 有关详细信息,请参阅 Azure Monitor 术语更改See Azure Monitor terminology changes for details.

通过 Azure CLI 添加代理扩展Add the agent extension via Azure CLI

将 Log Analytics 代理添加到群集的最佳方法是使用 Azure CLI 提供的虚拟机规模集 API。The best way to add the Log Analytics agent to your cluster is via the virtual machine scale set APIs available with the Azure CLI. 如果尚未安装 Azure CLI,请安装 Azure CLIIf you do not have Azure CLI set up yet, Install the Azure CLI.

  1. 请求本地 Shell 之后,请确保在资源所在的订阅中工作。Once your local Shell is requested, make sure you are working in the same subscription as your resource. 请使用 az account show 进行检查,并确保“名称”值与群集订阅的值匹配。Check this with az account show and make sure the "name" value matches that of your cluster's subscription.

  2. 在门户中,导航到 Log Analytics 工作区所在的资源组。In the Portal, navigate to the resource group where your Log Analytics workspace is located. 单击进入日志分析资源(资源类型为 Log Analytics 工作区)。Click into the log analytics resource (the type of the resource will be Log Analytics workspace). 进入资源概述页后,单击左侧菜单中“设置”部分下面的“高级设置”。 Once you are at the resource overview page, click on Advanced Settings under the Settings section on the left menu.

    日志分析属性页

  3. 若要建立 Windows 群集,请单击“Windows 服务器”;若要创建 Linux 群集,请单击“Linux 服务器” 。Click on Windows Servers if you are standing up a Windows cluster, and Linux Servers if you are creating a Linux cluster. 此页将显示 workspace IDworkspace key(在门户中列为“主键”)。This page will show you your workspace ID and workspace key (listed as Primary Key in the portal). 下一步骤需要使用这两个值。You will need both for the next step.

  4. 运行以下命令使用 vmss extension set API 将 Log Analytics 代理安装到群集中:Run the command to install the Log Analytics agent onto your cluster, using the vmss extension set API:

    对于 Windows 群集:For a Windows cluster:

    az vmss extension set --name MicrosoftMonitoringAgent --publisher Microsoft.EnterpriseCloud.Monitoring --resource-group <nameOfResourceGroup> --vmss-name <nameOfNodeType> --settings "{'workspaceId':'<Log AnalyticsworkspaceId>'}" --protected-settings "{'workspaceKey':'<Log AnalyticsworkspaceKey>'}"
    

    对于 Linux 群集:For a Linux cluster:

    az vmss extension set --name OmsAgentForLinux --publisher Microsoft.EnterpriseCloud.Monitoring --resource-group <nameOfResourceGroup> --vmss-name <nameOfNodeType> --settings "{'workspaceId':'<Log AnalyticsworkspaceId>'}" --protected-settings "{'workspaceKey':'<Log AnalyticsworkspaceKey>'}"
    

    以下示例展示如何将 Log Analytics 代理添加到 Windows 群集。Here's an example of the Log Analytics agent being added to a Windows cluster.

    Log Analytics 代理 cli 命令

  5. 15 分钟内即可将代理成功添加到节点上。This should take less than 15 min to successfully add the agent to your nodes. 可使用 az vmss extension list API 验证是否已添加代理:You can verify that the agents have been added by using the az vmss extension list API:

    az vmss extension list --resource-group <nameOfResourceGroup> --vmss-name <nameOfNodeType>
    

通过资源管理器模板添加代理Add the agent via the Resource Manager template

部署 Azure Log Analytics 工作区并将代理添加到每个节点的示例资源管理器模板可用于 WindowsLinuxSample Resource Manager templates that deploy an Azure Log Analytics workspace and add an agent to each of your nodes is available for Windows or Linux.

可下载和修改此模板以部署最适合需求的群集。You can download and modify this template to deploy a cluster that best suits your needs.

查看性能计数器View Performance Counters

添加 Log Analytics 代理后,请转到 Log Analytics 门户,选择要收集的性能计数器。Now that you have added the Log Analytics agent, head on over to the Log Analytics portal to choose which performance counters you'd like to collect.

  1. 在 Azure 门户中,转到在其中创建 Service Fabric 分析解决方案的资源组。In the Azure portal, go to the resource group in which you created the Service Fabric Analytics solution. 选择 ServiceFabric<nameOfLog AnalyticsWorkspace>。Select ServiceFabric<nameOfLog AnalyticsWorkspace>.

  2. 单击“Log Analytics” 。Click Log Analytics.

  3. 单击“高级设置” 。Click Advanced Settings.

  4. 单击“数据” ,然后单击“Windows 或 Linux 性能计数器” 。Click Data, then click Windows or Linux Performance Counters. 此时会显示一个可以选择的默认计数器列表,此外还可以设置收集间隔。There is a list of default counters you can choose to enable and you can set the interval for collection too. 还可以添加要收集的其他性能计数器You can also add additional performance counters to collect. 参考文章中介绍了正确的格式。The proper format is referenced in this article.

  5. 单击“保存”,然后单击“确定” 。Click Save, then click OK.

  6. 关闭“高级设置”边栏选项卡。Close the Advanced Settings blade.

  7. 在“常规”标题下,单击“工作区摘要” 。Under the General heading, click Workspace summary.

  8. 将看到每个已启用的解决方案的图形形式的磁贴,包括 Service Fabric 的磁贴。You will see tiles in the form of a graph for each of the solutions enabled, including one for Service Fabric. 单击 Service Fabric 图形以转到 Service Fabric 分析解决方案。Click the Service Fabric graph to continue to the Service Fabric Analytics solution.

  9. 将会看到一些带有有关操作通道和 Reliable Services 事件的图形的磁贴。You will see a few tiles with graphs on operational channel and reliable services events. 已选择的计数器的流入数据的图形表示形式将会显示在“节点指标”下。The graphical representation of the data flowing in for the counters you have selected will appear under Node Metrics.

  10. 单击“容器指标”图形可了解更多详细信息。Click on a Container Metric graph to see additional details. 还可以使用 Kusto 查询语言,像查询群集事件一样查询性能计数器数据,以及基于节点、性能计数器名称和值进行筛选。You can also query on performance counter data similarly to cluster events and filter on the nodes, perf counter name, and values using the Kusto query language.

Log Analytics 性能计数器查询

后续步骤Next steps