问题
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.
回答1:
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"
- Now, in the query builder, you have the matching entry that you select
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
- Now create your metric and name it.
- Finally, click on the 3 dots on the right and select create an alert on this metric
- 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)
来源:https://stackoverflow.com/questions/65092493/google-cloud-functions-monitor-http-status-codes