本文整理汇总了Java中org.hyperic.sigar.FileSystemUsage类的典型用法代码示例。如果您正苦于以下问题:Java FileSystemUsage类的具体用法?Java FileSystemUsage怎么用?Java FileSystemUsage使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
FileSystemUsage类属于org.hyperic.sigar包,在下文中一共展示了FileSystemUsage类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: totalDisk
import org.hyperic.sigar.FileSystemUsage; //导入依赖的package包/类
/**
* 磁盘总量
*/
public static long totalDisk() throws SigarException {
if(staticResource.totalDisk == null){
FileSystem[] fs = sigar.getFileSystemList();
long total = 0L;
for (FileSystem fileSystem : fs) {
try {
if(fileSystem.getType() == 2){
FileSystemUsage usage = sigar.getFileSystemUsage(fileSystem.getDirName());
total += usage.getTotal();
}
} catch (Exception e) {}
}
if(total == 0){
return 1;
}
staticResource.totalDisk = total;
}
return staticResource.totalDisk;
}
示例2: getDisks
import org.hyperic.sigar.FileSystemUsage; //导入依赖的package包/类
public static List<JSON> getDisks() throws SigarException {
_init();
FileSystem[] fs = getFileSystem();
List<JSON> l1 = new ArrayList<JSON>();
for (FileSystem f : fs) {
FileSystemUsage p = sigar.getFileSystemUsage(f.getDirName());
if (p.getTotal() > 0) {
l1.add(JSON.create().append("devname", f.getDevName()).append("dirname", f.getDirName())
.append("typename", f.getTypeName()).append("total", 1024 * p.getTotal())
.append("used", 1024 * p.getUsed()).append("free", 1024 * p.getFree())
.append("files", p.getFiles()).append("usepercent", p.getUsePercent())
.append("diskreads", p.getDiskReads()).append("diskreadbytes", p.getDiskReadBytes())
.append("diskwrites", p.getDiskWrites()).append("diskwritebytes", p.getDiskWriteBytes())
.append("diskqueue", p.getDiskQueue()));
}
}
return l1;
}
示例3: 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);
}
示例4: output
import org.hyperic.sigar.FileSystemUsage; //导入依赖的package包/类
public void output(FileSystem fs) throws SigarException {
FileSystemUsage usage =
this.sigar.getFileSystemUsage(fs.getDirName());
ArrayList items = new ArrayList();
items.add(fs.getDevName());
items.add(fs.getDirName());
items.add(String.valueOf(usage.getDiskReads()));
items.add(String.valueOf(usage.getDiskWrites()));
if (usage.getDiskReadBytes() == Sigar.FIELD_NOTIMPL) {
items.add("-");
items.add("-");
}
else {
items.add(Sigar.formatSize(usage.getDiskReadBytes()));
items.add(Sigar.formatSize(usage.getDiskWriteBytes()));
}
if (usage.getDiskQueue() == Sigar.FIELD_NOTIMPL) {
items.add("-");
}
else {
items.add(svctm(usage.getDiskQueue()));
}
if (usage.getDiskServiceTime() == Sigar.FIELD_NOTIMPL) {
items.add("-");
}
else {
items.add(svctm(usage.getDiskServiceTime()));
}
printf(items);
}
示例5: freeDisk
import org.hyperic.sigar.FileSystemUsage; //导入依赖的package包/类
/**
* 磁盘剩余量
*/
public static long freeDisk() throws SigarException {
FileSystem[] fs = sigar.getFileSystemList();
long free = 0L;
for (FileSystem fileSystem : fs) {
try {
if(fileSystem.getType() == 2){
FileSystemUsage usage = sigar.getFileSystemUsage(fileSystem.getDirName());
free += usage.getFree();
}
}catch (Exception e) {}
}
return free;
}
示例6: FileSystems
import org.hyperic.sigar.FileSystemUsage; //导入依赖的package包/类
FileSystems(
final UnitConversionService units,
final CachingService caching,
final Sigar sigar,
final AnnotationMBeanExporter server) throws SigarException, JMException {
final Set<String> seenFs = new HashSet<>();
for(final FileSystem fs : sigar.getFileSystemList()) {
final String devName = fs.getDevName();
if(seenFs.contains(devName)) {
continue;
}
seenFs.add(devName);
final Try.CheckedSupplier<FileSystemUsage> supplier = caching
.cache(() -> sigar.getFileSystemUsage(fs.getDirName()));
final SigarFileSystemMetrics filesystem = SigarFileSystemMetrics
.builder()
.units(units)
.usage(supplier)
.devName(devName)
.dirName(fs.getDirName())
.options(fs.getOptions())
.sysTypeName(fs.getSysTypeName())
.build();
final FilesystemType type = FilesystemType.values()[fs.getType()];
final ObjectName objectName = new ObjectName(format(OBJECT_NAME, type, ObjectName.quote(devName)));
server.registerManagedResource(filesystem, objectName);
}
}
示例7: getFileSystemUsage
import org.hyperic.sigar.FileSystemUsage; //导入依赖的package包/类
public static Map<String, FileSystemUsage> getFileSystemUsage() throws SigarException {
_init();
FileSystem[] fs = getFileSystem();
Map<String, FileSystemUsage> l1 = new TreeMap<String, FileSystemUsage>();
for (FileSystem f : fs) {
l1.put(f.getDirName(), sigar.getFileSystemUsage(f.getDirName()));
}
return l1;
}
示例8: 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;
}
示例9: getNativeInfo
import org.hyperic.sigar.FileSystemUsage; //导入依赖的package包/类
public static void getNativeInfo() {
Sigar sigar = new Sigar();
try {
int uptime = (int) sigar.getUptime().getUptime();
CpuInfo[] cpuInfoList = sigar.getCpuInfoList();
int mhz = cpuInfoList[0].getMhz();
CpuPerc cpuPerc = sigar.getCpuPerc();
//IO wait
double wait = cpuPerc.getWait();
Mem mem = sigar.getMem();
//included cache
long actualUsed = mem.getActualUsed();
long used = mem.getUsed();
long cache = used - actualUsed;
//net upload download
NetInterfaceStat usedNetInterfaceStat = null;
String[] netInterfaceList = sigar.getNetInterfaceList();
for (String interfaceName : netInterfaceList) {
NetInterfaceStat interfaceStat = sigar.getNetInterfaceStat(interfaceName);
if (interfaceStat.getRxBytes() != 0) {
usedNetInterfaceStat = interfaceStat;
break;
}
}
if (usedNetInterfaceStat != null) {
long speed = usedNetInterfaceStat.getSpeed();
long receivedBytes = usedNetInterfaceStat.getRxBytes();
long sentBytes = usedNetInterfaceStat.getTxBytes();
}
String rootFileSystem = File.listRoots()[0].getAbsolutePath();
FileSystemUsage fileSystemUsage = sigar.getFileSystemUsage(rootFileSystem);
long diskReadBytes = fileSystemUsage.getDiskReadBytes();
long diskWriteBytes = fileSystemUsage.getDiskWriteBytes();
} catch (SigarException ex) {
Logger.getLogger(NativeStats.class.getName()).log(Level.SEVERE, null, ex);
} finally {
sigar.close();
}
}
示例10: getTotal
import org.hyperic.sigar.FileSystemUsage; //导入依赖的package包/类
@Override
public long getTotal() {
return convert(FileSystemUsage::getTotal, KIBIS::toMebis);
}
示例11: getUsed
import org.hyperic.sigar.FileSystemUsage; //导入依赖的package包/类
@Override
public long getUsed() {
return convert(FileSystemUsage::getUsed, KIBIS::toMebis);
}
示例12: getFree
import org.hyperic.sigar.FileSystemUsage; //导入依赖的package包/类
@Override
public long getFree() {
return convert(FileSystemUsage::getFree, KIBIS::toMebis);
}
示例13: getDiskQueue
import org.hyperic.sigar.FileSystemUsage; //导入依赖的package包/类
@Override
public double getDiskQueue() {
return units.map(usage, FileSystemUsage::getDiskQueue, 0d);
}
示例14: getDiskReadMegaBytes
import org.hyperic.sigar.FileSystemUsage; //导入依赖的package包/类
@Override
public long getDiskReadMegaBytes() {
return convert(FileSystemUsage::getDiskReadBytes, UNIT::toMebis);
}
示例15: getDiskWriteMegaBytes
import org.hyperic.sigar.FileSystemUsage; //导入依赖的package包/类
@Override
public long getDiskWriteMegaBytes() {
return convert(FileSystemUsage::getDiskWriteBytes, UNIT::toMebis);
}