您可以建立自訂指標來發出快訊或提供資訊,以解決排程快照問題。
舉例來說,如要設定快照排程失敗的快訊,請按照下列程序操作:
事前準備
-
如果尚未設定,請先設定驗證機制。「驗證」是指驗證身分,以便存取 Google Cloud 服務和 API 的程序。如要從本機開發環境執行程式碼或範例,請選取下列任一選項,以便對 Compute Engine 進行驗證:
Select the tab for how you plan to use the samples on this page:
Console
When you use the Google Cloud console to access Google Cloud services and APIs, you don't need to set up authentication.
gcloud
-
After installing the Google Cloud CLI, initialize it by running the following command:
gcloud init
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
- Set a default region and zone.
REST
如要在本機開發環境中使用本頁的 REST API 範例,請使用您提供給 gcloud CLI 的憑證。
After installing the Google Cloud CLI, initialize it by running the following command:
gcloud init
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
詳情請參閱 Google Cloud 驗證說明文件中的「驗證以使用 REST」。
-
必要角色和權限
如要取得建立快照排程所需的權限,請要求管理員授予您專案的下列 IAM 角色:
-
Compute 執行個體管理員 (v1) (
roles/compute.instanceAdmin.v1
) -
如要連線至可以服務帳戶形式執行的 VM,請按照下列步驟操作:
服務帳戶使用者 (v1) (
roles/iam.serviceAccountUser
)
如要進一步瞭解如何授予角色,請參閱「管理專案、資料夾和機構的存取權」。
建立記錄檔篩選器
建立記錄篩選器,以便擷取排定的快照事件。
主控台
在 Google Cloud 控制台中,前往「Logging」>「Logs Explorer」 頁面。
在「Filter by label or text search」清單中,選取「Convert to advanced filter」。
請輸入以下文字取代篩選器欄位,並將
PROJECT_ID
替換為您的專案 ID:resource.type="gce_disk" logName="projects/PROJECT_ID/logs/cloudaudit.googleapis.com%2Fsystem_event" protoPayload.methodName="ScheduledSnapshots" severity>"INFO"
按一下 [Submit Filter] (提交篩選器)。
建立指標
建立記錄篩選器後,請建立用於計算排定快照失敗次數的指標。
主控台
在「Logs Explorer」頁面中,按一下「Create metric」。
在「Metric Editor」(指標編輯工具) 中輸入以下內容:
- 名稱:
scheduled_snapshot_failure_count
。 - 說明:
count of scheduled snapshot failures
。 - 類型:
Counter
- 名稱:
在「標籤」下方,按一下「新增項目」,然後輸入以下內容:
- Name (名稱):
status
- 說明:
status of scheduled snapshot request
- 標籤類型:
String
- 欄位名稱:
protoPayload.response.status
- Name (名稱):
按一下 [完成]。
按一下 [建立指標]。
建立快訊政策
建立指標後,請建立快訊政策,以便在排定的快照失敗時傳送快訊。
主控台
在 Google Cloud 控制台中,依序前往「Cloud Logging」>「Log-based metrics」(記錄指標) 頁面。
在「使用者定義指標」下方,找出名為
user/scheduled_snapshot_failure_count
的新指標。按一下這個資料列中的
「更多」選單按鈕,然後選取「運用指標建立快訊」。快訊政策條件建立頁面會隨即開啟。在「Target」面板的「Aggregator」下方,選取「none」。
在「Filter」下方:
- 按一下 [新增篩選器]。
- 從清單中選取「status」。
- 在「Value」欄位中輸入「DONE」。
- 按一下 [套用]。
按一下 [Show advanced options] (顯示進階選項)。
在「進階匯總」窗格中,按一下「Aligner」清單,然後選取「sum」。
在「Configuration」面板中,選取下列值:
- 符合下列情況時觸發條件:
Any time series violates
- 條件:
is above
- 門檻:
1
- For:
most recent value
- 符合下列情況時觸發條件:
按一下 [儲存]。
在「Create new alerting policy」頁面中,輸入政策名稱。您可以選擇為這項政策新增通知管道和說明文件。
按一下 [儲存]。