Search in sources :

Example 6 with SigarException

use of org.hyperic.sigar.SigarException in project graylog2-server by Graylog2.

the class SigarOsProbe method osStats.

@Override
public OsStats osStats() {
    final Sigar sigar = sigarService.sigar();
    double[] loadAverage;
    try {
        loadAverage = sigar.getLoadAverage();
    } catch (SigarException e) {
        loadAverage = OsStats.EMPTY_LOAD;
    }
    long uptime;
    try {
        uptime = (long) sigar.getUptime().getUptime();
    } catch (SigarException e) {
        uptime = -1L;
    }
    Processor processor;
    try {
        final CpuInfo[] cpuInfos = sigar.getCpuInfoList();
        final String vendor = cpuInfos[0].getVendor();
        final String model = cpuInfos[0].getModel();
        final int mhz = cpuInfos[0].getMhz();
        final int totalCores = cpuInfos[0].getTotalCores();
        final int totalSockets = cpuInfos[0].getTotalSockets();
        final int coresPerSocket = cpuInfos[0].getCoresPerSocket();
        long cacheSize = -1L;
        if (cpuInfos[0].getCacheSize() != Sigar.FIELD_NOTIMPL) {
            cacheSize = cpuInfos[0].getCacheSize();
        }
        final CpuPerc cpuPerc = sigar.getCpuPerc();
        final short sys = (short) (cpuPerc.getSys() * 100);
        final short user = (short) (cpuPerc.getUser() * 100);
        final short idle = (short) (cpuPerc.getIdle() * 100);
        final short stolen = (short) (cpuPerc.getStolen() * 100);
        processor = Processor.create(model, vendor, mhz, totalCores, totalSockets, coresPerSocket, cacheSize, sys, user, idle, stolen);
    } catch (SigarException e) {
        processor = Processor.create("Unknown", "Unknown", -1, -1, -1, -1, -1L, (short) -1, (short) -1, (short) -1, (short) -1);
    }
    Memory memory;
    try {
        Mem mem = sigar.getMem();
        long total = mem.getTotal();
        long free = mem.getFree();
        short freePercent = (short) mem.getFreePercent();
        long used = mem.getUsed();
        short usedPercent = (short) mem.getUsedPercent();
        long actualFree = mem.getActualFree();
        long actualUsed = mem.getActualUsed();
        memory = Memory.create(total, free, freePercent, used, usedPercent, actualFree, actualUsed);
    } catch (SigarException e) {
        memory = Memory.create(-1L, -1L, (short) -1, -1L, (short) -1, -1L, -1L);
    }
    Swap swap;
    try {
        org.hyperic.sigar.Swap sigSwap = sigar.getSwap();
        long total = sigSwap.getTotal();
        long free = sigSwap.getFree();
        long used = sigSwap.getUsed();
        swap = Swap.create(total, free, used);
    } catch (SigarException e) {
        swap = Swap.create(-1L, -1L, -1L);
    }
    return OsStats.create(loadAverage, uptime, processor, memory, swap);
}
Also used : Sigar(org.hyperic.sigar.Sigar) CpuInfo(org.hyperic.sigar.CpuInfo) SigarException(org.hyperic.sigar.SigarException) Mem(org.hyperic.sigar.Mem) CpuPerc(org.hyperic.sigar.CpuPerc)

Example 7 with SigarException

use of org.hyperic.sigar.SigarException 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 8 with SigarException

use of org.hyperic.sigar.SigarException in project ats-framework by Axway.

the class SigarWrapper method refresh.

/**
     * called on each poll
     *
     * @throws SigarException
     * @throws MonitorConfigurationException
     */
void refresh() throws SigarException, MonitorConfigurationException {
    try {
        this.swap = this.sigar.getSwap();
        this.memory = this.sigar.getMem();
        this.cpu = this.sigar.getCpu();
        this.cpuPerc = this.sigar.getCpuPerc();
        if (!OperatingSystemType.getCurrentOsType().equals(OperatingSystemType.AIX)) {
            this.netstat = this.sigar.getNetStat();
            this.tcp = this.sigar.getTcp();
        }
        this.loadAvrg = new SigarLoadAverage(this.sigar);
    } catch (Exception e) {
        final String errorMsg = "Error retrieving data from the Sigar monitoring system";
        log.error(errorMsg, e);
        throw new MonitorConfigurationException(errorMsg, e);
    }
}
Also used : MonitorConfigurationException(com.axway.ats.agent.components.monitoring.model.exceptions.MonitorConfigurationException) SigarLoadAverage(org.hyperic.sigar.jmx.SigarLoadAverage) SigarException(org.hyperic.sigar.SigarException) MonitorConfigurationException(com.axway.ats.agent.components.monitoring.model.exceptions.MonitorConfigurationException)

Example 9 with SigarException

use of org.hyperic.sigar.SigarException in project ats-framework by Axway.

the class AtsSystemMonitor method init.

