Configurare le notifiche per le metriche basate su log
Mantieni tutto organizzato con le raccolte
Salva e classifica i contenuti in base alle tue preferenze.
Questo documento spiega come configurare le notifiche quando una
metrica basata sui log corrisponde ai criteri specificati. Queste istruzioni,
che ti guidano nella creazione di un criterio di avviso e nella configurazione
dei canali di notifica, sono per la console Google Cloud . Puoi anche creare
policy di avviso utilizzando l'API Cloud Monitoring
e il comando Google Cloud CLI
gcloud alpha monitoring policies.
I criteri di avviso che monitorano le metriche basate su log non possono estrarre dati dalle voci di log. Se vuoi che una notifica estragga i dati da una voce di log,
crea un avviso basato su log.
Prima di iniziare
Verifica che il tuo ruolo Identity and Access Management includa le autorizzazioni necessarie per
creare e visualizzare metriche basate su log e per creare policy di avviso.
Per maggiori dettagli, vedi
Autorizzazioni per le metriche basate su log.
Configura i canali di notifica che vuoi utilizzare per ricevere le notifiche. Per informazioni su questi passaggi, vedi
Creare e gestire i canali di notifica.
Crea un criterio di avviso su una metrica di conteggio
Un criterio di avviso descrive un insieme di condizioni che vuoi monitorare.
Quando crei un criterio di avviso, devi anche specificarne le condizioni: cosa
viene monitorato e quando inviare le notifiche. Le notifiche
includono informazioni sull'incidente e pulsanti che ti consentono
di visualizzare i log pertinenti e i dettagli dell'incidente:
Per creare un criterio di avviso che confronta il valore di una
metrica di conteggio basata su log con una soglia:
Nella console Google Cloud , vai alla pagina Metriche basate su log:
Se utilizzi la barra di ricerca per trovare questa pagina, seleziona il risultato con il sottotitolo
Logging.
Trova la metrica che vuoi monitorare,
fai clic su more_vertAltro,
quindi seleziona Crea avviso da metrica.
Verifica che nel campo Seleziona una metrica siano elencati un
metric.type e un resource.type. Se necessario,
aggiungi una clausola resource.type.
Ad esempio, il seguente filtro specifica una metrica e una risorsa:
metric.type="logging.googleapis.com/byte_count"
AND resource.type="gce_instance"
Nel menu Finestra mobile, ti consigliamo di selezionare un valore di almeno 10 minuti. In particolare, questo valore deve
essere sufficientemente grande da garantire che vengano conteggiate più voci di log che corrispondono al tuo
filtro.
Ad esempio, se una metrica basata sui log conteggia le voci di log "heartbeat",
previste ogni N minuti, imposta il valore del menu
Finestra temporale mobile su 2N minuti o 10 minuti,
a seconda di quale sia il valore maggiore.
Fai clic su Avanti e seleziona Soglia.
Inserisci un Valore soglia e, se vuoi, configura i campi
Attivazione avviso e Posizione soglia.
(Facoltativo) Aggiorna la Finestra di ritest e utilizza i campi
Opzioni avanzate per configurare il modo in cui lacriterio di avvisoo
gestisce i dati mancanti. In genere, l'impostazione predefinita è appropriata.
Fai clic su Avanti, poi su Canali di notifica e seleziona i canali di notifica che vuoi utilizzare per il criterio di avviso.
(Facoltativo) Nella sezione Documentazione, inserisci tutte le informazioni che
vuoi includere nelle notifiche. In genere, le informazioni includono
informazioni su come rispondere alla notifica.
Non includere l'estrazione delle etichette dalle voci di log nella documentazione.
I criteri di avviso che monitorano una metrica basata su log non possono estrarre dati dalle voci di log.
Nel campo Assegna un nome alla policy di avviso,
inserisci un nome per la criterio di avviso.
[[["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-09-05 UTC."],[],[],null,["# Configure notifications for log-based metrics\n\nThis document explains how to configure notifications when a\nlog-based metric matches criteria that you specify. These instructions,\nwhich guide you through creating an alerting policy and configuring\nnotification channels, are for the Google Cloud console. You can also create\nalerting policies by using the\n[Cloud Monitoring API](/monitoring/alerts/using-alerting-api)\nand by using the Google Cloud CLI command\n[`gcloud alpha monitoring policies`](/sdk/gcloud/reference/alpha/monitoring/policies).\n\nAlerting policies that monitor log-based metrics can't extract data from\nlog entries. If you want a notification to extract data from a log entry,\nthen [create a log-based alert](/logging/docs/alerting/log-based-alerts).\n\nBefore you begin\n----------------\n\n1. Verify that your Identity and Access Management role includes the permissions required to\n create and view log-based metrics, and to create alerting policies.\n For details, see\n [Log-based metric permissions](/logging/docs/access-control#metrics-permissions).\n\n2. Verify that you are familiar with log-based metrics. For more information,\n see [Overview of log-based metrics](/logging/docs/logs-based-metrics).\n\n3. Configure the notification channels that you want to use to receive any\n notifications. For information about these steps, see\n [Create and manage notification channels](/monitoring/support/notification-options).\n\nCreate an alerting policy on a counter metric\n---------------------------------------------\n\nAn alerting policy describes a set of conditions that you want to monitor.\nWhen you create an alerting policy, you must also specify its conditions: what\nis monitored and when to send notifications. Notifications\ninclude information about the incident, and they include buttons that let\nyou view relevant logs and incident details:\n\nTo create an alerting policy that compares the value of a\nlog-based counter metric to a threshold, do the following:\n\n1. In the Google Cloud console, go to the **Log-based Metrics** page:\n\n [Go to **Log-based Metrics**](https://console.cloud.google.com/logs/metrics)\n\n \u003cbr /\u003e\n\n If you use the search bar to find this page, then select the result whose subheading is\n **Logging**.\n2. Find the metric that you want to monitor,\n click *more_vert* **More** ,\n and then select **Create alert from metric**.\n\n3. Verify that the **Select a metric** field lists a\n `metric.type` and a `resource.type`. If necessary,\n add a `resource.type` clause.\n\n For example, the following filter specifics a metric and a resource: \n\n metric.type=\"logging.googleapis.com/byte_count\"\n AND resource.type=\"gce_instance\"\n\n4. In the **Rolling window** menu, we recommend that you select a value that\n is at least 10 minutes. In particular, this value should\n be large enough to make sure that multiple log entries that match your\n filter are counted.\n\n For example, if a log-based metric counts \"heartbeat\" log entries,\n which are expected every `N` minutes, then set the value of the\n **Rolling window** menu to `2N` minutes or 10 minutes,\n whichever is larger.\n | **Note:** Log-based metric data can have gaps and those gaps can result in false notifications. Increasing the value of the **Rolling window** menu can reduce the risk of false notifications. For more information, see [Troubleshoot: Metric is missing logs data](/logging/docs/logs-based-metrics/troubleshooting#slow-startup).\n5. Click **Next** , select **Threshold**.\n\n6. Enter a **Threshold value** , and optionally, configure the\n **Alert trigger** and **Threshold position** fields.\n\n7. Optional: Update the **Retest window** and use the\n **Advanced Options** fields to configure how the alerting policy\n handles missing data. Typically, the default setting is appropriate.\n\n8. Click **Next** , click **Notification channels**, and then select the\n notification channels that you want to use for the alerting policy.\n\n9. Optional: In the **Documentation** section, enter any information that\n you want included in notifications. Typically, the information includes\n information about how to respond to the notification.\n\n Don't include label extraction from log entries in your documentation.\n Alerting policies that monitor a log-based metric can't extract data from\n log entries.\n10. In the **Name the alert policy** field,\n enter a name for the alerting policy.\n\n11. Click **Create policy**.\n\nTroubleshooting\n---------------\n\nIf you encounter issues, then see\n[Troubleshoot log-based metrics](/logging/docs/logs-based-metrics/troubleshooting).\n\nWhat's next\n-----------\n\n- For more information about alerting policies, see the following documents:\n\n - [Introduction to alerting](/monitoring/alerts)\n - [Managing alerting policies](/monitoring/alerts/using-alerting-api)\n- To chart your log-based metric, see\n [View your log-based metrics](/logging/docs/logs-based-metrics/view_your_log_based_metrics).\n\n- For information about how to monitor Cloud Logging and Cloud Monitoring\n usage and receive notifications you when you approach the threshold for\n billing, see [Monitor and optimize Google Cloud Observability costs](/stackdriver/docs/observability/pricing-optimize-and-monitor)."]]