use of org.hyperic.sigar.ProcCpu in project graylog2-server by Graylog2.
the class SigarProcessProbe method processStats.
@Override
public synchronized ProcessStats processStats() {
final Sigar sigar = sigarService.sigar();
final long pid = sigar.getPid();
final long openFileDescriptors = JmxProcessProbe.getOpenFileDescriptorCount();
final long maxFileDescriptorCount = JmxProcessProbe.getMaxFileDescriptorCount();
ProcessStats.Cpu cpu;
try {
ProcCpu procCpu = sigar.getProcCpu(pid);
cpu = ProcessStats.Cpu.create((short) (procCpu.getPercent() * 100), procCpu.getSys(), procCpu.getUser(), procCpu.getTotal());
} catch (SigarException e) {
cpu = null;
}
ProcessStats.Memory memory;
try {
ProcMem mem = sigar.getProcMem(sigar.getPid());
memory = ProcessStats.Memory.create(mem.getSize(), mem.getResident(), mem.getShare());
} catch (SigarException e) {
memory = null;
}
return ProcessStats.create(pid, openFileDescriptors, maxFileDescriptorCount, cpu, memory);
}
use of org.hyperic.sigar.ProcCpu in project storm by apache.
the class CPUMetric method getValueAndReset.
@Override
public Object getValueAndReset() {
try {
ProcCpu cpu = _sigar.getProcCpu(_pid);
long userTotal = cpu.getUser();
long sysTotal = cpu.getSys();
long user = userTotal - _prevUser;
long sys = sysTotal - _prevSys;
_prevUser = userTotal;
_prevSys = sysTotal;
HashMap<String, Long> ret = new HashMap<String, Long>();
ret.put("user-ms", user);
ret.put("sys-ms", sys);
return ret;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
Aggregations