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