use of com.axway.ats.common.performance.monitor.beans.ReadingBean in project ats-framework by Axway.
the class MatchedProcess method createStaticReadingInstances.
public static List<ReadingInstance> createStaticReadingInstances(ISystemInformation systemInfo, List<ReadingBean> readings) throws UnsupportedReadingException, SystemInformationException {
List<ReadingInstance> readingInstances = new ArrayList<ReadingInstance>();
// ADD SYSTEM READINGS
for (ReadingBean reading : readings) {
String readingName = reading.getName();
ReadingInstance readingInstance = null;
if (readingName.equalsIgnoreCase(SystemMonitorDefinitions.READING_VIRTUAL_MEMORY__TOTAL)) {
readingInstance = getSwapTotal(systemInfo, reading);
} else if (readingName.equalsIgnoreCase(SystemMonitorDefinitions.READING_VIRTUAL_MEMORY__USED)) {
readingInstance = getSwapUsed(systemInfo, reading);
} else if (readingName.equalsIgnoreCase(SystemMonitorDefinitions.READING_VIRTUAL_MEMORY__FREE)) {
readingInstance = getSwapFree(systemInfo, reading);
} else if (readingName.equalsIgnoreCase(SystemMonitorDefinitions.READING_VIRTUAL_MEMORY__PAGES_IN)) {
readingInstance = getSwapPagesIn(systemInfo, reading);
} else if (readingName.equalsIgnoreCase(SystemMonitorDefinitions.READING_VIRTUAL_MEMORY__PAGES_OUT)) {
readingInstance = getSwapPagesOut(systemInfo, reading);
} else if (readingName.equalsIgnoreCase(SystemMonitorDefinitions.READING_MEMORY__USED)) {
readingInstance = getMemoryUsed(systemInfo, reading);
} else if (readingName.equalsIgnoreCase(SystemMonitorDefinitions.READING_MEMORY__FREE)) {
readingInstance = getMemoryFree(systemInfo, reading);
} else if (readingName.equalsIgnoreCase(SystemMonitorDefinitions.READING_MEMORY__ACTUAL_USED)) {
readingInstance = getMemoryActualUsed(systemInfo, reading);
} else if (readingName.equalsIgnoreCase(SystemMonitorDefinitions.READING_MEMORY__ACTUAL_FREE)) {
readingInstance = getMemoryActualFree(systemInfo, reading);
} else if (readingName.equalsIgnoreCase(SystemMonitorDefinitions.READING_IO__READ_BYTES_ALL_DEVICES)) {
readingInstance = getReadBytesAllLocalDevices(systemInfo, reading);
} else if (readingName.equalsIgnoreCase(SystemMonitorDefinitions.READING_IO__WRITE_BYTES_ALL_DEVICES)) {
readingInstance = getWriteBytesAllLocalDevices(systemInfo, reading);
} else if (readingName.equalsIgnoreCase(SystemMonitorDefinitions.READING_CPU_LOAD__LAST_MINUTE)) {
if (!IS_WINDOWS) {
readingInstance = getLoadAverage1minute(systemInfo, reading);
}
} else if (readingName.equalsIgnoreCase(SystemMonitorDefinitions.READING_CPU_LOAD__LAST_5_MINUTES)) {
if (!IS_WINDOWS) {
readingInstance = getLoadAverage5minutes(systemInfo, reading);
}
} else if (readingName.equalsIgnoreCase(SystemMonitorDefinitions.READING_CPU_LOAD__LAST_15_MINUTES)) {
if (!IS_WINDOWS) {
readingInstance = getLoadAverage15minutes(systemInfo, reading);
}
} else if (readingName.equalsIgnoreCase(SystemMonitorDefinitions.READING_CPU_USAGE__TOTAL)) {
readingInstance = getCpuUsageTotal(systemInfo, reading);
} else if (readingName.equalsIgnoreCase(SystemMonitorDefinitions.READING_CPU_USAGE__WAIT)) {
readingInstance = getCpuUsageWaitingForIO(systemInfo, reading);
} else if (readingName.equalsIgnoreCase(SystemMonitorDefinitions.READING_CPU_USAGE__KERNEL)) {
readingInstance = getCpuUsageRunningKernelCode(systemInfo, reading);
} else if (readingName.equalsIgnoreCase(SystemMonitorDefinitions.READING_CPU_USAGE__USER)) {
readingInstance = getCpuUsageRunningUserCode(systemInfo, reading);
} else if (readingName.equalsIgnoreCase(SystemMonitorDefinitions.READING_NETWORK_TRAFFIC)) {
List<ReadingInstance> readingsList = getNetworkTraffic(systemInfo, reading);
readingInstances.addAll(readingsList);
} else if (readingName.equalsIgnoreCase(SystemMonitorDefinitions.READING_NETSTAT__ACTIVE_CONNECTION_OPENINGS)) {
readingInstance = getNetstatActiveConnectionOpenings(systemInfo, reading);
} else if (readingName.equalsIgnoreCase(SystemMonitorDefinitions.READING_NETSTAT__PASSIVE_CONNECTION_OPENINGS)) {
readingInstance = getNetstatPassiveConnectionOpenings(systemInfo, reading);
} else if (readingName.equalsIgnoreCase(SystemMonitorDefinitions.READING_NETSTAT__FAILED_CONNECTION_ATTEMPTS)) {
readingInstance = getNetstatFailedConnectionAttemtps(systemInfo, reading);
} else if (readingName.equalsIgnoreCase(SystemMonitorDefinitions.READING_NETSTAT__RESET_CONNECTIONS)) {
readingInstance = getNetstatResetConnections(systemInfo, reading);
} else if (readingName.equalsIgnoreCase(SystemMonitorDefinitions.READING_NETSTAT__CURRENT_CONNECTIONS)) {
readingInstance = getNetstatCurrentConnections(systemInfo, reading);
} else if (readingName.equalsIgnoreCase(SystemMonitorDefinitions.READING_NETSTAT__SEGMENTS_RECEIVED)) {
readingInstance = getNetstatSegmentsReceived(systemInfo, reading);
} else if (readingName.equalsIgnoreCase(SystemMonitorDefinitions.READING_NETSTAT__SEGMENTS_SENT)) {
readingInstance = getNetstatSegmentsSent(systemInfo, reading);
} else if (readingName.equalsIgnoreCase(SystemMonitorDefinitions.READING_NETSTAT__SEGMENTS_RETRANSMITTED)) {
readingInstance = getNetstatSegmentsRetransmitter(systemInfo, reading);
} else if (readingName.equalsIgnoreCase(SystemMonitorDefinitions.READING_NETSTAT__OUT_RESETS)) {
readingInstance = getNetstatOutResets(systemInfo, reading);
} else if (readingName.equalsIgnoreCase(SystemMonitorDefinitions.READING_NETSTAT__IN_ERRORS)) {
readingInstance = getNetstatInErrors(systemInfo, reading);
} else if (readingName.equalsIgnoreCase(SystemMonitorDefinitions.READING_TCP__CLOSE)) {
readingInstance = getTcpClose(systemInfo, reading);
} else if (readingName.equalsIgnoreCase(SystemMonitorDefinitions.READING_TCP__LISTEN)) {
readingInstance = getTcpListen(systemInfo, reading);
} else if (readingName.equalsIgnoreCase(SystemMonitorDefinitions.READING_TCP__SYN_SENT)) {
readingInstance = getTcpSynSent(systemInfo, reading);
} else if (readingName.equalsIgnoreCase(SystemMonitorDefinitions.READING_TCP__SYN_RECEIVED)) {
readingInstance = getTcpSynReceived(systemInfo, reading);
} else if (readingName.equalsIgnoreCase(SystemMonitorDefinitions.READING_TCP__ESTABLISHED)) {
readingInstance = getTcpEstablished(systemInfo, reading);
} else if (readingName.equalsIgnoreCase(SystemMonitorDefinitions.READING_TCP__CLOSE_WAIT)) {
readingInstance = getTcpCloseWait(systemInfo, reading);
} else if (readingName.equalsIgnoreCase(SystemMonitorDefinitions.READING_TCP__LAST_ACK)) {
readingInstance = getTcpLastAck(systemInfo, reading);
} else if (readingName.equalsIgnoreCase(SystemMonitorDefinitions.READING_TCP__FIN_WAIT1)) {
readingInstance = getTcpFinWait1(systemInfo, reading);
} else if (readingName.equalsIgnoreCase(SystemMonitorDefinitions.READING_TCP__FIN_WAIT2)) {
readingInstance = getTcpFinWait2(systemInfo, reading);
} else if (readingName.equalsIgnoreCase(SystemMonitorDefinitions.READING_TCP__CLOSING)) {
readingInstance = getTcpClosing(systemInfo, reading);
} else if (readingName.equalsIgnoreCase(SystemMonitorDefinitions.READING_TCP__TIME_WAIT)) {
readingInstance = getTcpTimeWait(systemInfo, reading);
} else if (readingName.equalsIgnoreCase(SystemMonitorDefinitions.READING_TCP__BOUND)) {
readingInstance = getTcpBound(systemInfo, reading);
} else if (readingName.equalsIgnoreCase(SystemMonitorDefinitions.READING_TCP__IDLE)) {
readingInstance = getTcpIdle(systemInfo, reading);
} else if (readingName.equalsIgnoreCase(SystemMonitorDefinitions.READING_TCP__TOTAL_INBOUND)) {
readingInstance = getTcpTotalInbound(systemInfo, reading);
} else if (readingName.equalsIgnoreCase(SystemMonitorDefinitions.READING_TCP__TOTAL_OUTBOUND)) {
readingInstance = getTcpTotalOutbound(systemInfo, reading);
} else {
throw new UnsupportedReadingException(readingName);
}
if (readingInstance != null) {
readingInstances.add(readingInstance);
}
}
return readingInstances;
}
use of com.axway.ats.common.performance.monitor.beans.ReadingBean in project ats-framework by Axway.
the class MatchedProcess method updateProcessesMatchingMap.
private static List<ReadingInstance> updateProcessesMatchingMap(ISystemInformation systemInfo, List<ReadingBean> initialProcessReadings, List<ReadingInstance> currentReadingInstances) throws SystemInformationException {
// remember to user process regex and alias
Map<String, Pattern> processPatterns = new HashMap<String, Pattern>();
Map<String, String> processAliases = new HashMap<String, String>();
Map<String, String> processUsernames = new HashMap<String, String>();
for (ReadingBean processReading : initialProcessReadings) {
String userRegex = processReading.getParameter(SystemMonitorDefinitions.PARAMETER_NAME__PROCESS_RECOGNITION_PATTERN);
Pattern compiledPattern = Pattern.compile(userRegex);
processPatterns.put(userRegex, compiledPattern);
String userProcessAlias = processReading.getParameter(SystemMonitorDefinitions.PARAMETER_NAME__PROCESS_ALIAS);
processAliases.put(userRegex, userProcessAlias);
String processUsername = processReading.getParameter(SystemMonitorDefinitions.PARAMETER_NAME__PROCESS_USERNAME);
processUsernames.put(userRegex, processUsername);
}
// at the end only processes that are not alive will be in this list
Set<Long> finishedProcessesIds = new HashSet<Long>(matchedProcessesIds);
// iterate all system processes and remember the ones we want to monitor
for (long pid : systemInfo.getProcList()) {
// check if we know this process from a previous poll, we do not want to add it again
if (!matchedProcessesIds.contains(pid)) {
// we try to match a process by its start command
String processStartCommand = constructProcessStartCommand(systemInfo, pid);
if (processStartCommand != null && !processStartCommand.isEmpty()) {
String processUsername = null;
// check this process against all patterns
for (String userRegex : processPatterns.keySet()) {
// by default we search processes from all users
boolean isExpectedProcessUsername = true;
// check if it matters who started this process
String requestedProcessUsername = processUsernames.get(userRegex);
if (!StringUtils.isNullOrEmpty(requestedProcessUsername)) {
if (processUsername == null) {
// we still do not know the user of this process
try {
processUsername = systemInfo.getProcessInformation(pid).getUser();
} catch (Exception e) {
// SystemInformationException was here before
// a specific username is required, but we can not get the info about this process
isExpectedProcessUsername = false;
}
}
isExpectedProcessUsername = requestedProcessUsername.equalsIgnoreCase(processUsername);
}
if (isExpectedProcessUsername) {
Pattern processPattern = processPatterns.get(userRegex);
if (processPattern.matcher(processStartCommand.trim()).matches()) {
Map<Long, MatchedProcess> processesMatchedThisRegex = matchedProcessesMap.get(userRegex);
if (processesMatchedThisRegex == null) {
processesMatchedThisRegex = new HashMap<Long, MatchedProcess>();
}
int processIndexForThisPattern = getNextIndexForThisProcessPattern(userRegex);
MatchedProcess matchedProcess = new MatchedProcess(pid, userRegex, processAliases.get(userRegex), processIndexForThisPattern, processStartCommand);
processesMatchedThisRegex.put(pid, matchedProcess);
matchedProcessesMap.put(userRegex, processesMatchedThisRegex);
matchedProcessesIds.add(pid);
log.info("We will monitor process: " + matchedProcess.toString());
}
}
}
}
} else {
// the process is still alive
finishedProcessesIds.remove(pid);
}
}
// check if some processes have died, we do not want to monitor them anymore
for (Long finishedProcessId : finishedProcessesIds) {
// cleanup the maps
matchedProcessesIds.remove(finishedProcessId);
for (Map<Long, MatchedProcess> matchedProcessMap : matchedProcessesMap.values()) {
MatchedProcess removedProcess = matchedProcessMap.remove(finishedProcessId);
if (removedProcess != null) {
log.info("This process is no more alive: " + removedProcess.toString());
}
}
Iterator<String> it = processesReadingInstanceIdentifiers.iterator();
while (it.hasNext()) {
String processesReadingInstanceIdentifier = it.next();
if (Long.parseLong(processesReadingInstanceIdentifier.split("->")[1]) == finishedProcessId) {
it.remove();
}
}
}
// return the updated list of reading instances we poll
List<ReadingInstance> newReadingInstances = new ArrayList<ReadingInstance>();
for (ReadingInstance currentReadingInstance : currentReadingInstances) {
boolean stillActiveInstance = true;
for (Long finishedProcessId : finishedProcessesIds) {
if (finishedProcessId == currentReadingInstance.getPid()) {
stillActiveInstance = false;
break;
}
}
if (stillActiveInstance) {
newReadingInstances.add(currentReadingInstance);
}
}
return newReadingInstances;
}
use of com.axway.ats.common.performance.monitor.beans.ReadingBean in project ats-framework by Axway.
the class ReadingsRepository method extractReading.
/**
* Extracts all the data for a given monitor by iterating over it's filters
*
* @param readingLevelElement the root element of the tree
* @throws MonitorConfigurationException
*/
private void extractReading(Element readingLevelElement, String monitorClass) throws MonitorConfigurationException {
String readingName = extractAttribute(readingLevelElement, READING_NODE__NAME);
if (readingName == null) {
this.readingParseState.throwException("No reading name specified");
}
this.readingParseState.rememberReadingName(readingName);
String readingUnit = extractAttribute(readingLevelElement, READING_NODE__UNIT);
if (readingUnit == null) {
this.readingParseState.throwException("No reading unit specified");
}
boolean dynamicReadingValue = false;
String dynamicReading = extractAttribute(readingLevelElement, READING_NODE__DYNAMIC);
if (dynamicReading != null && "true".equals(dynamicReading.trim())) {
dynamicReadingValue = true;
}
ReadingBean readingBean = new ReadingBean(monitorClass, readingName, readingUnit);
readingBean.setDynamicReading(dynamicReadingValue);
this.xmlRepository.addReading(readingName, readingBean);
// inform the user what we got
log.debug(readingBean.getDescription());
this.readingParseState.forgetReadingName();
}
use of com.axway.ats.common.performance.monitor.beans.ReadingBean in project ats-framework by Axway.
the class AgentSystemMonitor method initializeMonitoring.
public void initializeMonitoring(List<ReadingBean> readings, int pollInterval, long executorTimeOffset) {
monitoringAgent = new AtsSystemMonitoringAgent(pollInterval, executorTimeOffset);
if (pollInterval < 1) {
throw new MonitoringException("The interval for collecting statistical data must be at least 1 second. You have specified " + pollInterval + " seconds");
}
Map<String, List<ReadingBean>> readingsPerMonitor = new HashMap<String, List<ReadingBean>>();
// load all the monitors and initialize them
for (ReadingBean reading : readings) {
List<ReadingBean> readingsForThisMonitor = readingsPerMonitor.get(reading.getMonitorName());
if (readingsForThisMonitor == null) {
readingsForThisMonitor = new ArrayList<ReadingBean>();
readingsPerMonitor.put(reading.getMonitorName(), readingsForThisMonitor);
}
readingsForThisMonitor.add(reading);
}
for (String monitorClassName : readingsPerMonitor.keySet()) {
initializeMonitor(monitorClassName, readingsPerMonitor.get(monitorClassName), pollInterval);
}
}
use of com.axway.ats.common.performance.monitor.beans.ReadingBean in project ats-framework by Axway.
the class UserActivityLoggingUtils method parseReadings.
private static Map<Long, Map<String, Integer>> parseReadings(String monitoredAgent, MonitorResults newMonitorResults) {
// counter for user info
int resultsRead = 0;
// create a map, to store the parsed user activity statistics
Map<Long, Map<String, Integer>> readyToBeloggedReadingsMap = new HashMap<>();
// assign DB IDs to these readings if needed
List<ReadingBean> newReadings = newMonitorResults.getReadings();
updateDatabaseRepository(monitoredAgent, newReadings);
// Map<reading ID, reading value>
Map<String, Integer> readingsMap = new HashMap<String, Integer>();
for (ReadingBean newReading : newReadings) {
readingsMap.put(String.valueOf(newReading.getDbId()), Integer.valueOf(newReading.getValue()));
resultsRead++;
}
readyToBeloggedReadingsMap.put(newMonitorResults.getTimestamp(), readingsMap);
dbLog.debug("Successfully read " + resultsRead + " user activity results from " + monitoredAgent);
return readyToBeloggedReadingsMap;
}
Aggregations