Course contentsShow
← Cloud and Infrastructure
Lesson 682 of 2,98912. Monitoring FoundationsFree lesson

GCP Monitoring Query Language

Using MQL (Monitoring Query Language) to build advanced metric queries and aggregations in Cloud Monitoring.

Using MQL (Monitoring Query Language) to Build Advanced Metric Queries

What you'll learn: How to write powerful MQL queries in GCP Cloud Monitoring to filter, aggregate, and analyze your metrics beyond basic dashboard filters.

What Is MQL?

MQL (Monitoring Query Language) is GCP's specialized query language for Cloud Monitoring. While the console's basic metric explorer uses dropdown menus, MQL lets you write text-based queries for complex operations like time-series alignment, aggregation across dimensions, and mathematical transformations—similar to how Kusto Query Language (KQL) works in Azure.

Think of MQL as SQL for metrics: instead of querying database tables, you're querying time-series data streams.

Core MQL Structure

MQL queries follow a pipeline pattern:

fetch gce_instance
| metric 'compute.googleapis.com/instance/cpu/utilization'
| filter resource.zone == 'us-central1-a'
| group_by [resource.instance_id]
| aggregate mean()

You fetch a resource type, select a metric, apply filters, then group and aggregate the data. Each | pipes data to the next operation.

Common MQL Operations

  • Aggregation: Combine multiple time series with mean(), sum(), max()
  • Grouping: Organize by labels like instance ID or region
  • Time alignment: Control data point intervals (align with 1m, 5m, etc.)
  • Math operations: Calculate ratios, percentages, or custom metrics

MQL shines when you need to answer questions like "What's the average CPU across all instances per region?" or "Show me network throughput as a rate per second."

When to Use MQL

Use MQL when dashboard filters aren't flexible enough—especially for multi-step aggregations, cross-metric calculations, or building reusable query templates for alerts.

Key Takeaway: MQL transforms GCP Cloud Monitoring from a basic dashboard tool into a powerful metric analysis platform through text-based, composable queries.