Search in sources :

Example 1 with AbstractLoggerTask

use of com.axway.ats.monitoring.model.AbstractLoggerTask 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 AbstractLoggerTask

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

the class SystemMonitor method stopMonitoringAgents.

private boolean stopMonitoringAgents(boolean getRemainingData) {
    boolean successfulOperation = true;
    String monitoredAgentsString = Arrays.toString(monitoredAgents.toArray());
    // cancel the logging task
    ScheduledFuture<?> loggerTaskFuture = loggerTasksPerHost.get(UserActivityLoggerTask.ATS_AGENT_HOSTS);
    if (loggerTaskFuture != null) {
        log.debug("Stopping the logging task for monitoring " + monitoredAgentsString + " ATS agent(s) ");
        if (loggerTaskFuture.isCancelled()) {
            throw new MonitoringException("Logging task for monitoring " + monitoredAgentsString + " ATS agent(s) has been cancelled");
        }
        loggerTaskFuture.cancel(false);
        try {
            // log any remaining results by explicitly calling the task to get the results
            if (getRemainingData) {
                AbstractLoggerTask loggerTask = new UserActivityLoggerTask(monitoredAgents, lastUserActivityLoggerTask.getcollectTimesPerLoader());
                loggerTask.run();
            }
        } catch (Exception e) {
            successfulOperation = false;
            log.error("Error getting final monitoring results for " + monitoredAgentsString + " ATS agent(s)", e);
        }
        // Stop the monitoring process on all agents
        Iterator<String> monitoredAgentsIterator = monitoredAgents.iterator();
        while (monitoredAgentsIterator.hasNext()) {
            String monitoredAgent = monitoredAgentsIterator.next();
            try {
                stopMonitoringProcessOnAgent(monitoredAgent);
            } catch (MonitoringException e) {
                successfulOperation = false;
                log.error(e);
            }
        }
    }
    return successfulOperation;
}
Also used : MonitoringException(com.axway.ats.monitoring.model.exceptions.MonitoringException) AbstractLoggerTask(com.axway.ats.monitoring.model.AbstractLoggerTask) UserActivityLoggerTask(com.axway.ats.monitoring.model.UserActivityLoggerTask) AgentException(com.axway.ats.agent.core.exceptions.AgentException) MonitoringException(com.axway.ats.monitoring.model.exceptions.MonitoringException)

Example 3 with AbstractLoggerTask

use of com.axway.ats.monitoring.model.AbstractLoggerTask 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)3 MonitoringException (com.axway.ats.monitoring.model.exceptions.MonitoringException)3 AgentException (com.axway.ats.agent.core.exceptions.AgentException)2 SystemStatsLoggerTask (com.axway.ats.monitoring.model.SystemStatsLoggerTask)2 FullReadingBean (com.axway.ats.common.performance.monitor.beans.FullReadingBean)1 UserActivityLoggerTask (com.axway.ats.monitoring.model.UserActivityLoggerTask)1 ArrayList (java.util.ArrayList)1