use of java.lang.management.ThreadMXBean in project adempiere by adempiere.
the class MSystem method info.
// getDBInfoSQL
/**
* Print info
*/
public void info() {
if (!CLogMgt.isLevelFine())
return;
// OS
// OperatingSystemMXBean os = ManagementFactory.getOperatingSystemMXBean();
// log.fine(os.getName() + " " + os.getVersion() + " " + os.getArch()
// + " Processors=" + os.getAvailableProcessors());
// Runtime
RuntimeMXBean rt = ManagementFactory.getRuntimeMXBean();
// Memory
if (CLogMgt.isLevelFiner()) {
List<MemoryPoolMXBean> list = ManagementFactory.getMemoryPoolMXBeans();
Iterator<MemoryPoolMXBean> it = list.iterator();
while (it.hasNext()) {
MemoryPoolMXBean pool = (MemoryPoolMXBean) it.next();
/*
log.finer(pool.getName() + " " + pool.getType()
+ ": " + new CMemoryUsage(pool.getUsage()));
*/
}
} else {
MemoryMXBean memory = ManagementFactory.getMemoryMXBean();
// log.fine("VM: " + new CMemoryUsage(memory.getNonHeapMemoryUsage()));
// log.fine("Heap: " + new CMemoryUsage(memory.getHeapMemoryUsage()));
}
// Thread
ThreadMXBean th = ManagementFactory.getThreadMXBean();
/*
log.fine("Threads=" + th.getThreadCount()
+ ", Peak=" + th.getPeakThreadCount()
+ ", Demons=" + th.getDaemonThreadCount()
+ ", Total=" + th.getTotalStartedThreadCount()
);
*/
}
use of java.lang.management.ThreadMXBean in project adempiere by adempiere.
the class AdempiereMonitor method createLogMgtPage.
// createSummaryPage
/**
* Add Log Management to page
* @param bb body
*/
private void createLogMgtPage(body bb) {
bb.addElement(new hr());
// Ini Parameters
table table = new table();
table.setBorder(1);
table.setCellSpacing(2);
table.setCellPadding(2);
//
Properties ctx = new Properties();
MSystem system = MSystem.get(ctx);
tr line = new tr();
line.addElement(new th().addElement(system.getDBAddress()));
line.addElement(new td().addElement(Ini.getAdempiereHome()));
table.addElement(line);
// OS + Name
line = new tr();
String info = System.getProperty("os.name") + " " + System.getProperty("os.version");
String s = System.getProperty("sun.os.patch.level");
if (s != null && s.length() > 0)
info += " (" + s + ")";
line.addElement(new th().addElement(info));
info = system.getName();
if (system.getCustomPrefix() != null)
info += " (" + system.getCustomPrefix() + ")";
line.addElement(new td().addElement(info));
table.addElement(line);
// Java + email
line = new tr();
info = System.getProperty("java.vm.name") + " " + System.getProperty("java.vm.version");
line.addElement(new th().addElement(info));
line.addElement(new td().addElement(system.getUserName()));
table.addElement(line);
// DB + Instance
line = new tr();
CConnection cc = CConnection.get();
AdempiereDatabase db = cc.getDatabase();
info = db.getDescription();
line.addElement(new th().addElement(info));
line.addElement(new td().addElement(cc.getConnectionURL()));
// line.addElement(new td().addElement(system.getDBInstance()));
table.addElement(line);
// Processors/Support
line = new tr();
line.addElement(new th().addElement("Processor/Support"));
line.addElement(new td().addElement(system.getNoProcessors() + "/" + system.getSupportUnits()));
table.addElement(line);
// Memory
line = new tr();
MemoryMXBean memory = ManagementFactory.getMemoryMXBean();
line.addElement(new th().addElement("VM Memory"));
line.addElement(new td().addElement(new CMemoryUsage(memory.getNonHeapMemoryUsage()).toString()));
table.addElement(line);
line = new tr();
line.addElement(new th().addElement("Heap Memory"));
line.addElement(new td().addElement(new CMemoryUsage(memory.getHeapMemoryUsage()).toString()));
table.addElement(line);
// Runtime
line = new tr();
RuntimeMXBean rt = ManagementFactory.getRuntimeMXBean();
line.addElement(new th().addElement("Runtime " + rt.getName()));
line.addElement(new td().addElement(TimeUtil.formatElapsed(rt.getUptime())));
table.addElement(line);
// Threads
line = new tr();
ThreadMXBean th = ManagementFactory.getThreadMXBean();
line.addElement(new th().addElement("Threads " + th.getThreadCount()));
line.addElement(new td().addElement("Peak=" + th.getPeakThreadCount() + ", Demons=" + th.getDaemonThreadCount() + ", Total=" + th.getTotalStartedThreadCount()));
table.addElement(line);
//Transactions
Trx[] trxs = Trx.getActiveTransactions();
for (Trx trx : trxs) {
if (trx != null && trx.isActive()) {
line = new tr();
line.addElement(new th().addElement("Active Transaction "));
line.addElement(new td().addElement("Name=" + trx.getTrxName() + ", StartTime=" + trx.getStartTime()));
table.addElement(line);
}
}
// Cache Reset
line = new tr();
line.addElement(new th().addElement(CacheMgt.get().toStringX()));
line.addElement(new td().addElement(new a("adempiereMonitor?CacheReset=Yes", "Reset Cache")));
table.addElement(line);
// Trace Level
line = new tr();
line.addElement(new th().addElement(new label("TraceLevel").addElement("Trace Log Level")));
form myForm = new form("adempiereMonitor", form.METHOD_POST, form.ENC_DEFAULT);
// LogLevel Selection
option[] options = new option[CLogMgt.LEVELS.length];
for (int i = 0; i < options.length; i++) {
options[i] = new option(CLogMgt.LEVELS[i].getName());
options[i].addElement(CLogMgt.LEVELS[i].getName());
if (CLogMgt.LEVELS[i] == CLogMgt.getLevel())
options[i].setSelected(true);
}
select sel = new select("TraceLevel", options);
myForm.addElement(sel);
myForm.addElement(new input(input.TYPE_SUBMIT, "Set", "Set"));
line.addElement(new td().addElement(myForm));
table.addElement(line);
//
line = new tr();
CLogFile fileHandler = CLogFile.get(true, null, false);
line.addElement(new th().addElement("Trace File"));
line.addElement(new td().addElement(new a("adempiereMonitor?Trace=" + fileHandler.getFileName(), "Current")));
table.addElement(line);
//
line = new tr();
line.addElement(new td().addElement(new a("adempiereMonitor?Trace=ROTATE", "Rotate Trace Log")));
line.addElement(new td().addElement(new a("adempiereMonitor?Trace=DELETE", "Delete all Trace Logs")));
table.addElement(line);
//
bb.addElement(table);
// List Log Files
p p = new p();
p.addElement(new b("All Log Files: "));
// All in dir
File logDir = fileHandler.getLogDirectory();
if (logDir != null && logDir.isDirectory()) {
File[] logs = logDir.listFiles();
for (int i = 0; i < logs.length; i++) {
// Skip if is not a file - teo_sarca [ 1726066 ]
if (!logs[i].isFile())
continue;
if (i != 0)
p.addElement(" - ");
String fileName = logs[i].getAbsolutePath();
a link = new a("adempiereMonitor?Trace=" + fileName, fileName);
p.addElement(link);
int size = (int) (logs[i].length() / 1024);
if (size < 1024)
p.addElement(" (" + size + "k)");
else
p.addElement(" (" + size / 1024 + "M)");
}
}
bb.addElement(p);
// Clients and Web Stores
table = new table();
table.setBorder(1);
table.setCellSpacing(2);
table.setCellPadding(2);
//
line = new tr();
MClient[] clients = MClient.getAll(ctx);
line.addElement(new th().addElement("Client #" + clients.length + " - EMail Test:"));
p = new p();
for (int i = 0; i < clients.length; i++) {
MClient client = clients[i];
if (i > 0)
p.addElement(" - ");
p.addElement(new a("adempiereMonitor?EMail=" + client.getAD_Client_ID(), client.getName()));
}
if (clients.length == 0)
p.addElement(" ");
line.addElement(new td().addElement(p));
table.addElement(line);
//
line = new tr();
MStore[] wstores = MStore.getActive();
line.addElement(new th().addElement("Active Web Stores #" + wstores.length));
p = new p();
for (int i = 0; i < wstores.length; i++) {
MStore store = wstores[i];
if (i > 0)
p.addElement(" - ");
a a = new a(store.getWebContext(), store.getName());
a.setTarget("t" + i);
p.addElement(a);
}
if (wstores.length == 0)
p.addElement(" ");
line.addElement(new td().addElement(p));
table.addElement(line);
//
bb.addElement(table);
}
use of java.lang.management.ThreadMXBean in project lucene-solr by apache.
the class ThreadDumpHandler method handleRequestBody.
@Override
public void handleRequestBody(SolrQueryRequest req, SolrQueryResponse rsp) throws IOException {
SimpleOrderedMap<Object> system = new SimpleOrderedMap<>();
rsp.add("system", system);
ThreadMXBean tmbean = ManagementFactory.getThreadMXBean();
// Thread Count
SimpleOrderedMap<Object> nl = new SimpleOrderedMap<>();
nl.add("current", tmbean.getThreadCount());
nl.add("peak", tmbean.getPeakThreadCount());
nl.add("daemon", tmbean.getDaemonThreadCount());
system.add("threadCount", nl);
// Deadlocks
ThreadInfo[] tinfos;
long[] tids = tmbean.findMonitorDeadlockedThreads();
if (tids != null) {
tinfos = tmbean.getThreadInfo(tids, Integer.MAX_VALUE);
NamedList<SimpleOrderedMap<Object>> lst = new NamedList<>();
for (ThreadInfo ti : tinfos) {
if (ti != null) {
lst.add("thread", getThreadInfo(ti, tmbean));
}
}
system.add("deadlocks", lst);
}
// Now show all the threads....
tids = tmbean.getAllThreadIds();
tinfos = tmbean.getThreadInfo(tids, Integer.MAX_VALUE);
NamedList<SimpleOrderedMap<Object>> lst = new NamedList<>();
for (ThreadInfo ti : tinfos) {
if (ti != null) {
lst.add("thread", getThreadInfo(ti, tmbean));
}
}
system.add("threadDump", lst);
rsp.setHttpCaching(false);
}
use of java.lang.management.ThreadMXBean in project jackrabbit-oak by apache.
the class DocumentNodeStoreTest method backgroundLeaseUpdateThreadRunning.
private static boolean backgroundLeaseUpdateThreadRunning(int clusterId) {
String threadName = "DocumentNodeStore lease update thread (" + clusterId + ")";
ThreadMXBean threadBean = ManagementFactory.getThreadMXBean();
for (ThreadInfo ti : threadBean.getThreadInfo(threadBean.getAllThreadIds())) {
if (ti != null) {
if (threadName.equals(ti.getThreadName())) {
return true;
}
}
}
return false;
}
use of java.lang.management.ThreadMXBean in project karaf by apache.
the class InfoAction method execute.
@Override
public Object execute() throws Exception {
int maxNameLen;
RuntimeMXBean runtime = ManagementFactory.getRuntimeMXBean();
OperatingSystemMXBean os = ManagementFactory.getOperatingSystemMXBean();
ThreadMXBean threads = ManagementFactory.getThreadMXBean();
MemoryMXBean mem = ManagementFactory.getMemoryMXBean();
ClassLoadingMXBean cl = ManagementFactory.getClassLoadingMXBean();
//
// print Karaf informations
//
maxNameLen = 25;
System.out.println("Karaf");
printValue("Karaf version", maxNameLen, System.getProperty("karaf.version"));
printValue("Karaf home", maxNameLen, System.getProperty("karaf.home"));
printValue("Karaf base", maxNameLen, System.getProperty("karaf.base"));
String osgi = getOsgiFramework();
if (osgi != null) {
printValue("OSGi Framework", maxNameLen, osgi);
}
System.out.println();
System.out.println("JVM");
printValue("Java Virtual Machine", maxNameLen, runtime.getVmName() + " version " + runtime.getVmVersion());
printValue("Version", maxNameLen, System.getProperty("java.version"));
printValue("Vendor", maxNameLen, runtime.getVmVendor());
printValue("Pid", maxNameLen, getPid());
printValue("Uptime", maxNameLen, printDuration(runtime.getUptime()));
try {
printValue("Process CPU time", maxNameLen, printDuration(getSunOsValueAsLong(os, "getProcessCpuTime") / 1000000));
} catch (Throwable t) {
}
printValue("Total compile time", maxNameLen, printDuration(ManagementFactory.getCompilationMXBean().getTotalCompilationTime()));
System.out.println("Threads");
printValue("Live threads", maxNameLen, Integer.toString(threads.getThreadCount()));
printValue("Daemon threads", maxNameLen, Integer.toString(threads.getDaemonThreadCount()));
printValue("Peak", maxNameLen, Integer.toString(threads.getPeakThreadCount()));
printValue("Total started", maxNameLen, Long.toString(threads.getTotalStartedThreadCount()));
System.out.println("Memory");
printValue("Current heap size", maxNameLen, printSizeInKb(mem.getHeapMemoryUsage().getUsed()));
printValue("Maximum heap size", maxNameLen, printSizeInKb(mem.getHeapMemoryUsage().getMax()));
printValue("Committed heap size", maxNameLen, printSizeInKb(mem.getHeapMemoryUsage().getCommitted()));
printValue("Pending objects", maxNameLen, Integer.toString(mem.getObjectPendingFinalizationCount()));
for (GarbageCollectorMXBean gc : ManagementFactory.getGarbageCollectorMXBeans()) {
String val = "Name = '" + gc.getName() + "', Collections = " + gc.getCollectionCount() + ", Time = " + printDuration(gc.getCollectionTime());
printValue("Garbage collector", maxNameLen, val);
}
System.out.println("Classes");
printValue("Current classes loaded", maxNameLen, printLong(cl.getLoadedClassCount()));
printValue("Total classes loaded", maxNameLen, printLong(cl.getTotalLoadedClassCount()));
printValue("Total classes unloaded", maxNameLen, printLong(cl.getUnloadedClassCount()));
System.out.println("Operating system");
printValue("Name", maxNameLen, os.getName() + " version " + os.getVersion());
printValue("Architecture", maxNameLen, os.getArch());
printValue("Processors", maxNameLen, Integer.toString(os.getAvailableProcessors()));
try {
printValue("Total physical memory", maxNameLen, printSizeInKb(getSunOsValueAsLong(os, "getTotalPhysicalMemorySize")));
printValue("Free physical memory", maxNameLen, printSizeInKb(getSunOsValueAsLong(os, "getFreePhysicalMemorySize")));
printValue("Committed virtual memory", maxNameLen, printSizeInKb(getSunOsValueAsLong(os, "getCommittedVirtualMemorySize")));
printValue("Total swap space", maxNameLen, printSizeInKb(getSunOsValueAsLong(os, "getTotalSwapSpaceSize")));
printValue("Free swap space", maxNameLen, printSizeInKb(getSunOsValueAsLong(os, "getFreeSwapSpaceSize")));
} catch (Throwable t) {
}
//Display Information from external information providers.
Map<String, Map<Object, Object>> properties = new HashMap<>();
if (infoProviders != null) {
// dump all properties to Map, KARAF-425
for (InfoProvider provider : infoProviders) {
if (!properties.containsKey(provider.getName())) {
properties.put(provider.getName(), new Properties());
}
properties.get(provider.getName()).putAll(provider.getProperties());
}
List<String> sections = new ArrayList<>(properties.keySet());
Collections.sort(sections);
for (String section : sections) {
List<Object> keys = new ArrayList<>(properties.get(section).keySet());
if (keys.size() > 0) {
System.out.println(section);
keys.sort(Comparator.comparing(String::valueOf));
for (Object key : keys) {
printValue(String.valueOf(key), maxNameLen, String.valueOf(properties.get(section).get(key)));
}
}
}
}
return null;
}
Aggregations