如要從檢測應用程式收集 OTLP 記錄、指標和追蹤記錄,並將該遙測資料匯出至 Google Cloud,您可以在 Compute Engine 虛擬機器 (VM) 執行個體上部署 Google 建構的 OpenTelemetry Collector。
事前準備
如要執行 Google 建構的 OpenTelemetry 收集器,必須具備下列資源:
-
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
Roles required to select or create a project
- Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
-
Create a project: To create a project, you need the Project Creator role
(
roles/resourcemanager.projectCreator), which contains theresourcemanager.projects.createpermission. Learn how to grant roles.
-
Verify that billing is enabled for your Google Cloud project.
Enable the Cloud Logging, Cloud Monitoring, and Cloud Trace APIs, if any are not already enabled.
Roles required to enable APIs
To enable APIs, you need the
serviceusage.services.enablepermission. If you created the project, then you likely already have this permission through the Owner role (roles/owner). Otherwise, you can get this permission through the Service Usage Admin role (roles/serviceusage.serviceUsageAdmin). Learn how to grant roles.- Compute Engine 執行個體。如果您沒有 Compute Engine 執行個體,請按照「建立及啟動 Compute Engine 執行個體」一文中的操作說明操作。
- 安裝
gcloud。如要瞭解如何安裝gcloud,請參閱「安裝gcloudCLI」。
設定收集器的權限
根據預設,Compute Engine 執行個體會使用 Compute Engine 預設服務帳戶 PROJECT_NUMBER-compute@。這個服務帳戶通常具備必要的 Identity and Access Management (IAM) 角色,可寫入本文所述的指標和記錄:
如果您選擇使用使用者自行管理的服務帳戶,而非預設帳戶,則必須為該帳戶指派這些角色。詳情請參閱「服務帳戶」。
安裝收集器
如要將 Google 建構的 OpenTelemetry Collector 安裝為 Compute Engine 執行個體的套件,請完成下列步驟。
Debian 與 Ubuntu
使用 SSH 或類似工具開啟 VM 執行個體的終端機連線,並確認您具備
sudo存取權。執行下列指令,設定 Package Repository:
sudo mkdir -p /etc/apt/keyrings sudo curl -o /etc/apt/keyrings/otelcol-google.asc https://packages.cloud.google.com/apt/doc/apt-key.gpg cat <<EOF | sudo tee /etc/apt/sources.list.d/otelcol-google.list deb [signed-by=/etc/apt/keyrings/otelcol-google.asc] https://us-apt.pkg.dev/projects/cloud-ops-agents-artifacts google-cloud-opentelemetry-collector-apt main EOF重新整理套件管理工具並安裝套件:
sudo apt update sudo apt install otelcol-google安裝完成後,Google 建構的 OpenTelemetry Collector 會自動啟動。
CentOS、RHEL 和 Rocky Linux
使用 SSH 或類似工具開啟 VM 執行個體的終端機連線,並確認您具備
sudo存取權。執行下列指令,設定 Package Repository:
cat <<EOF | sudo tee /etc/yum.repos.d/otelcol-google.repo [otelcol-google] name=Google Built OpenTelemetry Collector baseurl=https://us-yum.pkg.dev/projects/cloud-ops-agents-artifacts/google-cloud-opentelemetry-collector-yum autorefresh=0 enabled=1 type=rpm-md gpgcheck=1 repo_gpgcheck=0 gpgkey=http://dl.google.com/linux/linux_signing_key.pub EOF安裝套件:
sudo yum install otelcol-google安裝完成後,Google 建構的 OpenTelemetry Collector 會自動啟動。
SLES
使用 SSH 或類似工具開啟 VM 執行個體的終端機連線,並確認您具備
sudo存取權。執行下列指令,設定 Package Repository:
cat <<EOF | sudo tee /etc/zypp/repos.d/otelcol-google.repo [otelcol-google] name=Google Built OpenTelemetry Collector baseurl=https://us-yum.pkg.dev/projects/cloud-ops-agents-artifacts/google-cloud-opentelemetry-collector-yum autorefresh=0 enabled=1 type=rpm-md gpgkey=http://dl.google.com/linux/linux_signing_key.pub EOF安裝套件:
sudo zypper install otelcol-google安裝完成後,Google 建構的 OpenTelemetry Collector 會自動啟動。
Windows
使用 RDP 或類似工具連線至執行個體,然後登入 Windows。
在 PowerShell 圖示上按一下滑鼠右鍵,然後選取「Run as Administrator」(以管理員身分執行),開啟具備管理員權限的 PowerShell 終端機。
執行下列 PowerShell 指令,設定 Package Repository:
googet addrepo otelcol-google ` https://us-googet.pkg.dev/projects/cloud-ops-agents-artifacts/repos/google-cloud-opentelemetry-collector-googet安裝套件:
googet install otelcol-google安裝完成後,Google 建構的 OpenTelemetry Collector 會自動啟動。
部署收集器
Google 建構的 OpenTelemetry Collector 預設包含最低限度的設定,不會匯出遙測資料。如要匯出遙測資料,請在安裝收集器後,覆寫預設設定來設定收集器。請將收集器的設定放在下列檔案中:
- Linux:
/etc/otelcol-google/config.yaml - Windows 系統:
C:\Program Files\Google\OpenTelemetry Collector\config.yaml
設定收集器
我們提供 OpenTelemetry Collector 設定,可與 Google 建構的 Collector 搭配使用。這項設定旨在提供大量 OTLP 指標、記錄和追蹤記錄。這項設定也能避免常見的攝入問題。您可以新增設定,但強烈建議不要移除元素。
本節說明提供的設定、匯出工具、處理器、接收器等重要元件,以及其他可用元件。
提供的收集器設定
您可以在opentelemetry-operations-collector 存放區的 google-built-opentelemetry-collector 目錄中找到收集器設定:
出口商
收集器設定會使用下列項目:
- OTLP gRPC 匯出工具,用於將記錄、指標和追蹤記錄傳送至 Telemetry (OTLP) API。
- 用於 API 驗證的
googleclientauthextension。
處理器
收集器設定包含下列處理器:
batch:設定為批次處理遙測要求,每項要求最多 Google Cloud 個項目,或每 5 秒 Google Cloud 最短間隔 (以先到者為準)。memory_limiter:限制收集器的記憶體用量,在超過限制時捨棄資料點,避免記憶體不足而當機。resourcedetection:自動偵測 Google Cloud 資源標籤,例如project_id。
接收器
收集器設定僅包含 otlp 接收器。如要瞭解如何檢測應用程式,將 OTLP 追蹤記錄和指標傳送至收集器的 OTLP 端點,請參閱「選擇檢測方法」。
可用元件
Google 建構的 OpenTelemetry Collector 包含大多數使用者所需的元件,可在 Google Cloud Observability 中提供豐富體驗。如需可用元件的完整清單,請參閱 opentelemetry-operations-collector 存放區中的元件。
如要要求變更或新增可用元件,請在 opentelemetry-operations-collector 存放區中提出功能要求。
生成遙測資料
您可以使用開放原始碼 telemetrygen 工具測試設定。連結中包含下載及執行工具的操作說明。如要執行工具,必須安裝 Go 或 Docker。
幾分鐘後,應用程式產生的遙測資料會開始透過收集器,流向每個信號的 Google Cloud 控制台。
查看遙測資料
Google 建構的 OpenTelemetry Collector 會將檢測應用程式的指標、記錄和追蹤記錄傳送至 Google Cloud Observability。收集器也會傳送自我觀測能力指標。以下各節說明如何查看這項遙測資料。
查看指標
Google 建構的 OpenTelemetry Collector 會收集 Prometheus 指標,您可以使用 Metrics Explorer 查看這些指標。收集的指標取決於應用程式的檢測,但 Google 建構的收集器也會寫入一些自我指標。
如要查看 Google 建構的 OpenTelemetry Collector 收集的指標,請按照下列步驟操作:-
前往 Google Cloud 控制台的leaderboard「Metrics Explorer」頁面:
如果您是使用搜尋列尋找這個頁面,請選取子標題為「Monitoring」的結果。
- 在 Google Cloud 控制台的工具列中,選取 Google Cloud 專案。如果是 App Hub 設定,請選取 App Hub 主專案或已啟用應用程式管理功能的資料夾管理專案。
- 在「Metric」(指標) 元素中,展開「Select a metric」(選取指標) 選單,在篩選列中輸入
Prometheus Target,然後使用子選單選取特定資源類型和指標:- 在「Active resources」(有效資源) 選單中,選取「Prometheus Target」(Prometheus 目標)。
- 如要選取指標,請使用「使用中的指標類別」和「使用中的指標」選單。
Google 建構的 OpenTelemetry Collector 收集的指標,前置字串為
prometheus.googleapis.com。 - 按一下「套用」。
如要新增篩選器,從查詢結果中移除時間序列,請使用「Filter」(篩選器) 元素。
- 設定資料的查看方式。
如果指標的測量結果是累計值,Metrics Explorer 會自動依據校正週期正規化測量資料,圖表則會顯示比率。詳情請參閱「種類、類型和轉換」。
測量整數或雙精度值時 (例如使用
counter指標),Metrics Explorer 會自動加總所有時間序列。如要變更這項行為,請將「Aggregation」(匯總) 項目中的第一個選單設為「None」(無)。如要進一步瞭解如何設定圖表,請參閱「在使用 Metrics Explorer 時選取指標」。
查看追蹤記錄
如要查看追蹤記錄資料,請按照下列步驟操作:
-
前往 Google Cloud 控制台的
「Trace Explorer」頁面:前往「Trace explorer」(Trace 探索工具)
您也可以透過搜尋列找到這個頁面。
- 在 Google Cloud 控制台的工具列中,選取 Google Cloud 專案。如要設定 App Hub,請選取 App Hub 主專案或管理專案。
- 在頁面的表格部分選取一列。
在「Trace details」(追蹤記錄詳細資料) 面板的甘特圖中,選取所需時距。
畫面上會開啟一個面板,顯示追蹤要求的相關資訊。這些詳細資料包括方法、狀態碼、位元組數,以及呼叫端的使用者代理程式。
如要查看與這個追蹤記錄相關聯的記錄檔,請選取「Logs & Events」(記錄檔和事件) 分頁標籤。
這個分頁會顯示個別記錄。如要查看記錄項目的詳細資料,請展開記錄項目。您也可以點選「View Logs」(查看記錄),並使用 Logs Explorer 查看記錄。
如要進一步瞭解如何使用 Cloud Trace Explorer,請參閱「尋找及探索追蹤記錄」。
查看記錄檔
您可以在 Logs Explorer 中檢查記錄,也可以查看相關聯的追蹤記錄 (如有)。
-
前往 Google Cloud 控制台的 「Logs Explorer」頁面:
如果您是使用搜尋列尋找這個頁面,請選取子標題為「Logging」的結果。
找出檢測應用程式的記錄項目,然後展開該項目查看詳細資料。
在含有追蹤訊息的記錄項目上,按一下
「Traces」(追蹤記錄),然後選取「View trace details」(查看追蹤記錄詳細資料)。「Trace details」(追蹤記錄詳細資料) 面板隨即開啟,並顯示所選追蹤記錄。
如要進一步瞭解如何使用 Logs Explorer,請參閱「使用 Logs Explorer 查看記錄檔」。
觀察收集器並偵錯
Google 建構的 OpenTelemetry Collector 會自動提供自我觀測能力指標,協助您監控其效能,並確保 OTLP 擷取管道持續正常運作。
如要監控收集器,請安裝收集器的範例資訊主頁。這個資訊主頁可讓您一目瞭然地查看 Collector 的多項指標,包括運作時間、記憶體用量,以及對 Google Cloud Observability 的 API 呼叫。
如要安裝資訊主頁,請按照下列步驟操作:
-
在 Google Cloud 控制台中,前往「Dashboards」(資訊主頁) 頁面:
如果您是使用搜尋列尋找這個頁面,請選取子標題為「Monitoring」的結果。
- 按一下「資訊主頁範本」。
- 搜尋「OpenTelemetry Collector」資訊主頁。
- 選用:如要預覽資訊主頁,請選取該資訊主頁。
按一下「playlist_add Add dashboard to your list」(將資訊主頁新增至清單),然後完成對話方塊。
您可以在對話方塊中選取資訊主頁名稱,並為資訊主頁新增標籤。
如要進一步瞭解如何安裝資訊主頁,請參閱「安裝資訊主頁範本」。