Se non l'hai ancora fatto, configura l'autenticazione.
L'autenticazione è il processo mediante il quale la tua identità viene verificata per l'accesso a servizi e API Google Cloud .
Per eseguire codice o esempi da un ambiente di sviluppo locale, puoi autenticarti su Compute Engine selezionando una delle seguenti opzioni:
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
Install the Google Cloud CLI.
After installation,
initialize the Google Cloud CLI by running the following command:
Per ottenere le autorizzazioni necessarie per creare una pianificazione degli snapshot, chiedi all'amministratore di concederti i seguenti ruoli IAM nel progetto:
In Metriche definite dall'utente, individua la nuova metrica denominata user/scheduled_snapshot_failure_count.
Fai clic sul pulsante di menu more_vertAltro in questa riga e seleziona Crea avviso da metrica. Viene visualizzata la pagina di creazione della condizione della policy di avviso.
Nel riquadro Target, seleziona nessuno in Aggregatore.
In Filtro:
Fai clic su Aggiungi un filtro.
Seleziona stato dall'elenco.
Nel campo Valore, digita FINE.
Fai clic su Applica.
Fai clic su Mostra opzioni avanzate.
Nel riquadro Aggregazione avanzata, fai clic sull'elenco Allineatore e seleziona somma.
Nel riquadro Configurazione, seleziona i seguenti valori:
La condizione si attiva se: Any time series violates
Condizione: is above
Soglia: 1
Per: most recent value
Fai clic su Salva.
Nella pagina Crea nuova policy di avviso, inserisci un nome per la policy.
Se vuoi, puoi aggiungere canali di notifica e documentazione per questa policy.
[[["Facile da capire","easyToUnderstand","thumb-up"],["Il problema è stato risolto","solvedMyProblem","thumb-up"],["Altra","otherUp","thumb-up"]],[["Difficile da capire","hardToUnderstand","thumb-down"],["Informazioni o codice di esempio errati","incorrectInformationOrSampleCode","thumb-down"],["Mancano le informazioni o gli esempi di cui ho bisogno","missingTheInformationSamplesINeed","thumb-down"],["Problema di traduzione","translationIssue","thumb-down"],["Altra","otherDown","thumb-down"]],["Ultimo aggiornamento 2025-08-18 UTC."],[[["\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)."]]