collectd:Application Insights 中的 Linux 性能指标 [已弃用]collectd: Linux performance metrics in Application Insights [Deprecated]


若要监视 Java 应用程序,建议的方法是在不更改代码的情况下使用自动检测。The recommended approach to monitor Java applications is to use the auto-instrumentation without changing the code. 请按照 Application Insights Java 3.0 代理指南进行操作。Please follow the guidelines for Application Insights Java 3.0 agent.

若要浏览 Application Insights 中 Linux 系统性能指标,请安装 collectd 及其 Application Insights 插件。To explore Linux system performance metrics in Application Insights, install collectd, together with its Application Insights plug-in. 此开放源解决方案收集了各种系统和网络统计信息。This open-source solution gathers various system and network statistics.

如果已使用 Application Insights 检测了 Java Web 服务,则通常会使用 collectd。Typically you'll use collectd if you have already instrumented your Java web service with Application Insights. 它可提供更多数据,有助于增强应用性能或诊断问题。It gives you more data to help you to enhance your app's performance or diagnose problems.

获取检测密钥Get your instrumentation key

Azure 门户中,打开要显示数据的 Application Insights 资源。In the Azure portal, open the Application Insights resource where you want the data to appear. (或创建新资源。)(Or create a new resource.)

复制可标识资源的检测密钥。Take a copy of the instrumentation key, which identifies the resource.


安装 collectd 和插件Install collectd and the plug-in

在 Linux 服务器计算机上:On your Linux server machines:

  1. 安装 collectd 版本 5.4.0 或更高版本。Install collectd version 5.4.0 or later.
  2. 下载 Application Insights collectd 编写器插件Download the Application Insights collectd writer plugin. 注意版本号。Note the version number.
  3. 将插件 JAR 复制到 /usr/share/collectd/javaCopy the plugin JAR into /usr/share/collectd/java.
  4. 编辑 /etc/collectd/collectd.confEdit /etc/collectd/collectd.conf:
    • 确保已启用 Java 插件Ensure that the Java plugin is enabled.
    • 更新 java.class.path 的 JVMArg,以包括以下 JAR。Update the JVMArg for the java.class.path to include the following JAR. 更新版本号,以匹配下载版本:Update the version number to match the one you downloaded:
    • /usr/share/collectd/java/applicationinsights-collectd-1.0.5.jar
    • 使用资源中的检测密钥添加此代码段:Add this snippet, using the Instrumentation Key from your resource:

     LoadPlugin ""
     <Plugin ApplicationInsightsWriter>
        InstrumentationKey "Your key"

以下是示例配置文件的一部分:Here's part of a sample configuration file:

    # collectd plugins
    LoadPlugin cpu
    LoadPlugin disk
    LoadPlugin load

    # Enable Java Plugin
    LoadPlugin "java"

    # Configure Java Plugin
    <Plugin "java">
      JVMArg "-verbose:jni"
      JVMArg "-Djava.class.path=/usr/share/collectd/java/applicationinsights-collectd-1.0.5.jar:/usr/share/collectd/java/collectd-api.jar"

      # Enabling Application Insights plugin
      LoadPlugin ""

      # Configuring Application Insights plugin
      <Plugin ApplicationInsightsWriter>
        InstrumentationKey "12345678-1234-1234-1234-123456781234"

      # Other plugin configurations ...

配置其他 collectd 插件,其可从不同源中收集各种数据。Configure other collectd plugins, which can collect various data from different sources.

根据其手册重启 collectd。Restart collectd according to its manual.

查看 Application Insights 中的数据View the data in Application Insights

在 Application Insights 资源中,打开指标和添加图表,选择要从“自定义”类别查看的指标。In your Application Insights resource, open Metrics and add charts, selecting the metrics you want to see from the Custom category.

默认情况下,会从收集指标的所有主机中聚合指标。By default, the metrics are aggregated across all host machines from which the metrics were collected. 要查看每个主机的指标,在“图表”详细信息边栏选项卡中,打开“分组”,并选择按 CollectD-Host 分组。To view the metrics per host, in the Chart details blade, turn on Grouping and then choose to group by CollectD-Host.

排除特定统计信息的上传To exclude upload of specific statistics

默认情况下,Application Insights 插件会发送由启用的所有 collectd“读取”插件收集的所有数据。By default, the Application Insights plugin sends all the data collected by all the enabled collectd 'read' plugins.

排除特定插件或数据源中的数据:To exclude data from specific plugins or data sources:

  • 编辑配置文件。Edit the configuration file.
  • <Plugin ApplicationInsightsWriter> 中,添加如下指令行:In <Plugin ApplicationInsightsWriter>, add directive lines like this:
指令Directive 效果Effect
Exclude disk 排除由 disk 插件收集的所有数据Exclude all data collected by the disk plugin
Exclude disk:read,write 排除 disk 插件中名为 readwrite 的源。Exclude the sources named read and write from the disk plugin.

使用新行分隔指令。Separate directives with a newline.


在门户中看不到数据I don't see data in the portal

  • 打开搜索,查看原始事件是否已到达。Open Search to see if the raw events have arrived. 有时需较长时间才能在指标资源管理器中看到数据。Sometimes they take longer to appear in metrics explorer.
  • 可能需要为传出数据设置防火墙例外。You might need to set firewall exceptions for outgoing data.
  • 在 Application Insights 插件中启用跟踪。Enable tracing in the Application Insights plugin. <Plugin ApplicationInsightsWriter> 中添加此行:Add this line within <Plugin ApplicationInsightsWriter>:
    • SDKLogger true
  • 打开终端并在详细模式下启动 collectd,查看其报告的任何问题:Open a terminal and start collectd in verbose mode, to see any issues it is reporting:
    • sudo collectd -f

已知问题Known issue

Application Insights 写入插件与某些读取插件不兼容。The Application Insights Write plugin is incompatible with certain Read plugins. Application Insights 插件需要浮点数时,有些插件有时会发送“NaN”。Some plugins sometimes send "NaN" where the Application Insights plugin expects a floating-point number.

症状:collectd 日志显示包括“AI: ...SyntaxError:意外的令牌 N”的错误。Symptom: The collectd log shows errors that include "AI: ... SyntaxError: Unexpected token N".

解决方法:排除由问题写入插件收集的数据。Workaround: Exclude data collected by the problem Write plugins.