Search in sources :

Example 1 with ManagedBeanInfo

use of com.haulmont.cuba.web.jmx.entity.ManagedBeanInfo in project cuba by cuba-platform.

the class ManagedBeanInfoDatasource method loadManagedBeans.

private List<ManagedBeanInfo> loadManagedBeans(Map<String, Object> params) {
    List<ManagedBeanInfo> managedBeans = jmxControlAPI.getManagedBeans(jmxInstance);
    List<ManagedBeanInfo> res = new ArrayList<>();
    // filter by object name
    String objectName = (String) params.get("objectName");
    if (objectName != null) {
        objectName = objectName.toLowerCase();
        for (ManagedBeanInfo mbi : managedBeans) {
            if (mbi.getObjectName() != null && mbi.getObjectName().toLowerCase().contains(objectName)) {
                res.add(mbi);
            }
        }
        return res;
    }
    return managedBeans;
}
Also used : ManagedBeanInfo(com.haulmont.cuba.web.jmx.entity.ManagedBeanInfo)

Example 2 with ManagedBeanInfo

use of com.haulmont.cuba.web.jmx.entity.ManagedBeanInfo in project cuba by cuba-platform.

the class ManagedBeanInfoDatasource method loadTree.

@Override
protected Tree<ManagedBeanInfo> loadTree(Map<String, Object> params) {
    String tag = getLoggingTag("TDS");
    StopWatch sw = new Slf4JStopWatch(tag, LoggerFactory.getLogger(UIPerformanceLogger.class));
    List<Node<ManagedBeanInfo>> nodes = new ArrayList<>();
    if (jmxInstance != null) {
        List<ManagedBeanDomain> domains = jmxControlAPI.getDomains(jmxInstance);
        Map<String, Node<ManagedBeanInfo>> domainMap = new HashMap<>();
        for (ManagedBeanDomain mbd : domains) {
            ManagedBeanInfo dummy = metadata.create(ManagedBeanInfo.class);
            dummy.setDomain(mbd.getName());
            Node<ManagedBeanInfo> node = new Node<>(dummy);
            domainMap.put(mbd.getName(), node);
            nodes.add(node);
        }
        List<ManagedBeanInfo> list = loadManagedBeans(params);
        for (ManagedBeanInfo mbi : list) {
            if (mbi != null) {
                if (domainMap.containsKey(mbi.getDomain())) {
                    domainMap.get(mbi.getDomain()).addChild(new Node<>(mbi));
                }
            }
        }
        // remove root nodes that might have left without children after filtering
        for (Node<ManagedBeanInfo> rootNode : new ArrayList<>(nodes)) {
            if (rootNode.getChildren().isEmpty()) {
                nodes.remove(rootNode);
            }
        }
    }
    sw.stop();
    return new Tree<>(nodes);
}
Also used : Slf4JStopWatch(org.perf4j.slf4j.Slf4JStopWatch) UIPerformanceLogger(com.haulmont.cuba.gui.logging.UIPerformanceLogger) Node(com.haulmont.bali.datastruct.Node) ManagedBeanInfo(com.haulmont.cuba.web.jmx.entity.ManagedBeanInfo) ManagedBeanDomain(com.haulmont.cuba.web.jmx.entity.ManagedBeanDomain) Slf4JStopWatch(org.perf4j.slf4j.Slf4JStopWatch) StopWatch(org.perf4j.StopWatch) Tree(com.haulmont.bali.datastruct.Tree)

Example 3 with ManagedBeanInfo

use of com.haulmont.cuba.web.jmx.entity.ManagedBeanInfo in project cuba by cuba-platform.

the class StatisticsDatasource method findAttribute.

@Nullable
protected ManagedBeanAttribute findAttribute(String beanObjectName, String attrName) {
    ManagedBeanAttribute res = name2attr.get(attrName);
    if (res == NOT_FOUND_ATTR)
        return null;
    if (res == null) {
        ManagedBeanInfo bean = jmxControlAPI.getManagedBean(node, beanObjectName);
        if (bean != null) {
            res = jmxControlAPI.loadAttribute(bean, attrName);
        }
        name2attr.put(attrName, res == null ? NOT_FOUND_ATTR : res);
    }
    if (res != null)
        jmxControlAPI.loadAttributeValue(res);
    return res;
}
Also used : ManagedBeanAttribute(com.haulmont.cuba.web.jmx.entity.ManagedBeanAttribute) ManagedBeanInfo(com.haulmont.cuba.web.jmx.entity.ManagedBeanInfo) Nullable(javax.annotation.Nullable)

Example 4 with ManagedBeanInfo

use of com.haulmont.cuba.web.jmx.entity.ManagedBeanInfo 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 5 with ManagedBeanInfo

use of com.haulmont.cuba.web.jmx.entity.ManagedBeanInfo in project cuba by cuba-platform.

the class ThreadsDatasource method getAttributeValue.

protected Object getAttributeValue(JmxInstance node, String beanObjectName, String attrName) {
    ManagedBeanInfo bean = jmxControlAPI.getManagedBean(node, beanObjectName);
    Object res = null;
    if (bean != null) {
        ManagedBeanAttribute attr = jmxControlAPI.loadAttribute(bean, attrName);
        jmxControlAPI.loadAttributeValue(attr);
        res = attr.getValue();
    }
    return res;
}
Also used : ManagedBeanAttribute(com.haulmont.cuba.web.jmx.entity.ManagedBeanAttribute) ManagedBeanInfo(com.haulmont.cuba.web.jmx.entity.ManagedBeanInfo)

Aggregations

ManagedBeanInfo (com.haulmont.cuba.web.jmx.entity.ManagedBeanInfo)8 JmxInstance (com.haulmont.cuba.core.entity.JmxInstance)3 ManagedBeanAttribute (com.haulmont.cuba.web.jmx.entity.ManagedBeanAttribute)3 JmxControlException (com.haulmont.cuba.web.jmx.JmxControlException)2 ManagedBeanOperation (com.haulmont.cuba.web.jmx.entity.ManagedBeanOperation)2 CompositeData (javax.management.openmbean.CompositeData)2 Node (com.haulmont.bali.datastruct.Node)1 Tree (com.haulmont.bali.datastruct.Tree)1 ParamsMap (com.haulmont.bali.util.ParamsMap)1 Metadata (com.haulmont.cuba.core.global.Metadata)1 OpenType (com.haulmont.cuba.gui.WindowManager.OpenType)1 com.haulmont.cuba.gui.components (com.haulmont.cuba.gui.components)1 BaseAction (com.haulmont.cuba.gui.components.actions.BaseAction)1 ItemTrackingAction (com.haulmont.cuba.gui.components.actions.ItemTrackingAction)1 RefreshAction (com.haulmont.cuba.gui.components.actions.RefreshAction)1 CollectionDatasource (com.haulmont.cuba.gui.data.CollectionDatasource)1 Datasource (com.haulmont.cuba.gui.data.Datasource)1 UIPerformanceLogger (com.haulmont.cuba.gui.logging.UIPerformanceLogger)1 ManagedBeanInfoDatasource (com.haulmont.cuba.web.app.ui.jmxcontrol.ds.ManagedBeanInfoDatasource)1 JmxInstanceEditor (com.haulmont.cuba.web.app.ui.jmxinstance.edit.JmxInstanceEditor)1