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


Java CpuInfo类代码示例

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


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

示例1: getCpuTotal

import org.hyperic.sigar.CpuInfo; //导入依赖的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.CpuInfo; //导入依赖的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: toString

import org.hyperic.sigar.CpuInfo; //导入依赖的package包/类
public String toString() {
    String ret = "os.name: " + System.getProperty("os.name") + "\n"
           + "os.version: " + System.getProperty("os.version") + "\n"
           + "os.arch: " + System.getProperty("os.arch") + "\n";
    try {
        ret += "total men:" + (sigar.getMem().getTotal() / 1024 / 1024);

        int i = 0;
        for(CpuInfo cpuInfo: sigar.getCpuInfoList()) {
            ret +=  "\ncpu " + i +":\n"
                + "\tmodel: "+ cpuInfo.getModel() + "\n"
                + "\tvendor: "+ cpuInfo.getVendor() + "\n"
                + "\tnf of core: " + cpuInfo.getTotalCores() + "\n"
                + "\tMhz:" + cpuInfo.getMhz();
             i++;
        }
    } catch (SigarException e) {
        e.printStackTrace();
    }
    return ret;
}
 
开发者ID:DIVERSIFY-project,项目名称:sosiefier,代码行数:22,代码来源:SystemInformation.java

示例4: calculateStats

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

示例5: outputCpu

import org.hyperic.sigar.CpuInfo; //导入依赖的package包/类
/**
 * Will set up the CPU information.
 * @throws SigarException 
 */
public void outputCpu() throws SigarException {
       // --- setting cpu-Information --------------------
	cpuInfos = this.sigar.getCpuInfoList();
	if(cpuInfos != null && cpuInfos.length!=0){
		CpuInfo info = cpuInfos[0];
        setVendor(info.getVendor());
        setModel(info.getModel());
        setMhz(info.getMhz());
        setTotalCpu(info.getTotalCores());
	}
   }
 
开发者ID:EnFlexIT,项目名称:AgentWorkbench,代码行数:16,代码来源:LoadMeasureSigar.java

示例6: compute

import org.hyperic.sigar.CpuInfo; //导入依赖的package包/类
private int compute(final Function<CpuInfo, Integer> func) {
  return Try.of(cpuInfo)
    .map(List::of)
    .map(List::head)
    .map(func)
    .getOrElse(0);
}
 
开发者ID:OctoPerf,项目名称:jmx-agent,代码行数:8,代码来源:SigarCpuMetrics.java

示例7: getNodeInfo

import org.hyperic.sigar.CpuInfo; //导入依赖的package包/类
private static V getNodeInfo() {
	V v = V.create("uptime", Model.UPTIME).append("ip", Host.getLocalip());

	try {
		CpuInfo[] cc = Host.getCpuInfo();
		if (cc != null && cc.length > 0) {
			v.append("cores", cc[0].getTotalCores());
		}
		v.append("os", Host.getOS().getName());
		v.append("mem", Host.getMem().getTotal());
	} catch (Exception e) {
		log.error(e.getMessage(), e);
	}
	return v;
}
 
开发者ID:giiwa,项目名称:giiwa,代码行数:16,代码来源:Node.java

示例8: setUp

import org.hyperic.sigar.CpuInfo; //导入依赖的package包/类
@Before
public void setUp() {
	sigar = mock(Sigar.class);
	swap = mock(Swap.class);
	cpuPerc = mock(CpuPerc.class);
	cpuInfo = mock(CpuInfo.class);
	mem = mock(Mem.class);
	
	machineStatsChecker = new MachineStatsChecker();		
}
 
开发者ID:aol,项目名称:micro-server,代码行数:11,代码来源:MachineStatsCheckerTest.java

示例9: initWorkerStat

import org.hyperic.sigar.CpuInfo; //导入依赖的package包/类
private void initWorkerStat(){
	try {
		workerStat.procThreadCount=procScheduler.numThreads;
		CpuInfo[] ci=sigar.getCpuInfoList();
		workerStat.cpuCoreCount=ci.length;
		workerStat.cpuHZ=1000000L*ci[0].getMhz();
	}
	catch (SigarException e) {			
		e.printStackTrace();
	}
}
 
开发者ID:HoratiusTang,项目名称:EsperDist,代码行数:12,代码来源:WorkerStatCollector.java

示例10: doMonitor

import org.hyperic.sigar.CpuInfo; //导入依赖的package包/类
public Object doMonitor(Map<String, Object> params) throws Exception {
	CpuInfo[] cpuInfos = SigarFactory.getSigar().getCpuInfoList();
	List<Map> result = Lists.newArrayList();
	if (cpuInfos != null) {
		for (CpuInfo cpuInfo : cpuInfos) {
			result.add(cpuInfo.toMap());
		}
	}
	return result;
}
 
开发者ID:cqyijifu,项目名称:watcher,代码行数:11,代码来源:CpuInfoMetrics.java

示例11: getCpuInfo

import org.hyperic.sigar.CpuInfo; //导入依赖的package包/类
protected List<CpuInfo> getCpuInfo() throws SigarException {
    List<CpuInfo> infos = new ArrayList<>();
    Set<String> models = new HashSet<>();
    for(CpuInfo cpuInfo: sigar.getCpuInfoList()) {
        if(!models.contains(cpuInfo.getModel())) {
            models.add(cpuInfo.getModel());
            infos.add(cpuInfo);
        }
    }

    return infos;
}
 
开发者ID:DIVERSIFY-project,项目名称:sosiefier,代码行数:13,代码来源:SystemInformation.java

示例12: getInfoFromSigar

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

示例13: getNativeInfo

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

示例14: cpuInfo

import org.hyperic.sigar.CpuInfo; //导入依赖的package包/类
@Bean
Try.CheckedSupplier<CpuInfo[]> cpuInfo(
  final Sigar sigar,
  final CachingService caching) {
  return caching.cache(sigar::getCpuInfoList);
}
 
开发者ID:OctoPerf,项目名称:jmx-agent,代码行数:7,代码来源:CpuConfig.java

示例15: getTotalCpuCores

import org.hyperic.sigar.CpuInfo; //导入依赖的package包/类
@Override
public int getTotalCpuCores() {
  return compute(CpuInfo::getTotalCores);
}
 
开发者ID:OctoPerf,项目名称:jmx-agent,代码行数:5,代码来源:SigarCpuMetrics.java


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