know the free space of a persistent disk

I'm looking for api which can determine the frees space of a persistent disk.

I have checked this but no proper attributes for determine the free space of a disk.

https://cloud.google.com/compute/docs/reference/rest/v1/disks

Ex: I have a disk which is size of 100GB but internal the OS/data was consumed only 60GB and there is 40GB free to use. I want to automate to add more disks if it hits the 90% of storage provisioned.

0 2 338
2 REPLIES 2

Hello sudheerdon,

Welcome to GCC!

Can you please confirm if your GCP persistent disks are associated with a pod in a GKE cluster?

Thanks!

I'll make a guess ... when you ask Google Cloud to create a persistent disk, it does just that ... it creates a representation of what would otherwise be a physical disk.  If I buy a physical disk, I am given its disk capacity (size) but it is up to me to format the disk for use.  The underlying disk provides an addressable collection of blocks but the disk has no idea what those blocks "mean" or whether or not they are in use/free.  When you create a Google Cloud disk, the disk itself doesn't see the blocks in use/free ... just how many blocks (size) you have requested.  When the disk is used by an operating system (eg. Linux or Windows), then the disk is formatted for use and some blocks are used to contain the "indices" of which blocks are in use and which are free.  However, this is a contract between the OS using the disk and the data contained on the disk ... not something that is queryable from the "physical disk".  If you want to know how much disk is "free" or "in use" one would have to load the index data from the disk and interrogate that.

To try and address your core question ... you may have to "mount" each of the disks that you want to examine.  Once the disk is mounted, the OS can look at the disk indicies and determine use/free.