使用 Linux 诊断扩展监视 Linux VM 的性能和诊断数据Use the Linux Diagnostic Extension to monitor the performance and diagnostic data of a Linux VM

本文档介绍 Linux 诊断扩展 2.3 版。This document describes version 2.3 of the Linux Diagnostic Extension.

Important

此版本已弃用,2018 年 6 月 30 日以后随时有可能取消发布该版本。This version is deprecated, and it may be unpublished any time after June 30, 2018.

简介Introduction

(注意:Linux 诊断扩展在 GitHub 上处于开源状态,其中首次发布有关该扩展的最新信息。(Note: The Linux Diagnostic Extension is open-sourced on GitHub where the most current information on the extension is first published. 建议先查看 GitHub 页。)You might want to check the GitHub page first.)

Linux 诊断扩展可帮助用户监视 Azure 上运行的 Linux VM。The Linux Diagnostic Extension helps a user monitor the Linux VMs that are running on Azure. 它具有以下功能:It has the following capabilities:

  • 从 Linux VM 收集系统性能信息并上传到用户的存储表,包括诊断和 syslog 信息。Collects and uploads the system performance information from the Linux VM to the user's storage table, including diagnostic and syslog information.
  • 让用户能够自定义将要收集并上传的数据指标。Enables users to customize the data metrics that will be collected and uploaded.
  • 让用户能够将指定日志文件上传到指定的存储表。Enables users to upload specified log files to a designated storage table.

在最新 2.3 版中,数据包括:In the current version 2.3, the data includes:

此扩展可搭配经典和 Resource Manager 部署模型使用。This extension works with both the classic and Resource Manager deployment models.

此扩展的当前版本和弃用的旧版本Current version of the extension and deprecation of old versions

此扩展的最新版本为 2.3,任何旧版本(2.0、2.1 和 2.2)都将于今年 (2017) 年底被弃用和取消发布。The latest version of the extension is 2.3, and any old versions (2.0, 2.1, and 2.2) will be deprecated and unpublished by end of this year (2017). 如果用户已安装禁用自动次要版本升级的 Linux 诊断扩展,强烈建议用户卸载该扩展,并在启用自动次要版本升级的情况下重新安装它。If you installed the Linux Diagnostic extension with automatic minor version upgrade disabled, it's strongly recommended that you uninstall the extension and reinstall it with automatic minor version upgrade enabled. 在经典 (ASM) VM 上,如果正在通过 Azure XPLAT CLI 或 Powershell 安装该扩展,则可以通过指定“2.*”作为版本来实现此目的。On classic (ASM) VMs, you can achieve this by specifying '2.*' as the version if you are installing the extension through Azure XPLAT CLI or Powershell. 在 ARM VM 上,可以通过在 VM 部署模板中包括 '"autoUpgradeMinorVersion": true' 来实现此目的。On ARM VMs, you can achieve this by including '"autoUpgradeMinorVersion": true' in the VM deployment template. 此外,此扩展的任何新安装都应自动次要版本升级选项启用。Also, any new installation of the extension should have the auto minor version upgrade option turned on.

启用扩展Enable the extension

使用 Azure 门户、Azure PowerShell 或 Azure CLI 脚本,可以启用此扩展。You can enable this extension by using the Azure portal, Azure PowerShell, or Azure CLI scripts.

若要直接从 Azure 门户查看和配置系统和性能数据,请执行 Azure 博客上的这些步骤To view and configure the system and performance data directly from the Azure portal, follow these steps on the Azure blog.

本文重点介绍如何使用 Azure CLI 命令来启用和配置此扩展。This article focuses on how to enable and configure the extension by using Azure CLI commands. 这可让你直接从存储表读取和查看数据。This allows you to read and view the data directly from the storage table.

请注意,此处所述的配置方法不适用于 Azure 门户。Note that the configuration methods that are described here won't work for the Azure portal. 若要直接从 Azure 门户查看和配置系统与性能数据,必须通过门户启用此扩展。To view and configure the system and performance data directly from the Azure portal, the extension must be enabled through the portal.

先决条件Prerequisites

  • Azure Linux Agent 2.0.6 版或更高版本Azure Linux Agent version 2.0.6 or later.

    请注意,大部分 Azure VM Linux 库映像都包含 2.0.6 版本或更高版本。Note that most Azure VM Linux gallery images include version 2.0.6 or later. 可以运行 WAAgent -version 以确认 VM 上安装的版本。You can run WAAgent -version to confirm which version is installed on the VM. 如果 VM 正在运行的版本早于 2.0.6,则可以按照 GitHub 上的这些说明 进行更新。If the VM is running a version that's earlier than 2.0.6, you can follow these instructions on GitHub to update it.

  • Azure CLIAzure CLI. 请按照此 CLI 安装指南中的说明在计算机上设置 Azure CLI 环境。Follow this guidance for installing CLI to set up the Azure CLI environment on your machine. 安装 Azure CLI 之后,可以从命令行接口(Bash、终端或命令提示符)使用“azure”命令访问 Azure CLI 命令。After Azure CLI is installed, you can use the azure command from your command-line interface (Bash, Terminal, or command prompt) to access the Azure CLI commands. 例如:For example:

    • 运行 azure vm extension set --help 了解详细的帮助信息。Run azure vm extension set --help for detailed help information.
    • 运行“azure login -e AzureChinaCloud”,登录到 Azure。Run azure login -e AzureChinaCloud to sign in to Azure.
    • 运行 azure vm list 可列出在 Azure 上拥有的所有虚拟机。Run azure vm list to list all the virtual machines that you have on Azure.
  • 用于存储数据的存储帐户。A storage account to store the data. 你将需要以前创建的存储帐户名称和访问密钥,以将数据上传到存储中。You will need a storage account name that was created previously and an access key to upload the data to your storage.

