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


Java ProcCpu类代码示例

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


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

示例1: collectMetrics

import org.hyperic.sigar.ProcCpu; //导入依赖的package包/类
private void collectMetrics()
{
	logger.debug("Collecting metrics...");
	try
	{
		//get process CPU usage
		ProcCpu procCpu = sigar.getProcCpu(pid);

		//get process memory usage
		ProcMem procMem = sigar.getProcMem(pid);

		// get network interface stats
		NetInterfaceStat netStat = sigar.getNetInterfaceStat(interfaceName);

		ProcessMetrics measurement = new ProcessMetrics(procCpu.getPercent(),
				procMem.getSize(), procMem.getResident(), procMem.getPageFaults(),
				interfaceName, netStat.getRxBytes(), netStat.getTxBytes());

		metrics.add(measurement);

	} catch(SigarException ex)
	{
		logger.error(ex.getMessage(), ex);
	}
}
 
开发者ID:filipecampos,项目名称:raft_tests,代码行数:26,代码来源:MonitoringThread.java

示例2: executeCommand

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

示例3: getValue

import org.hyperic.sigar.ProcCpu; //导入依赖的package包/类
@Override
public void getValue(StringBuffer res) throws SigarException {
	ProcCpu cpu = this.sigarProxy.getProcCpu(this.params.PID);
	double val;
	long cur;
	switch (this.type) {
	case 0:
		val = 100.0D * cpu.getPercent();
		break;
	case 1:
		cur = cpu.getTotal();
		val = this.prev > 0.0D ? cur - this.prev : 0.0D;
		this.prev = cur;
		break;
	case 2:
		cur = cpu.getSys();
		val = this.prev > 0.0D ? cur - this.prev : 0.0D;
		this.prev = cur;
		break;
	case 3:
		cur = cpu.getUser();
		val = this.prev > 0.0D ? cur - this.prev : 0.0D;
		this.prev = cur;
		break;
	default:
		throw new SigarException("Unknown proc cpu type " + this.type);
	}
	res.append(Double.toString(val));
}
 
开发者ID:junehappylove,项目名称:ServerAgent,代码行数:30,代码来源:CPUProcMetric.java

示例4: getProcessCPULoad

import org.hyperic.sigar.ProcCpu; //导入依赖的package包/类
public double getProcessCPULoad() {
    if (osBean instanceof com.sun.management.OperatingSystemMXBean) {
        com.sun.management.OperatingSystemMXBean nativeOsBean = (com.sun.management.OperatingSystemMXBean) osBean;
        return nativeOsBean.getProcessCpuLoad();
    } else if (sigar != null) {
        try {
            ProcCpu procCpu = sigar.getProcCpu(pid);
            return procCpu.getPercent();
        } catch (SigarException ex) {
            logger.log(Level.SEVERE, null, ex);
        }
    }

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

示例5: updateProcessCpuUsage

import org.hyperic.sigar.ProcCpu; //导入依赖的package包/类
private void updateProcessCpuUsage(Sigar sigar, MachineInfo info)
{
    try {
        long pid = sigar.getPid();
        ProcCpu cpu = sigar.getProcCpu(pid);
        info.setProcessCpuUsage((float) cpu.getPercent());
       } catch (SigarException e) {
           log.error(e.getMessage(), e);
       }
}
 
开发者ID:liulhdarks,项目名称:darks-grid,代码行数:11,代码来源:SigarMachineInfoFactory.java

示例6: getPercentCpuUsage

import org.hyperic.sigar.ProcCpu; //导入依赖的package包/类
@Override
public double getPercentCpuUsage() {
  return units.map(cpu, ProcCpu::getPercent, 0d) * 100d;
}
 
开发者ID:OctoPerf,项目名称:jmx-agent,代码行数:5,代码来源:SigarProcessMetrics.java

示例7: getUserCpuTimeSec

import org.hyperic.sigar.ProcCpu; //导入依赖的package包/类
@Override
public long getUserCpuTimeSec() {
  return units.map(cpu, ProcCpu::getUser, 0L) / ONE_SECOND;
}
 
开发者ID:OctoPerf,项目名称:jmx-agent,代码行数:5,代码来源:SigarProcessMetrics.java

示例8: getSysCpuTimeSec

import org.hyperic.sigar.ProcCpu; //导入依赖的package包/类
@Override
public long getSysCpuTimeSec() {
  return units.map(cpu, ProcCpu::getSys, 0L) / ONE_SECOND;
}
 
开发者ID:OctoPerf,项目名称:jmx-agent,代码行数:5,代码来源:SigarProcessMetrics.java

示例9: getTotalCpuTimeSec

import org.hyperic.sigar.ProcCpu; //导入依赖的package包/类
@Override
public long getTotalCpuTimeSec() {
  return units.map(cpu, ProcCpu::getTotal, 0L) / ONE_SECOND;
}
 
开发者ID:OctoPerf,项目名称:jmx-agent,代码行数:5,代码来源:SigarProcessMetrics.java

示例10: process

import org.hyperic.sigar.ProcCpu; //导入依赖的package包/类
@Counter
public void process(CounterBasket pw) {
	File dir = regRoot;
	if (dir == null)
		return;

	if (cpuCores == 0) {
		cpuCores = getCpuCore();
		Logger.info("Num of Cpu Cores : " + cpuCores);
	}
	long now = System.currentTimeMillis();
	File[] pids = dir.listFiles();
	for (int i = 0; i < pids.length; i++) {
		if (pids[i].isDirectory())
			continue;
		String name = pids[i].getName();
		if (name.endsWith(".scouter") == false) {
			continue;
		}
		int pid = CastUtil.cint(name.substring(0, name.lastIndexOf(".")));
		if (pid == 0)
			continue;

		if (now > pids[i].lastModified() + 5000) {
			pids[i].delete();
			continue;
		}

		String objname = new String(FileUtil.readAll(pids[i]));

		MeterResource meter = meterMap.get(objname);
		if (meter == null) {
			meter = new MeterResource();
			meterMap.put(objname, meter);
		}
		try {
			ProcCpu cpu = sigar.getProcCpu(pid);
			double value = cpu.getPercent() * 100.0D/cpuCores;
			meter.add(value);
			float procCpu = (float) meter.getAvg(Configure.getInstance()._cpu_value_avg_sec);
			PerfCounterPack p = pw.getPack(objname, TimeTypeEnum.REALTIME);
			p.put(CounterConstants.PROC_CPU, new FloatValue(procCpu));
			p = pw.getPack(objname, TimeTypeEnum.FIVE_MIN);
			p.put(CounterConstants.PROC_CPU, new FloatValue(procCpu));
		} catch (Exception e) {
			// ignore no proc
		}

	}
}
 
开发者ID:scouter-project,项目名称:scouter,代码行数:51,代码来源:ProcPerf.java


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