Search in sources :

Example 6 with SystemInformationException

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;
}
Also used : ArrayList(java.util.ArrayList) BigDecimal(java.math.BigDecimal) SystemInformationException(com.axway.ats.agent.core.monitoring.systemmonitor.systeminformation.exceptions.SystemInformationException)

Example 7 with SystemInformationException

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;
}
Also used : ArrayList(java.util.ArrayList) BigDecimal(java.math.BigDecimal) SystemInformationException(com.axway.ats.agent.core.monitoring.systemmonitor.systeminformation.exceptions.SystemInformationException)

Example 8 with SystemInformationException

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);
    }
}
Also used : OSFileStore(oshi.software.os.OSFileStore) FileSystem(oshi.software.os.FileSystem) IFileSystem(com.axway.ats.agent.core.monitoring.systemmonitor.systeminformation.IFileSystem) SystemInformationException(com.axway.ats.agent.core.monitoring.systemmonitor.systeminformation.exceptions.SystemInformationException) SystemInformationException(com.axway.ats.agent.core.monitoring.systemmonitor.systeminformation.exceptions.SystemInformationException)

Aggregations

SystemInformationException (com.axway.ats.agent.core.monitoring.systemmonitor.systeminformation.exceptions.SystemInformationException)8 ArrayList (java.util.ArrayList)6 BigDecimal (java.math.BigDecimal)4 ParentProcessReadingBean (com.axway.ats.common.performance.monitor.beans.ParentProcessReadingBean)2 ReadingBean (com.axway.ats.common.performance.monitor.beans.ReadingBean)2 HashSet (java.util.HashSet)2 IFileSystem (com.axway.ats.agent.core.monitoring.systemmonitor.systeminformation.IFileSystem)1 INetworkInterfaceStat (com.axway.ats.agent.core.monitoring.systemmonitor.systeminformation.INetworkInterfaceStat)1 ISystemInformation (com.axway.ats.agent.core.monitoring.systemmonitor.systeminformation.ISystemInformation)1 UnsupportedReadingException (com.axway.ats.core.monitoring.UnsupportedReadingException)1 HashMap (java.util.HashMap)1 Pattern (java.util.regex.Pattern)1 FileSystem (oshi.software.os.FileSystem)1 OSFileStore (oshi.software.os.OSFileStore)1