本文整理汇总了Java中org.hyperic.sigar.ProcCpu.getPercent方法的典型用法代码示例。如果您正苦于以下问题:Java ProcCpu.getPercent方法的具体用法?Java ProcCpu.getPercent怎么用?Java ProcCpu.getPercent使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.hyperic.sigar.ProcCpu
的用法示例。
在下文中一共展示了ProcCpu.getPercent方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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);
}
}
示例2: 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));
}
示例3: 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;
}
示例4: 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
}
}
}