[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["難以理解","hardToUnderstand","thumb-down"],["資訊或程式碼範例有誤","incorrectInformationOrSampleCode","thumb-down"],["缺少我需要的資訊/範例","missingTheInformationSamplesINeed","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["上次更新時間:2025-08-19 (世界標準時間)。"],[[["\u003cp\u003eYou can create custom metrics to monitor and troubleshoot scheduled snapshot issues, such as failures.\u003c/p\u003e\n"],["\u003cp\u003eTo set up alerts for scheduled snapshot failures, you must create a log filter, a metric based on the log filter, and finally an alert policy.\u003c/p\u003e\n"],["\u003cp\u003eAuthentication is required to access Google Cloud services and APIs, which can be set up through the gcloud CLI or the console.\u003c/p\u003e\n"],["\u003cp\u003eTo create a snapshot schedule, you need specific IAM roles, including Compute Instance Admin (v1) and Service Account User (v1).\u003c/p\u003e\n"],["\u003cp\u003eAfter creating the user metric you can set an alert policy to trigger any time the metric exceeds the threshold, which in this case is one failure.\u003c/p\u003e\n"]]],[],null,["Linux Windows\n\n*** ** * ** ***\n\nYou can [create a custom metric](/monitoring/custom-metrics)\nto raise alerts or provide information to troubleshoot problems with scheduled\nsnapshots.\n\nFor example, to set up an alert for scheduled snapshot failures, use the\nfollowing procedure:\n\n1. [Create a log filter](#ss_alert_filter) to capture scheduled snapshot events.\n2. [Create a metric](#ss_alert_metric) based off of the log filter that counts scheduled snapshot failures.\n3. [Create an alert policy](#ss_alert_policy) to send an alert when there is a scheduled snapshot failure.\n\nBefore you begin\n\n- If you haven't already, set up [authentication](/compute/docs/authentication). Authentication verifies your identity for access to Google Cloud services and APIs. To run code or samples from a local development environment, you can authenticate to Compute Engine by selecting one of the following options:\n\n Select the tab for how you plan to use the samples on this page: \n\n Console\n\n\n When you use the Google Cloud console to access Google Cloud services and\n APIs, you don't need to set up authentication.\n\n gcloud\n 1.\n [Install](/sdk/docs/install) the Google Cloud CLI.\n\n After installation,\n [initialize](/sdk/docs/initializing) the Google Cloud CLI by running the following command:\n\n ```bash\n gcloud init\n ```\n\n\n If you're using an external identity provider (IdP), you must first\n [sign in to the gcloud CLI with your federated identity](/iam/docs/workforce-log-in-gcloud).\n | **Note:** If you installed the gcloud CLI previously, make sure you have the latest version by running `gcloud components update`.\n 2. [Set a default region and zone](/compute/docs/gcloud-compute#set_default_zone_and_region_in_your_local_client).\n\n REST\n\n\n To use the REST API samples on this page in a local development environment, you use the\n credentials you provide to the gcloud CLI.\n 1. [Install](/sdk/docs/install) the Google Cloud CLI. After installation, [initialize](/sdk/docs/initializing) the Google Cloud CLI by running the following command: \n\n ```bash\n gcloud init\n ```\n 2. If you're using an external identity provider (IdP), you must first [sign in to the gcloud CLI with your federated identity](/iam/docs/workforce-log-in-gcloud).\n\n\n For more information, see\n [Authenticate for using REST](/docs/authentication/rest)\n in the Google Cloud authentication documentation.\n\nRequired roles and permissions\n\n\nTo get the permissions that\nyou need to create a snapshot schedule,\n\nask your administrator to grant you the\nfollowing IAM roles on the project:\n\n- [Compute Instance Admin (v1)](/iam/docs/roles-permissions/compute#compute.instanceAdmin.v1) (`roles/compute.instanceAdmin.v1`)\n- To connect to a VM that can run as a service account: [Service Account User (v1)](/iam/docs/roles-permissions/iam#iam.serviceAccountUser) (`roles/iam.serviceAccountUser`)\n\n\nFor more information about granting roles, see [Manage access to projects, folders, and organizations](/iam/docs/granting-changing-revoking-access).\n\n\nYou might also be able to get\nthe required permissions through [custom\nroles](/iam/docs/creating-custom-roles) or other [predefined\nroles](/iam/docs/roles-overview#predefined).\n\nCreate a log filter\n\nCreate a log filter to capture scheduled snapshot events. \n\nConsole\n\n1. In the Google Cloud console, go to the\n **Logging \\\u003e Logs Explorer** page.\n\n [Go to the Logs Explorer page](https://console.cloud.google.com/logs/query)\n2. In the **Filter by label or text search** list, select **Convert to advanced filter**.\n\n1. Replace the filter field by entering the following text, replacing\n \u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e with your project ID:\n\n resource.type=\"gce_disk\"\n logName=\"projects/\u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e/logs/cloudaudit.googleapis.com%2Fsystem_event\"\n protoPayload.methodName=\"ScheduledSnapshots\"\n severity\u003e\"INFO\"\n\n2. Click **Submit Filter**.\n\nCreate a metric\n\nAfter you create the log filter, create a metric that\ncounts scheduled snapshot failures. \n\nConsole\n\n1. On the **Logs Explorer** page, click **Create metric**.\n\n2. In the **Metric Editor**, enter the following:\n\n - **Name** : `scheduled_snapshot_failure_count`.\n - **Description** : `count of scheduled snapshot failures`.\n - **Type** : `Counter`\n3. Under **Labels** , click **Add item** and enter the following:\n\n - **Name** : `status`\n - **Description** : `status of scheduled snapshot request`\n - **Label type** : `String`\n - **Field name** : `protoPayload.response.status`\n4. Click **Done**.\n\n5. Click **Create Metric**.\n\nCreate an alert policy\n\nAfter you create the metric, create an alert policy to send an alert when\nthere is a scheduled snapshot failure. \n\nConsole\n\n1. In the Google Cloud console, go to the\n **Cloud Logging \\\u003e Logs-based metrics** page.\n\n [Go to the Logs-based metrics page](https://console.cloud.google.com/logs/metrics)\n2. Under **User-defined Metrics** , find your new metric named\n `user/scheduled_snapshot_failure_count`.\n\n3. Click the more_vert **More**\n menu button in this row and select **Create alert from metric**. The\n alert policy condition creation page opens.\n\n4. In the **Target** panel, under **Aggregator** , select **none**.\n\n5. Under **Filter**:\n\n 1. Click **Add a filter**.\n 2. Select **status** from the list.\n 3. In the **Value** field, type DONE.\n 4. Click **Apply**.\n\n6. Click **Show advanced options**.\n\n7. In the **Advanced aggregation** pane, click the **Aligner** list and select\n **sum**.\n\n8. In the **Configuration** panel, select the following values:\n\n - **Condition triggers if** : `Any time series violates`\n - **Condition** : `is above`\n - **Threshold** : `1`\n - **For** : `most recent value`\n\n9. Click **Save**.\n\n10. On the **Create new alerting policy** page, enter a policy name.\n Optionally, you can add notification channels and documentation for\n this policy.\n\n11. Click **Save**.\n\nWhat's next\n\n- Learn about snapshot schedule frequencies, retention policies, and naming rules in [About snapshot schedules for disks](/compute/docs/disks/about-snapshot-schedules).\n- Learn about [disk snapshots](/compute/docs/disks/snapshots).\n- Learn how to [create scheduled snapshots for disks](/compute/docs/disks/scheduled-snapshots).\n- Learn how to [view logs](/logging/docs/view/logs-explorer-interface)."]]