設定快照排程的警告通知


您可以建立自訂指標來發出快訊或提供資訊,以解決排程快照問題。

舉例來說,如要設定快照排程失敗的快訊,請按照下列程序操作:

  1. 建立記錄檔篩選器,以便擷取排定的快照事件。
  2. 根據記錄篩選條件建立指標,計算排定的快照失敗次數。
  3. 建立快訊政策,以便在排定的快照失敗時傳送快訊。

事前準備

  • 如果尚未設定,請先設定驗證機制。「驗證」是指驗證身分,以便存取 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

    1. 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.

    2. Set a default region and zone.
    3. 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 角色:

如要進一步瞭解如何授予角色,請參閱「管理專案、資料夾和機構的存取權」。

您或許還可透過自訂角色或其他預先定義的角色取得必要權限。

建立記錄檔篩選器

建立記錄篩選器,以便擷取排定的快照事件。

主控台

  1. 在 Google Cloud 控制台中,前往「Logging」>「Logs Explorer」 頁面。

    前往「Logs Explorer」頁面

  2. 在「Filter by label or text search」清單中,選取「Convert to advanced filter」

轉換為進階篩選器。

  1. 請輸入以下文字取代篩選器欄位,並將 PROJECT_ID 替換為您的專案 ID:

    resource.type="gce_disk"
    logName="projects/PROJECT_ID/logs/cloudaudit.googleapis.com%2Fsystem_event"
    protoPayload.methodName="ScheduledSnapshots"
    severity>"INFO"
    
  2. 按一下 [Submit Filter] (提交篩選器)

建立指標

建立記錄篩選器後,請建立用於計算排定快照失敗次數的指標。

主控台

  1. 在「Logs Explorer」頁面中,按一下「Create metric」

  2. 在「Metric Editor」(指標編輯工具) 中輸入以下內容:

    • 名稱scheduled_snapshot_failure_count
    • 說明count of scheduled snapshot failures
    • 類型Counter
  3. 在「標籤」下方,按一下「新增項目」,然後輸入以下內容:

    • Name (名稱):status
    • 說明status of scheduled snapshot request
    • 標籤類型String
    • 欄位名稱protoPayload.response.status
  4. 按一下 [完成]

  5. 按一下 [建立指標]

建立快訊政策

建立指標後,請建立快訊政策,以便在排定的快照失敗時傳送快訊。

主控台

  1. 在 Google Cloud 控制台中,依序前往「Cloud Logging」>「Log-based metrics」(記錄指標) 頁面。

    前往「Logs-based Metrics」(記錄指標) 頁面

  2. 在「使用者定義指標」下方,找出名為 user/scheduled_snapshot_failure_count 的新指標。

  3. 按一下這個資料列中的 「更多」選單按鈕,然後選取「運用指標建立快訊」。快訊政策條件建立頁面會隨即開啟。

    使用者定義指標。

  4. 在「Target」面板的「Aggregator」下方,選取「none」

  5. 在「Filter」下方:

    1. 按一下 [新增篩選器]
    2. 從清單中選取「status」
    3. 在「Value」欄位中輸入「DONE」。
    4. 按一下 [套用]

    警報篩選器狀態。

  6. 按一下 [Show advanced options] (顯示進階選項)

  7. 在「進階匯總」窗格中,按一下「Aligner」清單,然後選取「sum」

  8. 在「Configuration」面板中,選取下列值:

    • 符合下列情況時觸發條件Any time series violates
    • 條件is above
    • 門檻1
    • Formost recent value

    設定面板。

  9. 按一下 [儲存]

  10. 在「Create new alerting policy」頁面中,輸入政策名稱。您可以選擇為這項政策新增通知管道和說明文件。

  11. 按一下 [儲存]

後續步驟