排查 Ops Agent 安装和启动问题

本文档提供的信息可帮助您诊断和解决 Ops Agent 安装和启动过程中的问题。如果代理正在运行但无法注入日志或指标,请参阅排查数据注入问题

准备工作

在尝试解决问题之前,请检查代理的健康检查状态。

代理无法安装

您在运行安装脚本时可能会遇到以下错误。

操作系统不受支持

如果操作系统不受支持,则 Ops Agent 安装会失败。错误消息可能类似于以下内容:

Linux

https://packages.cloud.google.com/yum/repos/google-cloud-ops-agent-el6-x86_64-all/repodata/repomd.xml: [Errno 14] PYCURL ERROR 22 - "The requested URL returned error: 404 Not Found"
Trying other mirror.
To address this issue please refer to the below wiki article

https://wiki.centos.org/yum-errors

If above article doesn't help to resolve this issue please use https://bugs.centos.org/.

Error: Cannot retrieve repository metadata (repomd.xml) for repository: google-cloud-ops-agent. Please verify its path and try again

安装了与 Ops Agent 冲突的旧版代理

如果虚拟机已经安装了 Cloud Logging 代理Cloud Monitoring 代理,它们会与新代理冲突。错误消息可能类似于以下内容:

Linux

Error:
 Problem: problem with installed package stackdriver-agent-6.0.5-1.el8.x86_64 - package google-cloud-ops-agent-0.1.0-1.el8.x86_64 conflicts with stackdriver-agent provided by stackdriver-agent-6.0.5-1.el8.x86_64

Ops Agent 使用与旧代理不兼容的新配置文件。如需了解详情,请参阅配置 Ops Agent 指南。

要消除此错误,请执行以下操作:

  1. 保存 Cloud Monitoring 代理Cloud Logging 代理的自定义配置文件。

  2. 卸载旧的 Cloud Monitoring 代理Cloud Logging 代理

    卸载代理后,Google Cloud 控制台最多可能需要一小时才能报告此更改。

Monitoring 代理安装失败后,Ops Agent 安装也失败了

在尝试安装 Monitoring 代理失败后,Ops Agent 的安装也失败了。在 Debian 操作系统上,Ops Agent 安装失败时显示的错误消息与以下内容类似:

Linux

...
E: The repository 'https://packages.cloud.google.com/apt google-cloud-monitoring-jammy-all Release' does not have a Release file.
...
Could not refresh the google-cloud-ops-agent apt repositories.

如果您尝试在不受该代理支持的操作系统上安装 Monitoring 代理,则安装会失败。将 Monitoring 代理代码库添加到系统后,安装会失败。由于 Monitoring 代理代码库无效,因此在 Monitoring 代理安装失败后安装 Ops Agent 也会失败。

并非 Ops Agent 支持的所有操作系统也受 Monitoring 代理支持。如需了解受支持的操作系统,请参阅“Ops Agent:Linux 操作系统”“Monitoring 代理:Linux 操作系统”

如需安装 Ops Agent,请执行以下操作:

  1. 移除 Monitoring 代理的代码库:

    如果您的系统上有 add-monitoring-agent-repo.sh 脚本,请运行以下命令:

    sudo bash add-monitoring-agent-repo.sh --remove-repo
    

    否则,请手动移除代码库:

    Debian

    sudo rm /etc/apt/sources.list.d/google-cloud-monitoring.list

    RHEL

     sudo rm /etc/yum.repos.d/google-cloud-monitoring.repo

    苏斯

    sudo rm /etc/zypp/repos.d/google-cloud-monitoring.repo

  2. 运行 Ops Agent 安装脚本。

由于代码库刷新失败,Ops Agent 安装失败

安装 Ops Agent 失败,因为刷新已安装代码库失败。

Linux

如需查看 Debian 操作系统(其中由于调用 apt-get update 而刷新代码库)失败消息的示例,请参阅 Monitoring 代理安装失败后 Ops Agent 安装也失败了这一问题排查条目。

如果在刷新代码库时遇到故障,则必须先解决这些故障,然后才能安装 Ops Agent。您可以通过删除或停用不需要的代码库来解决这些故障。

能够刷新代码库后,您可以通过运行 Ops Agent 安装脚本来安装 Ops Agent。

代理已安装,但无法运行

如果您已安装此代理,但此代理未运行,则问题可能属于以下某一种:

代理服务未在运行

如果代理服务按预期运行,那么当您查询状态时,Metrics Agent 和 Logging 代理会列为正在运行:

适用于 Linux

sudo systemctl status google-cloud-ops-agent"*"

为简单起见,输出中的一些行已删除。

