Java Code Examples for java.lang.management.ManagementFactory#getGarbageCollectorMXBeans()
The following examples show how to use
java.lang.management.ManagementFactory#getGarbageCollectorMXBeans() .
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: JVMGC.java From light-task-scheduler with Apache License 2.0 | 6 votes |
private JVMGC() { for (GarbageCollectorMXBean item : ManagementFactory.getGarbageCollectorMXBeans()) { if ("ConcurrentMarkSweep".equals(item.getName()) // || "MarkSweepCompact".equals(item.getName()) // || "PS MarkSweep".equals(item.getName()) // || "G1 Old Generation".equals(item.getName()) // || "Garbage collection optimized for short pausetimes Old Collector".equals(item.getName()) // || "Garbage collection optimized for throughput Old Collector".equals(item.getName()) // || "Garbage collection optimized for deterministic pausetimes Old Collector".equals(item.getName()) // ) { fullGC = item; } else if ("ParNew".equals(item.getName()) // || "Copy".equals(item.getName()) // || "PS Scavenge".equals(item.getName()) // || "G1 Young Generation".equals(item.getName()) // || "Garbage collection optimized for short pausetimes Young Collector".equals(item.getName()) // || "Garbage collection optimized for throughput Young Collector".equals(item.getName()) // || "Garbage collection optimized for deterministic pausetimes Young Collector".equals(item.getName()) // ) { youngGC = item; } } }
Example 2
Source File: RuntimeInfoUtils.java From linden with Apache License 2.0 | 6 votes |
public static JVMInfo getJVMInfo() { JVMInfo jvmInfo = new JVMInfo(); Runtime runtime = Runtime.getRuntime(); jvmInfo.setFreeMemory(runtime.freeMemory()); jvmInfo.setTotalMemory(runtime.totalMemory()); jvmInfo.setMaxMemory(runtime.maxMemory()); int gcCount = 0; long gcTime = 0; for (GarbageCollectorMXBean gc : ManagementFactory.getGarbageCollectorMXBeans()) { long count = gc.getCollectionCount(); if (count >= 0) { gcCount += count; } long time = gc.getCollectionTime(); if (time >= 0) { gcTime += time; } } jvmInfo.setGcCount(gcCount); jvmInfo.setGcTime(gcTime); List<String> args = ManagementFactory.getRuntimeMXBean().getInputArguments(); jvmInfo.setArguments(joiner.join(args)); return jvmInfo; }
Example 3
Source File: PerformanceMonitor.java From Rainfall-core with Apache License 2.0 | 6 votes |
public String printGCStats() { long totalGarbageCollections = 0; long garbageCollectionTime = 0; for (java.lang.management.GarbageCollectorMXBean gc : ManagementFactory.getGarbageCollectorMXBeans()) { long count = gc.getCollectionCount(); if (count >= 0) { totalGarbageCollections += count; } long time = gc.getCollectionTime(); if (time >= 0) { garbageCollectionTime += time; } } return "Total Garbage Collections: " + totalGarbageCollections + "\n" + "Total Garbage Collection Time (ms): " + garbageCollectionTime + "\n"; }
Example 4
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 5
Source File: PrometheusMetrics.java From Lavalink with MIT License | 6 votes |
public PrometheusMetrics() { InstrumentedAppender prometheusAppender = new InstrumentedAppender(); //log metrics final LoggerContext factory = (LoggerContext) LoggerFactory.getILoggerFactory(); final ch.qos.logback.classic.Logger root = factory.getLogger(Logger.ROOT_LOGGER_NAME); prometheusAppender.setContext(root.getLoggerContext()); prometheusAppender.start(); root.addAppender(prometheusAppender); //jvm (hotspot) metrics DefaultExports.initialize(); //gc pause buckets final GcNotificationListener gcNotificationListener = new GcNotificationListener(); for (GarbageCollectorMXBean gcBean : ManagementFactory.getGarbageCollectorMXBeans()) { if (gcBean instanceof NotificationEmitter) { ((NotificationEmitter) gcBean).addNotificationListener(gcNotificationListener, null, gcBean); } } log.info("Prometheus metrics set up"); }
Example 6
Source File: GcProfiler.java From cache2k-benchmark with Apache License 2.0 | 5 votes |
@Override public void beforeIteration(BenchmarkParams benchmarkParams, IterationParams iterationParams) { installHooks(); long gcTime = 0; long gcCount = 0; for (GarbageCollectorMXBean bean : ManagementFactory.getGarbageCollectorMXBeans()) { gcCount += bean.getCollectionCount(); gcTime += bean.getCollectionTime(); } this.beforeGCCount = gcCount; this.beforeGCTime = gcTime; this.beforeAllocated = HotspotAllocationSnapshot.create(); this.beforeTime = System.nanoTime(); }
Example 7
Source File: GarbageCollectorStatistics.java From spark with GNU General Public License v3.0 | 5 votes |
public static Map<String, GarbageCollectorStatistics> pollStats() { ImmutableMap.Builder<String, GarbageCollectorStatistics> stats = ImmutableMap.builder(); for (GarbageCollectorMXBean bean : ManagementFactory.getGarbageCollectorMXBeans()) { stats.put(bean.getName(), new GarbageCollectorStatistics(bean)); } return stats.build(); }
Example 8
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 9
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 10
Source File: OmServiceMngr.java From TarsJava with BSD 3-Clause "New" or "Revised" License | 5 votes |
public void initAndStartOmService() { Communicator communicator = CommunicatorFactory.getInstance().getCommunicator(); String app = ConfigurationManager.getInstance().getServerConfig().getApplication(); String serverName = ConfigurationManager.getInstance().getServerConfig().getServerName(); String basePath = ConfigurationManager.getInstance().getServerConfig().getBasePath(); String modualName = ConfigurationManager.getInstance().getServerConfig().getCommunicatorConfig().getModuleName(); ConfigHelper.getInstance().setConfigInfo(communicator, app, serverName, basePath); NodeHelper.getInstance().setNodeInfo(communicator, app, serverName); NotifyHelper.getInstance().setNotifyInfo(communicator, app, serverName); PropertyReportHelper.getInstance().init(communicator, modualName); NodeHelper.getInstance().reportVersion(ClientVersion.getVersion()); Policy avgPolicy = new CommonPropertyPolicy.Avg(); Policy maxPolicy = new CommonPropertyPolicy.Max(); PropertyReportHelper.getInstance().createPropertyReporter(OmConstants.PropWaitTime, avgPolicy, maxPolicy); PropertyReportHelper.getInstance().createPropertyReporter(OmConstants.PropHeapUsed, new MemoryHeapUsedAvg()); PropertyReportHelper.getInstance().createPropertyReporter(OmConstants.PropHeapCommitted, new MemoryHeapCommittedAvg()); PropertyReportHelper.getInstance().createPropertyReporter(OmConstants.PropHeapMax, new MemoryHeapMaxAvg()); PropertyReportHelper.getInstance().createPropertyReporter(OmConstants.PropThreadCount, new ThreadNumAvg()); for (GarbageCollectorMXBean gcMXBean : ManagementFactory.getGarbageCollectorMXBeans()) { PropertyReportHelper.getInstance().createPropertyReporter(OmConstants.PropGcCount + gcMXBean.getName(), new GCNumCount(gcMXBean.getName())); PropertyReportHelper.getInstance().createPropertyReporter(OmConstants.PropGcTime + gcMXBean.getName(), new GCTimeSum(gcMXBean.getName())); } ServerStatHelper.getInstance().init(communicator); TarsTraceZipkinConfiguration.getInstance().init(); ScheduledServiceMngr.getInstance().start(); }
Example 11
Source File: DashboardCommand.java From arthas with Apache License 2.0 | 5 votes |
private static void addGcInfo(TableElement table) { List<GarbageCollectorMXBean> garbageCollectorMxBeans = ManagementFactory.getGarbageCollectorMXBeans(); for (GarbageCollectorMXBean garbageCollectorMXBean : garbageCollectorMxBeans) { String name = garbageCollectorMXBean.getName(); table.add(new RowElement().style(Decoration.bold.bold()).add("gc." + beautifyName(name) + ".count", "" + garbageCollectorMXBean.getCollectionCount())); table.row("gc." + beautifyName(name) + ".time(ms)", "" + garbageCollectorMXBean.getCollectionTime()); } }
Example 12
Source File: MetricUtils.java From flink with Apache License 2.0 | 5 votes |
private static void instantiateGarbageCollectorMetrics(MetricGroup metrics) { List<GarbageCollectorMXBean> garbageCollectors = ManagementFactory.getGarbageCollectorMXBeans(); for (final GarbageCollectorMXBean garbageCollector: garbageCollectors) { MetricGroup gcGroup = metrics.addGroup(garbageCollector.getName()); gcGroup.<Long, Gauge<Long>>gauge("Count", garbageCollector::getCollectionCount); gcGroup.<Long, Gauge<Long>>gauge("Time", garbageCollector::getCollectionTime); } }
Example 13
Source File: JVMMetrics.java From incubator-heron with Apache License 2.0 | 5 votes |
private void updateGcTimes() { long totalTimeMs = 0; for (GarbageCollectorMXBean bean : ManagementFactory.getGarbageCollectorMXBeans()) { long collectionTimeMs = bean.getCollectionTime(); totalTimeMs += collectionTimeMs; // Replace all non alpha-numeric characters to '-' String normalizedKeyName = bean.getName().replaceAll("[^\\w]", "-"); jvmGCTimeMsPerGCType.safeScope(normalizedKeyName).setValue(collectionTimeMs); } jvmGCTimeMs.setValue(totalTimeMs); }
Example 14
Source File: JvmMetrics.java From hadoop with Apache License 2.0 | 5 votes |
private void doGarbageCollectionUpdates() { List<GarbageCollectorMXBean> gcBeans = ManagementFactory.getGarbageCollectorMXBeans(); long count = 0; long timeMillis = 0; for (GarbageCollectorMXBean gcBean : gcBeans) { count += gcBean.getCollectionCount(); timeMillis += gcBean.getCollectionTime(); } metrics.incrMetric("gcCount", (int)(count - gcCount)); metrics.incrMetric("gcTimeMillis", (int)(timeMillis - gcTimeMillis)); gcCount = count; gcTimeMillis = timeMillis; }
Example 15
Source File: GCHelper.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
public static CollectionSummary createFromMxBeans() { CollectionSummary summary = new CollectionSummary(); List<GarbageCollectorMXBean> gcBeans = ManagementFactory.getGarbageCollectorMXBeans(); for (int c=0; c<gcBeans.size(); c++) { GarbageCollectorMXBean currBean = gcBeans.get(c); Boolean isYoung = beanCollectorTypes.get(currBean.getName()); assertNotNull(isYoung, "Unknown MXBean name: " + currBean.getName()); long collectionTime = currBean.getCollectionTime() * 1000; // Convert from millis to micros. summary.add(currBean.getName(), isYoung.booleanValue(), currBean.getCollectionCount(), collectionTime); } return summary; }
Example 16
Source File: JvmMetrics.java From hadoop-gpu with Apache License 2.0 | 5 votes |
private void doGarbageCollectionUpdates() { List<GarbageCollectorMXBean> gcBeans = ManagementFactory.getGarbageCollectorMXBeans(); long count = 0; long timeMillis = 0; for (GarbageCollectorMXBean gcBean : gcBeans) { count += gcBean.getCollectionCount(); timeMillis += gcBean.getCollectionTime(); } metrics.incrMetric("gcCount", (int)(count - gcCount)); metrics.incrMetric("gcTimeMillis", (int)(timeMillis - gcTimeMillis)); gcCount = count; gcTimeMillis = timeMillis; }
Example 17
Source File: GCNotifications.java From garmadon with Apache License 2.0 | 4 votes |
public void subscribe(BiConsumer<Long, ?> printer) { for (GarbageCollectorMXBean bean : ManagementFactory.getGarbageCollectorMXBeans()) { NotificationEmitter emitter = (NotificationEmitter) bean; emitter.addNotificationListener(listener, null, printer); } }
Example 18
Source File: Task.java From big-c with Apache License 2.0 | 4 votes |
public GcTimeUpdater() { this.gcBeans = ManagementFactory.getGarbageCollectorMXBeans(); getElapsedGc(); // Initialize 'lastGcMillis' with the current time spent. }
Example 19
Source File: GcTimeUpdater.java From tez with Apache License 2.0 | 4 votes |
public GcTimeUpdater(TezCounters counters) { this.gcBeans = ManagementFactory.getGarbageCollectorMXBeans(); getElapsedGc(); // Initialize 'lastGcMillis' with the current time spent. this.counters = counters; }
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()); } }); } } } } } }