@Override
public void init(FullReadingBean[] readings) throws Exception {
    log.info("Initializing the ATS System Monitor");
    try {
        this.sigarWrapper = new SigarWrapper();
    } catch (SigarException e) {
        log.error("Error initializing the Sigar System", e);
        throw new Exception("Error initializing the Sigar System", e);
    }
    List<FullReadingBean> staticReadings = new ArrayList<FullReadingBean>();
    List<FullReadingBean> dynamicReadings = new ArrayList<FullReadingBean>();
    for (FullReadingBean reading : readings) {
        if (!reading.isDynamicReading()) {
            staticReadings.add(reading);
        } else {
            // check if this process has parent
            String parentProcessName = reading.getParameter(SystemMonitorDefinitions.PARAMETER_NAME__PROCESS_PARENT_NAME);
            if (parentProcessName != null) {
                final String parentProcessId = parentProcessName + "-" + reading.getName();
                if (!parentProcessReadingInstances.containsKey(parentProcessId)) {
                    parentProcessReadingInstances.put(parentProcessId, new ParentProcessReadingBean(reading.getId(), reading.getMonitorName(), parentProcessName, reading.getName(), reading.getUnit()));
                }
            }
            dynamicReadings.add(reading);
        }
    }
    ReadingInstancesFactory.init(sigarWrapper, getPollInterval());
    // create the actual static reading instances
    staticReadingInstances = ReadingInstancesFactory.createStaticReadingInstances(sigarWrapper, staticReadings);
    // remember the initial dynamic readings
    initialDynamicReadings = new ArrayList<FullReadingBean>(dynamicReadings);
    // calculations on the first poll
    if (initialDynamicReadings.size() > 0) {
        dynamicReadingInstances = ReadingInstancesFactory.createOrUpdateDynamicReadingInstances(sigarWrapper, parentProcessReadingInstances, initialDynamicReadings, dynamicReadingInstances);
    }
}
Also used : SigarException(org.hyperic.sigar.SigarException) ParentProcessReadingBean(com.axway.ats.common.performance.monitor.beans.ParentProcessReadingBean) ArrayList(java.util.ArrayList) FullReadingBean(com.axway.ats.common.performance.monitor.beans.FullReadingBean) SigarException(org.hyperic.sigar.SigarException)

Example 10 with SigarException

use of org.hyperic.sigar.SigarException in project ats-framework by Axway.

the class MatchedProcess method getProcessCpuUsageRunningTotal.

private static List<ReadingInstance> getProcessCpuUsageRunningTotal(SigarWrapper sigarWrapper, FullReadingBean reading, ParentProcessReadingBean parentProcess) throws SigarException {
    String readingProcessPattern = reading.getParameter(SystemMonitorDefinitions.PARAMETER_NAME__PROCESS_RECOGNITION_PATTERN);
    // we can match more than 1 process
    List<ReadingInstance> readingInstancesList = new ArrayList<ReadingInstance>();
    // iterate all processes in the map
    Map<Long, MatchedProcess> processesForThisPattern = matchedProcessesMap.get(readingProcessPattern);
    if (processesForThisPattern != null) {
        for (final MatchedProcess processInfo : processesForThisPattern.values()) {
            // check if we are not already measuring this reading for this process
            String processesReadingInstanceIdentifier = reading.getName() + "->" + processInfo.getPid();
            if (!processesReadingInstanceIdentifiers.contains(processesReadingInstanceIdentifier)) {
                processesReadingInstanceIdentifiers.add(processesReadingInstanceIdentifier);
                // create a new reading for this process
                Map<String, String> parameters = constructProcessParametersMap(processInfo, readingProcessPattern, "3");
                readingInstancesList.add(new ReadingInstance(sigarWrapper, parentProcess, reading.getId() + "->" + processInfo.getPid(), processInfo.getPid(), reading.getMonitorName(), "[process] " + processInfo.getAlias() + " - CPU usage - Total", reading.getUnit(), parameters, 1.0F) {

                    private static final long serialVersionUID = 1L;

                    @Override
                    public void init() throws SigarException {
                        this.lastLongValue = fixLongValue(fixOverflow(getName(), sigarWrapper.getProcessCpuTimeRunningTotal(processInfo.getPid()), ReadingInstance.CPU_PROCESS_OVERFLOW_VALUE));
                    }

                    @Override
                    public float poll() throws SigarException {
                        long totalTime = fixLongValue(fixOverflow(getName(), sigarWrapper.getProcessCpuTimeRunningTotal(processInfo.getPid()), ReadingInstance.CPU_PROCESS_OVERFLOW_VALUE));
                        double deltaTotalTime;
                        if (totalTime > 0) {
                            deltaTotalTime = (totalTime - this.lastLongValue) / numberOfCPUs;
                            this.lastLongValue = totalTime;
                        } else {
                            return -1;
                        }
                        float deltaTotalPercentUsage = 0.0F;
                        long elapsedTime = getElapsedTime();
                        // moment of creating the ReadingInstance, it is normal for new processes
                        if (elapsedTime > 900) {
                            // calculate total code time for 1ms
                            deltaTotalTime = deltaTotalTime / elapsedTime;
                            // convert to percentage usage
                            deltaTotalPercentUsage = new BigDecimal(deltaTotalTime).setScale(2, BigDecimal.ROUND_DOWN).floatValue() * 100.0F;
                        }
                        addValueToParentProcess(deltaTotalPercentUsage);
                        return deltaTotalPercentUsage;
                    }
                });
            }
        }
    }
    return readingInstancesList;
}
Also used : SigarException(org.hyperic.sigar.SigarException) ArrayList(java.util.ArrayList) BigDecimal(java.math.BigDecimal)

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