Search in sources :

Example 11 with ReadingBean

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

the class AtsSystemMonitor method init.

@Override
public void init(ReadingBean[] readings) throws Exception {
    log.info("Initializing the ATS System Monitor");
    try {
        this.systemInfo = SystemInformationFactory.get();
    } catch (Exception e) {
        String errorMessage = "Error initializing the provider of system information. System monitoring will not work.";
        log.error(errorMessage, e);
        throw new SystemInformationException(errorMessage, e);
    }
    List<ReadingBean> staticReadings = new ArrayList<ReadingBean>();
    List<ReadingBean> dynamicReadings = new ArrayList<ReadingBean>();
    for (ReadingBean reading : readings) {
        if (!reading.isDynamicReading()) {
            staticReadings.add(reading);
        } else {
            // check if this process has a parent
            String parentProcessName = reading.getParameter(SystemMonitorDefinitions.PARAMETER_NAME__PROCESS_PARENT_NAME);
            if (parentProcessName != null) {
                final String parentProcessId = parentProcessName + "-" + reading.getName();
                if (!parentProcessReadingInstances.containsKey(parentProcessId)) {
                    ParentProcessReadingBean prentProcessBean = new ParentProcessReadingBean(reading.getId(), reading.getMonitorName(), parentProcessName, reading.getName(), reading.getUnit());
                    prentProcessBean.setParameters(reading.getParameters());
                    parentProcessReadingInstances.put(parentProcessId, prentProcessBean);
                }
            }
            dynamicReadings.add(reading);
        }
    }
    ReadingInstancesFactory.init(systemInfo, getPollInterval());
    // create the actual static reading instances
    staticReadingInstances = ReadingInstancesFactory.createStaticReadingInstances(systemInfo, staticReadings);
    // remember the initial dynamic readings
    initialDynamicReadings = new ArrayList<ReadingBean>(dynamicReadings);
    // calculations on the first poll
    if (initialDynamicReadings.size() > 0) {
        dynamicReadingInstances = ReadingInstancesFactory.createOrUpdateDynamicReadingInstances(systemInfo, parentProcessReadingInstances, initialDynamicReadings, dynamicReadingInstances);
    }
}
Also used : ReadingBean(com.axway.ats.common.performance.monitor.beans.ReadingBean) ParentProcessReadingBean(com.axway.ats.common.performance.monitor.beans.ParentProcessReadingBean) ParentProcessReadingBean(com.axway.ats.common.performance.monitor.beans.ParentProcessReadingBean) ArrayList(java.util.ArrayList) SystemInformationException(com.axway.ats.agent.core.monitoring.systemmonitor.systeminformation.exceptions.SystemInformationException) SystemInformationException(com.axway.ats.agent.core.monitoring.systemmonitor.systeminformation.exceptions.SystemInformationException)

Example 12 with ReadingBean

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

the class RestSystemMonitor method scheduleSystemMonitoring.

public Set<ReadingBean> scheduleSystemMonitoring(@Validate(name = "monitoredHost", type = ValidationType.STRING_SERVER_WITH_PORT) String monitoredHost, @Validate(name = "systemReadingTypes", type = ValidationType.NOT_NULL) String[] systemReadingTypes) {
    // validate input parameters
    monitoredHost = HostUtils.getAtsAgentIpAndPort(monitoredHost);
    new Validator().validateMethodParameters("Could not schedule monitoring system statistics on '" + monitoredHost + "'", new Object[] { monitoredHost, systemReadingTypes });
    Set<ReadingBean> readingTypes = new HashSet<ReadingBean>();
    try {
        log.debug("Scheduling system monitoring...");
        readingTypes.addAll(systemMonitor.scheduleSystemMonitoring(systemReadingTypes));
        logSystemStatistics = true;
        log.info("System monitoring scheduled.");
    } catch (Exception e) {
        log.error("Could not schedule system monitoring.", e);
        throw new MonitoringException("Could not schedule system monitoring. Did you initialize the monitoring context?", e);
    }
    return readingTypes;
}
Also used : ReadingBean(com.axway.ats.common.performance.monitor.beans.ReadingBean) MonitoringException(com.axway.ats.core.monitoring.MonitoringException) Validator(com.axway.ats.core.validation.Validator) MonitorConfigurationException(com.axway.ats.core.monitoring.MonitorConfigurationException) MonitoringException(com.axway.ats.core.monitoring.MonitoringException) HashSet(java.util.HashSet)

