使用 Cloud Monitoring 建立 pipeline 監控資訊主頁
瞭解如何使用 Cloud Monitoring 建立資訊主頁來監控管道。
如要直接在 Google Cloud 控制台按照逐步指南操作,請按一下「Guide me」(逐步引導):
事前準備
- Sign in to your Google Cloud account. If you're new to Google Cloud, create an account to evaluate how our products perform in real-world scenarios. New customers also get $300 in free credits to run, test, and deploy workloads.
-
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
(
roles/resourcemanager.projectCreator
), which contains theresourcemanager.projects.create
permission. Learn how to grant roles.
-
Verify that billing is enabled for your Google Cloud project.
-
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
(
roles/resourcemanager.projectCreator
), which contains theresourcemanager.projects.create
permission. Learn how to grant roles.
-
Verify that billing is enabled for your Google Cloud project.
-
Enable the Cloud Data Fusion, BigQuery, Cloud Storage, and Dataproc APIs.
Roles required to enable APIs
To enable APIs, you need the Service Usage Admin IAM role (
roles/serviceusage.serviceUsageAdmin
), which contains theserviceusage.services.enable
permission. Learn how to grant roles. 如要建立自訂資訊主頁,您必須取得服務帳戶的「Monitoring 編輯者」(
roles/monitoring.editor
) IAM 角色。如要進一步瞭解如何授予角色,請參閱管理存取權。
前往 Cloud Data Fusion 的「Instances」(執行個體) 頁面,然後按一下「Create instance」(建立執行個體)。
在「Instance name」(執行個體名稱) 欄位中,輸入新執行個體的名稱。
從「Region」(區域) 下拉式選單中,選取要建立執行個體的 Google Cloud 區域。
從「Version」(版本) 下拉式選單中選取 Cloud Data Fusion 版本。
選取一個版本。
展開進階選項
在「Logging and monitoring」(記錄和監控) 區段中,選取「Enable Stackdriver logging service」(啟用 Stackdriver Logging 服務)。
點選「建立」。
建立已啟用 Cloud Logging 的 Cloud Data Fusion 執行個體
如要搭配使用 Cloud Logging 和 Cloud Data Fusion 管道,請建立已啟用 Cloud Logging 的 Cloud Data Fusion 執行個體:
建立記錄指標
前往 Cloud Logging 的「Log-based metrics」(記錄指標) 頁面:
點選「建立指標」。
在「Create metric」(建立指標) 頁面中執行下列操作:
- 在「Metric type」(指標類型) 部分,選取「Counter」(計數器)。
- 在「Log-based metric name」(記錄指標名稱) 欄位中,輸入
pipeline_logs
。 - 在「Units」(單位) 欄位中輸入
1
。 在「Build filter」(建構篩選器) 欄位中輸入下列內容:
resource.type="cloud_dataproc_cluster" log_name=~"projects/.*/logs/datafusion-pipeline-logs"
在「Labels」(標籤) 專區中,按一下「Add label」(新增標籤),然後建立下列標籤。輸入每個標籤後,請按一下「Done」(完成),然後再次點選「Add label」(新增標籤) 來建立下一個標籤。
標籤名稱 標籤類型 欄位名稱 Project
STRING
resource.labels.project_id
Message
STRING
jsonPayload.message
LoggerName
STRING
labels.loggerName
ClusterName
STRING
resource.labels.cluster_name
SparkPhase
STRING
labels.".workflowSparkId"
Region
STRING
resource.labels.region
Pipeline
STRING
labels.".applicationId"
RunId
STRING
labels.".runId"
Namespace
STRING
labels.".namespaceId"
LogLevel
STRING
labels.levelName
按一下「Create metric」(建立指標)。
新建立的指標會出現在使用者定義的指標表格中。如果指標未立即顯示,請重新整理頁面。
資訊主頁包含下列圖表:
- 所有管道
- 已完成的管道
- 失敗的管道
- 所有管道執行作業
- 已完成的管道執行作業
- 失敗的管道執行作業
- 用於執行作業的 Dataproc 叢集
建立指標後,最多可能需要 24 小時,時間序列資料才會開始顯示。
安裝資訊主頁
下載 JSON 檔案至本機電腦。
前往 Cloud Monitoring 的「Dashboards」(資訊主頁) 頁面:
按一下「Create dashboard」(建立資訊主頁)。
按一下 >「JSON」>「JSON editor」(JSON 編輯器)。
「Dashboard settings」(資訊主頁設定)在文字編輯器中,開啟您下載的 JSON 檔案。
複製下載的 JSON 檔案內容,然後貼到 JSON 編輯器中,將 JSON 編輯器預設包含的內容更換成這些值。
按一下「Apply changes」(套用變更)。
這會重新整理資訊主頁。指標建立後,Cloud Data Fusion 管道會執行,並會顯示在資訊主頁上。如果建立指標之後未執行任何管道,資訊主頁就不會顯示任何內容。
自動儲存功能預設會啟用。如果自動儲存功能已停用,按一下「Save」(儲存) 即可儲存資訊主頁。
按一下「Close editor」(關閉編輯器)。
新的資訊主頁會顯示在「Monitoring overview」(Monitoring 總覽) 頁面的資訊主頁清單中。
清除所用資源
如要避免系統向您的 Google Cloud 帳戶收取本頁所用資源的費用,請按照下列步驟操作。
刪除 Cloud Data Fusion 執行個體
請按照刪除 Cloud Data Fusion 執行個體一文的操作說明進行。
刪除專案
如要避免付費,最簡單的方法就是刪除您為了本教學課程所建立的專案。
如要刪除專案:
- In the Google Cloud console, go to the Manage resources page.
- In the project list, select the project that you want to delete, and then click Delete.
- In the dialog, type the project ID, and then click Shut down to delete the project.
後續步驟
- 進一步瞭解 Cloud Monitoring