Azure Monitor 中的 Linux 代理上通过 CollectD 收集数据Collect data from CollectD on Linux agents in Azure Monitor

CollectD 是一个开源 Linux 守护程序,它定期从应用程序级和系统级信息中收集性能指标。CollectD is an open source Linux daemon that periodically collects performance metrics from applications and system level information. 示例应用程序包括 Java 虚拟机 (JVM)、MySQL Server 和 Nginx。Example applications include the Java Virtual Machine (JVM), MySQL Server, and Nginx. 本文介绍了如何在 Azure Monitor 中通过 CollectD 收集性能数据。This article provides information on collecting performance data from CollectD in Azure Monitor.

可以在插件表中找到可用插件的完整列表。A full list of available plugins can be found at Table of Plugins.

CollectD 概述

Log Analytics Linux 代理中包括了以下 CollectD 配置,用以将 CollectD 数据路由到 Log Analytics Linux 代理。The following CollectD configuration is included in the Log Analytics agent for Linux to route CollectD data to the Log Analytics agent for Linux.

备注

从 Microsoft Operations Management Suite (OMS) 过渡到 Azure Monitor 期间,Windows 或 Linux 的 OMS 代理称为 Windows 或 Linux 的 Log Analytics 代理。As part of the ongoing transition from Microsoft Operations Management Suite (OMS) to Azure Monitor, the OMS Agent for Windows or Linux will be referred to as the Log Analytics agent for Windows and Log Analytics agent for Linux.

LoadPlugin write_http

<Plugin write_http>
   <Node "oms">
      URL "127.0.0.1:26000/oms.collectd"
      Format "JSON"
      StoreRates true
   </Node>
</Plugin>

此外,如果使用的是 5.5 之前的某个 collectD 版本,请改用以下配置。Additionally, if using an versions of collectD before 5.5 use the following configuration instead.

LoadPlugin write_http

<Plugin write_http>
   <URL "127.0.0.1:26000/oms.collectd">
      Format "JSON"
      StoreRates true
   </URL>
</Plugin>

CollectD 配置使用默认的 write_http 插件通过端口 26000 将性能指标数据发送到 Log Analytics Linux 代理。The CollectD configuration uses the defaultwrite_http plugin to send performance metric data over port 26000 to Log Analytics agent for Linux.

备注

如果需要,可以将此端口配置为一个自定义的端口。This port can be configured to a custom-defined port if needed.

适用于 Linux 的 Log Analytics 代理也在端口 26000 上侦听 CollectD 指标,然后将其转换为 Azure Monitor 架构指标。The Log Analytics agent for Linux also listens on port 26000 for CollectD metrics and then converts them to Azure Monitor schema metrics. 下面是 Log Analytics Linux 代理配置 collectd.confThe following is the Log Analytics agent for Linux configuration collectd.conf.

<source>
   type http
   port 26000
   bind 127.0.0.1
</source>

<filter oms.collectd>
   type filter_collectd
</filter>

备注

默认情况下,CollectD 设置为以 10 秒的间隔读取值。CollectD by default is set to read values at a 10-second interval. 由于这会直接影响发送到 Azure Monitor 日志的数据量,因此你可能需要在 CollectD 配置中调整此时间间隔,以便在监视要求与 Azure Monitor 日志的相关成本和使用量之间取得良好的平衡。As this directly affects the volume of data sent to Azure Monitor Logs, you might need to tune this interval within the CollectD configuration to strike a good balance between the monitoring requirements and associated costs and usage for Azure Monitor Logs.

支持的版本Versions supported

  • Azure Monitor 当前支持 CollectD 4.8 版及更高版本。Azure Monitor currently supports CollectD version 4.8 and above.
  • 要收集 CollectD 指标,需要 Log Analytics Linux 代理 v1.1.0-217 或更高版本。Log Analytics agent for Linux v1.1.0-217 or above is required for CollectD metric collection.

配置Configuration

