Search in sources :

Example 1 with UserActivityLoggerTask

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

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

AgentException (com.axway.ats.agent.core.exceptions.AgentException)2 UserActivityLoggerTask (com.axway.ats.monitoring.model.UserActivityLoggerTask)2 MonitoringException (com.axway.ats.monitoring.model.exceptions.MonitoringException)2 AgentMonitoringClient (com.axway.ats.agent.webapp.client.AgentMonitoringClient)1 AbstractLoggerTask (com.axway.ats.monitoring.model.AbstractLoggerTask)1 ArrayList (java.util.ArrayList)1