You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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".
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.
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 ?
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 ?
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.
Activity
dbwiddis commentedon Nov 2, 2017
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...
NoPerfectName commentedon Nov 2, 2017
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".
dbwiddis commentedon Nov 2, 2017
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'sgetMountPoint(). These FileStores will havegetTotalSpace()andgetUsableSpace()which can be used to calculate the percentage of that file system that is used.In the simplest case, one
OSFileStoreoccupies 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.
NoPerfectName commentedon Nov 2, 2017
OK!u are so kind,your answer is what I want to ask.thank you so much.
Shikari0744 commentedon Sep 23, 2020
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 ?
Shikari0744 commentedon Sep 23, 2020
@dbwiddis
dbwiddis commentedon Sep 23, 2020
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.
edu-correa commentedon Nov 15, 2023
The external library Looca can help you with that, if it is with java of course.