Search in sources :

Example 16 with ReadingBean

use of com.axway.ats.common.performance.monitor.beans.ReadingBean in project ats-framework by Axway.

the class MonitoringServiceImpl method scheduleCustomJvmMonitoring.

@POST
@Path("scheduleCustomJvmMonitoring")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response scheduleCustomJvmMonitoring(@Context HttpServletRequest request, ScheduleCustomJvmMonitoringPojo 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.scheduleCustomJvmMonitoring(agent, monitoringPojo.getJmxPort(), monitoringPojo.getAlias(), monitoringPojo.getMbeanName(), monitoringPojo.getUnit(), monitoringPojo.getMbeanAttributes());
        restSystemMonitor.setScheduledReadingTypes(readings);
    } catch (Exception e) {
        return Response.serverError().entity(new ErrorPojo(e)).build();
    } finally {
        ThreadsPerCaller.unregisterThread();
    }
    String statusMessage = "{\"status \": \"scheduled custom JVM monitoring with parameters '" + monitoringPojo.toString() + "'\"}";
    return Response.ok(statusMessage).build();
}
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 17 with ReadingBean

use of com.axway.ats.common.performance.monitor.beans.ReadingBean in project ats-framework by Axway.

the class MonitoringServiceImpl method scheduleProcessMonitoring.

@POST
@Path("scheduleProcessMonitoring")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response scheduleProcessMonitoring(@Context HttpServletRequest request, ScheduleProcessMonitoringPojo 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.scheduleProcessMonitoring(agent, monitoringPojo.getProcessPattern(), monitoringPojo.getProcessAlias(), monitoringPojo.getProcessUsername(), monitoringPojo.getProcessReadingTypes());
        restSystemMonitor.setScheduledReadingTypes(readings);
    } catch (Exception e) {
        return Response.serverError().entity(new ErrorPojo(e)).build();
    } finally {
        ThreadsPerCaller.unregisterThread();
    }
    String statusMessage = "{\"status \": \"scheduled process monitoring with parameters '" + monitoringPojo.toString() + "'\"}";
    return Response.ok(statusMessage).build();
}
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 18 with ReadingBean

use of com.axway.ats.common.performance.monitor.beans.ReadingBean in project ats-framework by Axway.

the class MonitoringServiceImpl method scheduleChildProcessMonitoring.

@POST
@Path("scheduleChildProcessMonitoring")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response scheduleChildProcessMonitoring(@Context HttpServletRequest request, ScheduleProcessMonitoringPojo 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.scheduleChildProcessMonitoring(agent, monitoringPojo.getParentProcess(), monitoringPojo.getProcessPattern(), monitoringPojo.getProcessAlias(), monitoringPojo.getProcessUsername(), monitoringPojo.getProcessReadingTypes());
        restSystemMonitor.setScheduledReadingTypes(readings);
    } catch (Exception e) {
        return Response.serverError().entity(new ErrorPojo(e)).build();
    } finally {
        ThreadsPerCaller.unregisterThread();
    }
    String statusMessage = "{\"status \": \"scheduled child process monitoring with parameters '" + monitoringPojo.toString() + "'\"}";
    return Response.ok(statusMessage).build();
}
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 19 with ReadingBean

use of com.axway.ats.common.performance.monitor.beans.ReadingBean in project ats-framework by Axway.

the class DatabaseReadingsRepository method updateDatabaseRepository.

/**
 * Populate these reading to the DB, so they have their own DB IDs
 *
 * @param monitoredHost
 * @param readings
 * @param readingIdToDbIdMap
 * @throws DatabaseAccessException
 */
