Search in sources :

Example 11 with FullReadingBean

use of com.axway.ats.common.performance.monitor.beans.FullReadingBean in project ats-framework by Axway.

the class MatchedProcess method createStaticReadingInstances.

public static List<ReadingInstance> createStaticReadingInstances(SigarWrapper sigarWrapper, List<FullReadingBean> readings) throws UnsupportedReadingException, SigarException {
    List<ReadingInstance> readingInstances = new ArrayList<ReadingInstance>();
    // ADD SYSTEM READINGS
    for (FullReadingBean reading : readings) {
        String readingName = reading.getName();
        ReadingInstance readingInstance = null;
        if (readingName.equalsIgnoreCase(SystemMonitorDefinitions.READING_VIRTUAL_MEMORY__TOTAL)) {
            readingInstance = getSwapTotal(sigarWrapper, reading);
        } else if (readingName.equalsIgnoreCase(SystemMonitorDefinitions.READING_VIRTUAL_MEMORY__USED)) {
            readingInstance = getSwapUsed(sigarWrapper, reading);
        } else if (readingName.equalsIgnoreCase(SystemMonitorDefinitions.READING_VIRTUAL_MEMORY__FREE)) {
            readingInstance = getSwapFree(sigarWrapper, reading);
        } else if (readingName.equalsIgnoreCase(SystemMonitorDefinitions.READING_VIRTUAL_MEMORY__PAGES_IN)) {
            readingInstance = getSwapPagesIn(sigarWrapper, reading);
        } else if (readingName.equalsIgnoreCase(SystemMonitorDefinitions.READING_VIRTUAL_MEMORY__PAGES_OUT)) {
            readingInstance = getSwapPagesOut(sigarWrapper, reading);
        } else if (readingName.equalsIgnoreCase(SystemMonitorDefinitions.READING_MEMORY__USED)) {
            readingInstance = getMemoryUsed(sigarWrapper, reading);
        } else if (readingName.equalsIgnoreCase(SystemMonitorDefinitions.READING_MEMORY__FREE)) {
            readingInstance = getMemoryFree(sigarWrapper, reading);
        } else if (readingName.equalsIgnoreCase(SystemMonitorDefinitions.READING_MEMORY__ACTUAL_USED)) {
            readingInstance = getMemoryActualUsed(sigarWrapper, reading);
        } else if (readingName.equalsIgnoreCase(SystemMonitorDefinitions.READING_MEMORY__ACTUAL_FREE)) {
            readingInstance = getMemoryActualFree(sigarWrapper, reading);
        } else if (readingName.equalsIgnoreCase(SystemMonitorDefinitions.READING_IO__READ_BYTES_ALL_DEVICES)) {
            readingInstance = getReadBytesAllLocalDevices(sigarWrapper, reading);
        } else if (readingName.equalsIgnoreCase(SystemMonitorDefinitions.READING_IO__WRITE_BYTES_ALL_DEVICES)) {
            readingInstance = getWriteBytesAllLocalDevices(sigarWrapper, reading);
        } else if (readingName.equalsIgnoreCase(SystemMonitorDefinitions.READING_CPU_LOAD__LAST_MINUTE)) {
            if (!IS_WINDOWS) {
                readingInstance = getLoadAverage1minute(sigarWrapper, reading);
            }
        } else if (readingName.equalsIgnoreCase(SystemMonitorDefinitions.READING_CPU_LOAD__LAST_5_MINUTES)) {
            if (!IS_WINDOWS) {
                readingInstance = getLoadAverage5minutes(sigarWrapper, reading);
            }
        } else if (readingName.equalsIgnoreCase(SystemMonitorDefinitions.READING_CPU_LOAD__LAST_15_MINUTES)) {
            if (!IS_WINDOWS) {
                readingInstance = getLoadAverage15minutes(sigarWrapper, reading);
            }
        } else if (readingName.equalsIgnoreCase(SystemMonitorDefinitions.READING_CPU_USAGE__TOTAL)) {
            readingInstance = getCpuUsageTotal(sigarWrapper, reading);
        } else if (readingName.equalsIgnoreCase(SystemMonitorDefinitions.READING_CPU_USAGE__WAIT)) {
            readingInstance = getCpuUsageWaitingForIO(sigarWrapper, reading);
        } else if (readingName.equalsIgnoreCase(SystemMonitorDefinitions.READING_CPU_USAGE__KERNEL)) {
            readingInstance = getCpuUsageRunningKernelCode(sigarWrapper, reading);
        } else if (readingName.equalsIgnoreCase(SystemMonitorDefinitions.READING_CPU_USAGE__USER)) {
            readingInstance = getCpuUsageRunningUserCode(sigarWrapper, reading);
        } else if (readingName.equalsIgnoreCase(SystemMonitorDefinitions.READING_NETWORK_TRAFFIC)) {
            List<ReadingInstance> readingsList = getNetworkTraffic(sigarWrapper, reading);
            readingInstances.addAll(readingsList);
        } else if (readingName.equalsIgnoreCase(SystemMonitorDefinitions.READING_NETSTAT__ACTIVE_CONNECTION_OPENINGS)) {
            readingInstance = getNetstatActiveConnectionOpenings(sigarWrapper, reading);
        } else if (readingName.equalsIgnoreCase(SystemMonitorDefinitions.READING_NETSTAT__PASSIVE_CONNECTION_OPENINGS)) {
            readingInstance = getNetstatPassiveConnectionOpenings(sigarWrapper, reading);
        } else if (readingName.equalsIgnoreCase(SystemMonitorDefinitions.READING_NETSTAT__FAILED_CONNECTION_ATTEMPTS)) {
            readingInstance = getNetstatFailedConnectionAttemtps(sigarWrapper, reading);
        } else if (readingName.equalsIgnoreCase(SystemMonitorDefinitions.READING_NETSTAT__RESET_CONNECTIONS)) {
            readingInstance = getNetstatResetConnections(sigarWrapper, reading);
        } else if (readingName.equalsIgnoreCase(SystemMonitorDefinitions.READING_NETSTAT__CURRENT_CONNECTIONS)) {
            readingInstance = getNetstatCurrentConnections(sigarWrapper, reading);
        } else if (readingName.equalsIgnoreCase(SystemMonitorDefinitions.READING_NETSTAT__SEGMENTS_RECEIVED)) {
            readingInstance = getNetstatSegmentsReceived(sigarWrapper, reading);
        } else if (readingName.equalsIgnoreCase(SystemMonitorDefinitions.READING_NETSTAT__SEGMENTS_SENT)) {
            readingInstance = getNetstatSegmentsSent(sigarWrapper, reading);
        } else if (readingName.equalsIgnoreCase(SystemMonitorDefinitions.READING_NETSTAT__SEGMENTS_RETRANSMITTED)) {
            readingInstance = getNetstatSegmentsRetransmitter(sigarWrapper, reading);
        } else if (readingName.equalsIgnoreCase(SystemMonitorDefinitions.READING_NETSTAT__OUT_RESETS)) {
            readingInstance = getNetstatOutResets(sigarWrapper, reading);
        } else if (readingName.equalsIgnoreCase(SystemMonitorDefinitions.READING_NETSTAT__IN_ERRORS)) {
            readingInstance = getNetstatInErrors(sigarWrapper, reading);
        } else if (readingName.equalsIgnoreCase(SystemMonitorDefinitions.READING_TCP__CLOSE)) {
            readingInstance = getTcpClose(sigarWrapper, reading);
        } else if (readingName.equalsIgnoreCase(SystemMonitorDefinitions.READING_TCP__LISTEN)) {
            readingInstance = getTcpListen(sigarWrapper, reading);
        } else if (readingName.equalsIgnoreCase(SystemMonitorDefinitions.READING_TCP__SYN_SENT)) {
            readingInstance = getTcpSynSent(sigarWrapper, reading);
        } else if (readingName.equalsIgnoreCase(SystemMonitorDefinitions.READING_TCP__SYN_RECEIVED)) {
            readingInstance = getTcpSynReceived(sigarWrapper, reading);
        } else if (readingName.equalsIgnoreCase(SystemMonitorDefinitions.READING_TCP__ESTABLISHED)) {
            readingInstance = getTcpEstablished(sigarWrapper, reading);
        } else if (readingName.equalsIgnoreCase(SystemMonitorDefinitions.READING_TCP__CLOSE_WAIT)) {
            readingInstance = getTcpCloseWait(sigarWrapper, reading);
        } else if (readingName.equalsIgnoreCase(SystemMonitorDefinitions.READING_TCP__LAST_ACK)) {
            readingInstance = getTcpLastAck(sigarWrapper, reading);
        } else if (readingName.equalsIgnoreCase(SystemMonitorDefinitions.READING_TCP__FIN_WAIT1)) {
            readingInstance = getTcpFinWait1(sigarWrapper, reading);
        } else if (readingName.equalsIgnoreCase(SystemMonitorDefinitions.READING_TCP__FIN_WAIT2)) {
            readingInstance = getTcpFinWait2(sigarWrapper, reading);
        } else if (readingName.equalsIgnoreCase(SystemMonitorDefinitions.READING_TCP__CLOSING)) {
            readingInstance = getTcpClosing(sigarWrapper, reading);
        } else if (readingName.equalsIgnoreCase(SystemMonitorDefinitions.READING_TCP__TIME_WAIT)) {
            readingInstance = getTcpTimeWait(sigarWrapper, reading);
        } else if (readingName.equalsIgnoreCase(SystemMonitorDefinitions.READING_TCP__BOUND)) {
            readingInstance = getTcpBound(sigarWrapper, reading);
        } else if (readingName.equalsIgnoreCase(SystemMonitorDefinitions.READING_TCP__IDLE)) {
            readingInstance = getTcpIdle(sigarWrapper, reading);
        } else if (readingName.equalsIgnoreCase(SystemMonitorDefinitions.READING_TCP__TOTAL_INBOUND)) {
            readingInstance = getTcpTotalInbound(sigarWrapper, reading);
        } else if (readingName.equalsIgnoreCase(SystemMonitorDefinitions.READING_TCP__TOTAL_OUTBOUND)) {
            readingInstance = getTcpTotalOutbound(sigarWrapper, reading);
        } else {
            throw new UnsupportedReadingException(readingName);
        }
        if (readingInstance != null) {
            readingInstances.add(readingInstance);
        }
    }
    return readingInstances;
}
Also used : UnsupportedReadingException(com.axway.ats.agent.components.monitoring.model.exceptions.UnsupportedReadingException) ArrayList(java.util.ArrayList) FullReadingBean(com.axway.ats.common.performance.monitor.beans.FullReadingBean)

