本文整理汇总了Java中org.hyperic.sigar.FileSystemUsage.getUsePercent方法的典型用法代码示例。如果您正苦于以下问题:Java FileSystemUsage.getUsePercent方法的具体用法?Java FileSystemUsage.getUsePercent怎么用?Java FileSystemUsage.getUsePercent使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.hyperic.sigar.FileSystemUsage
的用法示例。
在下文中一共展示了FileSystemUsage.getUsePercent方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: output
import org.hyperic.sigar.FileSystemUsage; //导入方法依赖的package包/类
public void output(FileSystem fs) throws SigarException {
long used, avail, total, pct;
try {
FileSystemUsage usage;
if (fs instanceof NfsFileSystem) {
NfsFileSystem nfs = (NfsFileSystem)fs;
if (!nfs.ping()) {
println(nfs.getUnreachableMessage());
return;
}
}
usage = this.sigar.getFileSystemUsage(fs.getDirName());
if (this.opt_i) {
used = usage.getFiles() - usage.getFreeFiles();
avail = usage.getFreeFiles();
total = usage.getFiles();
if (total == 0) {
pct = 0;
}
else {
long u100 = used * 100;
pct = u100 / total +
((u100 % total != 0) ? 1 : 0);
}
}
else {
used = usage.getTotal() - usage.getFree();
avail = usage.getAvail();
total = usage.getTotal();
pct = (long)(usage.getUsePercent() * 100);
}
} catch (SigarException e) {
//e.g. on win32 D:\ fails with "Device not ready"
//if there is no cd in the drive.
used = avail = total = pct = 0;
}
String usePct;
if (pct == 0) {
usePct = "-";
}
else {
usePct = pct + "%";
}
ArrayList items = new ArrayList();
items.add(fs.getDevName());
items.add(formatSize(total));
items.add(formatSize(used));
items.add(formatSize(avail));
items.add(usePct);
items.add(fs.getDirName());
items.add(fs.getSysTypeName() + "/" + fs.getTypeName());
printf(items);
}
示例2: testFileSystemInfo
import org.hyperic.sigar.FileSystemUsage; //导入方法依赖的package包/类
public void testFileSystemInfo() throws Exception {
Sigar sigar = new Sigar();
FileSystem fslist[] = sigar.getFileSystemList();
DecimalFormat df = new DecimalFormat("#0.00");
// String dir = System.getProperty("user.home");// 当前用户文件夹路径
for (int i = 0; i < fslist.length; i++) {
System.out.println("\n~~~~~~~~~~" + i + "~~~~~~~~~~");
FileSystem fs = fslist[i];
// 分区的盘符名称
System.out.println("fs.getDevName() = " + fs.getDevName());
// 分区的盘符名称
System.out.println("fs.getDirName() = " + fs.getDirName());
System.out.println("fs.getFlags() = " + fs.getFlags());//
// 文件系统类型,比如 FAT32、NTFS
System.out.println("fs.getSysTypeName() = " + fs.getSysTypeName());
// 文件系统类型名,比如本地硬盘、光驱、网络文件系统等
System.out.println("fs.getTypeName() = " + fs.getTypeName());
// 文件系统类型
System.out.println("fs.getType() = " + fs.getType());
FileSystemUsage usage = null;
try {
usage = sigar.getFileSystemUsage(fs.getDirName());
} catch (SigarException e) {
if (fs.getType() == 2) throw e;
continue;
}
switch (fs.getType()) {
case 0: // TYPE_UNKNOWN :未知
break;
case 1: // TYPE_NONE
break;
case 2: // TYPE_LOCAL_DISK : 本地硬盘
// 文件系统总大小
System.out.println(" Total = " + df.format((float) usage.getTotal() / 1024 / 1024) + "G");
// 文件系统剩余大小
System.out.println(" Free = " + df.format((float) usage.getFree() / 1024 / 1024) + "G");
// 文件系统可用大小
System.out.println(" Avail = " + df.format((float) usage.getAvail() / 1024 / 1024) + "G");
// 文件系统已经使用量
System.out.println(" Used = " + df.format((float) usage.getUsed() / 1024 / 1024) + "G");
double usePercent = usage.getUsePercent() * 100D;
// 文件系统资源的利用率
System.out.println(" Usage = " + df.format(usePercent) + "%");
break;
case 3:// TYPE_NETWORK :网络
break;
case 4:// TYPE_RAM_DISK :闪存
break;
case 5:// TYPE_CDROM :光驱
break;
case 6:// TYPE_SWAP :页面交换
break;
}
System.out.println(" DiskReads = " + usage.getDiskReads());
System.out.println(" DiskWrites = " + usage.getDiskWrites());
}
return;
}