Skip to content

Get percentage of the disk #425

Closed
Closed

Description

@NoPerfectName

Is possible to get the usage percentage of the disk?

Activity

  1. added
    question
    on Nov 2, 2017
  2. dbwiddis commented on Nov 2, 2017

    @dbwiddis
    Member

    We try to provide "used" and "total" values where possible so users can calculate their own percentage. I'm not sure what you're asking for though...

  3. NoPerfectName commented on Nov 2, 2017

    @NoPerfectName
    Author

    Thank you for your answer,what I mean is there is any class or method to know how much space of the disk has been used, so I can calculate the "usage percentage".

  4. dbwiddis commented on Nov 2, 2017

    @dbwiddis
    Member

    Ah, that's a reasonable question but the answer is a bit more complex.

    OSHI deals with disks in two ways, with the hardware (HWDiskStore) and software (OSFileStore).

    From a hardware perspective, the space is immediately "used" when assigned to a partition, which the HWDiskStore tracks. Each HWPartition will have a mount point (accessible with getMountPoint()). So in many/most cases, disks are "100%" used from a hardware perspective, assigned to one or more partitions.

    From a software perspective, a FileStore is mounted on a partition (accessible with getMount()) that will correlate with a partition's getMountPoint(). These FileStores will have getTotalSpace() and getUsableSpace() which can be used to calculate the percentage of that file system that is used.

    In the simplest case, one OSFileStore occupies a partition that takes an entire Disk (or at least most of it) and that "usage" question is easily answered. In the more complex case of multiple partitions, one would have to iterate through the partitions, find the mounted filesystems, and add up all the used space.

    Hopefully this explanation answers your question.

  5. NoPerfectName commented on Nov 2, 2017

    @NoPerfectName
    Author

    OK!u are so kind,your answer is what I want to ask.thank you so much.

  6. Shikari0744 commented on Sep 23, 2020

    @Shikari0744

    I want to calculate disk usage for a particular process (say pid=1111). I am able to calculate read and write bytes for a particular process(like OSProcess process ... process.getBytesRead() ). How can I calculate percentage of disk usage. Any idea ?

  7. Shikari0744 commented on Sep 23, 2020

    @Shikari0744

    I want to calculate disk usage for a particular process (say pid=1111). I am able to calculate read and write bytes for a particular process(like OSProcess process ... process.getBytesRead() ). How can I calculate percentage of disk usage. Any idea ?

    @dbwiddis

  8. dbwiddis commented on Sep 23, 2020

    @dbwiddis
    Member

    While a process includes read/write statistics there is no way to know which disk is being read/written to. You could attempt to correlate the process disk usage with per-disk read/write statistics to make this identification and calculate the percentage.

  9. edu-correa commented on Nov 15, 2023

    @edu-correa

    The external library Looca can help you with that, if it is with java of course.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    question

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions