How to find the Peak usage of quota in last 7 days programmatically

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.  

0 2 186
2 REPLIES 2

While the gcloud compute regions describe command provides current quota usage, it does not track historical peak usage.

To achieve this programmatically, you might need to use Cloud Monitoring (Stackdriver), which allows you to query historical quota usage metrics.

Using Cloud Monitoring API

Google Cloud Monitoring stores historical quota usage, and you can query it using the Monitoring API:

  1. Enable Cloud Monitoring for your project.

  2. Use the Metric Explorer to find the relevant quota metric.

  3. Query the peak usage using the Monitoring API.

Example API request:

gcloud monitoring metrics list --filter="metric.type=serviceruntime.googleapis.com/quota/usage"

You can refine this query to fetch quota usage for SSD_TOTAL_GB and extract peak values.

Option 2: Using PromQL (Prometheus Query Language)

If you have Cloud Monitoring enabled, you can use PromQL queries to fetch peak quota usage:

max_over_time(serviceruntime_googleapis_com:quota_allocation_usage{monitored_resource="consumer_quota"}[7d])

This will return the maximum quota usage over the last 7 days.

Option 3: Using Logs and Custom Monitoring

If Cloud Monitoring does not provide the exact metric you need, you can:

  • Enable Cloud Logging to track quota usage over time.

  • Export logs to BigQuery and run SQL queries to find peak usage.

While the gcloud compute regions describe command provides current quota usage, it does not track historical peak usage.

To achieve this programmatically, you might need to use Cloud Monitoring (Stackdriver), which allows you to query historical quota usage metrics.

Using Cloud Monitoring API

Google Cloud Monitoring stores historical quota usage, and you can query it using the Monitoring API:

  1. Enable Cloud Monitoring for your project.

  2. Use the Metric Explorer to find the relevant quota metric.

  3. Query the peak usage using the Monitoring API.

Example API request:

gcloud monitoring metrics list --filter="metric.type=serviceruntime.googleapis.com/quota/usage"

You can refine this query to fetch quota usage for SSD_TOTAL_GB and extract peak values.

Option 2: Using PromQL (Prometheus Query Language)

If you have Cloud Monitoring enabled, you can use PromQL queries to fetch peak quota usage:

max_over_time(serviceruntime_googleapis_com:quota_allocation_usage{monitored_resource="consumer_quota"}[7d])

This will return the maximum quota usage over the last 7 days.

Option 3: Using Logs and Custom Monitoring

If Cloud Monitoring does not provide the exact metric you need, you can:

  • Enable Cloud Logging to track quota usage over time.

  • Export logs to BigQuery and run SQL queries to find peak usage.

Top Labels in this Space