● google-cloud-ops-agent.service - Google Cloud Ops Agent
     Loaded: loaded (/lib/systemd/system/google-cloud-ops-agent.service; enabled; vendor preset: enabled)
     Active: active (exited) since Wed 2023-05-03 21:22:28 UTC; 4 weeks 0 days ago
    Process: 3353828 ExecStartPre=/opt/google-cloud-ops-agent/libexec/google_cloud_ops_agent_engine -in /etc/go>
    Process: 3353837 ExecStart=/bin/true (code=exited, status=0/SUCCESS)
   Main PID: 3353837 (code=exited, status=0/SUCCESS)
        CPU: 195ms

[...]

● google-cloud-ops-agent-opentelemetry-collector.service - Google Cloud Ops Agent - Metrics Agent
     Loaded: loaded (/lib/systemd/system/google-cloud-ops-agent-opentelemetry-collector.service; static)
     Active: active (running) since Wed 2023-05-03 21:22:29 UTC; 4 weeks 0 days ago
    Process: 3353840 ExecStartPre=/opt/google-cloud-ops-agent/libexec/google_cloud_ops_agent_engine -service=ot>
   Main PID: 3353855 (otelopscol)
      Tasks: 9 (limit: 2355)
     Memory: 65.3M
        CPU: 40min 31.555s
     CGroup: /system.slice/google-cloud-ops-agent-opentelemetry-collector.service
             └─3353855 /opt/google-cloud-ops-agent/subagents/opentelemetry-collector/otelopscol --config=/run/g>

[...]

● google-cloud-ops-agent-fluent-bit.service - Google Cloud Ops Agent - Logging Agent
     Loaded: loaded (/lib/systemd/system/google-cloud-ops-agent-fluent-bit.service; static)
     Active: active (running) since Wed 2023-05-03 21:22:29 UTC; 4 weeks 0 days ago
    Process: 3353838 ExecStartPre=/opt/google-cloud-ops-agent/libexec/google_cloud_ops_agent_engine -service=fl>
   Main PID: 3353856 (google_cloud_op)
      Tasks: 31 (limit: 2355)
     Memory: 58.3M
        CPU: 29min 6.771s
     CGroup: /system.slice/google-cloud-ops-agent-fluent-bit.service
             ├─3353856 /opt/google-cloud-ops-agent/libexec/google_cloud_ops_agent_wrapper -config_path /etc/goo>
             └─3353872 /opt/google-cloud-ops-agent/subagents/fluent-bit/bin/fluent-bit --config /run/google-clo>

[...]

