To get a value about the actual resource's usage you can use a Cloud Monitoring API and the consumer_quota resource. It's not going to be a percentage but actual value.
For example:
You want to know how many VM's there's in us-central1
There's a metric for that: serviceruntime.googleapis.com/quota/allocation/usage. It provides with actual usage.
Then you can create a MQL query to filter everything you need:
fetch consumer_quota
| metric 'serviceruntime.googleapis.com/quota/allocation/usage'
| filter
(resource.service == 'compute.googleapis.com')
&& (metric.quota_metric == 'compute.googleapis.com/instances')
| group_by 1d, [value_usage_aggregate: aggregate(value.usage)]
| every 1d
Now - when you run this through API with curl:
curl -d @query.json -H "Authorization: Bearer $TOKEN" \
--header "Content-Type: application/json" -X POST \
https://monitoring.googleapis.com/v3/projects/${PROJECT_ID}/timeSeries:query
you will get a response:
{
"timeSeriesDescriptor": {
"labelDescriptors": [
{
"key": "resource.project_id"
},
{
"key": "resource.service"
},
{
"key": "resource.location"
},
{
"key": "metric.quota_metric"
}
],
"pointDescriptors": [
{
"key": "value_usage_aggregate",
"valueType": "INT64",
"metricKind": "GAUGE",
"unit": "1"
}
]
},
"timeSeriesData": [
{
"labelValues": [
{
"stringValue": "my-test-project"
},
{
"stringValue": "compute.googleapis.com"
},
{
"stringValue": "us-central1"
},
{
"stringValue": "compute.googleapis.com/instances"
}
],
"pointData": [
{
"values": [
{
"int64Value": "11"
}
],
"timeInterval": {
"startTime": "2022-03-30T08:38:44.064174Z",
"endTime": "2022-03-30T08:38:44.064174Z"
}
}
]
}
]
}
Line that you're interests you is "int64Value": "11" that contains number 11 which in my case is the current number or VM's (it's a sum of both running and stoped).
Now "all" you need to do is to incorporate that into your python script.