use of com.axway.ats.common.performance.monitor.beans.ReadingBean in project ats-framework by Axway.
the class MonitoringServiceImpl method scheduleMonitoring.
@POST
@Path("scheduleMonitoring")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response scheduleMonitoring(@Context HttpServletRequest request, ScheduleMonitoringPojo monitoringPojo) {
final String caller = getCaller(request, monitoringPojo, false);
ThreadsPerCaller.registerThread(caller);
try {
SessionData sd = getSessionData(request, monitoringPojo);
RestSystemMonitor restSystemMonitor = sd.getSystemMonitor();
String agent = request.getLocalAddr() + ":" + request.getLocalPort();
Set<ReadingBean> readings = restSystemMonitor.scheduleMonitoring(agent, monitoringPojo.getReading(), monitoringPojo.getReadingParametersAsMap());
restSystemMonitor.setScheduledReadingTypes(readings);
String readingParametersAsString = entrySetAsString(monitoringPojo.getReadingParametersAsMap());
return Response.ok("{\"status\":\"scheduled monitoring for reading '" + monitoringPojo.getReading() + "' and readingParameters '" + readingParametersAsString + "'\"}").build();
} catch (Exception e) {
return Response.serverError().entity(new ErrorPojo(e)).build();
} finally {
ThreadsPerCaller.unregisterThread();
}
}
use of com.axway.ats.common.performance.monitor.beans.ReadingBean in project ats-framework by Axway.
the class RestSystemMonitor method scheduleProcessMonitoring.
private Set<ReadingBean> scheduleProcessMonitoring(String monitoredHost, String parentProcess, String processPattern, String processAlias, String processUsername, String[] processReadingTypes) {
Set<ReadingBean> readingTypes = new HashSet<ReadingBean>();
try {
log.debug("Scheduling process monitoring...");
readingTypes.addAll(systemMonitor.scheduleProcessMonitoring(parentProcess, processPattern, processAlias, processUsername, processReadingTypes));
logSystemStatistics = true;
log.info("Process monitoring scheduled.");
return readingTypes;
} catch (Exception e) {
log.error("Could not schedule process monioring.");
throw new MonitoringException("Could not schedule process monioring. Did you initialize the monitoring context?", e);
}
}
use of com.axway.ats.common.performance.monitor.beans.ReadingBean in project ats-framework by Axway.
the class RestSystemMonitor method scheduleMonitoring.
public Set<ReadingBean> scheduleMonitoring(@Validate(name = "monitoredHost", type = ValidationType.STRING_SERVER_WITH_PORT) String monitoredHost, @Validate(name = "readingType", type = ValidationType.STRING_NOT_EMPTY) String readingType, @Validate(name = "readingParameters", type = ValidationType.NOT_NULL) Map<String, String> readingParameters) {
// validate input parameters
monitoredHost = HostUtils.getAtsAgentIpAndPort(monitoredHost);
new Validator().validateMethodParameters("Could not schedule monitoring a statistic on '" + monitoredHost + "'", new Object[] { monitoredHost, readingType, readingParameters });
Set<ReadingBean> readingTypes = new HashSet<ReadingBean>();
Set<String> readingNames = new HashSet<String>();
readingNames.add(readingType);
ReadingBean reading = null;
try {
log.debug("Scheduling monitoring...");
reading = systemMonitor.scheduleMonitoring(readingType, readingParameters);
logSystemStatistics = true;
log.info("Monitoring scheduled.");
} catch (Exception e) {
log.error("Could not schedule monitoring.", e);
throw new MonitoringException("Could not schedule monitoring. Did you initialize the monitoring context?", e);
}
readingTypes.add(reading);
return readingTypes;
}
use of com.axway.ats.common.performance.monitor.beans.ReadingBean in project ats-framework by Axway.
the class AgentSystemMonitor method initializeMonitor.
private void initializeMonitor(String monitorClassName, List<ReadingBean> readings, int pollInterval) throws MonitorConfigurationException {
// try to make an instance of the monitor class
Object monitorInstance;
try {
monitorInstance = Class.forName(monitorClassName).newInstance();
} catch (InstantiationException e) {
throw new MonitorConfigurationException("InstantiationException while constructing '" + monitorClassName + "' monitor. Exception error message: " + e.getMessage());
} catch (IllegalAccessException e) {
throw new MonitorConfigurationException("IllegalAccessException while constructing '" + monitorClassName + "' monitor. Exception error message: " + e.getMessage());
} catch (ClassNotFoundException e) {
throw new MonitorConfigurationException("ClassNotFoundException while constructing '" + monitorClassName + "' monitor. Exception error message: " + e.getMessage());
}
// check if it implements the needed interface
if (!(monitorInstance instanceof PerformanceMonitor)) {
throw new MonitorConfigurationException(monitorClassName + " is not a valid monitor class");
}
PerformanceMonitor monitor = (PerformanceMonitor) monitorInstance;
try {
// initialize the monitor
monitor.setPollInterval(pollInterval);
monitor.init(readings.toArray(new ReadingBean[readings.size()]));
} catch (Throwable e) {
throw new MonitorConfigurationException("Error initializing " + monitorClassName + " monitor: " + e.getMessage(), e);
}
monitoringAgent.addMonitor(monitor);
}
use of com.axway.ats.common.performance.monitor.beans.ReadingBean in project ats-framework by Axway.
the class AtsJvmMonitor method pollReadingInstances.
private List<ReadingBean> pollReadingInstances(List<JvmReadingInstance> readingInstances) throws Exception {
List<ReadingBean> redingsResult = new ArrayList<ReadingBean>();
for (JvmReadingInstance readingInstance : readingInstances) {
float value = readingInstance.poll();
ReadingBean newResult = readingInstance.getNewCopy();
newResult.setValue(String.valueOf(value));
redingsResult.add(newResult);
}
return redingsResult;
}
Aggregations