当前位置: 首页>>代码示例>>Java>>正文


Java FileSystem类代码示例

本文整理汇总了Java中org.hyperic.sigar.FileSystem的典型用法代码示例。如果您正苦于以下问题:Java FileSystem类的具体用法?Java FileSystem怎么用?Java FileSystem使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


FileSystem类属于org.hyperic.sigar包,在下文中一共展示了FileSystem类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: output

import org.hyperic.sigar.FileSystem; //导入依赖的package包/类
public void output(String[] args) throws SigarException {
    if (args.length == 1) {
        String arg = args[0];
        if ((arg.indexOf('/') != -1) || (arg.indexOf('\\') != -1)) {
            outputFileSystem(arg);
        }
        else {
            outputDisk(arg);
        }
    }
    else {
        FileSystem[] fslist = this.proxy.getFileSystemList();
        printHeader();
        for (int i=0; i<fslist.length; i++) {
            if (fslist[i].getType() == FileSystem.TYPE_LOCAL_DISK) {
                output(fslist[i]);
            }
        }
    }
}
 
开发者ID:EnFlexIT,项目名称:AgentWorkbench,代码行数:21,代码来源:Iostat.java

示例2: totalDisk

import org.hyperic.sigar.FileSystem; //导入依赖的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;
}
 
开发者ID:yanfanvip,项目名称:RedisClusterManager,代码行数:23,代码来源:MonitorUtil.java

示例3: getDisks

import org.hyperic.sigar.FileSystem; //导入依赖的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;
}
 
开发者ID:giiwa,项目名称:giiwa,代码行数:22,代码来源:Host.java

示例4: onCommand

import org.hyperic.sigar.FileSystem; //导入依赖的package包/类
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
    if (!isAllowed(sender, command)) {
        sender.sendMessage(org.bukkit.ChatColor.DARK_RED + "Not whitelisted");
        return true;
    }

    if (!plugin.getConfig().getBoolean("native-library")) {
        sender.sendMessage(ChatColor.DARK_RED + "Native support is disabled");
        return true;
    }

    //swap and load is already available in the environment command because MBeans already supports this
    Sigar sigar = plugin.getNativeData().getSigar();
    try {
        int uptime = (int) sigar.getUptime().getUptime();
        sender.sendMessage(PRIMARY_COLOR + "OS Uptime: " + SECONDARY_COLOR + formatUptime(uptime));

        CpuInfo[] cpuInfoList = sigar.getCpuInfoList();
        int mhz = cpuInfoList[0].getMhz();
        sender.sendMessage(PRIMARY_COLOR + "CPU MHZ: " + SECONDARY_COLOR + mhz);

        CpuPerc cpuPerc = sigar.getCpuPerc();
        //IO wait
        double wait = cpuPerc.getWait();
        sender.sendMessage(PRIMARY_COLOR + "CPU Wait (I/O): " + SECONDARY_COLOR + wait + '%');

        Mem mem = sigar.getMem();
        //included cache
        long actualUsed = mem.getActualUsed();
        long used = mem.getUsed();

        long cache = used - actualUsed;
        sender.sendMessage(PRIMARY_COLOR + "Memory Cache: " + SECONDARY_COLOR + Sigar.formatSize(cache));

        printNetworkInfo(sender, sigar);

        //disk read write
        List<String> diskNames = Arrays.stream(sigar.getFileSystemList())
                .map(FileSystem::getDevName)
                .filter(name -> name.startsWith("/dev/sd"))
                .distinct()
                .collect(Collectors.toList());

        Collection<DiskUsage> diskUsages = new ArrayList<>();
        for (String diskName : diskNames) {
            diskUsages.add(sigar.getDiskUsage(diskName));
        }

        long diskReads = diskUsages.stream().mapToLong(DiskUsage::getReadBytes).sum();
        long diskWrites = diskUsages.stream().mapToLong(DiskUsage::getWriteBytes).sum();


        String diskReadBytes = Sigar.formatSize(diskReads);
        String diskWriteBytes = Sigar.formatSize(diskWrites);

        sender.sendMessage(PRIMARY_COLOR + "Disk read bytes: " + SECONDARY_COLOR + diskReadBytes);
        sender.sendMessage(PRIMARY_COLOR + "Disk write bytes: " + SECONDARY_COLOR + diskWriteBytes);

        sender.sendMessage(PRIMARY_COLOR + "Filesystems:");
        for (FileSystem fileSystem : sigar.getFileSystemList()) {
            String dirName = fileSystem.getDirName();
            String typeName = fileSystem.getSysTypeName();
            sender.sendMessage(PRIMARY_COLOR + dirName + " - " + SECONDARY_COLOR + typeName);
        }
    } catch (SigarException sigarException) {
        plugin.getLogger().log(Level.SEVERE, null, sigarException);
    }

    return true;
}
 
