Search in sources :

Example 1 with ThreadView

use of org.olat.admin.sysinfo.model.ThreadView in project openolat by klemens.

the class ThreadInfosManager method updateTimeSeries.

private void updateTimeSeries() {
    ThreadMXBean threadProxy = ManagementFactory.getThreadMXBean();
    RuntimeMXBean runtimeProxy = ManagementFactory.getRuntimeMXBean();
    ThreadInfo[] tis = threadProxy.dumpAllThreads(false, false);
    List<String> currentThreadNames = new ArrayList<String>();
    Set<Long> currentThreadIds = new HashSet<Long>();
    for (ThreadInfo ti : tis) {
        Long threadId = new Long(ti.getThreadId());
        if (threadMap.containsKey(threadId)) {
            ThreadView threadVO = threadMap.get(threadId);
            threadVO.setState(ti.getThreadState());
        } else {
            ThreadView threadVO = new ThreadView();
            threadVO.setId(threadId);
            threadVO.setName(ti.getThreadName());
            threadVO.setState(ti.getThreadState());
            threadMap.put(threadId, threadVO);
        }
        currentThreadIds.add(threadId);
    }
    WorkThreadInformations.currentThreadNames(currentThreadNames);
    for (ThreadView threadVO : threadMap.values()) {
        threadVO.setPrevCpuTime(Math.max(0, threadVO.getCpuTime()));
        threadVO.setCpuTime(Math.max(0, threadProxy.getThreadCpuTime(threadVO.getId())));
    }
    long upTime = runtimeProxy.getUptime();
    if (prevUpTime > 0L && upTime > prevUpTime) {
        // elapsedTime is in ms
        long elapsedTime = upTime - prevUpTime;
        for (ThreadView threadVO : threadMap.values()) {
            // elapsedCpu is in ns
            long elapsedCpu = threadVO.getCpuTime() - threadVO.getPrevCpuTime();
            // cpuUsage could go higher than 100% because elapsedTime
            // and elapsedCpu are not fetched simultaneously. Limit to
            // 99% to avoid Chart showing a scale from 0% to 200%.
            float cpuUsage = Math.min(99f, elapsedCpu / (elapsedTime * 1000000F));
            threadVO.setCpuUsage(cpuUsage);
            threadVO.setCpuUsagePercent(percentFormat.format(cpuUsage));
            if (cpuUsage > 0.8) {
                threadVO.setWarningCounter(threadVO.getWarningCounter() + 1);
                if (threadVO.getWarningCounter() >= 2) {
                    String currentWork = WorkThreadInformations.get(threadVO.getName());
                    if (currentWork == null) {
                        currentWork = "unkown";
                    }
                    log.info("High usage on thread:" + threadVO + " because thread work at: " + currentWork);
                }
            } else {
                threadVO.setWarningCounter(0);
            }
        }
    }
    prevUpTime = upTime;
    // clean-up closed threads
    for (Iterator<Map.Entry<Long, ThreadView>> it = threadMap.entrySet().iterator(); it.hasNext(); ) {
        Map.Entry<Long, ThreadView> entry = it.next();
        if (!currentThreadIds.contains(entry.getKey())) {
            it.remove();
        }
    }
}
Also used : ThreadMXBean(java.lang.management.ThreadMXBean) ArrayList(java.util.ArrayList) RuntimeMXBean(java.lang.management.RuntimeMXBean) ThreadInfo(java.lang.management.ThreadInfo) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Map(java.util.Map) ThreadView(org.olat.admin.sysinfo.model.ThreadView) HashSet(java.util.HashSet)

Example 2 with ThreadView

use of org.olat.admin.sysinfo.model.ThreadView in project OpenOLAT by OpenOLAT.

the class ThreadInfosManager method updateTimeSeries.

