Hi Nham hong phuc,
Yes, there are several APIs that can be used to retrieve information about the free space and usage of the disk on a Linux VM.
For example the psutil
library can be used to retrieve the amount of free space on a disk in a Linux VM. Here is an example Python code snippet that uses psutil
to retrieve the amount of free space on the root filesystem:
import psutil
disk_usage = psutil.disk_usage('/')
free_space = disk_usage.free
print(f"Free space on root filesystem: {free_space} bytes")
In this example, the psutil.disk_usage()
function is called with the path of the filesystem (in this case, '/'
for the root filesystem) as an argument. This function returns a named tuple with three fields: total
, used
, and free
. The free
field contains the amount of free space on the filesystem in bytes.
I hope this helps?