开发者ID:games647,项目名称:LagMonitor,代码行数:72,代码来源:NativeCommand.java

示例5: output

import org.hyperic.sigar.FileSystem; //导入依赖的package包/类
public void output(String[] args) throws SigarException {
    this.opt_i = false;
    ArrayList sys = new ArrayList();

    if (args.length > 0) {
        FileSystemMap mounts = this.proxy.getFileSystemMap();
        for (int i=0; i<args.length; i++) {
            String arg = args[i];
            if (arg.equals("-i")) {
                this.opt_i = true;
                continue;
            }
            String name = FileCompleter.expand(arg);
            FileSystem fs = mounts.getMountPoint(name);

            if (fs == null) {
                throw new SigarException(arg +
                                         " No such file or directory");
            }
            sys.add(fs);
        }
    }
    if (sys.size() == 0) {
        FileSystem[] fslist = this.proxy.getFileSystemList();
        for (int i=0; i<fslist.length; i++) {
            sys.add(fslist[i]);
        }
    }

    printHeader();
    for (int i=0; i<sys.size(); i++) {
        output((FileSystem)sys.get(i));
    }
}
 
开发者ID:EnFlexIT,项目名称:AgentWorkbench,代码行数:35,代码来源:Df.java

示例6: outputFileSystem

import org.hyperic.sigar.FileSystem; //导入依赖的package包/类
public void outputFileSystem(String arg) throws SigarException {
    FileSystemMap mounts = this.proxy.getFileSystemMap();
    String name = FileCompleter.expand(arg);
    FileSystem fs = mounts.getMountPoint(name);

    if (fs != null) {
        printHeader();
        output(fs);
        return;
    }

    throw new SigarException(arg +
                             " No such file or directory");
}
 
开发者ID:EnFlexIT,项目名称:AgentWorkbench,代码行数:15,代码来源:Iostat.java

示例7: freeDisk

import org.hyperic.sigar.FileSystem; //导入依赖的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;
}
 
开发者ID:yanfanvip,项目名称:RedisClusterManager,代码行数:17,代码来源:MonitorUtil.java

示例8: FileSystems

import org.hyperic.sigar.FileSystem; //导入依赖的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);
  }
}
 
开发者ID:OctoPerf,项目名称:jmx-agent,代码行数:32,代码来源:FileSystems.java

示例9: getAllDiskFilesystems

import org.hyperic.sigar.FileSystem; //导入依赖的package包/类
private void getAllDiskFilesystems(SigarProxy aSigar, LinkedList<Object> list) {
	try {
		FileSystemMap map = aSigar.getFileSystemMap();
		Iterator<?> it = map.keySet().iterator();
		while (it.hasNext()) {
			Object key = it.next();
			FileSystem fs = (FileSystem) map.get(key);
			if (fs.getType() == 2) {
				list.add(key);
			}
		}
	} catch (SigarException e) {
		log.warn("Can't get filesystems map", e);
	}
}
 
开发者ID:junehappylove,项目名称:ServerAgent,代码行数:16,代码来源:DiskIOMetric.java

示例10: logAvailableFilesystems

import org.hyperic.sigar.FileSystem; //导入依赖的package包/类
public static void logAvailableFilesystems(SigarProxy aSigar) {
	log.info("*** Logging available filesystems ***");
	try {
		FileSystemMap map = aSigar.getFileSystemMap();
		Iterator<?> it = map.keySet().iterator();
		while (it.hasNext()) {
			Object key = it.next();
			FileSystem fs = (FileSystem) map.get(key);
			log.info("Filesystem: fs=" + fs.toString() + " type=" + fs.getSysTypeName());
		}
	} catch (SigarException e) {
		log.warn("Can't get filesystems map", e);
	}
}
 
