這份文件提供的資訊可協助您診斷及解決 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 衝突的舊版代理程式
如果 VM 已安裝 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」指南。
如要修正這項錯誤,請按照下列步驟操作:
儲存 Cloud Monitoring 代理程式和 Cloud Logging 代理程式的自訂設定檔。
解除安裝舊版 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 代理程式安裝失敗,Ops Agent 也會因為 Monitoring 代理程式存放區無效而無法安裝。
並非所有 Ops Agent 支援的作業系統,也支援 Monitoring Agent。如要瞭解支援的作業系統,請參閱「Ops Agent:Linux 作業系統」和「監控代理程式:Linux 作業系統」。
如要安裝 Ops Agent,請按照下列步驟操作:
移除 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
Suse
sudo rm /etc/zypp/repos.d/google-cloud-monitoring.repo
執行 Ops Agent 安裝指令碼。
存放區重新整理失敗,因此無法安裝 Ops Agent
由於已安裝存放區的重新整理作業失敗,因此無法安裝 Ops Agent。
Linux
如要查看 Debian 作業系統的失敗訊息範例 (因呼叫 apt-get update 而重新整理存放區),請參閱疑難排解項目「Ops Agent install fails after failed Monitoring agent install」(安裝 Monitoring 代理程式失敗後,無法安裝作業套件代理程式)。
如果重新整理存放區時發生失敗情形,請先解決這些問題,再安裝 Ops Agent。您或許可以刪除或停用不必要的存放區,解決這些失敗問題。
成功重新整理存放區後,即可執行 Ops Agent 安裝指令碼,安裝 Ops Agent。
公開金鑰無法使用,因此存放區重新整理失敗
Linux
由於呼叫 apt-get update,存放區重新整理作業失敗,因為公開金鑰無法使用。安裝或升級 Ops Agent 時也可能發生這種情況。您可能會看到下列失敗訊息:
W: GPG error: http://packages.cloud.google.com/apt google-cloud-ops-agent-focal-all InRelease: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY C0BA5CE6DC6315A3
E: The repository 'http://packages.cloud.google.com/apt google-cloud-ops-agent-focal-all InRelease' is not signed.
如要修正這項錯誤,請執行下列指令,將缺少的金鑰新增至系統:
curl -fsSL https://packages.cloud.google.com/apt/doc/apt-key.gpg \
| sudo gpg --dearmor -o /etc/apt/trusted.gpg.d/google-cloud-ops-agent.gpg
代理程式已安裝,但未執行
如果已安裝代理程式,但代理程式未執行,問題可能出在下列其中一項:
- 主要元件「指標代理程式」或「記錄代理程式」啟動失敗;請參閱「代理程式服務未執行」。
- VM 也安裝了其中一個舊版代理程式;請參閱「與目前安裝的代理程式衝突」一節。
- 某個元件所需的通訊埠正由其他程序使用;請參閱「無法使用的通訊埠」。
- Ops Agent 設定無效;請參閱「設定無效」。
代理程式服務未執行
如果代理程式服務正常運作,查詢狀態時會顯示 Metrics Agent 和 Logging Agent 正在執行:
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>
[...]
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
如果代理程式服務未執行,您可能會看到下列狀態:
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
如果服務無法啟動,可能是設定無效。
與目前安裝的代理程式衝突
VM 已安裝 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.
如要修正這項錯誤,請選擇下列任一做法:
停用 Ops Agent 設定檔中衝突的部分。詳情請參閱「設定 Ops Agent」指南。
停用衝突的 Cloud Logging 代理程式或 Cloud Monitoring 代理程式。
- 儲存 Cloud Logging 代理程式的所有自訂設定檔。
- 解除安裝舊版 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
記錄代理程式元件:如要查看哪個程序使用 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]
記錄代理程式元件:如要查看哪個程序使用 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 角色:
- 「記錄代理程式」元件:記錄寫入者 (
roles/logging.logWriter) - 「指標代理程式」元件:Monitoring 指標寫入者 (
roles/monitoring.metricWriter)。
這些角色包含寫入記錄或指標資料所需的權限,且必須授予與 VM 相關聯的服務帳戶。您使用的服務帳戶取決於 VM 的設定方式和代理程式的授權方式。您可能使用下列其中一項:
- 附加至 VM 的服務帳戶。
- 使用私密金鑰的服務帳戶。
如要找出與 VM 相關聯的服務帳戶,請執行下列操作:
-
前往 Google Cloud 控制台的「VM instances」(VM 執行個體) 頁面:
如果您是使用搜尋列尋找這個頁面,請選取子標題為「Compute Engine」的結果。
如有必要,請按一下專案的下拉式清單 Google Cloud ,然後選取專案名稱。
視需要選取「執行個體」分頁標籤。
在 VM 執行個體清單中,按一下 VM 名稱,即可查看 VM 的「詳細資料」頁面。
找到頁面的「API and identity management」(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
您嘗試在 Compute Engine VM 上執行 Ops Agent,但該 VM 已附加 GPU。代理程式當機,且輸出內容提及 NVIDIA。
這是 Ops Agent 2.39.0 和 2.40.0 版的已知問題。如要解決這個問題,請安裝 Ops Agent 2.38.0 版,或 2.41.0 以上版本。Google Cloud 控制台中的狀態資訊有誤
Google Cloud 控制台會在各種資訊主頁中,回報 Compute Engine VM 上的代理程式狀態資訊,例如 Cloud Monitoring 中的「VM Instances」(VM 執行個體) 資訊主頁。如果這項資訊與預期不符,原因可能只是系統延遲處理設定變更。但如果出現非預期的資訊,可能表示代理程式未如預期運作。
Google Cloud 控制台回報已安裝的代理程式未偵測到
代理程式必須正在執行並擷取資料, Google Cloud 控制台 才會辨識出代理程式。如果已安裝代理程式,但控制台狀態仍為「未偵測到」,表示代理程式未執行,或正在執行但未擷取資料。如要瞭解詳情,請參考下列資源:
已移除 Google Cloud 控制台回報為已安裝的代理程式
解除安裝代理程式後, Google Cloud 主控台最多可能需要一小時才會回報這項變更。