Search in sources :

Example 1 with MonitoringException

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

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

the class SystemMonitor method startSystemMonitoringProcess.

private void startSystemMonitoringProcess(String monitoredHost) throws MonitoringException {
    log.debug("Starting the system monitoring process on " + monitoredHost);
    try {
        InternalSystemMonitoringOperations sysMonitoringActions = new InternalSystemMonitoringOperations(monitoredHost);
        sysMonitoringActions.startMonitoring();
    } catch (AgentException e) {
        throw new MonitoringException("Could not start the system monitoring process on " + monitoredHost, e);
    }
}
Also used : InternalSystemMonitoringOperations(com.axway.ats.agent.components.monitoring.operations.clients.InternalSystemMonitoringOperations) AgentException(com.axway.ats.agent.core.exceptions.AgentException) MonitoringException(com.axway.ats.monitoring.model.exceptions.MonitoringException)

Example 3 with MonitoringException

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

the class SystemMonitor method startMonitoring.

/**
     * Start monitoring
     *
     * @param monitoredHost the host to monitor
     * @param collectInterval in how many seconds to record the requested data
     * @param loggingInterval in how many seconds to move the recorded data to the logging database
     */
@PublicAtsApi
public void startMonitoring(int collectInterval, int loggingInterval) {
    if (isStarted) {
        throw new MonitoringException("The system monitor is already started");
    }
    checkTimeIntervals(collectInterval, loggingInterval);
    this.scheduler = Executors.newScheduledThreadPool(10);
    this.startTimestamp = System.currentTimeMillis();
    this.pollInterval = collectInterval;
    this.loggingInterval = loggingInterval;
    List<MonitoringException> errorsStartingMonitoringPhysicalHosts = startMonitoringPhysicalHosts();
    if (errorsStartingMonitoringPhysicalHosts.size() > 0) {
        for (MonitoringException e : errorsStartingMonitoringPhysicalHosts) {
            log.error("The following error occured while stating the system monitoring process", e);
        }
        cancelAnyMonitoringActivity();
        throw new MonitoringException("There were error starting the system monitoring process");
    }
    List<MonitoringException> errorsStartingMonitoringAgents = startMonitoringAgent();
    if (errorsStartingMonitoringAgents.size() > 0) {
        for (MonitoringException e : errorsStartingMonitoringAgents) {
            log.error("The following error occured while stating the monitoring process on ATS Agent", e);
        }
        cancelAnyMonitoringActivity();
        throw new MonitoringException("There were errors starting the monitoring process on ATS Agent");
    }
    isStarted = true;
}
Also used : MonitoringException(com.axway.ats.monitoring.model.exceptions.MonitoringException) PublicAtsApi(com.axway.ats.common.PublicAtsApi)

Example 4 with MonitoringException

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

the class SystemMonitor method startMonitoringAgent.

private List<MonitoringException> startMonitoringAgent() {
    List<MonitoringException> errors = new ArrayList<MonitoringException>();
    int numberAgents = 0;
    // iterate the monitored hosts
    Iterator<String> monitoredAgentsIterator = monitoredAgents.iterator();
    while (monitoredAgentsIterator.hasNext()) {
        numberAgents++;
        String monitoredAgent = monitoredAgentsIterator.next();
        log.debug("Starting ATS Agent monitoring on " + monitoredAgent);
        try {
            new AgentMonitoringClient(monitoredAgent).startMonitoring(startTimestamp, pollInterval);
        } catch (AgentException e) {
            errors.add(new MonitoringException("Could not start monitoring ATS Agent " + monitoredAgent, e));
        }
    }
    // Note that we use just 1 task for monitoring all agents
    if (numberAgents > 0 && errors.size() == 0) {
        log.debug("Starting the logging task for the agent monitoring");
        lastUserActivityLoggerTask = new UserActivityLoggerTask(monitoredAgents);
        ScheduledFuture<?> loggerTaskFuture = scheduler.scheduleAtFixedRate(lastUserActivityLoggerTask, loggingInterval, loggingInterval, TimeUnit.SECONDS);
        // put the task in the map
        loggerTasksPerHost.put(UserActivityLoggerTask.ATS_AGENT_HOSTS, loggerTaskFuture);
        log.info("User activity on " + Arrays.toString(monitoredAgents.toArray()) + " agent(s) will be monitored every " + loggingInterval + " seconds");
    }
    return errors;
}
Also used : AgentMonitoringClient(com.axway.ats.agent.webapp.client.AgentMonitoringClient) MonitoringException(com.axway.ats.monitoring.model.exceptions.MonitoringException) AgentException(com.axway.ats.agent.core.exceptions.AgentException) ArrayList(java.util.ArrayList) UserActivityLoggerTask(com.axway.ats.monitoring.model.UserActivityLoggerTask)

Example 5 with MonitoringException

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

Aggregations

MonitoringException (com.axway.ats.monitoring.model.exceptions.MonitoringException)11 AgentException (com.axway.ats.agent.core.exceptions.AgentException)7 InternalSystemMonitoringOperations (com.axway.ats.agent.components.monitoring.operations.clients.InternalSystemMonitoringOperations)3 FullReadingBean (com.axway.ats.common.performance.monitor.beans.FullReadingBean)3 AbstractLoggerTask (com.axway.ats.monitoring.model.AbstractLoggerTask)3 ArrayList (java.util.ArrayList)3 AgentMonitoringClient (com.axway.ats.agent.webapp.client.AgentMonitoringClient)2 SystemStatsLoggerTask (com.axway.ats.monitoring.model.SystemStatsLoggerTask)2 UserActivityLoggerTask (com.axway.ats.monitoring.model.UserActivityLoggerTask)2 PublicAtsApi (com.axway.ats.common.PublicAtsApi)1 URL (java.net.URL)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1