Example 12 with FullReadingBean

use of com.axway.ats.common.performance.monitor.beans.FullReadingBean in project ats-framework by Axway.

the class InternalSystemMonitoringOperations method initializeMonitor.

private void initializeMonitor(String monitorClassName, List<FullReadingBean> readings, int pollInterval) throws MonitorConfigurationException {
    // try to make an instance of the monitor class
    Object monitorInstance;
    try {
        monitorInstance = Class.forName(monitorClassName).newInstance();
    } catch (InstantiationException e) {
        throw new MonitorConfigurationException("InstantiationException while constructing '" + monitorClassName + "' monitor. Exception error message: " + e.getMessage());
    } catch (IllegalAccessException e) {
        throw new MonitorConfigurationException("IllegalAccessException while constructing '" + monitorClassName + "' monitor. Exception error message: " + e.getMessage());
    } catch (ClassNotFoundException e) {
        throw new MonitorConfigurationException("ClassNotFoundException while constructing '" + monitorClassName + "' monitor. Exception error message: " + e.getMessage());
    }
    // check if it implements the needed interface
    if (!(monitorInstance instanceof PerformanceMonitor)) {
        throw new MonitorConfigurationException(monitorClassName + " is not a valid monitor class");
    }
    PerformanceMonitor monitor = (PerformanceMonitor) monitorInstance;
    try {
        // initialize the monitor
        monitor.setPollInterval(pollInterval);
        monitor.init(readings.toArray(new FullReadingBean[readings.size()]));
    } catch (Throwable e) {
        throw new MonitorConfigurationException("Error initializing " + monitorClassName + " monitor: " + e.getMessage(), e);
    }
    monitoringAgent.addMonitor(monitor);
}
Also used : MonitorConfigurationException(com.axway.ats.agent.components.monitoring.model.exceptions.MonitorConfigurationException) PerformanceMonitor(com.axway.ats.common.performance.monitor.PerformanceMonitor) FullReadingBean(com.axway.ats.common.performance.monitor.beans.FullReadingBean)

