Search code examples
google-cloud-platformgoogle-cloud-functionsgoogle-cloud-monitoring

Setup alerting policy for GCP Cloud Functions based on HTTP status codes


I want to setup Cloud Monitoring to alert me each time my Cloud Function responds with 4xx / 5xx HTTP status codes. Please let me know how to implement this from Cloud Console.


Solution

  • You can use Cloud Logging for this.

    • Go to the Cloud Logging page and filter your logs
    • Then select the part of the logs that you want (in my screen shot is the 200 HTTP response code), and click on "show matching entries"

    enter image description here

    • Now, in the query builder, you have the matching entry that you select enter image description here

    You can change it, the value (400 instead of 200) the equality by > or <,... So, you can see in the documentation how to build a Cloud Logging filter

    • Then go to Action and click on create metrics

    enter image description here

    • Now create your metric and name it.

    enter image description here

    • Finally, click on the 3 dots on the right and select create an alert on this metric

    enter image description here

    • From there, follow the wizard. Name your condition, define your threshold and notification channels. I think it's the easiest part (but if you need guidance, let me know)