Example 13 with ReadingBean

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

the class RestSystemMonitor method scheduleJvmMonitoring.

public Set<ReadingBean> scheduleJvmMonitoring(@Validate(name = "monitoredHost", type = ValidationType.STRING_SERVER_WITH_PORT) String monitoredHost, @Validate(name = "jvmPort", type = ValidationType.NUMBER_PORT_NUMBER) String jvmPort, @Validate(name = "alias", type = ValidationType.NOT_NULL) String alias, @Validate(name = "jvmReadingTypes", type = ValidationType.NOT_NULL) String[] jvmReadingTypes) {
    // validate input parameters
    monitoredHost = HostUtils.getAtsAgentIpAndPort(monitoredHost);
    new Validator().validateMethodParameters("Could not schedule monitoring JVM statistics on '" + monitoredHost + "' at " + jvmPort + " port", new Object[] { monitoredHost, jvmPort, jvmReadingTypes });
    Set<ReadingBean> readingTypes = new HashSet<ReadingBean>();
    Map<String, String> readingParameters = new HashMap<String, String>();
    readingParameters.put("JMX_PORT", jvmPort);
    if (!StringUtils.isNullOrEmpty(alias)) {
        readingParameters.put(SystemMonitorDefinitions.PARAMETER_NAME__PROCESS_ALIAS, alias);
    }
    for (String readingType : jvmReadingTypes) {
        ReadingBean reading = null;
        try {
            log.debug("Scheduling JVM monitoring...");
            reading = systemMonitor.scheduleJvmMonitoring(readingType, readingParameters);
            logSystemStatistics = true;
            log.info("JVM monitoring scheduled.");
        } catch (Exception e) {
            log.error("Could not schedule JVM monitoring.", e);
            throw new MonitoringException("Could not schedule JVM monitoring. Did you initialize the monitoring context?", e);
        }
        readingTypes.add(reading);
    }
    return readingTypes;
}
Also used : ReadingBean(com.axway.ats.common.performance.monitor.beans.ReadingBean) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) MonitoringException(com.axway.ats.core.monitoring.MonitoringException) Validator(com.axway.ats.core.validation.Validator) MonitorConfigurationException(com.axway.ats.core.monitoring.MonitorConfigurationException) MonitoringException(com.axway.ats.core.monitoring.MonitoringException) HashSet(java.util.HashSet)

Example 14 with ReadingBean

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

the class RestSystemMonitor method setScheduledReadingTypes.

public void setScheduledReadingTypes(Set<ReadingBean> readingTypes) {
    if (this.readingTypes == null) {
        this.readingTypes = new HashSet<>();
    }
    // see which readings are already scheduled and log a warning
    // add those that are new
    Iterator<ReadingBean> scheduledReadingsIretator = this.readingTypes.iterator();
    Iterator<ReadingBean> newReadingsIretator = readingTypes.iterator();
    while (newReadingsIretator.hasNext()) {
        ReadingBean newReadingBean = newReadingsIretator.next();
        while (scheduledReadingsIretator.hasNext()) {
            ReadingBean scheduledReadingBean = scheduledReadingsIretator.next();
            if (newReadingBean.equals(scheduledReadingBean)) {
                log.warn("The requested reading '" + newReadingBean.toString() + "' has already being scheduled.");
            }
        }
        // reset iterator by making the object again
        scheduledReadingsIretator = this.readingTypes.iterator();
    }
    /*
         * since this is a set, already presented readings, will be replaced, so
         * we add only the new ones
         */
    this.readingTypes.addAll(readingTypes);
}
Also used : ReadingBean(com.axway.ats.common.performance.monitor.beans.ReadingBean)

Example 15 with ReadingBean

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

the class RestSystemMonitor method scheduleCustomJvmMonitoring.