public void updateDatabaseRepository(String monitoredHost, List<ReadingBean> readings) throws DatabaseAccessException {
    Logger log = LogManager.getLogger(DatabaseReadingsRepository.class);
    String caller = ThreadsPerCaller.getCaller();
    if (dbAccess == null) {
        dbAccess = new DbAccessFactory().getNewDbWriteAccessObjectViaPassiveDbAppender(caller);
    }
    String dbConnectionHash = obtainDbConnectionHash(caller);
    Map<String, Integer> knownReadingBeansForCurrentDbConn = knownReadingBeans.get(dbConnectionHash);
    if (knownReadingBeansForCurrentDbConn == null) {
        knownReadingBeansForCurrentDbConn = new HashMap<String, Integer>();
        knownReadingBeans.put(dbConnectionHash, knownReadingBeansForCurrentDbConn);
    }
    for (ReadingBean reading : readings) {
        // check if the current reading already was flagged as known
        int dbId = getDbIdForReading(reading, knownReadingBeansForCurrentDbConn);
        reading.setDbId(dbId);
        if (reading.getDbId() == -1) {
            StringBuilder newReadingParameters = new StringBuilder();
            Map<String, String> readingParameters = reading.getParameters();
            if (readingParameters != null && readingParameters.size() > 0) {
                if (readingParameters.containsKey(SystemMonitorDefinitions.PARAMETER_NAME__PROCESS_ALIAS)) {
                    newReadingParameters.append("'");
                    newReadingParameters.append(readingParameters.get(SystemMonitorDefinitions.PARAMETER_NAME__PROCESS_ALIAS));
                    newReadingParameters.append("'_user pattern is '");
                    newReadingParameters.append(readingParameters.get(SystemMonitorDefinitions.PARAMETER_NAME__PROCESS_RECOGNITION_PATTERN));
                    newReadingParameters.append("'_reading=");
                    newReadingParameters.append(readingParameters.get(SystemMonitorDefinitions.PARAMETER_NAME__PROCESS_READING_ID));
                    newReadingParameters.append("_started by command '");
                    newReadingParameters.append(readingParameters.get(SystemMonitorDefinitions.PARAMETER_NAME__PROCESS_START_COMMAND));
                    newReadingParameters.append("'");
                } else {
                    newReadingParameters.append(readingParameters.get(SystemMonitorDefinitions.PARAMETER_NAME__CUSTOM_MESSAGE));
                }
            }
            int newReadingDatabaseId;
            if (reading instanceof ParentProcessReadingBean) {
                String thisProcessName = "[process] " + ((ParentProcessReadingBean) reading).getTheNameOfThisParentProcess();
                String thisReadingName = thisProcessName + " - " + reading.getName();
                newReadingDatabaseId = dbAccess.populateSystemStatisticDefinition(thisReadingName, reading.getParameter(SystemMonitorDefinitions.PARAMETER_NAME__PROCESS_PARENT_NAME), thisProcessName, reading.getUnit(), newReadingParameters.toString());
                log.debug("DB id " + newReadingDatabaseId + " for parent process reading: " + thisReadingName);
            } else {
                String parentName = reading.getParameter(SystemMonitorDefinitions.PARAMETER_NAME__PROCESS_PARENT_NAME);
                if (parentName != null) {
                    parentName = "[process] " + parentName;
                }
                newReadingDatabaseId = dbAccess.populateSystemStatisticDefinition(reading.getName(), parentName, "", reading.getUnit(), newReadingParameters.toString());
                log.debug("DB id " + newReadingDatabaseId + " for reading: " + reading.getName());
            }
            // remember the DB ID of this reading
            reading.setDbId(newReadingDatabaseId);
            knownReadingBeansForCurrentDbConn.put(reading.getDescription(), reading.getDbId());
        }
    }
}
Also used : ReadingBean(com.axway.ats.common.performance.monitor.beans.ReadingBean) ParentProcessReadingBean(com.axway.ats.common.performance.monitor.beans.ParentProcessReadingBean) ParentProcessReadingBean(com.axway.ats.common.performance.monitor.beans.ParentProcessReadingBean) DbAccessFactory(com.axway.ats.log.autodb.io.DbAccessFactory) Logger(org.apache.logging.log4j.Logger)

Example 20 with ReadingBean

use of com.axway.ats.common.performance.monitor.beans.ReadingBean in project ats-framework by Axway.

the class MatchedProcess method createOrUpdateDynamicReadingInstances.

