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


Java CpuPerc类代码示例

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


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

示例1: getPercPerThreadStats

import org.hyperic.sigar.CpuPerc; //导入依赖的package包/类
/**
 * this function calculates for each thread its load percentage, then return, in a single string, load percentage for each thread of CPU.
 * <p>
 * before return, this method call <code>setPercPerThreadInModel(String cpuLoad)</code> to set values in model
 * @see CPUStats#setPercPerThreadInModel(String)
 * @return this functions returns, in a single string, load percentage for each thread of CPU separated by a "\n".
 * In case of problem return the string "0"
 */
public String getPercPerThreadStats(){
    try {
        CpuPerc[] cpuperclist = SigarFactory.newSigar().getCpuPercList();
        genericStringBuilder.setLength(0);
        for (CpuPerc aCpuperclist : cpuperclist) {
            genericStringBuilder.append(GeneralStats.getInstance().round((float) (aCpuperclist.getCombined() * 100), 2)).append("\n");
        }
        setPercPerThreadInModel(genericStringBuilder.toString());
        return genericStringBuilder.toString();
    } catch (SigarException e) {
        setPercPerThreadInModel("0");
        e.printStackTrace();
        return "0";
    }
}
 
开发者ID:andrea9293,项目名称:pcstatus,代码行数:24,代码来源:CPUStats.java

示例2: 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

示例3: getCurrentWorkerStat

import org.hyperic.sigar.CpuPerc; //导入依赖的package包/类
public WorkerStat getCurrentWorkerStat(){
	try {
		CpuPerc cpp=sigar.getCpuPerc();
		Mem mem=sigar.getMem();			
		workerStat.cpuUsage=cpp.getCombined();
		workerStat.memUsed=mem.getActualUsed();
		workerStat.memFree=mem.getActualFree();
		workerStat.timestampMS=System.currentTimeMillis();
		workerStat.instanceCount=worker.insMap.size();
		return workerStat;
	}
	catch (SigarException e) {
		e.printStackTrace();
		return workerStat;
	}
}
 
开发者ID:HoratiusTang,项目名称:EsperDist,代码行数:17,代码来源:WorkerStatCollector.java

示例4: getCpuUsage

import org.hyperic.sigar.CpuPerc; //导入依赖的package包/类
/**
 * Gets the cpu usage.
 * 
 * @return the cpu usage
 */
private Object getCpuUsage() {
	try {
		// cpu percentage object.
		CpuPerc per = sigar.getCpuPerc();

		// getting the string value of percentage.
		String p = String.valueOf(per.getCombined() * 100.0);
		// getting index of the .
		int ix = p.indexOf('.') + 1;
		// getting only one digit after .
		return p.substring(0, ix) + p.substring(ix, ix + 1);
	} catch (Exception e) {
		LOGGER.error(e.getMessage(), e);
	}
	return null;
}
 
开发者ID:Impetus,项目名称:ankush,代码行数:22,代码来源:SigarNodeInfoProvider.java

示例5: executeCommand

import org.hyperic.sigar.CpuPerc; //导入依赖的package包/类
@Override
public String executeCommand(final SigarProxy sigar) throws SigarException {
	StrBuilder sb = new StrBuilder(200);

	CpuPerc[] cpus = sigar.getCpuPercList();
	CpuPerc cpuAll = sigar.getCpuPerc();

	sb.append(TYPE_CPU_X);
	sb.append(separator);
	writeCpu(sb, cpuAll);

	if (cpus.length > 1) { // more than one CPU
		appendLineBreak(sb);
		for (int i = 0; i < cpus.length; i++) {
			appendLineBreak(sb, i);
			sb.append(TYPE_CPU + i);
			sb.append(separator);
			writeCpu(sb, cpus[i]);
		}
	}

	return sb.toString();
}
 
开发者ID:mgm-tp,项目名称:perfload-perfmon,代码行数:24,代码来源:PerfMonCpu.java

示例6: executeCommand

import org.hyperic.sigar.CpuPerc; //导入依赖的package包/类
@Override
public String executeCommand(final SigarProxy sigar) throws SigarException {
	StrBuilder sb = new StrBuilder(200);

	String[] type = new String[] { "State.Name.sw=java" };
	long[] pids = Shell.getPids(sigar, type);

	for (int i = 0; i < pids.length; i++) {
		appendLineBreak(sb, i);

		sb.append(TYPE_JAVA_X + i);
		sb.append(separator);
		long pid = pids[i];

		String cpuPerc = "?";
		@SuppressWarnings("unchecked")
		List<Object> info = new ArrayList<Object>(Ps.getInfo(sigar, pid));
		ProcCpu cpu = sigar.getProcCpu(pid);
		cpuPerc = CpuPerc.format(cpu.getPercent());
		info.add(info.size() - 1, cpuPerc);
		sb.append(Ps.join(info));
	}

	return sb.toString();
}
 
开发者ID:mgm-tp,项目名称:perfload-perfmon,代码行数:26,代码来源:PerfMonJava.java

示例7: output

import org.hyperic.sigar.CpuPerc; //导入依赖的package包/类
private void output(CpuPerc cpu) {
    println("User Time....." + CpuPerc.format(cpu.getUser()));
    println("Sys Time......" + CpuPerc.format(cpu.getSys()));
    println("Idle Time....." + CpuPerc.format(cpu.getIdle()));
    println("Wait Time....." + CpuPerc.format(cpu.getWait()));
    println("Nice Time....." + CpuPerc.format(cpu.getNice()));
    println("Combined......" + CpuPerc.format(cpu.getCombined()));
    println("Irq Time......" + CpuPerc.format(cpu.getIrq()));
    if (SigarLoader.IS_LINUX) {
        println("SoftIrq Time.." + CpuPerc.format(cpu.getSoftIrq()));
        println("Stolen Time...." + CpuPerc.format(cpu.getStolen()));
    }
    println("");
}
 
