Java Code Examples for java.lang.management.ManagementFactory#getClassLoadingMXBean()

The following examples show how to use java.lang.management.ManagementFactory#getClassLoadingMXBean() . 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: ClassLoadingSampler.java    From kieker with Apache License 2.0 5 votes vote down vote up
@Override
protected IMonitoringRecord[] createNewMonitoringRecords(final long timestamp, final String hostname, final String vmName,
		final IMonitoringController monitoringCtr) {
	if (!monitoringCtr.isProbeActivated(SignatureFactory.createJVMClassLoadSignature())) {
		return new IMonitoringRecord[] {};
	}

	final ClassLoadingMXBean classLoadingBean = ManagementFactory.getClassLoadingMXBean();
	return new IMonitoringRecord[] { new ClassLoadingRecord(timestamp, hostname, vmName, classLoadingBean.getTotalLoadedClassCount(),
			classLoadingBean.getLoadedClassCount(), classLoadingBean.getUnloadedClassCount()), };
}
 
Example 2
Source File: ClassloadMetrics.java    From watcher with Apache License 2.0 5 votes vote down vote up
public Object doMonitor(Map<String, Object> params) {
	Map<String, Object> map = Maps.newHashMap();
	ClassLoadingMXBean mxBean = ManagementFactory.getClassLoadingMXBean();
	map.put("totalLoadedClassCount", mxBean.getTotalLoadedClassCount());
	map.put("loadedClassCount", mxBean.getLoadedClassCount());
	map.put("unloadedClassCount", mxBean.getUnloadedClassCount());
	return map;
}
 
Example 3
Source File: JavaInfo.java    From haxademic with MIT License 5 votes vote down vote up
public static void printClassLoaderInfo() {
    ClassLoader cl = Thread.currentThread().getContextClassLoader();
    out.println("thread context class loader "+cl.getClass().getName());
    out.println("system class loader "+ClassLoader.getSystemClassLoader().getClass().getName());
    ClassLoadingMXBean cx = ManagementFactory.getClassLoadingMXBean();
    out.println("loaded classes count "+cx.getLoadedClassCount());
}
 
Example 4
Source File: SystemMetrics.java    From hugegraph with Apache License 2.0 5 votes vote down vote up
private Map<String, Object> getClassLoadingMetrics() {
    Map<String, Object> metrics = new LinkedHashMap<>();
    ClassLoadingMXBean classLoadingMxBean = ManagementFactory
                                            .getClassLoadingMXBean();
    metrics.put("count", classLoadingMxBean.getLoadedClassCount());
    metrics.put("loaded", classLoadingMxBean.getTotalLoadedClassCount());
    metrics.put("unloaded", classLoadingMxBean.getUnloadedClassCount());
    return metrics;
}
 
Example 5
Source File: OperatingSystemInfoUtil.java    From Deta_Cache with Apache License 2.0 5 votes vote down vote up
/**
	 * Java ������������ϵͳ
	 */
	public static Map<String, String> showClassLoading(){
		Map<String, String> map = new HashMap<>();
		ClassLoadingMXBean cl = ManagementFactory.getClassLoadingMXBean();
		map.put("TotalLoadedClassCount: ", "" +cl.getTotalLoadedClassCount());
		map.put("LoadedClassCount", "" + cl.getLoadedClassCount());
		map.put("UnloadedClassCount:" , "" + cl.getTotalLoadedClassCount());	
		return map;	
//		System.out.println("TotalLoadedClassCount: " + cl.getTotalLoadedClassCount());
//		System.out.println("LoadedClassCount" + cl.getLoadedClassCount());
//		System.out.println("UnloadedClassCount:" + cl.getUnloadedClassCount());
	}
 
