Hello,
I have a requirement to find the Peak usage of Quota defined on specific resource in last 7 days programmatically.
I am able to find the Quota value and Current Usage using CLI for Persistent Disk SSD(as example).
gcloud compute regions describe us-central1 --project=project_learing \
--format="json" | jq '.quotas[] | select(.metric == "SSD_TOTAL_GB")'
But unable to find the way to get the peak usage using CLI or API.
Please read the following use case document from Google for the Quota monitoring.
https://cloud.google.com/docs/quotas/implement-common-use-cases
Also, use the Quota monitoring solution - https://cloud.google.com/blog/products/gcp/google-cloud-introduces-quota-monitoring-solution
Hi cloud_user,
Welcome to Google Cloud Community!
There are several approaches to get the specific metric quota programmaticaly, it could be using MQL, PromQL, Monitoring API/Libraries, and cURL command.
1. For MQL query, here’s the sample query:
fetch consumer_quota
| metric 'serviceruntime.googleapis.com/quota/allocation/usage'
| filter
(resource.location == 'us-central1'
&& resource.service == 'compute.googleapis.com')
&& (metric.quota_metric == 'compute.googleapis.com/ssd_total_storage')
| group_by 1m, [value_usage_mean: max(value.usage)]
| every 1m
| align delta(1h)
Note: Starting July 22, 2025, Monitoring Query Language (MQL) will no longer be available for new dashboards and alerts in the Google Cloud console, and Google Cloud customer support for MQL will end. Existing MQL dashboards and alerts will continue to work, and you will still be able to run MQL queries in Metrics Explorer.
2. For promQL query, MQL query can be converted to PromQL by clicking the button in Google Console. Here’s the sample PromQL query:
max(max_over_time(serviceruntime_googleapis_com:quota_allocation_usage{monitored_resource="consumer_quota",quota_metric="compute.googleapis.com/disks_total_storage"}[${__interval}]))
Output:
3. Using cURL command:
curl -X GET \
"https://monitoring.googleapis.com/v3/projects/PROJECT_ID/timeSeries?\
filter=metric.type%3D%22serviceruntime.googleapis.com/quota/allocation/usage%22%20AND%20\
metric.labels.quota_metric%3D%22compute.googleapis.com/ssd_total_storage%22%20AND%20\
resource.labels.location%3D%22us-central1%22&\
interval.startTime=$(date -u -d '7 days ago' +%Y-%m-%dT%H:%M:%SZ)&\
interval.endTime=$(date -u +%Y-%m-%dT%H:%M:%SZ)&\
aggregation.alignmentPeriod=86400s&\
aggregation.perSeriesAligner=ALIGN_MAX&\
aggregation.crossSeriesReducer=REDUCE_MAX" \
-H "Authorization: Bearer $(gcloud auth application-default print-access-token)"
output:
"timeSeries": [
{
"metric": {
"type": "serviceruntime.googleapis.com/quota/allocation/usage"
},
"resource": {
"type": "consumer_quota",
"labels": {
"project_id": "PROJECT_ID"
}
},
"metricKind": "GAUGE",
"valueType": "INT64",
"points": [
{
"interval": {
"startTime": "2025-05-07T03:05:00Z",
"endTime": "2025-05-07T03:05:00Z"
},
"value": {
"int64Value": "910"
}
}
4. Using Python client libraries(Monitoringv3)
For further insights on PromQL parameters, refer to these following documentation:
Was this helpful? If so, please accept this answer as “Solution”. If you need additional assistance, reply here within 2 business days and I’ll be happy to help.