Example 13 with FullReadingBean

use of com.axway.ats.common.performance.monitor.beans.FullReadingBean in project ats-framework by Axway.

the class SystemMonitor method scheduleMonitoring.

/**
     * Schedule a monitor and pass some custom parameters to it.
     * <br>No statistics collection will be triggered until the startMonitor method is called.
     *
     * @param monitoredHost the host to monitor
     * @param readingType what kind of data to collect. You call a custom monitor here or some of the SystemMonitor.MONITORTYPE_* constants
     * @param readingParameters the parameters this monitor knows how to work with
     */
@PublicAtsApi
public void scheduleMonitoring(@Validate(name = "monitoredHost", type = ValidationType.STRING_SERVER_WITH_PORT) String monitoredHost, @Validate(name = "readingType", type = ValidationType.STRING_NOT_EMPTY) String readingType, @Validate(name = "readingParameters", type = ValidationType.NOT_NULL) Map<String, String> readingParameters) {
    // validate input parameters
    monitoredHost = HostUtils.getAtsAgentIpAndPort(monitoredHost);
    new Validator().validateMethodParameters("Could not schedule monitoring a statistic on '" + monitoredHost + "'", new Object[] { monitoredHost, readingType, readingParameters });
    Set<FullReadingBean> readingTypes = requestedReadingTypesPerHosts.get(monitoredHost);
    if (readingTypes == null) {
        readingTypes = new HashSet<FullReadingBean>();
    }
    Set<String> readingNames = new HashSet<String>();
    readingNames.add(readingType);
    FullReadingBean reading = ReadingsRepository.getInstance().getReadingXmlDefinition(readingType, readingParameters);
    readingTypes.add(reading);
    requestedReadingTypesPerHosts.put(monitoredHost, readingTypes);
    monitoredHosts.add(monitoredHost);
}
Also used : FullReadingBean(com.axway.ats.common.performance.monitor.beans.FullReadingBean) Validator(com.axway.ats.core.validation.Validator) HashSet(java.util.HashSet) PublicAtsApi(com.axway.ats.common.PublicAtsApi)

