Java Code Examples for java.lang.management.MemoryMXBean#getHeapMemoryUsage()
The following examples show how to use
java.lang.management.MemoryMXBean#getHeapMemoryUsage() .
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: JvmCheck.java From appstatus with Apache License 2.0 | 6 votes |
@Override public ICheckResult checkStatus(Locale locale) { MemoryMXBean memory = ManagementFactory.getMemoryMXBean(); MemoryUsage heap = memory.getHeapMemoryUsage(); long heapRatio = heap.getUsed() * 100 / heap.getMax(); CheckResultBuilder result = result(this).messageBundle("net.sf.appstatus.core.check.impl.JvmCheck_msg", locale); if (heapRatio > limitError) { result.code(ICheckResult.ERROR).fatal().resolutionSteps("resolutionSteps.fatal", new Object[] {}); } else if (heapRatio > limitWarn) { result.code(ICheckResult.ERROR).resolutionSteps("resolutionSteps.warn", new Object[] {}); } else { result.code(ICheckResult.OK); } result.description("description", new Object[] { heapRatio }); return result.build(); }
Example 2
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 3
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 4
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 5
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 6
Source File: AutoScalerPolicyTest.java From brooklyn-server with Apache License 2.0 | 6 votes |
public static void dumpThreadsEtc() { ThreadMXBean threadMXBean = ManagementFactory.getThreadMXBean(); ThreadInfo[] threads = threadMXBean.dumpAllThreads(true, true); for (ThreadInfo thread : threads) { System.out.println(thread.getThreadName()+" ("+thread.getThreadState()+")"); for (StackTraceElement stackTraceElement : thread.getStackTrace()) { System.out.println("\t"+stackTraceElement); } } MemoryMXBean memoryMXBean = ManagementFactory.getMemoryMXBean(); MemoryUsage heapMemoryUsage = memoryMXBean.getHeapMemoryUsage(); MemoryUsage nonHeapMemoryUsage = memoryMXBean.getNonHeapMemoryUsage(); System.out.println("Memory:"); System.out.println("\tHeap: used="+heapMemoryUsage.getUsed()+"; max="+heapMemoryUsage.getMax()+"; init="+heapMemoryUsage.getInit()+"; committed="+heapMemoryUsage.getCommitted()); System.out.println("\tNon-heap: used="+nonHeapMemoryUsage.getUsed()+"; max="+nonHeapMemoryUsage.getMax()+"; init="+nonHeapMemoryUsage.getInit()+"; committed="+nonHeapMemoryUsage.getCommitted()); OperatingSystemMXBean operatingSystemMXBean = ManagementFactory.getOperatingSystemMXBean(); System.out.println("OS:"); System.out.println("\tsysLoadAvg="+operatingSystemMXBean.getSystemLoadAverage()+"; availableProcessors="+operatingSystemMXBean.getAvailableProcessors()+"; arch="+operatingSystemMXBean.getArch()); }
Example 7
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 8
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 9
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 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: MemorySensor.java From swage with Apache License 2.0 | 5 votes |
private void reportHeapUsage(MemoryMXBean memoryMxBean, MetricContext metricContext) { MemoryUsage usage = memoryMxBean.getHeapMemoryUsage(); long used = usage.getUsed(); metricContext.record(HEAP, used / M, Unit.MEGABYTE); long max = usage.getMax(); if (max >= 0) { metricContext.record(HEAP_MAX, max / M, Unit.MEGABYTE); double used_percent = 100.0 * ((double)used/(double)max); metricContext.record(HEAP_USED, used_percent, Unit.PERCENT); } }
Example 13
Source File: JvmMetrics.java From hadoop-gpu 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 14
Source File: JVMTest.java From bistoury with GNU General Public License v3.0 | 5 votes |
public static void getVmInfo() throws Exception { VirtualMachine vm = VirtualMachine.attach(String.valueOf(10248)); // 获得连接地址 Properties properties = vm.getAgentProperties(); String address = (String) properties.get("com.sun.management.jmxremote.localConnectorAddress"); System.out.println(address); JMXServiceURL url = new JMXServiceURL(address); JMXConnector connector = JMXConnectorFactory.connect(url); RuntimeMXBean rmxb = ManagementFactory.newPlatformMXBeanProxy(connector.getMBeanServerConnection(), "java.lang:type=Runtime", RuntimeMXBean.class); MemoryMXBean memoryMXBean = ManagementFactory.newPlatformMXBeanProxy(connector.getMBeanServerConnection(), ManagementFactory.MEMORY_MXBEAN_NAME, MemoryMXBean.class); OperatingSystemMXBean operatingSystemMXBean = ManagementFactory.newPlatformMXBeanProxy(connector.getMBeanServerConnection(), ManagementFactory.OPERATING_SYSTEM_MXBEAN_NAME, OperatingSystemMXBean.class); System.out.println(operatingSystemMXBean.getSystemCpuLoad()); MemoryUsage memoryUsage = memoryMXBean.getHeapMemoryUsage(); Map<String, Object> result = new HashMap<>(); //堆提交内存 result.put("heapCommitedMemory", memoryUsage.getCommitted() / KB); //当前堆内存 result.put("heapUsedMemory", memoryUsage.getUsed() / KB); //最大堆大小 result.put("heapMaxMemory", memoryUsage.getMax() / KB); memoryUsage = memoryMXBean.getNonHeapMemoryUsage(); //非堆提交内存 result.put("nonHeapCommitedMemory", memoryUsage.getCommitted() / KB); //当前非堆内存 result.put("nonHeapUsedMemory", memoryUsage.getUsed() / KB); //最大非堆大小 result.put("nonHeapMaxMemory", memoryUsage.getMax() / KB); System.out.println(result); vm.detach(); }
Example 15
Source File: MemoryInfo.java From phoebus with Eclipse Public License 1.0 | 5 votes |
/** Initialize with memory usage of this JVM */ public MemoryInfo() { final MemoryMXBean memory = ManagementFactory.getMemoryMXBean(); final MemoryUsage heap = memory.getHeapMemoryUsage(); used_mem = heap.getUsed(); max_mem = heap.getMax(); non_heap = memory.getNonHeapMemoryUsage().getUsed(); }
Example 16
Source File: MemoryUtils.java From berkeleyparser with GNU General Public License v2.0 | 4 votes |
public static double getHeapMemoryUsed() { MemoryMXBean bean = ManagementFactory.getMemoryMXBean(); MemoryUsage usage = bean.getHeapMemoryUsage(); long bytes = usage.getUsed(); return bytes / 1.0e6; }
Example 17
Source File: ExtractorUtils.java From gemfirexd-oss with Apache License 2.0 | 4 votes |
public static int getNumberOfThreads (List<ServerInfo> serverInfoList, List<DiskStoreImpl> diskStores) { /**** * As we extract one diskstore at a time for a given server. * Here the logic is we find the largest disk-store and use its size as a basis for worst case heap memory required * for salvaging a server at a given time. * This helps in determining how may servers can we salvage in parallel for given heap memory. * This is a very conservative estimate. */ long maxDiskStoreSizeOnDisk = 0; int maxNumberOfServersInParallel = 1; final double mbDiv = Math.pow(1024, 2); for (ServerInfo serverInfo : serverInfoList) { long maxDiskStoreSizeForServer = ExtractorUtils.getMaxDiskStoreSizeForServer(serverInfo, diskStores); if (maxDiskStoreSizeOnDisk < maxDiskStoreSizeForServer) { maxDiskStoreSizeOnDisk = maxDiskStoreSizeForServer; } } GemFireXDDataExtractorImpl.logInfo("Maximum disk-store size on disk " + maxDiskStoreSizeOnDisk/mbDiv + " MB"); MemoryMXBean memBean = ManagementFactory.getMemoryMXBean(); MemoryUsage heapMemUsage = memBean.getHeapMemoryUsage(); long usedMemory = heapMemUsage.getUsed(); long committedMemory = heapMemUsage.getCommitted(); //For safety using the committedMemory for calculation, as it is the memory that is guaranteed to be available for the VM. long availableMemory = (committedMemory - usedMemory); GemFireXDDataExtractorImpl.logInfo("Available memory : " + availableMemory/mbDiv + " MB"); double maxMemoryPerServer = (1.2)*maxDiskStoreSizeOnDisk; //Setting the lower limit if (maxMemoryPerServer < 1) { maxMemoryPerServer = 1; } GemFireXDDataExtractorImpl.logInfo("Estimated memory needed per server : " + maxMemoryPerServer/mbDiv + " MB"); if (availableMemory < maxMemoryPerServer) { GemFireXDDataExtractorImpl.logWarning("Not enough memory to extract the server, extractor could possibly run out of memory"); } maxNumberOfServersInParallel = (int) (availableMemory/maxMemoryPerServer); if (maxNumberOfServersInParallel < 1) { maxNumberOfServersInParallel = 1; } GemFireXDDataExtractorImpl.logInfo("Recommended number of threads to extract server(s) in parallel : " + maxNumberOfServersInParallel); return maxNumberOfServersInParallel; }
Example 18
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 19
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 20
Source File: ExtractorUtils.java From gemfirexd-oss with Apache License 2.0 | 4 votes |
public static int getNumberOfThreads (List<ServerInfo> serverInfoList, List<DiskStoreImpl> diskStores) { /**** * As we extract one diskstore at a time for a given server. * Here the logic is we find the largest disk-store and use its size as a basis for worst case heap memory required * for salvaging a server at a given time. * This helps in determining how may servers can we salvage in parallel for given heap memory. * This is a very conservative estimate. */ long maxDiskStoreSizeOnDisk = 0; int maxNumberOfServersInParallel = 1; final double mbDiv = Math.pow(1024, 2); for (ServerInfo serverInfo : serverInfoList) { long maxDiskStoreSizeForServer = ExtractorUtils.getMaxDiskStoreSizeForServer(serverInfo, diskStores); if (maxDiskStoreSizeOnDisk < maxDiskStoreSizeForServer) { maxDiskStoreSizeOnDisk = maxDiskStoreSizeForServer; } } GemFireXDDataExtractorImpl.logInfo("Maximum disk-store size on disk " + maxDiskStoreSizeOnDisk/mbDiv + " MB"); MemoryMXBean memBean = ManagementFactory.getMemoryMXBean(); MemoryUsage heapMemUsage = memBean.getHeapMemoryUsage(); long usedMemory = heapMemUsage.getUsed(); long committedMemory = heapMemUsage.getCommitted(); //For safety using the committedMemory for calculation, as it is the memory that is guaranteed to be available for the VM. long availableMemory = (committedMemory - usedMemory); GemFireXDDataExtractorImpl.logInfo("Available memory : " + availableMemory/mbDiv + " MB"); double maxMemoryPerServer = (1.2)*maxDiskStoreSizeOnDisk; //Setting the lower limit if (maxMemoryPerServer < 1) { maxMemoryPerServer = 1; } GemFireXDDataExtractorImpl.logInfo("Estimated memory needed per server : " + maxMemoryPerServer/mbDiv + " MB"); if (availableMemory < maxMemoryPerServer) { GemFireXDDataExtractorImpl.logWarning("Not enough memory to extract the server, extractor could possibly run out of memory"); } maxNumberOfServersInParallel = (int) (availableMemory/maxMemoryPerServer); if (maxNumberOfServersInParallel < 1) { maxNumberOfServersInParallel = 1; } GemFireXDDataExtractorImpl.logInfo("Recommended number of threads to extract server(s) in parallel : " + maxNumberOfServersInParallel); return maxNumberOfServersInParallel; }