下面是在 Azure Monitor 中配置 CollectD 数据收集的基本步骤。The following are basic steps to configure collection of CollectD data in Azure Monitor.

  1. 将 CollectD 配置为使用 write_http 插件将数据发送到 Log Analytics Linux 代理。Configure CollectD to send data to the Log Analytics agent for Linux using the write_http plugin.
  2. 将 Log Analytics Linux 代理配置为在相应的端口上侦听 CollectD 数据。Configure the Log Analytics agent for Linux to listen for the CollectD data on the appropriate port.
  3. 重新启动 CollectD 和 Log Analytics Linux 代理。Restart CollectD and Log Analytics agent for Linux.

配置 CollectD 来转发数据Configure CollectD to forward data

  1. 要将 CollectD 数据路由到 Log Analytics Linux 代理,需要将 oms.conf 添加到 CollectD 的配置目录中。To route CollectD data to the Log Analytics agent for Linux, oms.conf needs to be added to CollectD's configuration directory. 此文件的目的地取决于计算机的 Linux 发行版。The destination of this file depends on the Linux distro of your machine.

    如果 CollectD 配置目录位于 /etc/collectd.d/ 中:If your CollectD config directory is located in /etc/collectd.d/:

    sudo cp /etc/opt/microsoft/omsagent/sysconf/omsagent.d/oms.conf /etc/collectd.d/oms.conf
    

    如果 CollectD 配置目录位于 /etc/collectd/collectd.conf.d/ 中:If your CollectD config directory is located in /etc/collectd/collectd.conf.d/:

    sudo cp /etc/opt/microsoft/omsagent/sysconf/omsagent.d/oms.conf /etc/collectd/collectd.conf.d/oms.conf
    

    备注

    对于 5.5 之前的 CollectD 版本,必须如上所示修改 oms.conf 中的标记。For CollectD versions before 5.5 you will have to modify the tags in oms.conf as shown above.

  2. 将 collectd.conf 复制到所需工作区的 omsagent 配置目录中。Copy collectd.conf to the desired workspace's omsagent configuration directory.

    sudo cp /etc/opt/microsoft/omsagent/sysconf/omsagent.d/collectd.conf /etc/opt/microsoft/omsagent/<workspace id>/conf/omsagent.d/
    sudo chown omsagent:omiusers /etc/opt/microsoft/omsagent/<workspace id>/conf/omsagent.d/collectd.conf
    
  3. 使用以下命令重新启动 CollectD 和 Log Analytics Linux 代理。Restart CollectD and Log Analytics agent for Linux with the following commands.

    sudo service collectd restart
    sudo /opt/microsoft/omsagent/bin/service_control restart
    

CollectD 指标到 Azure Monitor 架构的转换CollectD metrics to Azure Monitor schema conversion

为了在 Log Analytics Linux 代理已收集的基础结构指标与 CollectD 收集的新指标之间维护一个熟悉的模型,将使用以下架构映射:To maintain a familiar model between infrastructure metrics already collected by Log Analytics agent for Linux and the new metrics collected by CollectD the following schema mapping is used:

CollectD 指标字段CollectD Metric field Azure Monitor 字段Azure Monitor field
host ComputerComputer
plugin None
plugin_instance Instance NameInstance Name
如果 plugin_instance 为 null,则 InstanceName="_Total"If plugin_instance is null then InstanceName="_Total"
type ObjectNameObjectName
type_instance CounterNameCounterName
如果 type_instance 为 null,则 CounterName=空白If type_instance is null then CounterName=blank
dsnames[] CounterNameCounterName
dstypes None
values[] CounterValueCounterValue

后续步骤Next steps

  • 了解日志查询以便分析从数据源和解决方案中收集的数据。Learn about log queries to analyze the data collected from data sources and solutions.
  • 使用自定义字段将来自 syslog 记录的数据解析为单个字段。Use Custom Fields to parse data from syslog records into individual fields.