使用 Azure CLI 命令启用 Linux 诊断扩展Use the Azure CLI command to enable the Linux Diagnostic Extension

方案 1.Scenario 1. 使用默认数据集启用扩展Enable the extension with the default data set

在 2.3 版或更高版本中,收集的默认数据包括:In version 2.3 or later, the default data that will be collected includes:

  • 所有 Rsyslog 信息(包括系统、安全性和应用程序日志)。All Rsyslog information (including system, security, and application logs).
  • 一组核心基础系统数据。A core set of basis system data. 请注意, System Center 跨平台解决方案站点上介绍了完整的数据集。Note that the full data set is described on the System Center Cross Platform Solutions site. 如果想要启用额外的数据,请继续执行方案 2 和 3 中的步骤。If you want to enable extra data, continue with the steps in Scenarios 2 and 3.

步骤 1。Step 1. 使用以下内容创建名为 PrivateConfig.json 的文件:Create a file named PrivateConfig.json with the following content:

{
    "storageAccountName" : "the storage account to receive data",
    "storageAccountKey" : "the key of the account"
}

步骤 2.Step 2. 运行 azure vm extension set vm_name LinuxDiagnostic Microsoft.OSTCExtensions 2.* --private-config-path PrivateConfig.jsonRun azure vm extension set vm_name LinuxDiagnostic Microsoft.OSTCExtensions 2.* --private-config-path PrivateConfig.json.

方案 2.Scenario 2. 自定义性能监视器指标Customize the performance monitor metrics

此节介绍如何自定义性能和诊断数据表。This section describes how to customize the performance and diagnostic data table.

步骤 1。Step 1. 使用方案 1 描述的内容创建名为 PrivateConfig.json 的文件。Create a file named PrivateConfig.json with the content that was described in Scenario 1. 同时也创建名为 PublicConfig.json 的文件。Also create a file named PublicConfig.json. 指定你想要收集的特定数据。Specify the particular data you want to collect.

有关所有受支持的提供程序和变量,请参考 System Center 跨平台解决方案站点For all supported providers and variables, reference the System Center Cross Platform Solutions site. 可以拥有多个查询,通过将更多查询追加到脚本中,你还可以将它们存储为多个表。You can have multiple queries and store them in multiple tables by appending more queries to the script.

默认始终收集 Rsyslog 数据。By default, the Rsyslog data is always collected.

{
      "perfCfg":
      [
          {
              "query" : "SELECT PercentAvailableMemory, AvailableMemory, UsedMemory ,PercentUsedSwap FROM SCX_MemoryStatisticalInformation",
              "table" : "LinuxMemory"
          }
      ]
}

步骤 2.Step 2. 运行 azure vm extension set vm_name LinuxDiagnostic Microsoft.OSTCExtensions '2.*' --private-config-path PrivateConfig.json --public-config-path PublicConfig.jsonRun azure vm extension set vm_name LinuxDiagnostic Microsoft.OSTCExtensions '2.*' --private-config-path PrivateConfig.json --public-config-path PublicConfig.json.

方案 3.Scenario 3. 上传自己的日志文件Upload your own log files

此节介绍如何收集特定的日志文件并将其上传到存储帐户。This section describes how to collect and upload specific log files to your storage account. 需要指定日志文件的路径,以及要用来存储日志的表名。You need to specify both the path to your log file and the name of the table where you want to store your log. 可以将多个文件/表条目添加到脚本,以创建多个日志文件。You can create multiple log files by adding multiple file/table entries to the script.

步骤 1。Step 1. 使用方案 1 描述的内容创建名为 PrivateConfig.json 的文件。Create a file named PrivateConfig.json with the content that was described in Scenario 1. 然后使用以下内容创建另一个名为 PublicConfig.json 的文件:Then create another file named PublicConfig.json with the following content:

{
    "fileCfg" :
    [
        {
            "file" : "/var/log/mysql.err",
            "table" : "mysqlerr"
            }
    ]
}

步骤 2.Step 2. 运行 azure vm extension set vm_name LinuxDiagnostic Microsoft.OSTCExtensions '2.*' --private-config-path PrivateConfig.json --public-config-path PublicConfig.jsonRun azure vm extension set vm_name LinuxDiagnostic Microsoft.OSTCExtensions '2.*' --private-config-path PrivateConfig.json --public-config-path PublicConfig.json.