private void updateTimeSeries() {
    ThreadMXBean threadProxy = ManagementFactory.getThreadMXBean();
    RuntimeMXBean runtimeProxy = ManagementFactory.getRuntimeMXBean();
    ThreadInfo[] tis = threadProxy.dumpAllThreads(false, false);
    List<String> currentThreadNames = new ArrayList<String>();
    Set<Long> currentThreadIds = new HashSet<Long>();
    for (ThreadInfo ti : tis) {
        Long threadId = new Long(ti.getThreadId());
        if (threadMap.containsKey(threadId)) {
            ThreadView threadVO = threadMap.get(threadId);
            threadVO.setState(ti.getThreadState());
        } else {
            ThreadView threadVO = new ThreadView();
            threadVO.setId(threadId);
            threadVO.setName(ti.getThreadName());
            threadVO.setState(ti.getThreadState());
            threadMap.put(threadId, threadVO);
        }
        currentThreadIds.add(threadId);
    }
    WorkThreadInformations.currentThreadNames(currentThreadNames);
    for (ThreadView threadVO : threadMap.values()) {
        threadVO.setPrevCpuTime(Math.max(0, threadVO.getCpuTime()));
        threadVO.setCpuTime(Math.max(0, threadProxy.getThreadCpuTime(threadVO.getId())));
    }
    long upTime = runtimeProxy.getUptime();
    if (prevUpTime > 0L && upTime > prevUpTime) {
        // elapsedTime is in ms
        long elapsedTime = upTime - prevUpTime;
        for (ThreadView threadVO : threadMap.values()) {
            // elapsedCpu is in ns
            long elapsedCpu = threadVO.getCpuTime() - threadVO.getPrevCpuTime();
            // cpuUsage could go higher than 100% because elapsedTime
            // and elapsedCpu are not fetched simultaneously. Limit to
            // 99% to avoid Chart showing a scale from 0% to 200%.
            float cpuUsage = Math.min(99f, elapsedCpu / (elapsedTime * 1000000F));
            threadVO.setCpuUsage(cpuUsage);
            threadVO.setCpuUsagePercent(percentFormat.format(cpuUsage));
            if (cpuUsage > 0.8) {
                threadVO.setWarningCounter(threadVO.getWarningCounter() + 1);
                if (threadVO.getWarningCounter() >= 2) {
                    String currentWork = WorkThreadInformations.get(threadVO.getName());
                    if (currentWork == null) {
                        currentWork = "unkown";
                    }
                    log.info("High usage on thread:" + threadVO + " because thread work at: " + currentWork);
                }
            } else {
                threadVO.setWarningCounter(0);
            }
        }
    }
    prevUpTime = upTime;
    // clean-up closed threads
    for (Iterator<Map.Entry<Long, ThreadView>> it = threadMap.entrySet().iterator(); it.hasNext(); ) {
        Map.Entry<Long, ThreadView> entry = it.next();
        if (!currentThreadIds.contains(entry.getKey())) {
            it.remove();
        }
    }
}
Also used : ThreadMXBean(java.lang.management.ThreadMXBean) ArrayList(java.util.ArrayList) RuntimeMXBean(java.lang.management.RuntimeMXBean) ThreadInfo(java.lang.management.ThreadInfo) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Map(java.util.Map) ThreadView(org.olat.admin.sysinfo.model.ThreadView) HashSet(java.util.HashSet)

Example 3 with ThreadView

use of org.olat.admin.sysinfo.model.ThreadView in project OpenOLAT by OpenOLAT.

the class ThreadsWebService method getThreadsCpu.

@GET
@Path("cpu")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public synchronized Response getThreadsCpu() {
    List<ThreadView> threadViews = CoreSpringFactory.getImpl(ThreadInfosManager.class).getThreadViews();
    List<ThreadVO> threads = new ArrayList<ThreadVO>(threadViews.size());
    for (ThreadView view : threadViews) {
        threads.add(new ThreadVO(view));
    }
    Collections.sort(threads);
    ThreadVO[] threadVos = threads.toArray(new ThreadVO[threads.size()]);
    ThreadVOes voes = new ThreadVOes();
    voes.setThreads(threadVos);
    voes.setTotalCount(threadVos.length);
    return Response.ok(voes).build();
}
Also used : ThreadVOes(org.olat.restapi.system.vo.ThreadVOes) ThreadInfosManager(org.olat.admin.sysinfo.manager.ThreadInfosManager) ThreadVO(org.olat.restapi.system.vo.ThreadVO) ArrayList(java.util.ArrayList) ThreadView(org.olat.admin.sysinfo.model.ThreadView) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 4 with ThreadView

use of org.olat.admin.sysinfo.model.ThreadView in project openolat by klemens.

the class ThreadsWebService method getThreadsCpu.

@GET
@Path("cpu")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public synchronized Response getThreadsCpu() {
    List<ThreadView> threadViews = CoreSpringFactory.getImpl(ThreadInfosManager.class).getThreadViews();
    List<ThreadVO> threads = new ArrayList<ThreadVO>(threadViews.size());
    for (ThreadView view : threadViews) {
        threads.add(new ThreadVO(view));
    }
    Collections.sort(threads);
    ThreadVO[] threadVos = threads.toArray(new ThreadVO[threads.size()]);
    ThreadVOes voes = new ThreadVOes();
    voes.setThreads(threadVos);
    voes.setTotalCount(threadVos.length);
    return Response.ok(voes).build();
}
Also used : ThreadVOes(org.olat.restapi.system.vo.ThreadVOes) ThreadInfosManager(org.olat.admin.sysinfo.manager.ThreadInfosManager) ThreadVO(org.olat.restapi.system.vo.ThreadVO) ArrayList(java.util.ArrayList) ThreadView(org.olat.admin.sysinfo.model.ThreadView) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Aggregations

ArrayList (java.util.ArrayList)4 ThreadView (org.olat.admin.sysinfo.model.ThreadView)4 RuntimeMXBean (java.lang.management.RuntimeMXBean)2 ThreadInfo (java.lang.management.ThreadInfo)2 ThreadMXBean (java.lang.management.ThreadMXBean)2 HashSet (java.util.HashSet)2 Map (java.util.Map)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 GET (javax.ws.rs.GET)2 Path (javax.ws.rs.Path)2 Produces (javax.ws.rs.Produces)2 ThreadInfosManager (org.olat.admin.sysinfo.manager.ThreadInfosManager)2 ThreadVO (org.olat.restapi.system.vo.ThreadVO)2 ThreadVOes (org.olat.restapi.system.vo.ThreadVOes)2