use of com.axway.ats.agent.core.monitoring.systemmonitor.systeminformation.exceptions.SystemInformationException in project ats-framework by Axway.
the class MatchedProcess method getProcessCpuUsageRunningTotal.
private static List<ReadingInstance> getProcessCpuUsageRunningTotal(ISystemInformation systemInfo, ReadingBean reading, ParentProcessReadingBean parentProcess) throws SystemInformationException {
String readingProcessPattern = reading.getParameter(SystemMonitorDefinitions.PARAMETER_NAME__PROCESS_RECOGNITION_PATTERN);
// we can match more than 1 process
List<ReadingInstance> readingInstancesList = new ArrayList<ReadingInstance>();
// iterate all processes in the map
Map<Long, MatchedProcess> processesForThisPattern = matchedProcessesMap.get(readingProcessPattern);
if (processesForThisPattern != null) {
for (final MatchedProcess processInfo : processesForThisPattern.values()) {
// check if we are not already measuring this reading for this process
String processesReadingInstanceIdentifier = reading.getName() + "->" + processInfo.getPid();
if (!processesReadingInstanceIdentifiers.contains(processesReadingInstanceIdentifier)) {
processesReadingInstanceIdentifiers.add(processesReadingInstanceIdentifier);
// create a new reading for this process
Map<String, String> parameters = constructProcessParametersMap(processInfo, readingProcessPattern, "3");
readingInstancesList.add(new ReadingInstance(systemInfo, parentProcess, String.valueOf(reading.getDbId()), processInfo.getPid(), reading.getMonitorName(), "[process] " + processInfo.getAlias() + " - CPU usage - Total", reading.getUnit(), parameters, 1.0F) {
private static final long serialVersionUID = 1L;
@Override
public void init() throws SystemInformationException {
this.lastLongValue = fixLongValue(fixOverflow(getName(), systemInfo.getProcessCpuTimeRunningTotal(processInfo.getPid()), ReadingInstance.CPU_PROCESS_OVERFLOW_VALUE));
}
@Override
public float poll() throws SystemInformationException {
long totalTime = fixLongValue(fixOverflow(getName(), systemInfo.getProcessCpuTimeRunningTotal(processInfo.getPid()), ReadingInstance.CPU_PROCESS_OVERFLOW_VALUE));
double deltaTotalTime;
if (totalTime > 0) {
deltaTotalTime = (totalTime - this.lastLongValue) / numberOfCPUs;
this.lastLongValue = totalTime;
} else {
return -1;
}
float deltaTotalPercentUsage = 0.0F;
long elapsedTime = getElapsedTime();
// moment of creating the ReadingInstance, it is normal for new processes
if (elapsedTime > 900) {
// calculate total code time for 1ms
deltaTotalTime = deltaTotalTime / elapsedTime;
// convert to percentage usage
deltaTotalPercentUsage = new BigDecimal(deltaTotalTime).setScale(2, BigDecimal.ROUND_DOWN).floatValue() * 100.0F;
}
addValueToParentProcess(deltaTotalPercentUsage);
return deltaTotalPercentUsage;
}
});
}
}
}
return readingInstancesList;
}
use of com.axway.ats.agent.core.monitoring.systemmonitor.systeminformation.exceptions.SystemInformationException in project ats-framework by Axway.
the class MatchedProcess method getProcessCpuUsageRunningUser.
private static List<ReadingInstance> getProcessCpuUsageRunningUser(ISystemInformation systemInfo, ReadingBean reading, ParentProcessReadingBean parentProcess) throws SystemInformationException {
String readingProcessPattern = reading.getParameter(SystemMonitorDefinitions.PARAMETER_NAME__PROCESS_RECOGNITION_PATTERN);
// we can match more than 1 process
List<ReadingInstance> readingInstancesList = new ArrayList<ReadingInstance>();
// iterate all processes in the map
Map<Long, MatchedProcess> processesForThisPattern = matchedProcessesMap.get(readingProcessPattern);
if (processesForThisPattern != null) {
for (final MatchedProcess processInfo : processesForThisPattern.values()) {
// check if we are not already measuring this reading for this process
String processesReadingInstanceIdentifier = reading.getName() + "->" + processInfo.getPid();
if (!processesReadingInstanceIdentifiers.contains(processesReadingInstanceIdentifier)) {
processesReadingInstanceIdentifiers.add(processesReadingInstanceIdentifier);
// create a new reading for this process
Map<String, String> parameters = constructProcessParametersMap(processInfo, readingProcessPattern, "1");
readingInstancesList.add(new ReadingInstance(systemInfo, parentProcess, String.valueOf(reading.getDbId()), processInfo.getPid(), reading.getMonitorName(), "[process] " + processInfo.getAlias() + " - CPU usage - User", reading.getUnit(), parameters, 1.0F) {
private static final long serialVersionUID = 1L;
@Override
public void init() throws SystemInformationException {
this.lastLongValue = fixLongValue(fixOverflow(getName(), systemInfo.getProcessCpuTimeRunningUser(processInfo.getPid()), ReadingInstance.CPU_PROCESS_OVERFLOW_VALUE));
}
@Override
public float poll() throws SystemInformationException {
long userTime = fixLongValue(fixOverflow(getName(), systemInfo.getProcessCpuTimeRunningUser(processInfo.getPid()), ReadingInstance.CPU_PROCESS_OVERFLOW_VALUE));
double deltaUserTime;
if (userTime > 0) {
deltaUserTime = (userTime - this.lastLongValue) / numberOfCPUs;
this.lastLongValue = userTime;
} else {
return -1;
}
float deltaUserPercentUsage = 0.0F;
long elapsedTime = getElapsedTime();
// moment of creating the ReadingInstance, it is normal for new processes
if (elapsedTime > 900) {
// calculate user code time for 1ms
deltaUserTime = deltaUserTime / elapsedTime;
// convert to percentage usage
deltaUserPercentUsage = new BigDecimal(deltaUserTime).setScale(2, BigDecimal.ROUND_DOWN).floatValue() * 100.0F;
}
addValueToParentProcess(deltaUserPercentUsage);
return deltaUserPercentUsage;
}
});
}
}
}
return readingInstancesList;
}
use of com.axway.ats.agent.core.monitoring.systemmonitor.systeminformation.exceptions.SystemInformationException in project ats-framework by Axway.
the class OshiSystemInformation method getFileSystem.
@Override
public IFileSystem getFileSystem(String devName) {
try {
FileSystem fs = this.os.getFileSystem();
List<OSFileStore> fileStores = fs.getFileStores();
for (OSFileStore fileStore : fileStores) {
if (fileStore.getName().equals(devName)) {
return new OshiFileSystem(fileStore, fileStore.getName());
}
}
throw new SystemInformationException("No such file system drive device '" + devName + "'");
} catch (Exception e) {
throw new SystemInformationException("Could not obtain file system for/from device '" + devName + "'", e);
}
}
Aggregations