Example 6
Source File: SmallRyeMetricsRecorder.java    From quarkus with Apache License 2.0 5 votes vote down vote up
private void micrometerJvmClassLoaderMetrics(MetricRegistry registry) {
    // The ClassLoadingMXBean can be used in native mode, but it only returns zeroes, so there's no point in including such metrics.
    if (!ImageInfo.inImageCode()) {
        ClassLoadingMXBean classLoadingBean = ManagementFactory.getClassLoadingMXBean();

        registry.register(
                new ExtendedMetadataBuilder()
                        .withName("jvm.classes.loaded")
                        .withType(MetricType.GAUGE)
                        .withUnit("classes")
                        .withDescription("The number of classes that are currently loaded in the Java virtual machine")
                        .withOpenMetricsKeyOverride("jvm_classes_loaded_classes")
                        .build(),
                new Gauge() {
                    @Override
                    public Number getValue() {
                        return classLoadingBean.getLoadedClassCount();
                    }
                });

        registry.register(
                new ExtendedMetadataBuilder()
                        .withName("jvm.classes.unloaded")
                        .withType(MetricType.COUNTER)
                        .withUnit("classes")
                        .withDescription(
                                "The total number of classes unloaded since the Java virtual machine has started execution")
                        .withOpenMetricsKeyOverride("jvm_classes_unloaded_classes_total")
                        .build(),
                new GetCountOnlyCounter() {
                    @Override
                    public long getCount() {
                        return classLoadingBean.getUnloadedClassCount();
                    }
                });
    }
}
 
Example 7
Source File: JvmClassLoadingImpl.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
static ClassLoadingMXBean getClassLoadingMXBean() {
    return ManagementFactory.getClassLoadingMXBean();
}
 
Example 8
Source File: TestJmx.java    From util4j with Apache License 2.0 4 votes vote down vote up
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 9
Source File: JavaInfoPage.java    From scelight with Apache License 2.0 4 votes vote down vote up
@Override
public JComponent createPageComp() {
	final BorderPanel p = new BorderPanel();
	
	final XTable table = new XTable();
	
	final Vector< Vector< Object > > data = new Vector<>();
	
	data.add( Utils.vector( "Java vendor", System.getProperty( "java.vendor" ) ) );
	data.add( Utils.vector( "Java version", System.getProperty( "java.version" ) ) );
	data.add( Utils.vector( "Java home", System.getProperty( "java.home" ) ) );
	data.add( Utils.vector( "Java runtime name", System.getProperty( "java.runtime.name" ) ) );
	data.add( Utils.vector( "Java runtime version", System.getProperty( "java.runtime.version" ) ) );
	data.add( Utils.vector( "Java spec. vendor", System.getProperty( "java.specification.vendor" ) ) );
	data.add( Utils.vector( "Java spec. name", System.getProperty( "java.specification.name" ) ) );
	data.add( Utils.vector( "Java spec. version", System.getProperty( "java.specification.version" ) ) );
	
	final RuntimeMXBean bean = ManagementFactory.getRuntimeMXBean();
	if ( SkillLevel.DEVELOPER.isAtLeast() ) {
		data.add( Utils.vector( "Java VM spec. vendor", bean.getSpecVendor() ) );
		data.add( Utils.vector( "Java VM spec. name", bean.getSpecName() ) );
		data.add( Utils.vector( "Java VM spec. version", bean.getSpecVersion() ) );
		
		data.add( Utils.vector( "Java VM impl. vendor", bean.getVmVendor() ) );
		data.add( Utils.vector( "Java VM impl. name", bean.getVmName() ) );
		data.add( Utils.vector( "Java VM impl. version", bean.getVmVersion() ) );
		
		data.add( Utils.vector( "Java input arguments", bean.getInputArguments() ) );
		
		data.add( Utils.vector( "Boot class path", bean.getBootClassPath() ) );
		data.add( Utils.vector( "Library path", bean.getLibraryPath() ) );
		data.add( Utils.vector( "Class path", bean.getClassPath() ) );
	}
	
	data.add( Utils.vector( "Java start time", new Date( bean.getStartTime() ) ) );
	data.add( Utils.vector( "Java uptime", DurationFormat.AUTO.formatDuration( bean.getUptime() ) ) );
	
	if ( SkillLevel.DEVELOPER.isAtLeast() ) {
		final ClassLoadingMXBean clBean = ManagementFactory.getClassLoadingMXBean();
		data.add( Utils.vector( "Currently loaded classes", clBean.getLoadedClassCount() ) );
		data.add( Utils.vector( "Total loaded classes", clBean.getTotalLoadedClassCount() ) );
		data.add( Utils.vector( "Unloaded classes", clBean.getUnloadedClassCount() ) );
		
		final ThreadMXBean tBean = ManagementFactory.getThreadMXBean();
		data.add( Utils.vector( "Current thread count", tBean.getThreadCount() ) );
		data.add( Utils.vector( "Peak thread count", tBean.getPeakThreadCount() ) );
		data.add( Utils.vector( "Total started thread count", tBean.getTotalStartedThreadCount() ) );
	}
	
	table.getXTableModel().setDataVector( data, Utils.vector( "Property name", "Property value" ) );
	table.packColumnsExceptLast();
	
	p.addCenter( table.createWrapperBox( true, table.createToolBarParams( p ) ) );
	
	return p;
}
 
