Builders and operators on IT and growth groups need highly effective metric querying, evaluation, charting, and alerting capabilities to troubleshoot outages, carry out root trigger evaluation, create customized SLI / SLOs, stories and analytics, arrange complicated alert logic, and extra. So right this moment we’re excited to announce the Common Availability of Monitoring Query Language (MQL) in Cloud Monitoring!
MQL represents a decade of learnings and enhancements on Google’s inner metric question language. The identical language that powers superior querying for inner Google manufacturing customers, is now obtainable to Google Cloud customers as properly. As an example, you need to use MQL to:
Create ratio-based charts and alerts
Carry out time-shift evaluation (examine metric information week over week, month over month, yr over yr, and many others.)
Apply mathematical, logical, desk operations, and different features to metrics
Fetch, be a part of, and combination over a number of metrics
Choose by arbitrary, moderately than predefined, percentile values
Create new labels to combination information by, utilizing arbitrary string manipulations together with common expressions
Let’s check out methods to entry and use MQL from inside Cloud Monitoring.
Getting began with MQL
It’s simple to get began with MQL. To entry the MQL Question Editor, simply click on on the button in Cloud Monitoring Metrics Explorer:
Then, create a question within the Metrics Explorer UI, and click on the Question Editor button. This converts the present question into an MQL question:
MQL is constructed utilizing operations and features. Operations are linked collectively utilizing the widespread ‘pipe’ idiom, the place the output of 1 operation turns into the enter to the subsequent. Linking operations makes it doable to construct up complicated queries incrementally. In the identical means you’ll compose and chain instructions and information through pipes on the Linux command line, you’ll be able to fetch metrics and apply operations utilizing MQL.
For a extra superior instance, suppose you have constructed a distributed net service that runs on Compute Engine VM cases and makes use of Cloud Load Balancing, and also you wish to analyze error price—one of many SRE “golden signals”.
You wish to see a chart that shows the ratio of requests that return HTTP 500 responses (inner errors) to the overall variety of requests; that’s, the request-failure ratio. The loadbalancing.googleapis.com/https/request_count metric sort has a response_code_class label, which captures the category of response codes.
On this instance, as a result of the numerator and denominator for the ratio are derived from the identical time sequence, you can too compute the ratio by grouping. The next question exhibits this strategy:
This question makes use of an aggregation expression constructed on the ratio of two sums:
The primary sum makes use of the if operate to rely 500-valued HTTP responses and a rely of zero for different HTTP response codes. The sum operate computes the rely of the requests that returned 500.
The second sum provides up the counts for all requests, as represented by val().
The 2 sums are then divided, ensuing within the ratio of 500 responses to all responses.
Now let’s say that we wish to create an alert coverage from this question. You may go to Alerting, click on “Create Policy”, click on “Add Condition”, and also you’ll see the identical “Query Editor” button you noticed in Metrics Explorer.
You should utilize the identical question as above, however with a situation operator that gives the edge for the alert:
The situation exams every information level within the aligned enter desk to find out whether or not the ratio worth exceeds the edge worth of 50%. The string ’10^2.%’ specifies that the worth must be used as a share.
Along with ratios, one other widespread use case for MQL is time shifting. For brevity, we received’t cowl this in our weblog publish, however the instance documentation walks you thru performing week-over-week or month-over-month comparisons. That is notably highly effective when coupled with long-term retention of 24 months of customized and Prometheus metrics.
Take monitoring to the subsequent stage
The sky’s the restrict for the use instances that MQL makes doable. Whether or not it’s essential carry out joins, show arbitrary percentages, or make superior calculations, we’re excited to make this obtainable to all prospects and we have an interest to see how you’ll use MQL to unravel your monitoring, alerting, and operations wants. To be taught extra about MQL, take a look at the documentation, quickstarts, examples (queries, alerts), a language and function reference, and extra.