Java Code Examples for java.lang.management.MemoryMXBean#getNonHeapMemoryUsage()
The following examples show how to use
java.lang.management.MemoryMXBean#getNonHeapMemoryUsage() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MemoryLogger.java From Flink-CEPplus with Apache License 2.0 | 6 votes |
/** * Gets the memory footprint of the JVM in a string representation. * * @return A string describing how much heap memory and direct memory are allocated and used. */ public static String getMemoryUsageStatsAsString(MemoryMXBean memoryMXBean) { MemoryUsage heap = memoryMXBean.getHeapMemoryUsage(); MemoryUsage nonHeap = memoryMXBean.getNonHeapMemoryUsage(); long heapUsed = heap.getUsed() >> 20; long heapCommitted = heap.getCommitted() >> 20; long heapMax = heap.getMax() >> 20; long nonHeapUsed = nonHeap.getUsed() >> 20; long nonHeapCommitted = nonHeap.getCommitted() >> 20; long nonHeapMax = nonHeap.getMax() >> 20; return String.format("Memory usage stats: [HEAP: %d/%d/%d MB, " + "NON HEAP: %d/%d/%d MB (used/committed/max)]", heapUsed, heapCommitted, heapMax, nonHeapUsed, nonHeapCommitted, nonHeapMax); }
Example 2
Source File: MemoryLogger.java From flink with Apache License 2.0 | 6 votes |
/** * Gets the memory footprint of the JVM in a string representation. * * @return A string describing how much heap memory and direct memory are allocated and used. */ public static String getMemoryUsageStatsAsString(MemoryMXBean memoryMXBean) { MemoryUsage heap = memoryMXBean.getHeapMemoryUsage(); MemoryUsage nonHeap = memoryMXBean.getNonHeapMemoryUsage(); long heapUsed = heap.getUsed() >> 20; long heapCommitted = heap.getCommitted() >> 20; long heapMax = heap.getMax() >> 20; long nonHeapUsed = nonHeap.getUsed() >> 20; long nonHeapCommitted = nonHeap.getCommitted() >> 20; long nonHeapMax = nonHeap.getMax() >> 20; return String.format("Memory usage stats: [HEAP: %d/%d/%d MB, " + "NON HEAP: %d/%d/%d MB (used/committed/max)]", heapUsed, heapCommitted, heapMax, nonHeapUsed, nonHeapCommitted, nonHeapMax); }
Example 3
Source File: GarbageCollectorMonitor.java From joyqueue with Apache License 2.0 | 6 votes |
/** * JVM memory snapshot **/ @Override public MemoryStat memSnapshot() { MemoryMXBean memBean = ManagementFactory.getMemoryMXBean() ; MemoryUsage heap = memBean.getHeapMemoryUsage(); MemoryUsage nonHeap = memBean.getNonHeapMemoryUsage(); MemoryStat stat=new MemoryStat(); // heap stat.setHeapMax(heap.getMax()); stat.setHeapInit(heap.getInit()); stat.setHeapCommitted(heap.getCommitted()); stat.setHeapUsed(heap.getUsed()); // non-heap stat.setNonHeapInit(nonHeap.getInit()); stat.setNonHeapMax(nonHeap.getMax()); stat.setNonHeapUsed(nonHeap.getUsed()); stat.setNonHeapCommitted(nonHeap.getCommitted()); // allocated by ByteBuffer.allocateDirect() stat.setDirectBufferSize(SharedSecrets.getJavaNioAccess().getDirectBufferPool().getMemoryUsed()); return stat; }
Example 4
Source File: MemoryMeter.java From DeconvolutionLab2 with GNU General Public License v3.0 | 6 votes |
@Override public void setDetail() { MemoryMXBean mem = ManagementFactory.getMemoryMXBean(); MemoryUsage heapU = mem.getHeapMemoryUsage(); MemoryUsage nonhU = mem.getNonHeapMemoryUsage(); Runtime runt = Runtime.getRuntime(); int i = 0; add(i++, new String[] { "JVM", "Initial Memory (-Xms)", NumFormat.bytes(runt.freeMemory()) }); add(i++, new String[] { "JVM", "Maximum Memory (-Xmx)", NumFormat.bytes(runt.maxMemory()) }); add(i++, new String[] { "JVM", "Total Used Memory", NumFormat.bytes(runt.totalMemory()) }); add(i++, new String[] { "Memory", "Heap Used", NumFormat.bytes(heapU.getUsed()) }); add(i++, new String[] { "Memory", "Heap Init", NumFormat.bytes(heapU.getInit()) }); add(i++, new String[] { "Memory", "Heap Max ", NumFormat.bytes(heapU.getMax()) }); add(i++, new String[] { "Memory", "NonHeap Used", NumFormat.bytes(nonhU.getUsed()) }); add(i++, new String[] { "Memory", "NonHeap Init", NumFormat.bytes(nonhU.getInit()) }); }
Example 5
Source File: Test.java From ClusterDeviceControlPlatform with MIT License | 6 votes |
private static void printMemoryInfo() { MemoryMXBean memory = ManagementFactory.getMemoryMXBean(); MemoryUsage headMemory = memory.getHeapMemoryUsage(); System.out.println("head堆:"); System.out.println("\t初始(M):" + headMemory.getInit() / MB); System.out.println("\t最大(上限)(M):" + headMemory.getMax() / MB); System.out.println("\t当前(已使用)(M):" + headMemory.getUsed() / MB); System.out.println("\t提交的内存(已申请)(M):" + headMemory.getCommitted() / MB); System.out.println("\t使用率:" + headMemory.getUsed() * 100 / headMemory.getCommitted() + "%"); System.out.println("non-head非堆:"); MemoryUsage nonheadMemory = memory.getNonHeapMemoryUsage(); System.out.println("\t初始(M):" + nonheadMemory.getInit() / MB); System.out.println("\t最大(上限)(M):" + nonheadMemory.getMax() / MB); System.out.println("\t当前(已使用)(M):" + nonheadMemory.getUsed() / MB); System.out.println("\t提交的内存(已申请)(M):" + nonheadMemory.getCommitted() / MB); System.out.println("\t使用率:" + nonheadMemory.getUsed() * 100 / nonheadMemory.getCommitted() + "%"); }
Example 6
Source File: MemoryProfiler.java From bazel with Apache License 2.0 | 6 votes |
public synchronized void markPhase(ProfilePhase nextPhase) throws InterruptedException { if (memoryProfile != null) { MemoryMXBean bean = ManagementFactory.getMemoryMXBean(); prepareBean(nextPhase, bean, (duration) -> Thread.sleep(duration.toMillis())); String name = currentPhase.description; MemoryUsage memoryUsage = bean.getHeapMemoryUsage(); memoryProfile.println(name + ":heap:init:" + memoryUsage.getInit()); memoryProfile.println(name + ":heap:used:" + memoryUsage.getUsed()); memoryProfile.println(name + ":heap:commited:" + memoryUsage.getCommitted()); memoryProfile.println(name + ":heap:max:" + memoryUsage.getMax()); if (nextPhase == ProfilePhase.FINISH) { heapUsedMemoryAtFinish = memoryUsage.getUsed(); } memoryUsage = bean.getNonHeapMemoryUsage(); memoryProfile.println(name + ":non-heap:init:" + memoryUsage.getInit()); memoryProfile.println(name + ":non-heap:used:" + memoryUsage.getUsed()); memoryProfile.println(name + ":non-heap:commited:" + memoryUsage.getCommitted()); memoryProfile.println(name + ":non-heap:max:" + memoryUsage.getMax()); currentPhase = nextPhase; } }
Example 7
Source File: Test.java From ClusterDeviceControlPlatform with MIT License | 6 votes |
private static void printMemoryInfo() { MemoryMXBean memory = ManagementFactory.getMemoryMXBean(); MemoryUsage headMemory = memory.getHeapMemoryUsage(); System.out.println("head堆:"); System.out.println("\t初始(M):" + headMemory.getInit() / MB); System.out.println("\t最大(上限)(M):" + headMemory.getMax() / MB); System.out.println("\t当前(已使用)(M):" + headMemory.getUsed() / MB); System.out.println("\t提交的内存(已申请)(M):" + headMemory.getCommitted() / MB); System.out.println("\t使用率:" + headMemory.getUsed() * 100 / headMemory.getCommitted() + "%"); System.out.println("non-head非堆:"); MemoryUsage nonheadMemory = memory.getNonHeapMemoryUsage(); System.out.println("\t初始(M):" + nonheadMemory.getInit() / MB); System.out.println("\t最大(上限)(M):" + nonheadMemory.getMax() / MB); System.out.println("\t当前(已使用)(M):" + nonheadMemory.getUsed() / MB); System.out.println("\t提交的内存(已申请)(M):" + nonheadMemory.getCommitted() / MB); System.out.println("\t使用率:" + nonheadMemory.getUsed() * 100 / nonheadMemory.getCommitted() + "%"); }
Example 8
Source File: MemorySampler.java From kieker with Apache License 2.0 | 5 votes |
@Override protected IMonitoringRecord[] createNewMonitoringRecords(final long timestamp, final String hostname, final String vmName, final IMonitoringController monitoringCtr) { if (!monitoringCtr.isProbeActivated(SignatureFactory.createJVMMemSignature())) { return new IMonitoringRecord[] {}; } final MemoryMXBean memoryBean = ManagementFactory.getMemoryMXBean(); final MemoryUsage heapMemoryUsage = memoryBean.getHeapMemoryUsage(); final MemoryUsage nonHeapMemoryUsage = memoryBean.getNonHeapMemoryUsage(); return new IMonitoringRecord[] { new MemoryRecord(timestamp, hostname, vmName, heapMemoryUsage.getMax(), heapMemoryUsage.getUsed(), heapMemoryUsage.getCommitted(), heapMemoryUsage.getInit(), nonHeapMemoryUsage.getMax(), nonHeapMemoryUsage.getUsed(), nonHeapMemoryUsage.getCommitted(), nonHeapMemoryUsage.getInit(), memoryBean.getObjectPendingFinalizationCount()), }; }
Example 9
Source File: GfxdConfigMessage.java From gemfirexd-oss with Apache License 2.0 | 5 votes |
@Override public Object process(Object arg, Set<DistributedMember> members, GfxdConfigMessage<?> msg) { TreeMap<Object, Object> map = new TreeMap<Object, Object>(); // GC information for (GarbageCollectorMXBean gcBean : ManagementFactory .getGarbageCollectorMXBeans()) { final String gcPrefix = "gc-" + gcBean.getName(); map.put(gcPrefix + "-collection-count", gcBean.getCollectionCount()); map.put(gcPrefix + "-collection-time", gcBean.getCollectionTime()); map.put(gcPrefix + "-memory-pools", GemFireXDUtils.toCSV(gcBean.getMemoryPoolNames())); } // some thread information ThreadMXBean threadBean = ManagementFactory.getThreadMXBean(); map.put("thread-count", threadBean.getThreadCount()); map.put("thread-total-count", threadBean.getTotalStartedThreadCount()); map.put("thread-peak-count", threadBean.getPeakThreadCount()); // some memory information MemoryMXBean memBean = ManagementFactory.getMemoryMXBean(); MemoryUsage heapUsage = memBean.getHeapMemoryUsage(); MemoryUsage nonHeapUsage = memBean.getNonHeapMemoryUsage(); map.put("memory-heap-max", heapUsage.getMax()); map.put("memory-heap-committed", heapUsage.getCommitted()); map.put("memory-heap-used", heapUsage.getUsed()); map.put("memory-nonheap-max", nonHeapUsage.getMax()); map.put("memory-nonheap-committed", nonHeapUsage.getCommitted()); map.put("memory-nonheap-used", nonHeapUsage.getUsed()); // some more runtime memory information Runtime rt = Runtime.getRuntime(); map.put("memory-free", rt.freeMemory()); map.put("memory-max", rt.maxMemory()); map.put("memory-total", rt.totalMemory()); map.put("available-processors", rt.availableProcessors()); return map; }
Example 10
Source File: JvmMetrics.java From big-c with Apache License 2.0 | 5 votes |
private void doMemoryUpdates() { MemoryMXBean memoryMXBean = ManagementFactory.getMemoryMXBean(); MemoryUsage memNonHeap = memoryMXBean.getNonHeapMemoryUsage(); MemoryUsage memHeap = memoryMXBean.getHeapMemoryUsage(); Runtime runtime = Runtime.getRuntime(); metrics.setMetric("memNonHeapUsedM", memNonHeap.getUsed()/M); metrics.setMetric("memNonHeapCommittedM", memNonHeap.getCommitted()/M); metrics.setMetric("memHeapUsedM", memHeap.getUsed()/M); metrics.setMetric("memHeapCommittedM", memHeap.getCommitted()/M); metrics.setMetric("maxMemoryM", runtime.maxMemory()/M); }
Example 11
Source File: GfxdConfigMessage.java From gemfirexd-oss with Apache License 2.0 | 5 votes |
@Override public Object process(Object arg, Set<DistributedMember> members, GfxdConfigMessage<?> msg) { TreeMap<Object, Object> map = new TreeMap<Object, Object>(); // GC information for (GarbageCollectorMXBean gcBean : ManagementFactory .getGarbageCollectorMXBeans()) { final String gcPrefix = "gc-" + gcBean.getName(); map.put(gcPrefix + "-collection-count", gcBean.getCollectionCount()); map.put(gcPrefix + "-collection-time", gcBean.getCollectionTime()); map.put(gcPrefix + "-memory-pools", GemFireXDUtils.toCSV(gcBean.getMemoryPoolNames())); } // some thread information ThreadMXBean threadBean = ManagementFactory.getThreadMXBean(); map.put("thread-count", threadBean.getThreadCount()); map.put("thread-total-count", threadBean.getTotalStartedThreadCount()); map.put("thread-peak-count", threadBean.getPeakThreadCount()); // some memory information MemoryMXBean memBean = ManagementFactory.getMemoryMXBean(); MemoryUsage heapUsage = memBean.getHeapMemoryUsage(); MemoryUsage nonHeapUsage = memBean.getNonHeapMemoryUsage(); map.put("memory-heap-max", heapUsage.getMax()); map.put("memory-heap-committed", heapUsage.getCommitted()); map.put("memory-heap-used", heapUsage.getUsed()); map.put("memory-nonheap-max", nonHeapUsage.getMax()); map.put("memory-nonheap-committed", nonHeapUsage.getCommitted()); map.put("memory-nonheap-used", nonHeapUsage.getUsed()); // some more runtime memory information Runtime rt = Runtime.getRuntime(); map.put("memory-free", rt.freeMemory()); map.put("memory-max", rt.maxMemory()); map.put("memory-total", rt.totalMemory()); map.put("available-processors", rt.availableProcessors()); return map; }
Example 12
Source File: JvmMetrics.java From hadoop with Apache License 2.0 | 5 votes |
private void doMemoryUpdates() { MemoryMXBean memoryMXBean = ManagementFactory.getMemoryMXBean(); MemoryUsage memNonHeap = memoryMXBean.getNonHeapMemoryUsage(); MemoryUsage memHeap = memoryMXBean.getHeapMemoryUsage(); Runtime runtime = Runtime.getRuntime(); metrics.setMetric("memNonHeapUsedM", memNonHeap.getUsed()/M); metrics.setMetric("memNonHeapCommittedM", memNonHeap.getCommitted()/M); metrics.setMetric("memHeapUsedM", memHeap.getUsed()/M); metrics.setMetric("memHeapCommittedM", memHeap.getCommitted()/M); metrics.setMetric("maxMemoryM", runtime.maxMemory()/M); }
Example 13
Source File: JvmPropertyProvider.java From appstatus with Apache License 2.0 | 5 votes |
public Map<String, String> getProperties() { Map<String, String> map = new TreeMap<String, String>(); RuntimeMXBean runtimeMXBean = ManagementFactory.getRuntimeMXBean(); List<String> aList = runtimeMXBean.getInputArguments(); String parameters = ""; for (int i = 0; i < aList.size(); i++) { parameters = parameters + " " + aList.get(i); } map.put("params", parameters); map.put("name", runtimeMXBean.getVmName()); map.put("vendor", runtimeMXBean.getVmVendor()); map.put("version", runtimeMXBean.getVmVersion()); map.put("specification", runtimeMXBean.getSpecVersion()); map.put("uptime", DurationFormatUtils.formatDurationHMS(runtimeMXBean.getUptime())); Date date = new Date(runtimeMXBean.getStartTime()); SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss"); map.put("start time", sdf.format(date)); MemoryMXBean memory = ManagementFactory.getMemoryMXBean(); MemoryUsage heap = memory.getHeapMemoryUsage(); map.put("memory. (heap)", readableFileSize(heap.getUsed()) + "/" + readableFileSize(heap.getCommitted()) + " min:" + readableFileSize(heap.getInit()) + " max:" + readableFileSize(heap.getMax())); MemoryUsage nonheap = memory.getNonHeapMemoryUsage(); map.put("memory (non heap)", readableFileSize(nonheap.getUsed()) + "/" + readableFileSize(nonheap.getCommitted()) + " min:" + readableFileSize(nonheap.getInit()) + " max:" + readableFileSize(nonheap.getMax())); return map; }
Example 14
Source File: JvmMetrics.java From RDFS with Apache License 2.0 | 5 votes |
private void doMemoryUpdates() { MemoryMXBean memoryMXBean = ManagementFactory.getMemoryMXBean(); MemoryUsage memNonHeap = memoryMXBean.getNonHeapMemoryUsage(); MemoryUsage memHeap = memoryMXBean.getHeapMemoryUsage(); metrics.setMetric("memNonHeapUsedM", memNonHeap.getUsed()/M); metrics.setMetric("memNonHeapCommittedM", memNonHeap.getCommitted()/M); metrics.setMetric("memHeapUsedM", memHeap.getUsed()/M); metrics.setMetric("memHeapCommittedM", memHeap.getCommitted()/M); }
Example 15
Source File: BaseVM.java From unidbg with Apache License 2.0 | 5 votes |
@Override public final void printMemoryInfo() { System.gc(); MemoryMXBean memoryMXBean = ManagementFactory.getMemoryMXBean(); MemoryUsage heap = memoryMXBean.getHeapMemoryUsage(); MemoryUsage nonheap = memoryMXBean.getNonHeapMemoryUsage(); System.err.println("globalObjectSize=" + globalObjectMap.size() + ", localObjectSize=" + localObjectMap.size() + ", classSize=" + classMap.size()); System.err.println("heap: " + memoryUsage(heap) + ", nonheap: " + memoryUsage(nonheap)); }
Example 16
Source File: DiagnosticTask.java From netbeans with Apache License 2.0 | 4 votes |
private String logParams() { StringBuilder sb = new StringBuilder(500); sb.append("Diagnostic information\n"); try { RuntimeMXBean rmBean = ManagementFactory.getRuntimeMXBean(); CompilationMXBean cmpMBean = ManagementFactory.getCompilationMXBean(); // ThreadMXBean tmBean = ManagementFactory.getThreadMXBean(); MemoryMXBean memoryBean = ManagementFactory.getMemoryMXBean(); ClassLoadingMXBean clMBean = ManagementFactory.getClassLoadingMXBean(); // MBeanServer mbs = ManagementFactory.getPlatformMBeanServer(); // ObjectName hsDiag = new ObjectName("com.sun.management:name=HotSpotDiagnostic"); // com.sun.management.OperatingSystemMXBean sunOSMBean = // ManagementFactory.getSunOperatingSystemMXBean(); // Map<String, String> props = new TreeMap<String, String>(rmBean.getSystemProperties()); // System.out.println("System properties"); // for (Map.Entry<String, String> entry: props.entrySet()) { // System.out.println("Property: "+entry.getKey()+" Value: "+entry.getValue()); // } sb.append("Input arguments:"); for (String s: rmBean.getInputArguments()) { sb.append("\n\t").append(s); } if (cmpMBean != null) { sb.append("\nCompiler: "+cmpMBean.getName()).append('\n'); } // Memory MemoryUsage usage = memoryBean.getHeapMemoryUsage(); logMemoryUsage(sb, usage, "Heap memory"); usage = memoryBean.getNonHeapMemoryUsage(); logMemoryUsage(sb, usage, "Non heap memory"); for (GarbageCollectorMXBean gcMBean: ManagementFactory.getGarbageCollectorMXBeans()) { sb.append("Garbage collector: ").append(gcMBean.getName()) .append(" (Collections=").append(gcMBean.getCollectionCount()) .append(" Total time spent=").append(formatTime(gcMBean.getCollectionTime())) .append(")\n"); } // classes int clsLoaded; long clsTotal, clsUnloaded; clsLoaded = clMBean.getLoadedClassCount(); clsTotal = clMBean.getTotalLoadedClassCount(); clsUnloaded = clMBean.getUnloadedClassCount(); sb.append("Classes: loaded=").append(clsLoaded) .append(" total loaded=").append(clsTotal) .append(" unloaded ").append(clsUnloaded).append('\n'); // } catch (MalformedObjectNameException ex) { // Logger.getLogger("global").log(Level.WARNING, null, ex); } catch (NullPointerException ex) { LOG.log(Level.WARNING, null, ex); } return sb.toString(); }
Example 17
Source File: NamenodeAnalyticsMethods.java From NNAnalytics with Apache License 2.0 | 4 votes |
/** * SYSTEM endpoint is meant to show the system resource usage of the NNA instance in PLAINTEXT * form. TODO: Convert the output to JSON form. */ @GET @Path("/system") @Produces({MediaType.TEXT_PLAIN}) public Response system() { try { before(); Runtime runtime = Runtime.getRuntime(); OperatingSystemMXBean systemMxBean = (OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean(); RuntimeMXBean rb = ManagementFactory.getRuntimeMXBean(); MemoryMXBean mb = ManagementFactory.getMemoryMXBean(); MemoryUsage memNonHeap = mb.getNonHeapMemoryUsage(); MemoryUsage memHeap = mb.getHeapMemoryUsage(); StringBuilder sb = new StringBuilder(); int availableCores = runtime.availableProcessors(); double cpuLoad = systemMxBean.getSystemCpuLoad(); double procLoad = systemMxBean.getProcessCpuLoad(); sb.append("Server uptime (ms): ").append(rb.getUptime()).append("\n\n"); sb.append("Available Processor Cores: ").append(availableCores).append("\n"); sb.append("System CPU Load: ").append(cpuLoad).append("\n"); sb.append("Process CPU Load: ").append(procLoad).append("\n\n"); sb.append("Non-Heap Used Memory (KB): ").append(memNonHeap.getUsed() / 1024).append("\n"); sb.append("Non-Heap Committed Memory (KB): ") .append((memNonHeap.getCommitted() / 1024)) .append("\n"); sb.append("Non-Heap Max Memory (KB): ").append((memNonHeap.getMax() / 1024)).append("\n\n"); sb.append("Heap Used Memory (KB): ").append(memHeap.getUsed() / 1024).append("\n"); sb.append("Heap Committed Memory (KB): ") .append((memHeap.getCommitted() / 1024)) .append("\n"); sb.append("Heap Max Memory (KB): ").append((memHeap.getMax() / 1024)).append("\n\n"); sb.append("Max Memory (KB): ").append((runtime.maxMemory() / 1024)).append("\n"); return Response.ok(sb.toString(), MediaType.TEXT_PLAIN).build(); } catch (RuntimeException rtex) { return handleException(rtex); } catch (Exception ex) { return handleException(ex); } finally { after(); } }
Example 18
Source File: RuntimeStatsServlet.java From lams with GNU General Public License v2.0 | 4 votes |
private static String getLongStats() { StringBuilder resp = new StringBuilder(); MBeanServer server = ManagementFactory.getPlatformMBeanServer(); try { resp.append("jvmRoute: ").append(SessionManager.getJvmRoute()).append("\n"); MemoryMXBean memoryBean = ManagementFactory.getMemoryMXBean(); MemoryUsage memoryUsage = memoryBean.getHeapMemoryUsage(); resp.append("Heap memory MB [init/used/committed/max]: ") .append(RuntimeStatsServlet.toMB(memoryUsage.getInit())).append("/") .append(RuntimeStatsServlet.toMB(memoryUsage.getUsed())).append("/") .append(RuntimeStatsServlet.toMB(memoryUsage.getCommitted())).append("/") .append(RuntimeStatsServlet.toMB(memoryUsage.getMax())).append("\n"); memoryUsage = memoryBean.getNonHeapMemoryUsage(); resp.append("Non-heap memory MB [init/used/committed/max]: ") .append(RuntimeStatsServlet.toMB(memoryUsage.getInit())).append("/") .append(RuntimeStatsServlet.toMB(memoryUsage.getUsed())).append("/") .append(RuntimeStatsServlet.toMB(memoryUsage.getCommitted())).append("/") .append(RuntimeStatsServlet.toMB(memoryUsage.getMax())).append("\n"); ThreadMXBean threadBean = ManagementFactory.getThreadMXBean(); resp.append("JVM threads [daemon/total/peak]: ").append(threadBean.getDaemonThreadCount()).append("/") .append(threadBean.getThreadCount()).append("/").append(threadBean.getPeakThreadCount()) .append("\n"); ObjectName connectorName = new ObjectName("jboss.as.expr:subsystem=io,worker=default"); String busyThreads = (String) server.getAttribute(connectorName, "ioThreads"); String maxThreads = (String) server.getAttribute(connectorName, "taskMaxThreads"); resp.append("IO threads [io/task max]: ").append(busyThreads).append("/").append(maxThreads).append("\n"); resp.append("Active sessions [user/total]: ").append(SessionManager.getSessionUserCount()).append("/") .append(SessionManager.getSessionTotalCount()).append("\n"); ObjectName dataSourceName = new ObjectName( "jboss.as.expr:subsystem=datasources,data-source=lams-ds,statistics=pool"); Integer inUseConnections = Integer.parseInt((String) server.getAttribute(dataSourceName, "InUseCount")); Integer activeConnections = Integer.parseInt((String) server.getAttribute(dataSourceName, "ActiveCount")); Integer availConnections = Integer.parseInt((String) server.getAttribute(dataSourceName, "AvailableCount")); String maxUsageTime = (String) server.getAttribute(dataSourceName, "MaxUsageTime"); resp.append("Connection count [in use/idle/left]: ").append(inUseConnections).append("/") .append(activeConnections - inUseConnections).append("/") .append(availConnections - activeConnections).append("\n"); resp.append("Connection max usage time ms: ").append(maxUsageTime); } catch (Exception e) { log.error("Error while getting long runtime stats", e); } return resp.toString(); }
Example 19
Source File: TestJmx.java From util4j with Apache License 2.0 | 4 votes |
private void setFactory() { mxbean = ManagementFactory.getRuntimeMXBean(); // 以下是取得虚拟机的属性 System.out.println("===============虚拟机信息==================="); System.out.println("虚拟机提供商:" + mxbean.getVmVendor()); System.out.println("虚拟机名称:" + mxbean.getVmName()); System.out.println("当前类路径:" + mxbean.getClassPath()); System.out.println("进程号@机器:" + mxbean.getName()); System.out.println("运行时间(毫秒):" + mxbean.getUptime()); // 类管理接口 System.out.println("===============类加载信息==================="); ClassLoadingMXBean aClassLoadingMXBean = ManagementFactory .getClassLoadingMXBean(); System.out.println("已加载类总数:" + aClassLoadingMXBean.getLoadedClassCount()); System.out.println("Verbose状态:" + aClassLoadingMXBean.isVerbose()); // 内存管理接口 System.out.println("===============内存信息====================="); MemoryMXBean aMemoryMXBean = ManagementFactory.getMemoryMXBean(); System.out.println("终止被挂起数:" + aMemoryMXBean.getObjectPendingFinalizationCount());// 返回其终止被挂起的对象的近似数目 // 返回 Java 虚拟机使用的非堆内存的当前使用量 MemoryUsage aMemoryUsage = aMemoryMXBean.getNonHeapMemoryUsage(); // 虚拟机启动时从系统得到的内存(以字节为单位) System.out.println("虚拟机启动时从系统得到的内存:" + aMemoryUsage.getInit()); // 表示当前已经使用的内存量(以字节为单位) System.out.println("当前已经使用的内存量:" + aMemoryUsage.getUsed()); // 表示保证可以由 // Java // 虚拟机使用的内存量(以字节为单位) System.out.println("虚拟机使用的内存量:" + aMemoryUsage.getCommitted()); // 表示可以用于内存管理的最大内存量(以字节为单位) System.out.println("内存管理的初始内存量:" + aMemoryUsage.getInit()); System.out.println("内存管理的最大内存量:" + aMemoryUsage.getMax()); System.out.println("总体描述:" + aMemoryUsage.toString()); java.util.List<GarbageCollectorMXBean> aGCMXBeans = ManagementFactory.getGarbageCollectorMXBeans(); GarbageCollectorMXBean aGCMXBean = aGCMXBeans.get(0); System.out.println("===============GC信息====================="); System.out.println("收集总数:" + aGCMXBean.getCollectionCount()); System.out.println("收集时间:" + aGCMXBean.getCollectionTime()); System.out.println("内存管理器有效:" + aGCMXBean.isValid()); System.out.println("内存池名:" + aGCMXBean.getMemoryPoolNames()[0]); System.out.println("内存池名:" + aGCMXBean.getMemoryPoolNames()[1]); System.out.println("*****************End**********************"); }
Example 20
Source File: JMServer.java From jmonitor with GNU General Public License v2.0 | 4 votes |
public static JSONObject loadMemoryInfo(String app) { try { MemoryMXBean mBean = JMConnManager.getMemoryMBean(app); MemoryUsage nonHeap = mBean.getNonHeapMemoryUsage(); MemoryUsage heap = mBean.getHeapMemoryUsage(); JSONObject map = new JSONObject(true); buildMemoryJSon(heap, "heap", map); buildMemoryJSon(nonHeap, "nonheap", map); JSONObject heapChild = new JSONObject(); JSONObject nonheapChild = new JSONObject(); JSONObject heapUsed = new JSONObject(); JSONObject heapMax = new JSONObject(); heapUsed.put("used", heap.getUsed()); heapMax.put("used", heap.getCommitted()); heapChild.put("HeapUsed", heapUsed); heapChild.put("HeapCommit", heapMax); JSONObject nonheapUsed = new JSONObject(); JSONObject noheapMax = new JSONObject(); nonheapUsed.put("used", nonHeap.getUsed()); noheapMax.put("used", nonHeap.getCommitted()); nonheapChild.put("NonheapUsed", nonheapUsed); nonheapChild.put("NonheapCommit", noheapMax); ObjectName obj = new ObjectName("java.lang:type=MemoryPool,*"); MBeanServerConnection conn = JMConnManager.getConn(app); Set<ObjectInstance> MBeanset = conn.queryMBeans(obj, null); for (ObjectInstance objx : MBeanset) { String name = objx.getObjectName().getCanonicalName(); String keyName = objx.getObjectName().getKeyProperty("name"); MemoryPoolMXBean bean = JMConnManager.getServer(app, name, MemoryPoolMXBean.class); JSONObject item = toJson(bean.getUsage()); if (JMConnManager.HEAP_ITEM.contains(keyName)) { heapChild.put(keyName, item); } else { nonheapChild.put(keyName, item); } } map.getJSONObject("heap").put("childs", heapChild); map.getJSONObject("nonheap").put("childs", nonheapChild); return map; } catch (Exception e) { throw new RuntimeException(e); } }