Have any API can return free space or used of OS disk which is attached to my linux VM?

nhâm hồng phúc 20 Reputation points
2023-05-08T08:11:58.76+00:00

I want to find an API which can return free space or anything similar of disk on my Linux VM.

Azure Virtual Machines
Azure Virtual Machines
An Azure service that is used to provision Windows and Linux virtual machines.
7,363 questions
{count} votes

Accepted answer
  1. RevelinoB 2,775 Reputation points
    2023-05-08T08:22:09.2133333+00:00

    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?


0 additional answers

Sort by: Most helpful