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


Java CpuPerc.getWait方法代码示例

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


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

示例1: onCommand

import org.hyperic.sigar.CpuPerc; //导入方法依赖的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

示例2: getNativeInfo

import org.hyperic.sigar.CpuPerc; //导入方法依赖的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();
    }
}
 
开发者ID:games647,项目名称:Java-Snippets,代码行数:48,代码来源:NativeStats.java

示例3: getValue

import org.hyperic.sigar.CpuPerc; //导入方法依赖的package包/类
@Override
public void getValue(StringBuffer res) throws SigarException {
	CpuPerc cpu;
	if (this.coreID < 0) {
		cpu = this.sigarProxy.getCpuPerc();
	} else {
		cpu = this.sigarProxy.getCpuPercList()[this.coreID];
	}
	double val;
	switch (this.type) {
	case 0:
		val = cpu.getCombined();
		break;
	case 1:
		val = cpu.getIdle();
		break;
	case 2:
		val = cpu.getIrq();
		break;
	case 3:
		val = cpu.getNice();
		break;
	case 4:
		val = cpu.getSoftIrq();
		break;
	case 5:
		val = cpu.getStolen();
		break;
	case 6:
		val = cpu.getSys();
		break;
	case 7:
		val = cpu.getUser();
		break;
	case 8:
		val = cpu.getWait();
		break;
	default:
		throw new SigarException("Unknown proc total type " + this.type);
	}
	if (!Double.isNaN(val)) {
		res.append(Double.toString(100.0D * val));
	} else {
		log.warn("Failed to get total cpu metric: " + types[this.type]);
	}
}
 
开发者ID:junehappylove,项目名称:ServerAgent,代码行数:47,代码来源:CPUTotalMetric.java


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