Using MQL with Google Cloud Monitoring (Stackdriver) Alerting Policy

3.5k Views Asked by At

I have used MQL to create charts in Google Cloud Monitoring that are a ratio of two metrics.

I would like to create an alerting policy based on the MQL, but the UI in Cloud Console does not have a query editor, like it does in Metrics Explorer.

Is there a way to use MQL when defining conditions for alerting policies using Google Cloud Monitoring (Stackdriver)?

3

There are 3 best solutions below

0
On BEST ANSWER

Creating alerts with MQL is now supported :) Both in UI and API.


  1. To create a valid alert - pipe either condition or absent_for keyword* at the end of your query. See https://cloud.google.com/monitoring/mql/alerts for documentation.

  2. For ratio alerts, follow the tips from regular ratio queries https://cloud.google.com/monitoring/mql/examples#qlx-ratio-ratio

  3. There are two major difference compared to dashboards - all MQL alerts must be saved in strict-form, and most of the conditions will need to have units-of-measure specified. See https://cloud.google.com/monitoring/mql/qn-from-api#ql-alert-condition


) * - they are technically "table operators", not "keywords".

0
On

Quoting c69:

There is a Feature Request for MQL-based alerts in issuetracker.google.com/157770220

As at the date of this post, MQL-based alerts are not supported.

0
On

I'm not sure if this is helpful, but you could create a custom service and then define an SLO for it using the ratio of two metrics. You could then create an error budget burn alert.

"requestBased": {
    "goodTotalRatio": {
      "totalServiceFilter": "metric.type=\"appengine.googleapis.com/http/server/response_count\" resource.type=\"gae_app\" resource.label.\"module_id\"=\"default\"",
      "goodServiceFilter": "metric.type=\"appengine.googleapis.com/http/server/response_count\" resource.type=\"gae_app\" resource.label.\"module_id\"=\"default\" metric.label.\"response_code\"=\"200\"",
    }
  }

https://medium.com/google-cloud/slos-with-stackdriver-service-monitoring-62f193147b3f