use of com.axway.ats.common.performance.monitor.beans.ParentProcessReadingBean in project ats-framework by Axway.
the class MatchedProcess method createOrUpdateDynamicReadingInstances.
public static List<ReadingInstance> createOrUpdateDynamicReadingInstances(SigarWrapper sigarWrapper, Map<String, ParentProcessReadingBean> parentProcessReadingInstances, List<FullReadingBean> initialReadings, List<ReadingInstance> currentReadingInstances) throws UnsupportedReadingException, SigarException {
// update the list of matching processes now, this must be done as quickly as possible
// as it happens prior to each polling
currentReadingInstances = updateProcessesMatchingMap(sigarWrapper.getSigarInstance(), initialReadings, currentReadingInstances);
List<ReadingInstance> readingInstances = new ArrayList<ReadingInstance>(currentReadingInstances);
for (FullReadingBean 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(sigarWrapper, reading, parentProcess);
readingInstances.addAll(readingsList);
} else if (readingName.equalsIgnoreCase(SystemMonitorDefinitions.READING_PROCESS_CPU__USAGE_KERNEL)) {
List<ReadingInstance> readingsList = getProcessCpuUsageRunningKernel(sigarWrapper, reading, parentProcess);
readingInstances.addAll(readingsList);
} else if (readingName.equalsIgnoreCase(SystemMonitorDefinitions.READING_PROCESS_CPU__USAGE_TOTAL)) {
List<ReadingInstance> readingsList = getProcessCpuUsageRunningTotal(sigarWrapper, reading, parentProcess);
readingInstances.addAll(readingsList);
} else if (readingName.equalsIgnoreCase(SystemMonitorDefinitions.READING_PROCESS_MEMORY__VIRTUAL)) {
List<ReadingInstance> readingsList = getProcessVirtualMemory(sigarWrapper, reading, parentProcess);
readingInstances.addAll(readingsList);
} else if (readingName.equalsIgnoreCase(SystemMonitorDefinitions.READING_PROCESS_MEMORY__RESIDENT)) {
List<ReadingInstance> readingsList = getProcessResidentMemory(sigarWrapper, reading, parentProcess);
readingInstances.addAll(readingsList);
} else if (readingName.equalsIgnoreCase(SystemMonitorDefinitions.READING_PROCESS_MEMORY__SHARED) && !IS_WINDOWS) {
List<ReadingInstance> readingsList = getProcessSharedMemory(sigarWrapper, reading, parentProcess);
readingInstances.addAll(readingsList);
} else if (readingName.equalsIgnoreCase(SystemMonitorDefinitions.READING_PROCESS_MEMORY__PAGE_FAULTS)) {
List<ReadingInstance> readingsList = getProcessMemoryPageFaults(sigarWrapper, 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;
}
use of com.axway.ats.common.performance.monitor.beans.ParentProcessReadingBean 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<BasicReadingBean> readings, Map<String, Integer> readingIdToDbIdMap) throws DatabaseAccessException {
Logger log = Logger.getLogger(DatabaseReadingsRepository.class);
if (dbAccess == null) {
dbAccess = new DbAccessFactory().getNewDbWriteAccessObject();
}
List<BasicReadingBean> repository = repositoryPerHostMap.get(monitoredHost);
if (repository == null) {
repository = new ArrayList<BasicReadingBean>();
repositoryPerHostMap.put(monitoredHost, repository);
}
for (BasicReadingBean reading : readings) {
if (reading instanceof FullReadingBean) {
FullReadingBean newReading = (FullReadingBean) reading;
StringBuilder newReadingParameters = new StringBuilder();
Map<String, String> readingParameters = newReading.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) newReading).getTheNameOfThisParentProcess();
String thisReadingName = thisProcessName + " - " + newReading.getName();
newReadingDatabaseId = dbAccess.populateSystemStatisticDefinition(thisReadingName, newReading.getParameter(SystemMonitorDefinitions.PARAMETER_NAME__PROCESS_PARENT_NAME), thisProcessName, newReading.getUnit(), newReadingParameters.toString());
log.debug("DB id " + newReadingDatabaseId + " for parent process reading: " + thisReadingName);
} else {
String parentName = newReading.getParameter(SystemMonitorDefinitions.PARAMETER_NAME__PROCESS_PARENT_NAME);
if (parentName != null) {
parentName = "[process] " + parentName;
}
newReadingDatabaseId = dbAccess.populateSystemStatisticDefinition(newReading.getName(), parentName, "", newReading.getUnit(), newReadingParameters.toString());
log.debug("DB id " + newReadingDatabaseId + " for reading: " + newReading.getName());
}
// remember the DB ID of this reading, because the monitoring remote service gives us the
// full reading information only the first time
newReading.setDbId(newReadingDatabaseId);
// we maintain this map so can easily find the DB id of each Basic reading(it has reading id only)
readingIdToDbIdMap.put(newReading.getId(), newReading.getDbId());
}
}
}
use of com.axway.ats.common.performance.monitor.beans.ParentProcessReadingBean 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());
}
}
}
use of com.axway.ats.common.performance.monitor.beans.ParentProcessReadingBean 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;
}
use of com.axway.ats.common.performance.monitor.beans.ParentProcessReadingBean in project ats-framework by Axway.
the class AtsSystemMonitor method doPoll.
public List<ReadingBean> doPoll(boolean isFirstTime) throws Exception {
List<ReadingBean> redingsResult = new ArrayList<ReadingBean>();
// clear the values from previous poll for all parent processes
for (ParentProcessReadingBean parentProcessReading : parentProcessReadingInstances.values()) {
parentProcessReading.resetValue();
}
// update the list of dynamic reading instances
if (initialDynamicReadings.size() > 0) {
dynamicReadingInstances = ReadingInstancesFactory.createOrUpdateDynamicReadingInstances(systemInfo, parentProcessReadingInstances, initialDynamicReadings, dynamicReadingInstances);
}
this.systemInfo.refresh();
// poll the static reading instances
redingsResult.addAll(pollReadingInstances(staticReadingInstances));
// poll the dynamic reading instances
if (initialDynamicReadings.size() > 0) {
redingsResult.addAll(pollReadingInstances(dynamicReadingInstances));
}
// add the parent process values
redingsResult.addAll(pollParentProcessInstances(parentProcessReadingInstances.values()));
return redingsResult;
}
Aggregations