Search in sources :

Example 11 with SigarException

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

the class SigarNetworkProbe method networkStats.

@Override
public synchronized NetworkStats networkStats() {
    final Sigar sigar = sigarService.sigar();
    String primaryInterface;
    try {
        final NetInterfaceConfig netInterfaceConfig = sigar.getNetInterfaceConfig(null);
        primaryInterface = netInterfaceConfig.getName();
    } catch (SigarException e) {
        primaryInterface = null;
    }
    final Map<String, NetworkStats.Interface> interfaces = new HashMap<>();
    try {
        final String[] netInterfaceList = firstNonNull(sigar.getNetInterfaceList(), new String[0]);
        for (String interfaceName : netInterfaceList) {
            final NetInterfaceStat netInterfaceStat = sigar.getNetInterfaceStat(interfaceName);
            final NetworkStats.InterfaceStats interfaceStats = NetworkStats.InterfaceStats.create(netInterfaceStat.getRxPackets(), netInterfaceStat.getRxErrors(), netInterfaceStat.getRxDropped(), netInterfaceStat.getRxOverruns(), netInterfaceStat.getRxFrame(), netInterfaceStat.getTxPackets(), netInterfaceStat.getTxErrors(), netInterfaceStat.getTxDropped(), netInterfaceStat.getTxOverruns(), netInterfaceStat.getTxCarrier(), netInterfaceStat.getTxCollisions(), netInterfaceStat.getRxBytes(), netInterfaceStat.getTxBytes());
            final NetInterfaceConfig netInterfaceConfig = sigar.getNetInterfaceConfig(interfaceName);
            final NetworkStats.Interface networkInterface = NetworkStats.Interface.create(netInterfaceConfig.getName(), Collections.singleton(netInterfaceConfig.getAddress()), netInterfaceConfig.getHwaddr(), netInterfaceConfig.getMtu(), interfaceStats);
            interfaces.put(interfaceName, networkInterface);
        }
    } catch (SigarException e) {
    // ignore
    }
    NetworkStats.TcpStats tcpStats;
    try {
        final Tcp tcp = sigar.getTcp();
        tcpStats = NetworkStats.TcpStats.create(tcp.getActiveOpens(), tcp.getPassiveOpens(), tcp.getAttemptFails(), tcp.getEstabResets(), tcp.getCurrEstab(), tcp.getInSegs(), tcp.getOutSegs(), tcp.getRetransSegs(), tcp.getInErrs(), tcp.getOutRsts());
    } catch (SigarException e) {
        tcpStats = null;
    }
    return NetworkStats.create(primaryInterface, interfaces, tcpStats);
}
Also used : Sigar(org.hyperic.sigar.Sigar) Tcp(org.hyperic.sigar.Tcp) NetInterfaceConfig(org.hyperic.sigar.NetInterfaceConfig) HashMap(java.util.HashMap) SigarException(org.hyperic.sigar.SigarException) NetInterfaceStat(org.hyperic.sigar.NetInterfaceStat)

Example 12 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 13 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)

Example 14 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)

Aggregations

SigarException (org.hyperic.sigar.SigarException)14 ArrayList (java.util.ArrayList)7 Sigar (org.hyperic.sigar.Sigar)6 BigDecimal (java.math.BigDecimal)4 HashMap (java.util.HashMap)4 FullReadingBean (com.axway.ats.common.performance.monitor.beans.FullReadingBean)2 HashSet (java.util.HashSet)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 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 NetInterfaceConfig (org.hyperic.sigar.NetInterfaceConfig)1