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;
}
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;
}
Aggregations