org.hyperic.sigar.CpuInfo Java Examples

The following examples show how to use org.hyperic.sigar.CpuInfo. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Monitor.java    From JobX with Apache License 2.0 6 votes vote down vote up
public CPU(int index, CpuInfo info, CpuPerc perc) {
    this.index = index;
    this.cacheSize = info.getCacheSize();
    this.coresPerSocket = info.getCoresPerSocket();
    this.totalCores = info.getTotalCores();
    this.totalSockets = info.getTotalSockets();
    this.mhz = info.getMhz();
    this.model = info.getModel();
    this.vendor = info.getVendor();

    this.user = perc.getUser();
    this.sys = perc.getSys();
    this.nice = perc.getNice();
    this.idle = perc.getIdle();
    this.wait = perc.getWait();
    this.irq = perc.getIrq();
    this.softIrq = perc.getSoftIrq();
    this.stolen = perc.getStolen();
    this.combined = perc.getCombined();
}
 
Example #2
Source File: sigar.java    From sigar-system_runtime with MIT License 6 votes vote down vote up
private static void cpu() throws SigarException {
    Sigar sigar = new Sigar();
    
    CpuPerc perc = sigar.getCpuPerc();
    System.out.println("整体cpu的占用情况:");
    System.out.println("空闲率: " + CpuPerc.format(perc.getIdle()));//获取当前cpu的空闲率
    System.out.println("占用率: "+ CpuPerc.format(perc.getCombined()));//获取当前cpu的占用率
    
    
    CpuInfo infos[] = sigar.getCpuInfoList();
    CpuPerc cpuList[] = null;
    cpuList = sigar.getCpuPercList();
    for (int i = 0; i < infos.length; i++) {// 不管是单块CPU还是多CPU都适用
        CpuInfo info = infos[i];
        System.out.println("第" + (i + 1) + "块CPU信息");
        System.out.println("CPU的总量MHz:    " + info.getMhz());// CPU的总量MHz
        System.out.println("CPU生产商:    " + info.getVendor());// 获得CPU的卖主,如:Intel
        System.out.println("CPU类别:    " + info.getModel());// 获得CPU的类别,如:Celeron
        System.out.println("CPU缓存数量:    " + info.getCacheSize());// 缓冲存储器数量
        printCpuPerc(cpuList[i]);
    }
}
 
Example #3
Source File: PerformanceService.java    From WeBASE-Front with Apache License 2.0 5 votes vote down vote up
/**
 * getConfigInfo.
 * 
 * @return
 */
public Map<String, String> getConfigInfo() throws UnknownHostException, SigarException {
    log.info("getConfigInfo.");
    Map<String, String> configMap = new HashMap<>();
    String ip = getIp();
    log.debug("local ip:    " + ip);
    configMap.put("ip", ip);
    Mem mem = sigar.getMem();
    log.debug("memory total:    " + mem.getTotal() / 1024L + "K av");
    log.debug("memory used now:    " + mem.getUsed() / 1024L + "K used");
    configMap.put("memoryTotalSize", Long.toString(mem.getTotal() / 1024L));
    configMap.put("memoryUsedSize", Long.toString(mem.getUsed() / 1024L));
    CpuPerc cpu = sigar.getCpuPerc();
    CpuInfo[] infos = sigar.getCpuInfoList();
    log.debug("CPU mhz:    " + infos[0].getMhz());
    log.debug("CPU core number:    " + infos.length);
    configMap.put("cpuSize", Integer.toString(infos[0].getMhz()));
    configMap.put("cpuAmount", Integer.toString(infos.length));
    long total;
    long use;
    FileSystem[] fslist = sigar.getFileSystemList();
    log.debug("****fs " + fslist.length);
    use = sigar.getFileSystemUsage(constants.getMonitorDisk()).getUsed();
    total = sigar.getFileSystemUsage(constants.getMonitorDisk()).getTotal();
    log.debug("diskTotalSize:    " + total);
    log.debug("diskUsedSize:    " + use);
    configMap.put("diskTotalSize", Long.toString(total));
    configMap.put("diskUsedSize", Long.toString(use));
    return configMap;
}
 
Example #4
Source File: CpuInfoMetrics.java    From watcher with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example #5
Source File: MachineStatsCheckerTest.java    From micro-server with Apache License 2.0 5 votes vote down vote up
@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();		
}
 
Example #6
Source File: MachineDescriptionOperations.java    From ats-framework with Apache License 2.0 4 votes vote down vote up
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;
    }
 
Example #7
Source File: Cpu.java    From maintain with MIT License 4 votes vote down vote up
public Cpu(CpuInfo cpuInfo, CpuPerc cpuPerc) {
	this.cpuInfo = cpuInfo;
	this.cpuPerc = cpuPerc;
}
 
Example #8
Source File: Cpu.java    From maintain with MIT License 4 votes vote down vote up
public CpuInfo getCpuInfo() {
	return cpuInfo;
}
 
Example #9
Source File: Cpu.java    From maintain with MIT License 4 votes vote down vote up
public void setCpuInfo(CpuInfo cpuInfo) {
	this.cpuInfo = cpuInfo;
}
 
Example #10
Source File: MachineStatsCheckerTest.java    From micro-server with Apache License 2.0 4 votes vote down vote up
@Test
public void testGetStats() throws SigarException {
	
	when(sigar.getSwap()).thenReturn(swap)
	                     .thenReturn(swap)
	                     .thenReturn(swap)
	                     .thenReturn(swap)
	                     .thenReturn(swap);
	
	when(sigar.getCpuPerc()).thenReturn(cpuPerc)
							.thenReturn(cpuPerc)
							.thenReturn(cpuPerc);
	
	CpuInfo[] cpuInfos = new CpuInfo[] { cpuInfo };
	
	when(sigar.getCpuInfoList()).thenReturn(cpuInfos)
								.thenReturn(cpuInfos)
								.thenReturn(cpuInfos);
	
	double[] doubleValue = new double[] { 0.0 };
	when(sigar.getLoadAverage()).thenReturn(doubleValue);
	
	when(sigar.getMem()).thenReturn(mem)
					    .thenReturn(mem)
					    .thenReturn(mem)
					    .thenReturn(mem)
					    .thenReturn(mem);
	
	
	machineStatsChecker.getStats(sigar);
	
	verify(sigar, times(5)).getSwap();
	verify(swap, times(1)).getPageIn();
	verify(swap, times(1)).getPageOut();
	verify(swap, times(1)).getFree();
	verify(swap, times(1)).getUsed();
	verify(swap, times(1)).getTotal();
	
	verify(sigar, times(1)).getCpuPerc();
	verify(cpuPerc, times(1)).getIdle();
	
	
	verify(sigar, times(3)).getCpuInfoList();
	verify(cpuInfo, times(1)).getTotalCores();
	verify(cpuInfo, times(1)).getMhz();
	verify(cpuInfo, times(1)).getModel();
	
	verify(sigar, times(1)).getLoadAverage();
	
	verify(sigar, times(5)).getMem();
	verify(mem, times(1)).getActualFree();
	verify(mem, times(1)).getActualUsed();
	verify(mem, times(1)).getTotal();
	verify(mem, times(1)).getUsedPercent();
	verify(mem, times(1)).getFreePercent();
	
	verify(sigar, times(1)).close();
	
}