I am trying to create an alert in Google Cloud Monitoring that runs a custom count query on a Cloud SQL database (postgresql) and returns the result.
Eg.: SELECT count(*) FROM your_table WHERE [field] IS NULL OR LTRIM(RTRIM([field])) = ”
The main goal is to then create a threshold in the alert that will activate it when it is passed.
I don’t see any built-in option in GCP that will allow such sql query. Is there any alternative solution to this? (using a third party, cloud functions or mql query?)
2
Answers
You can set up an alert policy in Google Cloud Monitoring, create a log-based metric based on your desired conditions, export database logs to Cloud Logging, create thresholds for triggering alerts based on the log-based metric, and monitor particular conditions in a Google Cloud SQL database. This strategy refers to standard practices for cloud monitoring and makes use of log-based analytics.
Yes, there are a few alternative solutions to creating an alert in Google Cloud Monitoring that runs a custom count query on a Cloud SQL database (PostgreSQL) and returns the result.
Cloud Functions
One way to do this is to use Cloud Functions. You can create a Cloud Function that runs your custom SQL query and returns the result. Then, you can create an alert in Cloud Monitoring that triggers when the result of the Cloud Function exceeds a certain threshold.
To create a Cloud Function that runs a custom SQL query, you can use the following steps:
Once your Cloud Function is deployed, you can create an alert in Cloud Monitoring that triggers when the result of the Cloud Function exceeds a certain threshold.
To create an alert in Cloud Monitoring, you can use the following steps:
Now, when the result of your Cloud Function exceeds the threshold value that you specified, an alert will be triggered.
The best solution for you will depend on your specific needs and requirements. If you need a simple solution that is easy to set up, then using Cloud Functions is a good option. If you need a more powerful solution that offers more features, then you may want to consider using a third-party solution.