Search in sources :

Example 16 with SigarException

use of org.hyperic.sigar.SigarException in project scheduling by ow2-proactive.

the class SigarProcesses method getProcesses.

@SuppressWarnings("unchecked")
@Override
public ProcessInfo[] getProcesses() throws SigarException {
    Sigar sigar = new Sigar();
    long[] pids = sigar.getProcList();
    List<ProcessInfo> result = new ArrayList<>(pids.length);
    for (int i = 0; i < pids.length; i++) {
        long pid = pids[i];
        try {
            @SuppressWarnings("rawtypes") List // Add standard info.
            info = Ps.getInfo(sigar, pid);
            // Add also arguments of each process.
            info.add(sigar.getProcArgs(pid));
            // Add cpu usage (perc.).
            info.add(sigar.getProcCpu(pid).getPercent());
            result.add(new ProcessInfo(info));
        } catch (SigarException e) {
            // Ignore it, probably the process does not exist anymore.
            logger.warn("Could not get information for PID " + pid + ": " + e.getMessage());
        }
    // TODO see why sigar.getProcCpu(pid).getPercent()
    // returns '0.0' always.
    }
    return result.toArray(new ProcessInfo[] {});
}
Also used : Sigar(org.hyperic.sigar.Sigar) SigarException(org.hyperic.sigar.SigarException) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

SigarException (org.hyperic.sigar.SigarException)16 ArrayList (java.util.ArrayList)8 Sigar (org.hyperic.sigar.Sigar)8 BigDecimal (java.math.BigDecimal)4 HashMap (java.util.HashMap)4 HashSet (java.util.HashSet)3 FullReadingBean (com.axway.ats.common.performance.monitor.beans.FullReadingBean)2 FileSystem (org.hyperic.sigar.FileSystem)2 NetInterfaceStat (org.hyperic.sigar.NetInterfaceStat)2 MonitorConfigurationException (com.axway.ats.agent.components.monitoring.model.exceptions.MonitorConfigurationException)1 ParentProcessReadingBean (com.axway.ats.common.performance.monitor.beans.ParentProcessReadingBean)1 File (java.io.File)1 List (java.util.List)1 Map (java.util.Map)1 Pattern (java.util.regex.Pattern)1 CpuInfo (org.hyperic.sigar.CpuInfo)1 CpuPerc (org.hyperic.sigar.CpuPerc)1 FileSystemMap (org.hyperic.sigar.FileSystemMap)1 FileSystemUsage (org.hyperic.sigar.FileSystemUsage)1 Mem (org.hyperic.sigar.Mem)1