Search in sources :

Example 1 with SystemStatsLoggerTask

use of com.axway.ats.monitoring.model.SystemStatsLoggerTask in project ats-framework by Axway.

the class SystemMonitor method startMonitoringPhysicalHosts.

private List<MonitoringException> startMonitoringPhysicalHosts() {
    List<MonitoringException> errors = new ArrayList<MonitoringException>();
    // initialize the monitoring processes
    Iterator<String> monitoredHostsIterator = monitoredHosts.iterator();
    while (monitoredHostsIterator.hasNext()) {
        String monitoredHost = monitoredHostsIterator.next();
        log.debug("Initializing system monitoring on " + monitoredHost);
        final String ERR_MSG = "Could not initialize monitoring " + monitoredHost + ". ";
        Set<FullReadingBean> readings = requestedReadingTypesPerHosts.get(monitoredHost);
        if (readings == null || readings.size() == 0) {
            errors.add(new MonitoringException(ERR_MSG + " as no monitor types are provided"));
            break;
        }
        try {
            initializeSystemMonitoringProcess(monitoredHost, readings);
        } catch (MonitoringException e) {
            errors.add(e);
            break;
        }
        log.info("Successfully initialized monitoring " + monitoredHost);
    }
    // run the monitoring processes
    monitoredHostsIterator = monitoredHosts.iterator();
    while (monitoredHostsIterator.hasNext()) {
        String monitoredHost = monitoredHostsIterator.next();
        log.debug("Starting system monitoring on " + monitoredHost);
        try {
            startSystemMonitoringProcess(monitoredHost);
        } catch (MonitoringException e) {
            errors.add(e);
            break;
        }
        // start the task which will log into the database at a scheduled interval
        log.debug("Starting the logging task for the system monitoring on " + monitoredHost);
        AbstractLoggerTask loggerTask = new SystemStatsLoggerTask(monitoredHost);
        ScheduledFuture<?> loggerTaskFuture = scheduler.scheduleAtFixedRate(loggerTask, loggingInterval, loggingInterval, TimeUnit.SECONDS);
        //put the task in the map
        loggerTasksPerHost.put(monitoredHost, loggerTaskFuture);
        log.info("Successfully started monitoring " + monitoredHost + ". Monitoring results will be collected on every " + loggingInterval + " seconds");
    }
    return errors;
}
Also used : MonitoringException(com.axway.ats.monitoring.model.exceptions.MonitoringException) ArrayList(java.util.ArrayList) AbstractLoggerTask(com.axway.ats.monitoring.model.AbstractLoggerTask) FullReadingBean(com.axway.ats.common.performance.monitor.beans.FullReadingBean) SystemStatsLoggerTask(com.axway.ats.monitoring.model.SystemStatsLoggerTask)

Example 2 with SystemStatsLoggerTask

use of com.axway.ats.monitoring.model.SystemStatsLoggerTask in project ats-framework by Axway.

the class SystemMonitor method stopMonitoringPhysicalHosts.

private boolean stopMonitoringPhysicalHosts(boolean getRemainingData) {
    boolean successfulOperation = true;
    // cancel the logging tasks
    Iterator<String> loggerTasksIterator = monitoredHosts.iterator();
    while (loggerTasksIterator.hasNext()) {
        String monitoredHost = loggerTasksIterator.next();
        log.debug("Stopping the logging task for the system monitoring on " + monitoredHost);
        ScheduledFuture<?> loggerTaskFuture = loggerTasksPerHost.get(monitoredHost);
        if (loggerTaskFuture != null) {
            if (loggerTaskFuture.isCancelled()) {
                throw new MonitoringException("Logging task for the system monitoring process on " + monitoredHost + " has been cancelled");
            }
            loggerTaskFuture.cancel(false);
            try {
                // log any remaining results by explicitly calling the task to get the results
                if (getRemainingData) {
                    log.debug("Get any remaining monitoring results for " + monitoredHost);
                    AbstractLoggerTask loggerTask = new SystemStatsLoggerTask(monitoredHost);
                    loggerTask.run();
                }
            } catch (Exception e) {
                successfulOperation = false;
                log.error("Error getting final monitoring results for " + monitoredHost, e);
            }
        }
    }
    // stop the monitoring process
    Iterator<String> monitoredHostsIterator = monitoredHosts.iterator();
    while (monitoredHostsIterator.hasNext()) {
        String monitoredHost = monitoredHostsIterator.next();
        try {
            stopSystemMonitoringProcess(monitoredHost);
        } catch (MonitoringException e) {
            successfulOperation = false;
            log.error("Could not stop monitoring " + monitoredHost, e);
        }
    }
    return successfulOperation;
}
Also used : MonitoringException(com.axway.ats.monitoring.model.exceptions.MonitoringException) AbstractLoggerTask(com.axway.ats.monitoring.model.AbstractLoggerTask) AgentException(com.axway.ats.agent.core.exceptions.AgentException) MonitoringException(com.axway.ats.monitoring.model.exceptions.MonitoringException) SystemStatsLoggerTask(com.axway.ats.monitoring.model.SystemStatsLoggerTask)

Aggregations

AbstractLoggerTask (com.axway.ats.monitoring.model.AbstractLoggerTask)2 SystemStatsLoggerTask (com.axway.ats.monitoring.model.SystemStatsLoggerTask)2 MonitoringException (com.axway.ats.monitoring.model.exceptions.MonitoringException)2 AgentException (com.axway.ats.agent.core.exceptions.AgentException)1 FullReadingBean (com.axway.ats.common.performance.monitor.beans.FullReadingBean)1 ArrayList (java.util.ArrayList)1