Search in sources :

Example 1 with ProcCpu

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);
}
Also used : Sigar(org.hyperic.sigar.Sigar) SigarException(org.hyperic.sigar.SigarException) ProcCpu(org.hyperic.sigar.ProcCpu) ProcMem(org.hyperic.sigar.ProcMem)

Example 2 with ProcCpu

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);
    }
}
Also used : HashMap(java.util.HashMap) ProcCpu(org.hyperic.sigar.ProcCpu)

Aggregations

ProcCpu (org.hyperic.sigar.ProcCpu)2 HashMap (java.util.HashMap)1 ProcMem (org.hyperic.sigar.ProcMem)1 Sigar (org.hyperic.sigar.Sigar)1 SigarException (org.hyperic.sigar.SigarException)1