Example 14 with FullReadingBean

use of com.axway.ats.common.performance.monitor.beans.FullReadingBean in project ats-framework by Axway.

the class ReadingTypes method expandProcessReadings.

/**
     * @param processPattern the pattern to use in order to find the monitored process
     * @param processAlias the alias this process will have into the database
     * @param readingTypes the readings to collect
     *
     * @return a set of readings, if pass more than once the same reading it will be automatically mearged into one
     */
public static Set<FullReadingBean> expandProcessReadings(String parentProcess, String processPattern, String processAlias, String processUsername, String[] readingTypes) {
    Set<String> readingNames = new HashSet<String>();
    for (String readingType : readingTypes) {
        if (readingType.equals(READING_PROCESS_CPU)) {
            // expand all CPU
            readingNames.addAll(SystemMonitorDefinitions.getAllProcessCpuReadings());
        } else if (readingType.equals(READING_PROCESS_MEMORY)) {
            // expand all MEMORY
            readingNames.addAll(SystemMonitorDefinitions.getAllProcessMemoryReadings());
        } else if (SystemMonitorDefinitions.isProcessReading(readingType)) {
            // add this a known process reading
            readingNames.add(readingType);
        } else {
            // unknown process reading
            throw new MonitoringException("Unknown process monitor type " + readingType);
        }
    }
    Map<String, String> parameters = new HashMap<String, String>();
    parameters.put(SystemMonitorDefinitions.PARAMETER_NAME__PROCESS_PARENT_NAME, parentProcess);
    parameters.put(SystemMonitorDefinitions.PARAMETER_NAME__PROCESS_RECOGNITION_PATTERN, processPattern);
    parameters.put(SystemMonitorDefinitions.PARAMETER_NAME__PROCESS_ALIAS, processAlias);
    parameters.put(SystemMonitorDefinitions.PARAMETER_NAME__PROCESS_USERNAME, processUsername);
    List<FullReadingBean> processReadingDefinitions = ReadingsRepository.getInstance().getReadingXmlDefinitions(readingNames);
    for (FullReadingBean processReadingDefinition : processReadingDefinitions) {
        processReadingDefinition.setParameters(parameters);
    }
    // return a set of reading beans
    return new HashSet<FullReadingBean>(processReadingDefinitions);
}
Also used : HashMap(java.util.HashMap) MonitoringException(com.axway.ats.monitoring.model.exceptions.MonitoringException) FullReadingBean(com.axway.ats.common.performance.monitor.beans.FullReadingBean) HashSet(java.util.HashSet)

