Search in sources :

Example 26 with ReadingBean

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();
    }
}
Also used : ReadingBean(com.axway.ats.common.performance.monitor.beans.ReadingBean) ErrorPojo(com.axway.ats.agent.webapp.restservice.model.pojo.ErrorPojo) SessionData(com.axway.ats.agent.webapp.restservice.model.SessionData) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces)

Example 27 with ReadingBean

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);
    }
}
Also used : ReadingBean(com.axway.ats.common.performance.monitor.beans.ReadingBean) MonitoringException(com.axway.ats.core.monitoring.MonitoringException) MonitorConfigurationException(com.axway.ats.core.monitoring.MonitorConfigurationException) MonitoringException(com.axway.ats.core.monitoring.MonitoringException) HashSet(java.util.HashSet)

Example 28 with ReadingBean

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;
}
Also used : ReadingBean(com.axway.ats.common.performance.monitor.beans.ReadingBean) MonitoringException(com.axway.ats.core.monitoring.MonitoringException) Validator(com.axway.ats.core.validation.Validator) MonitorConfigurationException(com.axway.ats.core.monitoring.MonitorConfigurationException) MonitoringException(com.axway.ats.core.monitoring.MonitoringException) HashSet(java.util.HashSet)

Example 29 with ReadingBean

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);
}
Also used : ReadingBean(com.axway.ats.common.performance.monitor.beans.ReadingBean) MonitorConfigurationException(com.axway.ats.core.monitoring.MonitorConfigurationException) PerformanceMonitor(com.axway.ats.common.performance.monitor.PerformanceMonitor)

Example 30 with ReadingBean

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;
}
Also used : ReadingBean(com.axway.ats.common.performance.monitor.beans.ReadingBean) ArrayList(java.util.ArrayList)

Aggregations

ReadingBean (com.axway.ats.common.performance.monitor.beans.ReadingBean)30 ArrayList (java.util.ArrayList)10 ParentProcessReadingBean (com.axway.ats.common.performance.monitor.beans.ParentProcessReadingBean)8 MonitoringException (com.axway.ats.core.monitoring.MonitoringException)7 HashSet (java.util.HashSet)7 SessionData (com.axway.ats.agent.webapp.restservice.model.SessionData)6 ErrorPojo (com.axway.ats.agent.webapp.restservice.model.pojo.ErrorPojo)6 MonitorConfigurationException (com.axway.ats.core.monitoring.MonitorConfigurationException)6 Consumes (javax.ws.rs.Consumes)6 POST (javax.ws.rs.POST)6 Path (javax.ws.rs.Path)6 Produces (javax.ws.rs.Produces)6 HashMap (java.util.HashMap)5 UnsupportedReadingException (com.axway.ats.core.monitoring.UnsupportedReadingException)3 Validator (com.axway.ats.core.validation.Validator)3 SystemInformationException (com.axway.ats.agent.core.monitoring.systemmonitor.systeminformation.exceptions.SystemInformationException)2 LinkedHashMap (java.util.LinkedHashMap)2 List (java.util.List)2 AtsSystemMonitoringAgent (com.axway.ats.agent.core.monitoring.agents.AtsSystemMonitoringAgent)1 PerformanceMonitor (com.axway.ats.common.performance.monitor.PerformanceMonitor)1