public Set<ReadingBean> scheduleCustomJvmMonitoring(@Validate(name = "monitoredHost", type = ValidationType.STRING_SERVER_WITH_PORT) String monitoredHost, @Validate(name = "jmxPort", type = ValidationType.NUMBER_PORT_NUMBER) String jmxPort, @Validate(name = "alias", type = ValidationType.NOT_NULL) String alias, @Validate(name = "mbeanName", type = ValidationType.NOT_NULL) String mbeanName, @Validate(name = "unit", type = ValidationType.NOT_NULL) String unit, @Validate(name = "mbeanAttributes", type = ValidationType.NOT_NULL) String... mbeanAttributes) {
    // validate input parameters
    monitoredHost = HostUtils.getAtsAgentIpAndPort(monitoredHost);
    Set<ReadingBean> readingTypes = new HashSet<ReadingBean>();
    Map<String, String> readingParameters = new LinkedHashMap<String, String>();
    readingParameters.put("JMX_PORT", jmxPort);
    readingParameters.put("MBEAN_NAME", mbeanName);
    if (!StringUtils.isNullOrEmpty(alias)) {
        readingParameters.put(SystemMonitorDefinitions.PARAMETER_NAME__PROCESS_ALIAS, alias);
    }
    // already existing map
    if (mbeanAttributes.length > 1) {
        for (String att : mbeanAttributes) {
            readingParameters.put(att, "");
        }
    }
    // the first element in the array is always the mbean name
    ReadingBean reading = new ReadingBean(ATS_JVM_MONITOR_CLASS_FULL_NAME, mbeanAttributes[0], unit);
    try {
        log.debug("Scheduling custom JVM monitoring...");
        int newReadingId = systemMonitor.scheduleCustomJvmMonitoring();
        reading.setDbId(newReadingId);
        logSystemStatistics = true;
        log.info("Custom JVM monitoring scheduled.");
    } catch (Exception e) {
        log.error("Could not schedule custom JVM monitoring.", e);
        throw new MonitoringException("Could not schedule custom JVM monitoring. Did you initialize the monitoring context?", e);
    }
    reading.setParameters(readingParameters);
    readingTypes.add(reading);
    return readingTypes;
}
Also used : ReadingBean(com.axway.ats.common.performance.monitor.beans.ReadingBean) MonitoringException(com.axway.ats.core.monitoring.MonitoringException) MonitorConfigurationException(com.axway.ats.core.monitoring.MonitorConfigurationException) MonitoringException(com.axway.ats.core.monitoring.MonitoringException) HashSet(java.util.HashSet) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

ReadingBean (com.axway.ats.common.performance.monitor.beans.ReadingBean)30 ArrayList (java.util.ArrayList)10 ParentProcessReadingBean (com.axway.ats.common.performance.monitor.beans.ParentProcessReadingBean)8 MonitoringException (com.axway.ats.core.monitoring.MonitoringException)7 HashSet (java.util.HashSet)7 SessionData (com.axway.ats.agent.webapp.restservice.model.SessionData)6 ErrorPojo (com.axway.ats.agent.webapp.restservice.model.pojo.ErrorPojo)6 MonitorConfigurationException (com.axway.ats.core.monitoring.MonitorConfigurationException)6 Consumes (javax.ws.rs.Consumes)6 POST (javax.ws.rs.POST)6 Path (javax.ws.rs.Path)6 Produces (javax.ws.rs.Produces)6 HashMap (java.util.HashMap)5 UnsupportedReadingException (com.axway.ats.core.monitoring.UnsupportedReadingException)3 Validator (com.axway.ats.core.validation.Validator)3 SystemInformationException (com.axway.ats.agent.core.monitoring.systemmonitor.systeminformation.exceptions.SystemInformationException)2 LinkedHashMap (java.util.LinkedHashMap)2 List (java.util.List)2 AtsSystemMonitoringAgent (com.axway.ats.agent.core.monitoring.agents.AtsSystemMonitoringAgent)1 PerformanceMonitor (com.axway.ats.common.performance.monitor.PerformanceMonitor)1