Example 15 with FullReadingBean

use of com.axway.ats.common.performance.monitor.beans.FullReadingBean in project ats-framework by Axway.

the class DatabaseReadingsRepository method updateDatabaseRepository.

/**
     * Populate these reading to the DB, so they have their own DB IDs
     *
     * @param monitoredHost
     * @param readings
     * @param readingIdToDbIdMap
     * @throws DatabaseAccessException
     */
public void updateDatabaseRepository(String monitoredHost, List<BasicReadingBean> readings, Map<String, Integer> readingIdToDbIdMap) throws DatabaseAccessException {
    Logger log = Logger.getLogger(DatabaseReadingsRepository.class);
    if (dbAccess == null) {
        dbAccess = new DbAccessFactory().getNewDbWriteAccessObject();
    }
    List<BasicReadingBean> repository = repositoryPerHostMap.get(monitoredHost);
    if (repository == null) {
        repository = new ArrayList<BasicReadingBean>();
        repositoryPerHostMap.put(monitoredHost, repository);
    }
    for (BasicReadingBean reading : readings) {
        if (reading instanceof FullReadingBean) {
            FullReadingBean newReading = (FullReadingBean) reading;
            StringBuilder newReadingParameters = new StringBuilder();
            Map<String, String> readingParameters = newReading.getParameters();
            if (readingParameters != null && readingParameters.size() > 0) {
                if (readingParameters.containsKey(SystemMonitorDefinitions.PARAMETER_NAME__PROCESS_ALIAS)) {
                    newReadingParameters.append("'");
                    newReadingParameters.append(readingParameters.get(SystemMonitorDefinitions.PARAMETER_NAME__PROCESS_ALIAS));
                    newReadingParameters.append("'_user pattern is '");
                    newReadingParameters.append(readingParameters.get(SystemMonitorDefinitions.PARAMETER_NAME__PROCESS_RECOGNITION_PATTERN));
                    newReadingParameters.append("'_reading=");
                    newReadingParameters.append(readingParameters.get(SystemMonitorDefinitions.PARAMETER_NAME__PROCESS_READING_ID));
                    newReadingParameters.append("_started by command '");
                    newReadingParameters.append(readingParameters.get(SystemMonitorDefinitions.PARAMETER_NAME__PROCESS_START_COMMAND));
                    newReadingParameters.append("'");
                } else {
                    newReadingParameters.append(readingParameters.get(SystemMonitorDefinitions.PARAMETER_NAME__CUSTOM_MESSAGE));
                }
            }
            int newReadingDatabaseId;
            if (reading instanceof ParentProcessReadingBean) {
                String thisProcessName = "[process] " + ((ParentProcessReadingBean) newReading).getTheNameOfThisParentProcess();
                String thisReadingName = thisProcessName + " - " + newReading.getName();
                newReadingDatabaseId = dbAccess.populateSystemStatisticDefinition(thisReadingName, newReading.getParameter(SystemMonitorDefinitions.PARAMETER_NAME__PROCESS_PARENT_NAME), thisProcessName, newReading.getUnit(), newReadingParameters.toString());
                log.debug("DB id " + newReadingDatabaseId + " for parent process reading: " + thisReadingName);
            } else {
                String parentName = newReading.getParameter(SystemMonitorDefinitions.PARAMETER_NAME__PROCESS_PARENT_NAME);
                if (parentName != null) {
                    parentName = "[process] " + parentName;
                }
                newReadingDatabaseId = dbAccess.populateSystemStatisticDefinition(newReading.getName(), parentName, "", newReading.getUnit(), newReadingParameters.toString());
                log.debug("DB id " + newReadingDatabaseId + " for reading: " + newReading.getName());
            }
            // remember the DB ID of this reading, because the monitoring remote service gives us the
            // full reading information only the first time
            newReading.setDbId(newReadingDatabaseId);
            // we maintain this map so can easily find the DB id of each Basic reading(it has reading id only)
            readingIdToDbIdMap.put(newReading.getId(), newReading.getDbId());
        }
    }
}
Also used : ParentProcessReadingBean(com.axway.ats.common.performance.monitor.beans.ParentProcessReadingBean) DbAccessFactory(com.axway.ats.log.autodb.DbAccessFactory) BasicReadingBean(com.axway.ats.common.performance.monitor.beans.BasicReadingBean) Logger(org.apache.log4j.Logger) FullReadingBean(com.axway.ats.common.performance.monitor.beans.FullReadingBean)

