Java Code Examples for java.lang.management.GarbageCollectorMXBean#getName()
The following examples show how to use
java.lang.management.GarbageCollectorMXBean#getName() .
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: Measure.java From ohmdb with Apache License 2.0 | 6 votes |
private static void debug(String data) { Runtime rt = Runtime.getRuntime(); long totalMem = rt.totalMemory(); long maxMem = rt.maxMemory(); long freeMem = rt.freeMemory(); long usedMem = totalMem - freeMem; int megs = 1024 * 1024; String gcinfo = ""; List<GarbageCollectorMXBean> gcs = ManagementFactory.getGarbageCollectorMXBeans(); for (GarbageCollectorMXBean gc : gcs) { gcinfo += " | " + gc.getName() + " x " + gc.getCollectionCount() + " (" + gc.getCollectionTime() + "ms)"; } String msg = "%s | MEM [total=%sMB, used=%sMB, max=%sMB] %s"; String info = String.format(msg, data, totalMem / megs, usedMem / megs, maxMem / megs, gcinfo); System.out.println(info); }
Example 2
Source File: JvmGcMetricsImporter.java From sofa-lookout with Apache License 2.0 | 6 votes |
static synchronized void refresh() { if (System.currentTimeMillis() - lastRefreshedTime <= 1000) {//1s cache return; } List<GarbageCollectorMXBean> garbageCollectorMxBeans = ManagementFactory .getGarbageCollectorMXBeans(); for (GarbageCollectorMXBean garbageCollectorMXBean : garbageCollectorMxBeans) { String name = garbageCollectorMXBean.getName(); long gccount = garbageCollectorMXBean.getCollectionCount(); long gctime = garbageCollectorMXBean.getCollectionTime(); GcType type = m.get(name); switch (type) { case YOUNG: youngGCCount = gccount; youngGCTime = gctime; break; case OLD: oldGCCount = gccount; oldGCTime = gctime; break; } } lastRefreshedTime = System.currentTimeMillis(); }
Example 3
Source File: GCSampler.java From kieker with Apache License 2.0 | 6 votes |
@Override protected IMonitoringRecord[] createNewMonitoringRecords(final long timestamp, final String hostname, final String vmName, final IMonitoringController monitoringCtr) { if (!monitoringCtr.isProbeActivated(SignatureFactory.createJVMGarbageCollectorSignature())) { return new IMonitoringRecord[] {}; } final List<GarbageCollectorMXBean> gcBeans = ManagementFactory.getGarbageCollectorMXBeans(); final int numberOfGCs = gcBeans.size(); final IMonitoringRecord[] records = new IMonitoringRecord[numberOfGCs]; for (int i = 0; i < numberOfGCs; i++) { final GarbageCollectorMXBean gcBean = gcBeans.get(i); records[i] = new GCRecord(timestamp, hostname, vmName, gcBean.getName(), gcBean.getCollectionCount(), gcBean.getCollectionTime()); } return records; }
Example 4
Source File: ManagementFactoryTest.java From banyan with MIT License | 6 votes |
public static void main(String[] args) { ThreadMXBean threadMXBean = ManagementFactory.getThreadMXBean(); List<GarbageCollectorMXBean> garbageCollectorMXBeanList = ManagementFactory.getGarbageCollectorMXBeans(); for (GarbageCollectorMXBean gcMXBean : garbageCollectorMXBeanList) { String gcName = gcMXBean.getName(); String memoryPoolNames[] = gcMXBean.getMemoryPoolNames(); for (String memoryPoolName : memoryPoolNames) { System.out.println(memoryPoolName); } ObjectName objectName = gcMXBean.getObjectName(); String domainName = objectName.getDomain(); System.out.println(domainName+"__"+objectName.getCanonicalName()); System.out.println(gcName); } //不需要获取同步的monitor 和 synchronize信息,仅获取线程和线程堆栈信息。 ThreadInfo[] allThreads = threadMXBean.dumpAllThreads(true, true); for (ThreadInfo threadInfo : allThreads) { String threadName = threadInfo.getThreadName(); long threadId = threadInfo.getThreadId(); System.out.println(threadName + "," + threadId + "," + threadInfo.getLockOwnerName()); } }
Example 5
Source File: GarbageCollectionNotificationTest.java From openjdk-systemtest with Apache License 2.0 | 6 votes |
private static boolean assumeGCIsPartiallyConcurrent(GarbageCollectorMXBean gc) { switch (gc.getName()) { // First two are from the serial collector case "Copy": case "MarkSweepCompact": // Parallel collector case "PS MarkSweep": case "PS Scavenge": case "G1 Young Generation": // CMS young generation collector case "ParNew": return false; case "ConcurrentMarkSweep": case "G1 Old Generation": return true; // IBM J9 garbage collectors case "scavenge": case "partial gc": case "global": case "global garbage collect": return false; default: // Assume possibly concurrent if unsure return true; } }
Example 6
Source File: JVMToolHelper.java From uavstack with Apache License 2.0 | 6 votes |
public static Map<String, Long> readGCUsage(List<GarbageCollectorMXBean> gcmbList) { Map<String, Long> m = new LinkedHashMap<String, Long>(); for (GarbageCollectorMXBean gcmb : gcmbList) { String name = gcmb.getName(); String gcName = null; if (minorGC.contains(name)) { gcName = "mgc"; } else if (fullGC.contains(name)) { gcName = "fgc"; } if (gcName == null) { continue; } m.put(gcName + "_count", gcmb.getCollectionCount()); m.put(gcName + "_time", gcmb.getCollectionTime()); } return m; }
Example 7
Source File: JVMStateCapHandler.java From uavstack with Apache License 2.0 | 6 votes |
private void readGCUsage(MonitorElementInstance instance) { List<GarbageCollectorMXBean> gcmbList = ManagementFactory.getGarbageCollectorMXBeans(); for (GarbageCollectorMXBean gcmb : gcmbList) { String name = gcmb.getName(); String gcName = null; if (minorGC.contains(name)) { gcName = "mgc"; } else if (fullGC.contains(name)) { gcName = "fgc"; } if (gcName == null) { continue; } instance.setValue(gcName + "_count", gcmb.getCollectionCount()); instance.setValue(gcName + "_time", gcmb.getCollectionTime()); } }
Example 8
Source File: GcEventTest.java From spectator with Apache License 2.0 | 5 votes |
@Test public void toStringSizes() { // Try to ensure that at least one GC event has occurred System.gc(); // Loop through and get a GcInfo for (GarbageCollectorMXBean mbean : ManagementFactory.getGarbageCollectorMXBeans()) { GcInfo gcInfo = ((com.sun.management.GarbageCollectorMXBean) mbean).getLastGcInfo(); if (gcInfo != null) { GarbageCollectionNotificationInfo info = new GarbageCollectionNotificationInfo( mbean.getName(), "Action", "Allocation Failure", gcInfo); GcEvent event = new GcEvent(info, 0L); final String eventStr = event.toString(); Assertions.assertTrue(eventStr.contains("cause=[Allocation Failure]")); // TODO: need to find a better way to create a fake GcInfo object for tests final long max = HelperFunctions.getTotalMaxUsage(gcInfo.getMemoryUsageAfterGc()); if (max > (1L << 30)) { Assertions.assertTrue(eventStr.contains("GiB")); } else if (max > (1L << 20)) { Assertions.assertTrue(eventStr.contains("MiB")); } else { Assertions.assertTrue(eventStr.contains("KiB")); } } } }
Example 9
Source File: FlowController.java From nifi with Apache License 2.0 | 5 votes |
public List<GarbageCollectionStatus> getGarbageCollectionStatus() { final List<GarbageCollectionStatus> statuses = new ArrayList<>(); final Date now = new Date(); for (final GarbageCollectorMXBean mbean : ManagementFactory.getGarbageCollectorMXBeans()) { final String managerName = mbean.getName(); final long count = mbean.getCollectionCount(); final long millis = mbean.getCollectionTime(); final GarbageCollectionStatus status = new StandardGarbageCollectionStatus(managerName, now, count, millis); statuses.add(status); } return statuses; }
Example 10
Source File: ServerSchemaTablesServiceImpl.java From sql-layer with GNU Affero General Public License v3.0 | 5 votes |
@Override public GroupScan getGroupScan(VirtualAdapter adapter, Group group) { Iterator<GarbageCollectorMXBean> collectors = ManagementFactory.getGarbageCollectorMXBeans().iterator(); return new SimpleVirtualGroupScan<GarbageCollectorMXBean>(group.getAIS(), getName(), collectors) { @Override protected Object[] createRow(GarbageCollectorMXBean data, int hiddenPk) { return new Object[] { data.getName(), data.getCollectionCount(), data.getCollectionTime(), hiddenPk }; } }; }
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: JVMGC.java From mpush with Apache License 2.0 | 5 votes |
public JVMGC() { for (GarbageCollectorMXBean item : ManagementFactory.getGarbageCollectorMXBeans()) { String name = item.getName(); if (youngGcName.contains(name)) { yongGc = item; } else if (fullGcName.contains(name)) { fullGc = item; } } }
Example 13
Source File: GCStatsRecorder.java From bazel with Apache License 2.0 | 5 votes |
public Iterable<GCStat> getCurrentGcStats() { List<GCStat> stats = new ArrayList<>(); for (GarbageCollectorMXBean mxBean : mxBeans) { String name = mxBean.getName(); GCStat initStat = Preconditions.checkNotNull(initialData.get(name)); stats.add(new GCStat(name, mxBean.getCollectionCount() - initStat.getNumCollections(), mxBean.getCollectionTime() - initStat.getTotalTimeInMs())); } return stats; }
Example 14
Source File: GCStatsRecorder.java From bazel with Apache License 2.0 | 5 votes |
public GCStatsRecorder(Iterable<GarbageCollectorMXBean> mxBeans) { this.mxBeans = mxBeans; ImmutableMap.Builder<String, GCStat> initialData = ImmutableMap.builder(); for (GarbageCollectorMXBean mxBean : mxBeans) { String name = mxBean.getName(); initialData.put(name, new GCStat(name, mxBean.getCollectionCount(), mxBean.getCollectionTime())); } this.initialData = initialData.build(); }
Example 15
Source File: GCStatsGetter.java From s2g-zuul with MIT License | 5 votes |
@Override public Stats get() { List<GarbageCollectorMXBean> beans = ManagementFactory.getGarbageCollectorMXBeans(); int minorGcCount=0, fullGcCount=0, otherGcCount=0; long minorGcTime=0, fullGcTime=0, otherGcTime=0; for (GarbageCollectorMXBean b : beans) { String name = b.getName(); if (young.contains(name)) { minorGcCount += b.getCollectionCount(); minorGcTime += b.getCollectionTime(); }else if (old.contains(name)) { fullGcCount += b.getCollectionCount(); fullGcTime += b.getCollectionTime(); }else{ otherGcCount += b.getCollectionCount(); otherGcTime += b.getCollectionTime(); } } GCStats s = new GCStats(); s.setMinorGcCount(minorGcCount - previous.getMinorGcCount()); s.setMinorGcTime(minorGcTime - previous.getMinorGcTime()); s.setFullGcCount(fullGcCount - previous.getFullGcCount()); s.setFullGcTime(fullGcTime - previous.getFullGcTime()); s.setOtherGcCount(otherGcCount - previous.getOtherGcCount()); s.setOtherGcCount(otherGcTime - previous.getOtherGcTime()); previous.setMinorGcCount(minorGcCount); previous.setMinorGcTime(minorGcTime); previous.setFullGcCount(fullGcCount); previous.setFullGcTime(fullGcTime); previous.setOtherGcCount(otherGcCount); previous.setOtherGcCount(otherGcTime); return s; }
Example 16
Source File: JmxMetricTrackerTest.java From apm-agent-java with Apache License 2.0 | 5 votes |
@Test void testGC() throws Exception { setConfig(JmxMetric.valueOf("object_name[java.lang:type=GarbageCollector,name=*] attribute[CollectionCount:metric_name=collection_count]")); setConfig(JmxMetric.valueOf("object_name[java.lang:type=GarbageCollector,name=*] attribute[CollectionCount:metric_name=collection_count] attribute[CollectionTime]")); for (GarbageCollectorMXBean gcBean : ManagementFactory.getGarbageCollectorMXBeans()) { String memoryManagerName = gcBean.getName(); assertThat(metricRegistry.getGaugeValue("jvm.jmx.collection_count", Labels.Mutable.of("name", memoryManagerName).add("type", "GarbageCollector"))).isNotNegative(); assertThat(metricRegistry.getGaugeValue("jvm.jmx.CollectionTime", Labels.Mutable.of("name", memoryManagerName).add("type", "GarbageCollector"))).isNotNegative(); } printMetricSets(); }
Example 17
Source File: DefaultActivityListener.java From TNT4J with Apache License 2.0 | 4 votes |
/** * This method appends a default set of properties when activity timing stops. Developers should override this * method to add user defined set of properties. By default this method appends default set of properties defined by * {@code DEFAULT_PROPERTY_XXX} property values. Example: {@code DEFAULT_PROPERTY_CPU_TOTAL_TIME}. */ @Override public void stopped(Activity activity) { long start = System.nanoTime(); ThreadContext ctx = THREAD_CONTEXT.remove(activity); if (ctx != null) { ctx.end(); } PropertySnapshot cpu = new PropertySnapshot(DEFAULT_SNAPSHOT_CATEGORY, SNAPSHOT_CPU, activity.getSeverity()); double load = ManagementFactory.getOperatingSystemMXBean().getSystemLoadAverage(); if (load >= 0) { cpu.add(new Property(DEFAULT_PROPERTY_LOAD_AVG, load, ValueTypes.VALUE_TYPE_GAUGE)); } if (ctx != null && cpuTimingSupported) { cpu.add(DEFAULT_PROPERTY_COUNT, ManagementFactory.getOperatingSystemMXBean().getAvailableProcessors()); cpu.add(new Property(DEFAULT_PROPERTY_CPU_TIME, ((double) tmbean.getThreadCpuTime(ctx.ownerThread.getThreadId()) / 1000.0d), ValueTypes.VALUE_TYPE_AGE_USEC)); cpu.add(new Property(DEFAULT_PROPERTY_TOTAL_USER_TIME, ((double) tmbean.getThreadUserTime(ctx.ownerThread.getThreadId()) / 1000.0d), ValueTypes.VALUE_TYPE_AGE_USEC)); } activity.add(cpu); PropertySnapshot thread = new PropertySnapshot(DEFAULT_SNAPSHOT_CATEGORY, SNAPSHOT_THREAD, activity.getSeverity()); thread.add(new Property(DEFAULT_PROPERTY_COUNT, tmbean.getThreadCount(), ValueTypes.VALUE_TYPE_GAUGE)); thread.add(new Property(DEFAULT_PROPERTY_DAEMON_COUNT, tmbean.getDaemonThreadCount(), ValueTypes.VALUE_TYPE_GAUGE)); thread.add(new Property(DEFAULT_PROPERTY_STARTED_COUNT, tmbean.getTotalStartedThreadCount(), ValueTypes.VALUE_TYPE_COUNTER)); thread.add(new Property(DEFAULT_PROPERTY_PEAK_COUNT, tmbean.getPeakThreadCount(), ValueTypes.VALUE_TYPE_GAUGE)); if (ctx != null) { thread.add(new Property(DEFAULT_PROPERTY_BLOCKED_COUNT, ctx.ownerThread.getBlockedCount(), ValueTypes.VALUE_TYPE_COUNTER)); thread.add(new Property(DEFAULT_PROPERTY_WAITED_COUNT, ctx.ownerThread.getWaitedCount(), ValueTypes.VALUE_TYPE_COUNTER)); } if (ctx != null && contTimingSupported) { thread.add(new Property(DEFAULT_PROPERTY_BLOCKED_TIME, ctx.ownerThread.getBlockedTime() * 1000, ValueTypes.VALUE_TYPE_AGE_USEC)); thread.add(new Property(DEFAULT_PROPERTY_WAITED_TIME, ctx.ownerThread.getWaitedTime() * 1000, ValueTypes.VALUE_TYPE_AGE_USEC)); } activity.add(thread); PropertySnapshot mem = new PropertySnapshot(DEFAULT_SNAPSHOT_CATEGORY, SNAPSHOT_MEMORY, activity.getSeverity()); long usedMem = Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory(); double memPct = (double) ((double) usedMem / (double) Runtime.getRuntime().totalMemory()); mem.add(new Property(DEFAULT_PROPERTY_MAX_BYTES, Runtime.getRuntime().maxMemory(), ValueTypes.VALUE_TYPE_SIZE_BYTE)); mem.add(new Property(DEFAULT_PROPERTY_TOTAL_BYTES, Runtime.getRuntime().totalMemory(), ValueTypes.VALUE_TYPE_SIZE_BYTE)); mem.add(new Property(DEFAULT_PROPERTY_FREE_BYTES, Runtime.getRuntime().freeMemory(), ValueTypes.VALUE_TYPE_SIZE_BYTE)); mem.add(new Property(DEFAULT_PROPERTY_USED_BYTES, usedMem, ValueTypes.VALUE_TYPE_SIZE_BYTE)); mem.add(new Property(DEFAULT_PROPERTY_USAGE, memPct, ValueTypes.VALUE_TYPE_PERCENT)); activity.add(mem); List<GarbageCollectorMXBean> gcList = ManagementFactory.getGarbageCollectorMXBeans(); for (GarbageCollectorMXBean gc : gcList) { PropertySnapshot gcSnap = new PropertySnapshot(SNAPSHOT_CATEGORY_GC, gc.getName(), activity.getSeverity()); gcSnap.add(new Property(DEFAULT_PROPERTY_COUNT, gc.getCollectionCount(), ValueTypes.VALUE_TYPE_COUNTER)); gcSnap.add(new Property(DEFAULT_PROPERTY_TIME, gc.getCollectionTime(), ValueTypes.VALUE_TYPE_AGE_MSEC)); gcSnap.add(new Property(DEFAULT_PROPERTY_VALID, gc.isValid())); activity.add(gcSnap); } if (ctx != null && ctx.startCPUTime > 0) { PropertySnapshot snapshot = new PropertySnapshot(DEFAULT_SNAPSHOT_CATEGORY, SNAPSHOT_ACTIVITY, activity.getSeverity()); if (cpuTimingSupported) { long cpuUsed = getUsedCpuTimeNanos(ctx); double cpuUsec = ((double) cpuUsed / 1000.0d); snapshot.add(new Property(DEFAULT_PROPERTY_CPU_TIME, cpuUsec)); long slackTime = (long) (activity.getElapsedTimeUsec() - activity.getWaitTimeUsec() - cpuUsec); snapshot.add(new Property(DEFAULT_PROPERTY_SLACK_TIME, slackTime, ValueTypes.VALUE_TYPE_AGE_USEC)); snapshot.add(new Property(DEFAULT_PROPERTY_WALL_TIME, (cpuUsec + activity.getWaitTimeUsec()), ValueTypes.VALUE_TYPE_AGE_USEC)); } snapshot.add(new Property(DEFAULT_PROPERTY_BLOCKED_COUNT, (ctx.stopBlockCount - ctx.startBlockCount), ValueTypes.VALUE_TYPE_GAUGE)); snapshot.add(new Property(DEFAULT_PROPERTY_WAITED_COUNT, (ctx.stopWaitCount - ctx.startWaitCount), ValueTypes.VALUE_TYPE_GAUGE)); if (contTimingSupported) { snapshot.add(new Property(DEFAULT_PROPERTY_BLOCKED_TIME, ((ctx.stopBlockTime - ctx.startBlockTime) * 1000), ValueTypes.VALUE_TYPE_AGE_USEC)); snapshot.add(new Property(DEFAULT_PROPERTY_WAITED_TIME, ((ctx.stopWaitTime - ctx.startWaitTime) * 1000), ValueTypes.VALUE_TYPE_AGE_USEC)); } ctx.overHeadTimeNano += (System.nanoTime() - start); snapshot.add(new Property(DEFAULT_PROPERTY_OVERHEAD_TIME, ((double) ctx.overHeadTimeNano / 1000.0d), ValueTypes.VALUE_TYPE_AGE_USEC)); activity.add(snapshot); } }
Example 18
Source File: VMInfo.java From DataLink with Apache License 2.0 | 4 votes |
private VMInfo() { //初始化静态信息 osMXBean = java.lang.management.ManagementFactory.getOperatingSystemMXBean(); runtimeMXBean = java.lang.management.ManagementFactory.getRuntimeMXBean(); garbageCollectorMXBeanList = java.lang.management.ManagementFactory.getGarbageCollectorMXBeans(); memoryPoolMXBeanList = java.lang.management.ManagementFactory.getMemoryPoolMXBeans(); osInfo = runtimeMXBean.getVmVendor() + " " + runtimeMXBean.getSpecVersion() + " " + runtimeMXBean.getVmVersion(); jvmInfo = osMXBean.getName() + " " + osMXBean.getArch() + " " + osMXBean.getVersion(); totalProcessorCount = osMXBean.getAvailableProcessors(); //构建startPhyOSStatus startPhyOSStatus = new PhyOSStatus(); LOG.info("VMInfo# operatingSystem class => " + osMXBean.getClass().getName()); if (VMInfo.isSunOsMBean(osMXBean)) { { startPhyOSStatus.totalPhysicalMemory = VMInfo.getLongFromOperatingSystem(osMXBean, "getTotalPhysicalMemorySize"); startPhyOSStatus.freePhysicalMemory = VMInfo.getLongFromOperatingSystem(osMXBean, "getFreePhysicalMemorySize"); startPhyOSStatus.maxFileDescriptorCount = VMInfo.getLongFromOperatingSystem(osMXBean, "getMaxFileDescriptorCount"); startPhyOSStatus.currentOpenFileDescriptorCount = VMInfo.getLongFromOperatingSystem(osMXBean, "getOpenFileDescriptorCount"); } } //初始化processGCStatus; for (GarbageCollectorMXBean garbage : garbageCollectorMXBeanList) { GCStatus gcStatus = new GCStatus(); gcStatus.name = garbage.getName(); processGCStatus.gcStatusMap.put(garbage.getName(), gcStatus); } //初始化processMemoryStatus if (memoryPoolMXBeanList != null && !memoryPoolMXBeanList.isEmpty()) { for (MemoryPoolMXBean pool : memoryPoolMXBeanList) { MemoryStatus memoryStatus = new MemoryStatus(); memoryStatus.name = pool.getName(); memoryStatus.initSize = pool.getUsage().getInit(); memoryStatus.maxSize = pool.getUsage().getMax(); processMomoryStatus.memoryStatusMap.put(pool.getName(), memoryStatus); } } }
Example 19
Source File: GCStatistics.java From garmadon with Apache License 2.0 | 4 votes |
GCStatistics(GarbageCollectorMXBean gc) { super(GC_HEADER + "(" + gc.getName() + ")"); this.gc = gc; }
Example 20
Source File: AbstractStatisticsCollector.java From database with GNU General Public License v2.0 | 2 votes |
/** * Adds/updates counters relating to JVM Garbage Collection. These counters * should be located within a per-service path. * * @param counterSet * The counters set that is the direct parent. */ static public void addGarbageCollectorMXBeanCounters( final CounterSet counterSet) { final String name_pools = "Memory Pool Names"; final String name_count = "Collection Count"; final String name_time = "Cumulative Collection Time"; synchronized (counterSet) { final List<GarbageCollectorMXBean> list = ManagementFactory .getGarbageCollectorMXBeans(); for (final GarbageCollectorMXBean bean : list) { final String name = bean.getName(); // counter set for this GC bean (may be pre-existing). final CounterSet tmp = counterSet.makePath(name); synchronized (tmp) { // memory pool names. { if (tmp.getChild(name_pools) == null) { tmp.addCounter(name_pools, new Instrument<String>() { @Override protected void sample() { setValue(Arrays.toString(bean .getMemoryPoolNames())); } }); } } // collection count. { if (tmp.getChild(name_count) == null) { tmp.addCounter(name_count, new Instrument<Long>() { @Override protected void sample() { setValue(bean.getCollectionCount()); } }); } } // collection time. { if (tmp.getChild(name_time) == null) { tmp.addCounter(name_time, new Instrument<Long>() { @Override protected void sample() { setValue(bean.getCollectionTime()); } }); } } } } } }