开发者ID:junehappylove,项目名称:ServerAgent,代码行数:15,代码来源:DiskIOMetric.java

示例11: getFileSystemUsage

import org.hyperic.sigar.FileSystem; //导入依赖的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;
}
 
开发者ID:giiwa,项目名称:giiwa,代码行数:11,代码来源:Host.java

示例12: output

import org.hyperic.sigar.FileSystem; //导入依赖的package包/类
public void output(FileSystem fs) throws SigarException {
	//
	// 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());

}
 
开发者ID:scouter-project,项目名称:scouter,代码行数:14,代码来源:DiskPerf.java

示例13: initializePlugin

import org.hyperic.sigar.FileSystem; //导入依赖的package包/类
@Override
public void initializePlugin(StagemonitorPlugin.InitArguments initArguments) throws Exception {
	final CorePlugin corePlugin = initArguments.getPlugin(CorePlugin.class);

	corePlugin.getGrafanaClient().sendGrafanaDashboardAsync("grafana/ElasticsearchHostDashboard.json");
	if (sigar == null) {
		if (!SigarNativeBindingLoader.loadNativeSigarBindings()) {
			// redeploys are a problem, because the native libs can only be loaded by one class loader
			// this would lead to a UnsatisfiedLinkError: Native Library sigar already loaded in another class loader
			throw new RuntimeException("The OsPlugin only works with one application per JVM " +
					"and does not work after a redeploy");
		}
		sigar = newSigar();
	}
	initArguments.getMetricRegistry().registerAll(init(new CpuMetricSet(sigar, sigar.getCpuInfoList()[0])));
	initArguments.getMetricRegistry().registerAll(init(new MemoryMetricSet(sigar)));
	initArguments.getMetricRegistry().registerAll(init(new SwapMetricSet(sigar)));

	Set<String> routedNetworkInterfaces = new HashSet<String>();
	for (NetRoute netRoute : sigar.getNetRouteList()) {
		routedNetworkInterfaces.add(netRoute.getIfname());
	}
	for (String ifname : routedNetworkInterfaces) {
		initArguments.getMetricRegistry().registerAll(init(new NetworkMetricSet(ifname, sigar)));
	}
	@SuppressWarnings("unchecked")
	final Set<Map.Entry<String, FileSystem>> entries = (Set<Map.Entry<String, FileSystem>>) sigar.getFileSystemMap().entrySet();
	for (Map.Entry<String, FileSystem> e : entries) {
		final FileSystem fs = e.getValue();
		if (fs.getType() == FileSystem.TYPE_LOCAL_DISK || fs.getType() == FileSystem.TYPE_NETWORK) {
			initArguments.getMetricRegistry().registerAll(init(new FileSystemMetricSet(e.getKey(), sigar)));
		}
	}
}
 
开发者ID:stagemonitor,项目名称:stagemonitor,代码行数:35,代码来源:OsPlugin.java

示例14: getFirstMountPoint

import org.hyperic.sigar.FileSystem; //导入依赖的package包/类
private String getFirstMountPoint() throws SigarException {
	@SuppressWarnings("unchecked")
	final Set<Map.Entry<String, FileSystem>> entries = (Set<Map.Entry<String, FileSystem>>) sigar.getFileSystemMap().entrySet();
	for (Map.Entry<String, FileSystem> e : entries) {
		if (e.getValue().getType() == FileSystem.TYPE_LOCAL_DISK) {
			return e.getKey();
		}
	}
	throw new IllegalStateException("No mount point found");
}
 
开发者ID:stagemonitor,项目名称:stagemonitor,代码行数:11,代码来源:OsPluginTest.java

示例15: testFileSystemInfo

import org.hyperic.sigar.FileSystem; //导入依赖的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;
}
 
开发者ID:funtl,项目名称:framework,代码行数:59,代码来源:SysInfo.java


注:本文中的org.hyperic.sigar.FileSystem类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。