Search code examples
google-cloud-platformpoliciesnetwork-monitoring

GCP Monitoring: Is it possible to set up the monitor with a time range specifically


I want to set up a monitor just at night as its when we really need the alert monitoring, is it possible?


Solution

  • I think you want to enable|disable or snooze Alerting during specific periods.

    Snoozing alerts appears (!?) to be currently only possible through Cloud Console which may be restrictive and don't appear to support recurring (everyday) schedules.

    I think another alternative, is to disable alerts during the day and re-enable them overnight. You can use the API's projects.alertPolicies.Patch method or gcloud alpha monitoring policies update

    # During the day
    gcloud alpha monitoring policies update ${POLICY} \
    --no-enabled \
    --project=${PROJECT}
    
    # During the night
    gcloud alpha monitoring policies update ${POLICY} \
    --enabled \
    --project=${PROJECT}
    

    Rather than remembering to do this, you could use cron or e.g. Cloud Scheduler to schedule the switch.