● google-cloud-ops-agent-diagnostics.service - Google Cloud Ops Agent - Diagnostics
     Loaded: loaded (/lib/systemd/system/google-cloud-ops-agent-diagnostics.service; disabled; vendor preset: e>
     Active: active (running) since Wed 2023-05-03 21:22:26 UTC; 4 weeks 0 days ago
   Main PID: 3353819 (google_cloud_op)
      Tasks: 8 (limit: 2355)
     Memory: 36.0M
        CPU: 3min 19.488s
     CGroup: /system.slice/google-cloud-ops-agent-diagnostics.service
             └─3353819 /opt/google-cloud-ops-agent/libexec/google_cloud_ops_agent_diagnostics -config /etc/goog>

[...]

适用于 Windows

Get-Service google-cloud-ops-agent*

Status   Name               DisplayName
------   ----               -----------
Running  google-cloud-op... Google Cloud Ops Agent
Running  google-cloud-op... Google Cloud Ops Agent - Logging Agent
Running  google-cloud-op... Google Cloud Ops Agent - Metrics Agent
Running  google-cloud-op... Google Cloud Ops Agent - Diagnostics

如果代理服务无法运行,您可能会看到以下状态:

Linux

$ sudo service google-cloud-ops-agent status
● google-cloud-ops-agent.service - Google Cloud Ops Agent
   Loaded: loaded (/lib/systemd/system/google-cloud-ops-agent.service; enabled; vendor preset: enabled)
   Active: inactive (dead) since Wed 2021-06-30 21:20:43 UTC; 6s ago

Windows

Get-Service google-cloud-ops-agent

Status   Name                    DisplayName
------   ----                    -----------
Stopped  google-cloud-ops-agent  Google Cloud Ops Agent

如需消除此错误,请运行以下命令来启动服务:

Linux

sudo service google-cloud-ops-agent start

Windows

Start-Service google-cloud-ops-agent

如果服务无法启动,则说明配置可能无效。

与当前已安装的代理冲突

  • 虚拟机已安装 Cloud Logging 代理Cloud Monitoring 代理,并且其配置与新代理的配置冲突。错误消息可能类似于以下内容:

    Windows

    We detected an existing Windows service for the StackdriverLogging agent,
    which is not compatible with the Ops Agent when the Ops Agent configuration
    has a non-empty logging section. Please either remove the logging section
    from the Ops Agent configuration, or disable the StackdriverLogging agent,
    and then retry enabling the Ops Agent.
    

    如需修复此错误,您有以下两种选择:

    1. 停用 Ops Agent 配置文件的冲突部分。如需了解详情,请参阅配置 Ops Agent 指南。

    2. 停用有冲突的 Cloud Logging 代理Cloud Monitoring 代理

      1. 保存 Cloud Logging 代理的所有自定义配置文件。
      2. 卸载旧的 Cloud Monitoring 代理Cloud Logging 代理

      卸载代理后,Google Cloud 控制台最多可能需要一小时才能报告此更改。

所需端口不可用

当 Ops Agent 或其某个组件所需的端口正被其他进程使用时,可能无法启动。Ops Agent 使用以下端口:

  • 端口 20201,用于“指标代理”组件
  • 端口 20202,用于“Logging 代理”组件

如果 Ops Agent 组件以外的进程正在使用端口 20201 或端口 20202,请停止该进程并重启 Ops Agent。如需确定哪个进程正在使用这些端口,请按以下步骤操作:

Linux

指标代理组件:要查看哪个进程正在使用端口 20201,请使用以下命令:

sudo netstat -ns -p | grep '20201'

以下输出显示了预期结果:Ops Agent 指标收集器 otelopscol 正在使用端口:

tcp        0      0 127.0.0.1:50138         127.0.0.1:20201         ESTABLISHED 16850/otelopscol
tcp6       0      0 :::20201                :::*                    LISTEN      16850/otelopscol
tcp6       0      0 127.0.0.1:20201         127.0.0.1:50138         ESTABLISHED 16850/otelopscol

Logging 代理组件:如需查看哪个进程正在使用端口 20202,请使用以下命令:

sudo netstat -ns -p | grep '20202'

以下输出显示了预期结果:Ops Agent 日志收集器 fluent-bit 正在使用端口:

tcp        0      0 0.0.0.0:20202           0.0.0.0:*               LISTEN      16640/fluent-bit
tcp        0      0 127.0.0.1:20202         127.0.0.1:52998         TIME_WAIT   -

Windows

指标代理组件:要查看哪个进程正在使用端口 20201,请使用以下命令:

netstat -na -b  | Select-String "20201" -Context 0,1

以下输出显示了预期结果:Ops Agent 指标收集器 google-cloud-metrics-agent_windows_amd64.exe 正在使用端口:

>   TCP    0.0.0.0:20201          0.0.0.0:0              LISTENING
   [google-cloud-metrics-agent_windows_amd64.exe]
>   TCP    127.0.0.1:20201        127.0.0.1:50090        ESTABLISHED
   [google-cloud-metrics-agent_windows_amd64.exe]
>   TCP    127.0.0.1:50090        127.0.0.1:20201        ESTABLISHED
   [google-cloud-metrics-agent_windows_amd64.exe]
>   TCP    [::]:20201             [::]:0                 LISTENING
   [google-cloud-metrics-agent_windows_amd64.exe]

Logging 代理组件:如需查看哪个进程正在使用端口 20202,请使用以下命令:

netstat -na -b  | Select-String "20202" -Context 0,1

以下输出显示了预期结果:Ops Agent 日志收集器 fluent-bit.exe 正在使用端口:

>   TCP    0.0.0.0:20202          0.0.0.0:0              LISTENING
   [fluent-bit.exe]
>   TCP    127.0.0.1:20202        127.0.0.1:57535        TIME_WAIT
>   TCP    127.0.0.1:20202        127.0.0.1:57539        TIME_WAIT
    TCP    127.0.0.1:49807        127.0.0.1:49808        ESTABLISHED

Ops Agent 运行的健康检查可以检测端口可用性错误。

代理缺少 API 权限

如果代理无法启动或无法注入数据,则问题可能是“指标代理”或“Logging 代理”组件缺少访问 API 所需的权限。

Ops Agent 使用的服务帐号需要以下 Identity and Access Management 角色:

这些角色包括写入日志记录或指标数据所需的权限,并且必须授予与虚拟机关联的服务帐号。您正在使用的服务帐号取决于您配置虚拟机以及向代理授权的方式。您可能正在使用以下某个命令:

如需确定与虚拟机关联的服务帐号,请执行以下操作:

  1. 在 Google Cloud 控制台的导航面板中,选择 Compute Engine,然后选择虚拟机实例

    前往虚拟机实例

  2. 如有必要,点击 Google Cloud 项目的下拉列表,然后选择您项目的名称。

  3. 如有必要,选择实例标签页。

  4. 在虚拟机实例列表中,点击虚拟机的名称以查看该虚拟机的详细信息页面。

  5. 找到页面的 API 和身份管理部分。 服务帐号被列为 Service account 字段的值。

如需了解如何设置授予服务帐号的角色,请参阅验证和修改现有服务帐号的角色

Ops Agent 运行的健康检查可以检测 API 权限错误。

配置无效

如果配置无效,您可能会在尝试重启代理服务时看到以下错误:

Linux

$ sudo service google-cloud-ops-agent restart \
    && sudo service google-cloud-ops-agent status
● google-cloud-ops-agent-fluent-bit.service - Google Cloud Ops Agent - Logging Agent
   Loaded: loaded (/usr/lib/systemd/system/google-cloud-ops-agent-fluent-bit.service; static; vendor preset: disabled)
  Drop-In: /usr/lib/systemd/system/google-cloud-ops-agent-fluent-bit.service.d
           └─directories.conf
   Active: failed (Result: exit-code) since Wed 2021-06-30 22:21:08 UTC; 2s ago
  Process: 1141421 ExecStart=/opt/google-cloud-ops-agent/subagents/fluent-bit/bin/fluent-bit --config ${RUNTIME_DIRECTORY}/fluent_bit_main.conf --parser ${RUNTIME_DIRECTORY}/fluent_bit_parser.conf --log_>
  Process: 1141847 ExecStartPre=/opt/google-cloud-ops-agent/libexec/google_cloud_ops_agent_engine -service=fluentbit -in /etc/google-cloud-ops-agent/config.yaml -logs ${LOGS_DIRECTORY} -state ${STATE_DIR>
 Main PID: 1141421 (code=exited, status=0/SUCCESS)

Jun 30 22:21:08 centos8-2 systemd[1]: google-cloud-ops-agent-fluent-bit.service: Control process exited, code=exited status=1
Jun 30 22:21:08 centos8-2 systemd[1]: google-cloud-ops-agent-fluent-bit.service: Failed with result 'exit-code'.
Jun 30 22:21:08 centos8-2 systemd[1]: Failed to start Google Cloud Ops Agent - Logging Agent.
Jun 30 22:21:08 centos8-2 systemd[1]: google-cloud-ops-agent-fluent-bit.service: Service RestartSec=100ms expired, scheduling restart.
Jun 30 22:21:08 centos8-2 systemd[1]: google-cloud-ops-agent-fluent-bit.service: Scheduled restart job, restart counter is at 5.
Jun 30 22:21:08 centos8-2 systemd[1]: Stopped Google Cloud Ops Agent - Logging Agent.
Jun 30 22:21:08 centos8-2 systemd[1]: google-cloud-ops-agent-fluent-bit.service: Start request repeated too quickly.
Jun 30 22:21:08 centos8-2 systemd[1]: google-cloud-ops-agent-fluent-bit.service: Failed with result 'exit-code'.
Jun 30 22:21:08 centos8-2 systemd[1]: Failed to start Google Cloud Ops Agent - Logging Agent.

使用 journalctl 获取确切的错误消息:

sudo journalctl -xe | grep "google_cloud_ops_agent_engine"

您可能会看到类似如下内容的消息:

Jun 30 22:00:26 centos8-2 google_cloud_ops_agent_engine[1141491]: 2021/06/30 22:00:26 the agent config file is not valid YAML. detailed error: yaml: line 21: did not find expected key

Windows

failed to generate config files: can't parse configuration: yaml: line 20: could not find expected ':'

如需修复该错误,请更正无效配置并重启代理。如需了解参考信息,请参阅配置 Ops Agent 指南。

代理崩溃并报告提及 NVIDIA

您正尝试在 挂接了 GPU 的 Compute Engine 虚拟机上运行 Ops Agent。代理发生崩溃,并且输出中会提示 NVIDIA。

这是 Ops Agent 2.39.0 和 2.40.0 版本的已知问题。如需缓解此问题,请安装 Ops Agent 2.38.0 版、2.41.0 版或更高版本。

Google Cloud 控制台中的状态信息有误

Google Cloud 控制台会在各种信息中心(例如 Cloud Monitoring 中的虚拟机实例信息中心)报告有关 Compute Engine 虚拟机上的代理状态的信息。如果这些信息与您的预期不符,原因可能只是延迟而已,因为配置更改在系统中传播需要一点时间。但是,意外信息也可能表示代理并未按预期运行。

安装了由 Google Cloud 控制台报告为未检测到的代理

代理必须正在运行并提取数据,以便 Google Cloud 控制台能够识别代理的存在。 如果您已安装代理,但控制台状态仍为“未检测到”,则表示代理未运行或正在运行但未注入数据。详情请参阅以下内容:

移除了由 Google Cloud 控制台报告为已安装的代理

卸载代理后,Google Cloud 控制台最多可能需要一小时才能报告此更改。