请注意,在 2.3 版之前的扩展版本上使用此设置,所有写入到 /var/log/mysql.err 的日志也可能会复制到 /var/log/syslog(或 /var/log/messages,具体取决于 Linux 发行版)。Note that with this setting on the extension versions prior to 2.3, all logs written to /var/log/mysql.err might be duplicated to /var/log/syslog (or /var/log/messages depending on the Linux distro) as well. 如果要避免此重复的日志记录,可以在 rsyslog 配置中不包括 local6 设备日志的日志记录。If you'd like to avoid this duplicate logging, you can exclude logging of local6 facility logs in your rsyslog configuration. 这取决于 Linux 发行版,但在 Ubuntu 14.04 系统中,要修改的文件是 /etc/rsyslog.d/50-default.conf,你可以将行 *.*;auth,authpriv.none -/var/log/syslog 替换为 *.*;auth,authpriv,local6.none -/var/log/syslogIt depends on the Linux distro, but on an Ubuntu 14.04 system, the file to modify is /etc/rsyslog.d/50-default.conf and you can replace the line *.*;auth,authpriv.none -/var/log/syslog to *.*;auth,authpriv,local6.none -/var/log/syslog. 在最新修补程序版本 2.3 (2.3.9007) 中解决了此问题,因此,如果使用扩展版本 2.3,此问题应该不会发生。This issue is fixed in the latest hotfix release of 2.3 (2.3.9007), so if you have the extension version 2.3, this issue should not happen. 如果在重新启动 VM 后此问题仍存在,请与我们联系,并帮助我们故障排除以确定未自动安装最新修补程序版本的原因。If it still does even after restarting your VM, please contact us and help us troubleshoot why the latest hotfix version is not installed automatically.

方案 4.Scenario 4. 阻止扩展收集任何日志Stop the extension from collecting any logs

本节说明如何阻止扩展收集日志。This section describes how to stop the extension from collecting logs. 请注意,即使使用此重新配置,监视代理进程仍会启动并运行。Note that the monitoring agent process will be still up and running even with this reconfiguration. 如果想要完全停止监视代理进程,可以通过禁用扩展来实现此目的。If you'd like to stop the monitoring agent process completely, you can do so by disabling the extension. 用于禁用扩展的命令是 azure vm extension set --disable <vm_name> LinuxDiagnostic Microsoft.OSTCExtensions '2.*'The command to disable the extension is azure vm extension set --disable <vm_name> LinuxDiagnostic Microsoft.OSTCExtensions '2.*'.

步骤 1。Step 1. 使用方案 1 描述的内容创建名为 PrivateConfig.json 的文件。Create a file named PrivateConfig.json with the content that was described in Scenario 1. 使用以下内容创建另一个名为 PublicConfig.json 的文件:Create another file named PublicConfig.json with the following content:

{
    "perfCfg" : [],
    "enableSyslog" : "false"
}

步骤 2.Step 2. 运行 azure vm extension set vm_name LinuxDiagnostic Microsoft.OSTCExtensions '2.*' --private-config-path PrivateConfig.json --public-config-path PublicConfig.jsonRun azure vm extension set vm_name LinuxDiagnostic Microsoft.OSTCExtensions '2.*' --private-config-path PrivateConfig.json --public-config-path PublicConfig.json.

查看数据Review your data

性能和诊断数据存储在 Azure 存储表中。The performance and diagnostic data are stored in an Azure Storage table. 查看如何通过 Ruby 使用 Azure 表存储,了解如何使用 Azure CLI 脚本访问存储表中的数据。Review How to use Azure Table Storage from Ruby to learn how to access the data in the storage table by using Azure CLI scripts.

此外,可以使用以下 UI 工具来访问数据:In addition, you can use following UI tools to access the data:

  1. Visual Studio 服务器资源管理器。Visual Studio Server Explorer. 转到存储帐户。Go to your storage account. VM 运行约 5 分钟后,会看到四个默认表:“LinuxCpu”、“LinuxDisk”、“LinuxMemory”和“Linuxsyslog”。After the VM runs for about five minutes, you'll see the four default tables: "LinuxCpu", "LinuxDisk", "LinuxMemory", and "Linuxsyslog". 双击表名以查看数据。Double-click the table names to view the data.
  2. Azure 存储资源管理器上指定的所有系统数据。Azure Storage Explorer.

图像

如果已启用 fileCfg 或 perfCfg(如方案 2 和 3 所述),则可以使用 Visual Studio 服务器资源管理器和 Azure 存储资源管理器查看非默认数据。If you've enabled fileCfg or perfCfg (as described in Scenarios 2 and 3), you can use Visual Studio Server Explorer and Azure Storage Explorer to view non-default data.

已知问题Known issues

  • 只能通过脚本访问 Rsyslog 信息和客户指定日志文件。The Rsyslog information and customer-specified log file can only be accessed via scripting.