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();
}
}
}
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();
}
}
}
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();
}
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();
}
Aggregations