Example 10
Source File: JvmClassLoadingImpl.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
static ClassLoadingMXBean getClassLoadingMXBean() {
    return ManagementFactory.getClassLoadingMXBean();
}
 
Example 11
Source File: DiagnosticTask.java    From netbeans with Apache License 2.0 4 votes vote down vote up
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 12
Source File: MetricUtils.java    From flink with Apache License 2.0 4 votes vote down vote up
private static void instantiateClassLoaderMetrics(MetricGroup metrics) {
	final ClassLoadingMXBean mxBean = ManagementFactory.getClassLoadingMXBean();
	metrics.<Long, Gauge<Long>>gauge("ClassesLoaded", mxBean::getTotalLoadedClassCount);
	metrics.<Long, Gauge<Long>>gauge("ClassesUnloaded", mxBean::getUnloadedClassCount);
}
 
Example 13
Source File: Classes.java    From visualvm with GNU General Public License v2.0 4 votes vote down vote up
/** Should be called at earliest possible time */
public static void initialize() {
    classLoadingBean = ManagementFactory.getClassLoadingMXBean();
}
 
Example 14
Source File: JvmClassLoadingImpl.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
static ClassLoadingMXBean getClassLoadingMXBean() {
    return ManagementFactory.getClassLoadingMXBean();
}
 
Example 15
Source File: JvmClassLoadingImpl.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
static ClassLoadingMXBean getClassLoadingMXBean() {
    return ManagementFactory.getClassLoadingMXBean();
}
 
Example 16
Source File: JvmClassLoadingImpl.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
static ClassLoadingMXBean getClassLoadingMXBean() {
    return ManagementFactory.getClassLoadingMXBean();
}
 
Example 17
Source File: JvmClassLoadingImpl.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
static ClassLoadingMXBean getClassLoadingMXBean() {
    return ManagementFactory.getClassLoadingMXBean();
}
 
Example 18
Source File: JvmClassLoadingImpl.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
static ClassLoadingMXBean getClassLoadingMXBean() {
    return ManagementFactory.getClassLoadingMXBean();
}
 
Example 19
Source File: MetricUtils.java    From flink with Apache License 2.0 4 votes vote down vote up
private static void instantiateClassLoaderMetrics(MetricGroup metrics) {
	final ClassLoadingMXBean mxBean = ManagementFactory.getClassLoadingMXBean();
	metrics.<Long, Gauge<Long>>gauge("ClassesLoaded", mxBean::getTotalLoadedClassCount);
	metrics.<Long, Gauge<Long>>gauge("ClassesUnloaded", mxBean::getUnloadedClassCount);
}
 
Example 20
Source File: MetricUtils.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
private static void instantiateClassLoaderMetrics(MetricGroup metrics) {
	final ClassLoadingMXBean mxBean = ManagementFactory.getClassLoadingMXBean();
	metrics.<Long, Gauge<Long>>gauge("ClassesLoaded", mxBean::getTotalLoadedClassCount);
	metrics.<Long, Gauge<Long>>gauge("ClassesUnloaded", mxBean::getUnloadedClassCount);
}