FileSystem[] fsList = sigar.getFileSystemList();
for (FileSystem fs : fsList) {
// make sure it is a hard disk
if (fs.getType() == FileSystem.TYPE_LOCAL_DISK) {
IOInformationObject temp = new IOInformationObject();
FileSystemUsage usage = null;
try {
usage = sigar.getFileSystemUsage(fs.getDirName());
// Color the filesystem.
temp.setColor(colors[counter % colors.length]);
// name related
temp.setFilesystem(fs.getDevName());
temp.setMountOn(fs.getDirName());
// speed related
Long[] fsWrites = (writes.size() > counter)
? writes.get(counter) : new Long[]{0L, 0L};
long numOfWrites = usage.getDiskWrites();
if (fsWrites[1] != 0) {
fsWrites[0] = numOfWrites - fsWrites[1];
}
fsWrites[1] = numOfWrites;
if (writes.size() > counter) {
writes.set(counter, fsWrites);
} else {
writes.add(fsWrites);
}
Long[] fsReads = (reads.size() > counter)
? reads.get(counter) : new Long[]{0L, 0L};
long numOfReads = usage.getDiskReads();
if (fsReads[1] != 0) {
fsReads[0] = numOfReads - fsReads[1];
}
fsReads[1] = numOfReads;
if (reads.size() > counter) {
reads.set(counter, fsReads);
} else {
reads.add(fsReads);
}
temp.setReads(numOfReads);
temp.setWrites(numOfWrites);
temp.setrBytes(usage.getDiskReadBytes());
temp.setwBytes(usage.getDiskWriteBytes());
// space related
temp.setAvailable(usage.getAvail() * 1000);
temp.setTotal(usage.getTotal() * 1000);
temp.setUsed(usage.getUsed() * 1000);
temp.setUsedPercent(usage.getUsePercent());
// misc
temp.setDiskQueue(usage.getDiskQueue());
temp.setDiskServiceTime(usage.getDiskServiceTime());
ioList.add(temp);
} catch (SigarException ex) {
Logger.getLogger(IOInformation.class.getName()).log(
Level.SEVERE, null, ex);