Search in sources :

Example 1 with JmxInstance

use of com.haulmont.cuba.core.entity.JmxInstance in project cuba by cuba-platform.

the class ServerLogWindow method downloadLog.

public void downloadLog() {
    final String fileName = logFileNameField.getValue();
    if (fileName != null) {
        try {
            final JmxInstance selectedConnection = getSelectedConnection();
            // check if we have many suitable JmxControlBean instances
            // show dialog with context select and size options if needed
            List<String> availableContexts = jmxRemoteLoggingAPI.getAvailableContexts(selectedConnection);
            long size = jmxRemoteLoggingAPI.getLogFileSize(selectedConnection, fileName);
            if (size <= LogArchiver.LOG_TAIL_FOR_PACKING_SIZE && availableContexts.size() == 1) {
                LogDataProvider dataProvider = new LogDataProvider(selectedConnection, fileName, availableContexts.get(0), false);
                dataProvider.obtainUrl();
                ExportDisplay exportDisplay = AppConfig.createExportDisplay(this);
                exportDisplay.show(dataProvider, fileName + ".zip");
            } else {
                openWindow("serverLogDownloadOptionsDialog", OpenType.DIALOG, ParamsMap.of("logFileName", fileName, "connection", selectedConnection, "logFileSize", size, "remoteContextList", availableContexts));
            }
        } catch (RuntimeException | LogControlException e) {
            showNotification(getMessage("exception.logControl"), NotificationType.ERROR);
            log.error("Error downloading log", e);
        }
    } else {
        showNotification(getMessage("log.notSelected"), NotificationType.HUMANIZED);
    }
}
Also used : ExportDisplay(com.haulmont.cuba.gui.export.ExportDisplay) LogControlException(com.haulmont.cuba.core.sys.logging.LogControlException) JmxInstance(com.haulmont.cuba.core.entity.JmxInstance) LogDataProvider(com.haulmont.cuba.web.export.LogDataProvider)

Example 2 with JmxInstance

use of com.haulmont.cuba.core.entity.JmxInstance in project cuba by cuba-platform.

the class ThreadsDatasource method loadData.

@Override
protected void loadData(Map<String, Object> params) {
    JmxInstance node = (JmxInstance) params.get("node");
    ManagedBeanInfo threadingBean = jmxControlAPI.getManagedBean(node, "java.lang:type=Threading");
    int nCPUs = (int) getAttributeValue(node, "java.lang:type=OperatingSystem", "AvailableProcessors");
    final long[] allThreadsIds = (long[]) getAttributeValue(node, "java.lang:type=Threading", "AllThreadIds");
    ManagedBeanOperation getThreadInfo = jmxControlAPI.getOperation(threadingBean, "getThreadInfo", new String[] { "[J" });
    CompositeData[] threadsInfo = (CompositeData[]) jmxControlAPI.invokeOperation(getThreadInfo, new Object[] { allThreadsIds });
    final long currentUptime = (long) getAttributeValue(node, "java.lang:type=Runtime", "Uptime");
    ManagedBeanOperation getThreadCpuTime = jmxControlAPI.getOperation(threadingBean, "getThreadCpuTime", new String[] { "[J" });
    long[] threadCpuTime = (long[]) jmxControlAPI.invokeOperation(getThreadCpuTime, new Object[] { allThreadsIds });
    if (prevUptime > 0L && currentUptime > prevUptime) {
        // elapsedTime is in ms
        long elapsedTime = currentUptime - prevUptime;
        for (int i = 0; i < allThreadsIds.length; i++) {
            // elapsedCpu is in ns
            Long threadId = allThreadsIds[i];
            // for new threads returns null.
            Long prevCpuTimeLong = prevThread2CpuTime.get(threadId);
            long prevCpuTime = prevCpuTimeLong != null ? prevCpuTimeLong : 0L;
            long elapsedCpu = threadCpuTime[i] - prevCpuTime;
            // cpuUsage could go higher than 100% because elapsedTime
            // and elapsedCpu are not fetched simultaneously. Limit to 99%.
            double cpuUsage = Math.min(99d, elapsedCpu / (elapsedTime * 1000000d / /*convert to ns*/
            100 * /*percents*/
            nCPUs));
            getThreadSnapshot(threadId).setCpu(cpuUsage);
        }
    }
    prevUptime = currentUptime;
    for (int i = 0; i < allThreadsIds.length; i++) {
        long time = threadCpuTime[i] != -1L ? threadCpuTime[i] : 0L;
        prevThread2CpuTime.put(allThreadsIds[i], time);
    }
    ManagedBeanOperation findDeadlockedThreads = jmxControlAPI.getOperation(threadingBean, "findDeadlockedThreads", null);
    Long[] deadlockedThreads = (Long[]) jmxControlAPI.invokeOperation(findDeadlockedThreads, null);
    Set<Long> deadLockedThreadsSet = new HashSet<>();
    if (deadlockedThreads != null) {
        CollectionUtils.addAll(deadLockedThreadsSet, deadlockedThreads);
    }
    Set<Long> allThreadsSet = new HashSet<>();
    CollectionUtils.addAll(allThreadsSet, ArrayUtils.toObject(allThreadsIds));
    // remove all terminated threads.
    Collection<ThreadSnapshot> toRemove = new LinkedList<>();
    for (ThreadSnapshot snapshot : getItems()) {
        if (!allThreadsSet.contains(snapshot.getThreadId())) {
            toRemove.add(snapshot);
        }
    }
    for (ThreadSnapshot snapshot : toRemove) {
        removeItem(snapshot);
    }
    // update visual data.
    for (int i = 0; i < threadsInfo.length; i++) {
        CompositeData info = threadsInfo[i];
        if (info != null) {
            Long threadId = (Long) info.get("threadId");
            ThreadSnapshot item = getThreadSnapshot(threadId);
            item.setName((String) info.get("threadName"));
            item.setStatus(info.get("threadState").toString());
            item.setDeadLocked(deadLockedThreadsSet.contains(threadId));
        } else {
            // no thread info available.
            removeItem(getThreadSnapshot(allThreadsIds[i]));
        }
    }
}
Also used : CompositeData(javax.management.openmbean.CompositeData) ManagedBeanInfo(com.haulmont.cuba.web.jmx.entity.ManagedBeanInfo) JmxInstance(com.haulmont.cuba.core.entity.JmxInstance) ManagedBeanOperation(com.haulmont.cuba.web.jmx.entity.ManagedBeanOperation)