Aggregations

FullReadingBean (com.axway.ats.common.performance.monitor.beans.FullReadingBean)18 ArrayList (java.util.ArrayList)7 PublicAtsApi (com.axway.ats.common.PublicAtsApi)4 HashMap (java.util.HashMap)4 ParentProcessReadingBean (com.axway.ats.common.performance.monitor.beans.ParentProcessReadingBean)3 Validator (com.axway.ats.core.validation.Validator)3 MonitoringException (com.axway.ats.monitoring.model.exceptions.MonitoringException)3 HashSet (java.util.HashSet)3 UnsupportedReadingException (com.axway.ats.agent.components.monitoring.model.exceptions.UnsupportedReadingException)2 LinkedHashMap (java.util.LinkedHashMap)2 List (java.util.List)2 SigarException (org.hyperic.sigar.SigarException)2 AtsSystemMonitoringAgent (com.axway.ats.agent.components.monitoring.model.agents.AtsSystemMonitoringAgent)1 MonitorConfigurationException (com.axway.ats.agent.components.monitoring.model.exceptions.MonitorConfigurationException)1 InternalSystemMonitoringOperations (com.axway.ats.agent.components.monitoring.operations.clients.InternalSystemMonitoringOperations)1 AgentException (com.axway.ats.agent.core.exceptions.AgentException)1 Action (com.axway.ats.agent.core.model.Action)1 PerformanceMonitor (com.axway.ats.common.performance.monitor.PerformanceMonitor)1 BasicReadingBean (com.axway.ats.common.performance.monitor.beans.BasicReadingBean)1 DbAccessFactory (com.axway.ats.log.autodb.DbAccessFactory)1