public static List<ReadingInstance> createOrUpdateDynamicReadingInstances(ISystemInformation systemInfo, Map<String, ParentProcessReadingBean> parentProcessReadingInstances, List<ReadingBean> initialReadings, List<ReadingInstance> currentReadingInstances) throws UnsupportedReadingException, SystemInformationException {
    // update the list of matching processes now, this must be done as quickly as possible
    // as it happens prior to each polling
    currentReadingInstances = updateProcessesMatchingMap(systemInfo, initialReadings, currentReadingInstances);
    List<ReadingInstance> readingInstances = new ArrayList<ReadingInstance>(currentReadingInstances);
    for (ReadingBean reading : initialReadings) {
        // the list of matching processes is ready, now create the reading instances
        String readingName = reading.getName();
        ParentProcessReadingBean parentProcess = null;
        String parentProcessName = reading.getParameter(SystemMonitorDefinitions.PARAMETER_NAME__PROCESS_PARENT_NAME);
        if (parentProcessName != null) {
            parentProcess = parentProcessReadingInstances.get(parentProcessName + "-" + reading.getName());
        }
        /*
             * the process monitoring methods are adding a reading identifier to the parameters
             * like "reading=1", "reading=2" etc.
             * These values are not important, but they must be unique as they are later used by
             * the Test Explorer to map same processes monitored on different machines.
             * Of course we can use a more descriptive values like "reading=CPU percent reading", but this will take
             * some space on the database, and we know these values are never seen by the user.
             */
        if (readingName.equalsIgnoreCase(SystemMonitorDefinitions.READING_PROCESS_CPU__USAGE_USER)) {
            List<ReadingInstance> readingsList = getProcessCpuUsageRunningUser(systemInfo, reading, parentProcess);
            readingInstances.addAll(readingsList);
        } else if (readingName.equalsIgnoreCase(SystemMonitorDefinitions.READING_PROCESS_CPU__USAGE_KERNEL)) {
            List<ReadingInstance> readingsList = getProcessCpuUsageRunningKernel(systemInfo, reading, parentProcess);
            readingInstances.addAll(readingsList);
        } else if (readingName.equalsIgnoreCase(SystemMonitorDefinitions.READING_PROCESS_CPU__USAGE_TOTAL)) {
            List<ReadingInstance> readingsList = getProcessCpuUsageRunningTotal(systemInfo, reading, parentProcess);
            readingInstances.addAll(readingsList);
        } else if (readingName.equalsIgnoreCase(SystemMonitorDefinitions.READING_PROCESS_MEMORY__VIRTUAL)) {
            List<ReadingInstance> readingsList = getProcessVirtualMemory(systemInfo, reading, parentProcess);
            readingInstances.addAll(readingsList);
        } else if (readingName.equalsIgnoreCase(SystemMonitorDefinitions.READING_PROCESS_MEMORY__RESIDENT)) {
            List<ReadingInstance> readingsList = getProcessResidentMemory(systemInfo, reading, parentProcess);
            readingInstances.addAll(readingsList);
        } else if (readingName.equalsIgnoreCase(SystemMonitorDefinitions.READING_PROCESS_MEMORY__SHARED) && !IS_WINDOWS) {
            List<ReadingInstance> readingsList = getProcessSharedMemory(systemInfo, reading, parentProcess);
            readingInstances.addAll(readingsList);
        } else if (readingName.equalsIgnoreCase(SystemMonitorDefinitions.READING_PROCESS_MEMORY__PAGE_FAULTS)) {
            List<ReadingInstance> readingsList = getProcessMemoryPageFaults(systemInfo, reading, parentProcess);
            readingInstances.addAll(readingsList);
        } else {
        // We do nothing here as for example we do not support Shared Memory on windows
        // throw new UnsupportedReadingException( readingName );
        }
    }
    return readingInstances;
}
Also used : ReadingBean(com.axway.ats.common.performance.monitor.beans.ReadingBean) ParentProcessReadingBean(com.axway.ats.common.performance.monitor.beans.ParentProcessReadingBean) ParentProcessReadingBean(com.axway.ats.common.performance.monitor.beans.ParentProcessReadingBean) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List)

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