Example 3 with JmxInstance

use of com.haulmont.cuba.core.entity.JmxInstance in project cuba by cuba-platform.

the class ThreadsMonitoringWindow method init.

@Override
public void init(Map<String, Object> params) {
    threadsDs.refresh(params);
    threadsDs.addItemChangeListener(e -> updateStacktrace(e.getItem()));
    JmxInstance node = (JmxInstance) params.get("node");
    setCaption(formatMessage("threadsMonitoring.caption", node.getNodeName()));
    threadsTable.getColumn("cpu").setFormatter(new PercentFormatter());
}
Also used : JmxInstance(com.haulmont.cuba.core.entity.JmxInstance)

Example 4 with JmxInstance

use of com.haulmont.cuba.core.entity.JmxInstance in project cuba by cuba-platform.

the class JmxControlBean method getInstances.

@SuppressWarnings("unchecked")
@Override
public List<JmxInstance> getInstances() {
    LoadContext loadContext = new LoadContext(JmxInstance.class);
    loadContext.setView(View.LOCAL);
    loadContext.setQueryString("select jmx from sys$JmxInstance jmx");
    List<JmxInstance> clusterInstances = dataService.loadList(loadContext);
    List<JmxInstance> jmxInstances = new ArrayList<>(clusterInstances.size() + 1);
    jmxInstances.add(getLocalInstance());
    jmxInstances.addAll(clusterInstances);
    return jmxInstances;
}
Also used : LoadContext(com.haulmont.cuba.core.global.LoadContext) JmxInstance(com.haulmont.cuba.core.entity.JmxInstance)

Example 5 with JmxInstance

use of com.haulmont.cuba.core.entity.JmxInstance in project cuba by cuba-platform.

the class JmxControlBean method getLocalInstance.

@Override
public JmxInstance getLocalInstance() {
    JmxInstance localJmxInstance = metadata.create(JmxInstance.class);
    localJmxInstance.setId(JmxConnectionHelper.LOCAL_JMX_INSTANCE_ID);
    localJmxInstance.setNodeName(getLocalNodeName());
    return localJmxInstance;
}
Also used : JmxInstance(com.haulmont.cuba.core.entity.JmxInstance)

Aggregations

JmxInstance (com.haulmont.cuba.core.entity.JmxInstance)11 ParamsMap (com.haulmont.bali.util.ParamsMap)3 Metadata (com.haulmont.cuba.core.global.Metadata)3 OpenType (com.haulmont.cuba.gui.WindowManager.OpenType)3 com.haulmont.cuba.gui.components (com.haulmont.cuba.gui.components)3 BaseAction (com.haulmont.cuba.gui.components.actions.BaseAction)3 CollectionDatasource (com.haulmont.cuba.gui.data.CollectionDatasource)3 JmxInstanceEditor (com.haulmont.cuba.web.app.ui.jmxinstance.edit.JmxInstanceEditor)3 JmxControlAPI (com.haulmont.cuba.web.jmx.JmxControlAPI)3 JmxControlException (com.haulmont.cuba.web.jmx.JmxControlException)3 ManagedBeanInfo (com.haulmont.cuba.web.jmx.entity.ManagedBeanInfo)3 Inject (javax.inject.Inject)3 LogControlException (com.haulmont.cuba.core.sys.logging.LogControlException)2 ExportDisplay (com.haulmont.cuba.gui.export.ExportDisplay)2 LogDataProvider (com.haulmont.cuba.web.export.LogDataProvider)2 ManagedBeanOperation (com.haulmont.cuba.web.jmx.entity.ManagedBeanOperation)2 Map (java.util.Map)2 UUID (java.util.UUID)2 StringUtils (org.apache.commons.lang.StringUtils)2 Level (ch.qos.logback.classic.Level)1