當前位置: 首頁>>代碼示例>>Java>>正文


Java Sigar.getCpuInfoList方法代碼示例

本文整理匯總了Java中org.hyperic.sigar.Sigar.getCpuInfoList方法的典型用法代碼示例。如果您正苦於以下問題:Java Sigar.getCpuInfoList方法的具體用法?Java Sigar.getCpuInfoList怎麽用?Java Sigar.getCpuInfoList使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.hyperic.sigar.Sigar的用法示例。


在下文中一共展示了Sigar.getCpuInfoList方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getCpuTotal

import org.hyperic.sigar.Sigar; //導入方法依賴的package包/類
public void getCpuTotal() {
	Sigar sigar = new Sigar();
	CpuInfo[] infos;
	try {
		infos = sigar.getCpuInfoList();
		for (int i = 0; i < infos.length; i++) {// 不管是單塊CPU還是多CPU都適用
			CpuInfo info = infos[i];
			System.out.println("CPU的總量:" + info.getMhz());// CPU的總量MHz
			System.out.println("獲得CPU的賣主:" + info.getVendor());// 獲得CPU的賣主,如:Intel
			System.out.println("CPU的類別:" + info.getModel());// 獲得CPU的類別,如:Celeron
			System.out.println("緩衝存儲器數量:" + info.getCacheSize());// 緩衝存儲器數量
			System.out.println("**************");
		}
	} catch (SigarException e) {
		e.printStackTrace();
	}
}
 
開發者ID:funtl,項目名稱:framework,代碼行數:18,代碼來源:SysInfo.java

示例2: onCommand

import org.hyperic.sigar.Sigar; //導入方法依賴的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

示例3: calculateStats

import org.hyperic.sigar.Sigar; //導入方法依賴的package包/類
public void calculateStats() {
    numCores = Runtime.getRuntime().availableProcessors();
    Sigar sigar = new Sigar();
    try {
        CpuInfo[] cpuInfo = sigar.getCpuInfoList();
        cpuFreq = cpuInfo[0].getMhz();
        Mem memInfo = sigar.getMem();
        freeRAM = memInfo.getFreePercent();
        cpuLoad = sigar.getLoadAverage();
        for (int i = 0; i < getCpuLoad().length; i++) {
            cpuLoad[i] /= numCores;
        }
    } catch (SigarException ex) {
        ex.printStackTrace();
    }
}
 
開發者ID:adityashah30,項目名稱:dcs,代碼行數:17,代碼來源:StatsCalculator.java

示例4: getCpuCount

import org.hyperic.sigar.Sigar; //導入方法依賴的package包/類
/**
 * 1.CPU資源信息
 */
// a)CPU數量(單位:個)
public static int getCpuCount() throws SigarException {
	Sigar sigar = new Sigar();
	try {
		return sigar.getCpuInfoList().length;
	} finally {
		sigar.close();
	}
}
 
開發者ID:funtl,項目名稱:framework,代碼行數:13,代碼來源:SysInfo.java

示例5: newSigar

import org.hyperic.sigar.Sigar; //導入方法依賴的package包/類
private Sigar newSigar() throws Exception {
	try {
		final Sigar s = new Sigar();
		s.getCpuInfoList();
		return s;
	} catch (UnsatisfiedLinkError e) {
		throw new RuntimeException(e);
	}
}
 
開發者ID:stagemonitor,項目名稱:stagemonitor,代碼行數:10,代碼來源:OsPlugin.java

示例6: getInfoFromSigar

import org.hyperic.sigar.Sigar; //導入方法依賴的package包/類
private StringBuilder getInfoFromSigar() throws Exception {

        StringBuilder sb = new StringBuilder();
        Sigar sigar = new Sigar();

        sb.append("Fully Qualified Domain Name:\n\t" + sigar.getFQDN().toString());
        sb.append("\nSystem uptime:\n\t" + new Double(sigar.getUptime().getUptime()).intValue()
                  + " seconds");
        sb.append("\nDate:\n\t" + new Date());
        sb.append("\nNetwork settings:" + format(sigar.getNetInfo().toString(), 1));

        sb.append("\nCPU info:");
        CpuInfo[] cpuInfoList = sigar.getCpuInfoList();
        for (int i = 0; i < cpuInfoList.length; i++) {
            CpuInfo cpuInfo = cpuInfoList[i];
            sb.append("\n\tCPU " + i + ": ");
            sb.append(format(cpuInfo.toString(), 2));
        }

        double totalMemory = (new Long(sigar.getMem().getTotal()).doubleValue() / 1024 / 1024 / 1024);
        sb.append("\nTotal memory:\n\t"
                  + new BigDecimal(totalMemory).setScale(2, BigDecimal.ROUND_DOWN).floatValue() + " GB");

        String[] nicList = sigar.getNetInterfaceList();
        sb.append("\nNIC info: ");
        for (int i = 0; i < nicList.length; i++) {
            NetInterfaceConfig nic = sigar.getNetInterfaceConfig(nicList[i]);
            sb.append("\n\tNIC " + i + ": ");
            sb.append(format(nic.toString(), 2));
        }

        FileSystem[] fileSystemList = sigar.getFileSystemList();
        sb.append("\nFile system info: ");
        for (int i = 0; i < fileSystemList.length; i++) {
            FileSystem fileSystem = fileSystemList[i];

            sb.append("\n\t" + fileSystem.getDevName() + " is a");
            if (fileSystem.getType() == FileSystem.TYPE_LOCAL_DISK) {
                sb.append(" local");
            } else if (fileSystem.getType() == FileSystem.TYPE_NETWORK) {
                sb.append(" network");
            } else if (fileSystem.getType() == FileSystem.TYPE_RAM_DISK) {
                sb.append(" ram disk");
            } else if (fileSystem.getType() == FileSystem.TYPE_SWAP) {
                sb.append(" swap");
            }

            sb.append(" " + fileSystem.getSysTypeName() + ", dir name '" + fileSystem.getDirName()
                      + "', options '" + fileSystem.getOptions() + "'");
        }

        sb.append("\nResource limits:" + format(sigar.getResourceLimit().toString(), "max", 1));
        return sb;
    }
 
開發者ID:Axway,項目名稱:ats-framework,代碼行數:55,代碼來源:MachineDescriptionOperations.java

示例7: getNativeInfo

import org.hyperic.sigar.Sigar; //導入方法依賴的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


注:本文中的org.hyperic.sigar.Sigar.getCpuInfoList方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。