开发者ID:EnFlexIT,项目名称:AgentWorkbench,代码行数:15,代码来源:CpuInfo.java

示例8: output

import org.hyperic.sigar.CpuPerc; //导入依赖的package包/类
public void output(String[] args) throws SigarException {
    String query = args[0];
    MultiProcCpu cpu = this.proxy.getMultiProcCpu(query);
    println("Number of processes: " + cpu.getProcesses());
    println("Cpu usage: " + CpuPerc.format(cpu.getPercent()));
    println("Cpu time: "  + Ps.getCpuTime(cpu.getTotal()));

    ProcMem mem = this.proxy.getMultiProcMem(query);
    println("Size: " + Sigar.formatSize(mem.getSize()));
    println("Resident: " + Sigar.formatSize(mem.getResident()));
    println("Share: " + Sigar.formatSize(mem.getShare()));
}
 
开发者ID:EnFlexIT,项目名称:AgentWorkbench,代码行数:13,代码来源:MultiPs.java

示例9: printCpuPerc

import org.hyperic.sigar.CpuPerc; //导入依赖的package包/类
private void printCpuPerc(CpuPerc cpu) {
	System.out.println("用户使用率:" + CpuPerc.format(cpu.getUser()));// 用户使用率
	System.out.println("系统使用率:" + CpuPerc.format(cpu.getSys()));// 系统使用率
	System.out.println("当前等待率:" + CpuPerc.format(cpu.getWait()));// 当前等待率
	System.out.println("Nice :" + CpuPerc.format(cpu.getNice()));//
	System.out.println("当前空闲率:" + CpuPerc.format(cpu.getIdle()));// 当前空闲率
	System.out.println("总的使用率:" + CpuPerc.format(cpu.getCombined()));// 总的使用率
	System.out.println("**************");
}
 
开发者ID:funtl,项目名称:framework,代码行数:10,代码来源:SysInfo.java

示例10: getCPUUsage

import org.hyperic.sigar.CpuPerc; //导入依赖的package包/类
/**
 * @desc 获取cpu使用率
 *
 * @author liuliang
 *
 * @return Double 比例(保留2位小数)
 */
public static Double getCPUUsage() {
	double cpuUsage = 0;
	try {
		CpuPerc[] cpuList = getInstance().getCpuPercList();
		// 不管是单块CPU还是多CPU都适用
		for (int i = 0; i < cpuList.length; i++) {
			cpuUsage += cpuList[i].getCombined() * 100;
		}
		cpuUsage = NumberUtil.format(cpuUsage / cpuList.length);
	} catch (SigarException e) {
		e.printStackTrace();
	}
	return cpuUsage;
}
 
开发者ID:yunjiweidian,项目名称:TITAN,代码行数:22,代码来源:SigarUtil.java

示例11: getCPULoad

import org.hyperic.sigar.CpuPerc; //导入依赖的package包/类
public double getCPULoad() {
    if (osBean instanceof com.sun.management.OperatingSystemMXBean) {
        com.sun.management.OperatingSystemMXBean nativeOsBean = (com.sun.management.OperatingSystemMXBean) osBean;
        return nativeOsBean.getSystemCpuLoad();
    } else if (sigar != null) {
        try {
            CpuPerc systemCpu = sigar.getCpuPerc();
            return systemCpu.getCombined();
        } catch (SigarException ex) {
            logger.log(Level.SEVERE, null, ex);
        }
    }

    return -1;
}
 
开发者ID:games647,项目名称:LagMonitor,代码行数:16,代码来源:NativeData.java

示例12: setUp

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

示例13: updateSystemCpuUsage

import org.hyperic.sigar.CpuPerc; //导入依赖的package包/类
private void updateSystemCpuUsage(Sigar sigar, MachineInfo info)
{
       try {
           CpuPerc perc = sigar.getCpuPerc();
           info.setSystemCpuUsage((float) perc.getCombined());
       } catch (SigarException e) {
           log.error(e.getMessage(), e);
       }
}
 
开发者ID:liulhdarks,项目名称:darks-grid,代码行数:10,代码来源:SigarMachineInfoFactory.java

示例14: writeCpu

import org.hyperic.sigar.CpuPerc; //导入依赖的package包/类
private void writeCpu(final StrBuilder sb, final CpuPerc cpuPerc) {
	appendPercent(sb, cpuPerc.getCombined());
	sb.append(separator);
	appendPercent(sb, cpuPerc.getUser());
	sb.append(separator);
	appendPercent(sb, cpuPerc.getNice());
	sb.append(separator);
	appendPercent(sb, cpuPerc.getSys());
	sb.append(separator);
	appendPercent(sb, cpuPerc.getWait());
	sb.append(separator);
	appendPercent(sb, cpuPerc.getIdle());
}
 
开发者ID:mgm-tp,项目名称:perfload-perfmon,代码行数:14,代码来源:PerfMonCpu.java

示例15: getCpuCombined

import org.hyperic.sigar.CpuPerc; //导入依赖的package包/类
/**
 * CPU总使用率
 */
public static double getCpuCombined() throws SigarException {
	Sigar sigar = new Sigar();
	CpuPerc cpuPerc = sigar.getCpuPerc();
	return new Double(df.format(cpuPerc.getCombined() * 100));
}
 
开发者ID:funtl,项目名称:framework,代码行数:9,代码来源:SysInfoAPI.java


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