Java Code Examples for java.lang.management.ClassLoadingMXBean

The following are top voted examples for showing how to use java.lang.management.ClassLoadingMXBean. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: flink   File: MetricUtils.java   Source Code and License 6 votes vote down vote up
private static void instantiateClassLoaderMetrics(MetricGroup metrics) {
	final ClassLoadingMXBean mxBean = ManagementFactory.getClassLoadingMXBean();

	metrics.<Long, Gauge<Long>>gauge("ClassesLoaded", new Gauge<Long> () {
		@Override
		public Long getValue() {
			return mxBean.getTotalLoadedClassCount();
		}
	});

	metrics.<Long, Gauge<Long>>gauge("ClassesUnloaded", new Gauge<Long> () {
		@Override
		public Long getValue() {
			return mxBean.getUnloadedClassCount();
		}
	});
}
 
Example 2
Project: flink   File: TaskExecutorMetricsInitializer.java   Source Code and License 6 votes vote down vote up
private static void instantiateClassLoaderMetrics(MetricGroup metrics) {
	final ClassLoadingMXBean mxBean = ManagementFactory.getClassLoadingMXBean();

	metrics.<Long, Gauge<Long>>gauge("ClassesLoaded", new Gauge<Long> () {
		@Override
		public Long getValue() {
			return mxBean.getTotalLoadedClassCount();
		}
	});

	metrics.<Long, Gauge<Long>>gauge("ClassesUnloaded", new Gauge<Long> () {
		@Override
		public Long getValue() {
			return mxBean.getUnloadedClassCount();
		}
	});
}
 
Example 3
Project: ktop   File: KTop.java   Source Code and License 6 votes vote down vote up
protected Object doExecute() throws Exception {
    if (numThreads != null) {
         numberOfDisplayedThreads = Integer.parseInt(numThreads);
    }
    if (updates != null) {
         DEFAULT_REFRESH_INTERVAL = Integer.parseInt(updates);
    } 
    try {
        RuntimeMXBean runtime = ManagementFactory.getRuntimeMXBean();
        OperatingSystemMXBean os = ManagementFactory.getOperatingSystemMXBean();
        ThreadMXBean threads = ManagementFactory.getThreadMXBean();
        MemoryMXBean mem = ManagementFactory.getMemoryMXBean();
        ClassLoadingMXBean cl = ManagementFactory.getClassLoadingMXBean();
        KTop(runtime, os, threads, mem, cl);
    } catch (IOException e) {
        //Ignore
    }
    return null;
}
 
Example 4
Project: cn1   File: Test.java   Source Code and License 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    ClassLoadingMXBean classMXBean = ManagementFactory
            .getClassLoadingMXBean();
    if (!classMXBean.isVerbose()) {
        fail();
    }
    Class.forName(args[0]);
    classMXBean.setVerbose(false);
    if (classMXBean.isVerbose()) {
        fail();
    }
    System.out.println(args[1]);
    Class.forName(args[2]);
    classMXBean.setVerbose(true);
    if (!classMXBean.isVerbose()) {
        fail();
    }
    System.out.println(args[3]);
    System.exit(77);
}
 
Example 5
Project: cn1   File: ManagementUtils.java   Source Code and License 6 votes vote down vote up
/**
 * Creates the metadata for the {@link ClassLoadingMXBean}bean. For this
 * type of platform bean the metadata covers :
 * <ul>
 * <li>4 attributes
 * <li>0 constructors
 * <li>0 operations
 * <li>0 notifications
 * </ul>
 * 
 * @param result
 */
private static void addClassLoadingInfo(HashMap<String, MBeanInfo> result) {
    // Attributes
    MBeanAttributeInfo[] attributes = new MBeanAttributeInfo[4];
    attributes[0] = new MBeanAttributeInfo("LoadedClassCount", Integer.TYPE
            .getName(), "LoadedClassCount", true, false, false);
    attributes[1] = new MBeanAttributeInfo("TotalLoadedClassCount",
            Long.TYPE.getName(), "TotalLoadedClassCount", true, false,
            false);
    attributes[2] = new MBeanAttributeInfo("UnloadedClassCount", Long.TYPE
            .getName(), "UnloadedClassCount", true, false, false);
    attributes[3] = new MBeanAttributeInfo("Verbose", Boolean.TYPE
            .getName(), "Verbose", true, true, true);
    result.put(ClassLoadingMXBean.class.getName(), new MBeanInfo(
            ClassLoadingMXBeanImpl.class.getName(),
            ClassLoadingMXBeanImpl.class.getName(), attributes, null, null,
            null));
}
 
Example 6
Project: cn1   File: ManagementFactoryTest.java   Source Code and License 6 votes vote down vote up
public void testNewPlatformMXBeanProxy_ClassLoadingMXBean()
        throws Exception {
    ClassLoadingMXBean proxy = ManagementFactory.newPlatformMXBeanProxy(
            ManagementFactory.getPlatformMBeanServer(),
            "java.lang:type=ClassLoading", ClassLoadingMXBean.class);
    assertNotNull(proxy);
    ClassLoadingMXBean classLoadingMXBean = ManagementFactory
            .getClassLoadingMXBean();
    assertEquals(proxy.getLoadedClassCount(), classLoadingMXBean
            .getLoadedClassCount());
    assertEquals(proxy.getTotalLoadedClassCount(), classLoadingMXBean
            .getTotalLoadedClassCount());
    assertEquals(proxy.getUnloadedClassCount(), classLoadingMXBean
            .getUnloadedClassCount());
    assertEquals(proxy.isVerbose(), classLoadingMXBean.isVerbose());

    boolean initialVal = proxy.isVerbose();
    proxy.setVerbose(!initialVal);
    assertTrue(proxy.isVerbose() != initialVal);
    proxy.setVerbose(initialVal);
    assertEquals(initialVal, proxy.isVerbose());
}
 
Example 7
Project: wildfly-core   File: PlatformMBeanResourceUnitTestCase.java   Source Code and License 6 votes vote down vote up
@Test
public void testClassLoadingMXBean() throws IOException {
    DescribedResource describedResource = basicResourceTest("class-loading", null);

    ClassLoadingMXBean mbean = ManagementFactory.getClassLoadingMXBean();
    boolean verbose = describedResource.resource.get("verbose").asBoolean();
    Assert.assertEquals(mbean.isVerbose(), verbose);

    ModelNode op = getOperation("write-attribute", "class-loading", null);
    op.get("name").set("verbose");
    op.get("value").set(!verbose);
    executeOp(op, false);
    Assert.assertEquals(mbean.isVerbose(), !verbose);

    // Restore
    mbean.setVerbose(verbose);
}
 
Example 8
Project: freeVM   File: ManagementUtils.java   Source Code and License 6 votes vote down vote up
/**
 * Creates the metadata for the {@link ClassLoadingMXBean}bean. For this
 * type of platform bean the metadata covers :
 * <ul>
 * <li>4 attributes
 * <li>0 constructors
 * <li>0 operations
 * <li>0 notifications
 * </ul>
 * 
 * @param result
 */
private static void addClassLoadingInfo(HashMap<String, MBeanInfo> result) {
    // Attributes
    MBeanAttributeInfo[] attributes = new MBeanAttributeInfo[4];
    attributes[0] = new MBeanAttributeInfo("LoadedClassCount", Integer.TYPE
            .getName(), "LoadedClassCount", true, false, false);
    attributes[1] = new MBeanAttributeInfo("TotalLoadedClassCount",
            Long.TYPE.getName(), "TotalLoadedClassCount", true, false,
            false);
    attributes[2] = new MBeanAttributeInfo("UnloadedClassCount", Long.TYPE
            .getName(), "UnloadedClassCount", true, false, false);
    attributes[3] = new MBeanAttributeInfo("Verbose", Boolean.TYPE
            .getName(), "Verbose", true, true, true);
    result.put(ClassLoadingMXBean.class.getName(), new MBeanInfo(
            ClassLoadingMXBeanImpl.class.getName(),
            ClassLoadingMXBeanImpl.class.getName(), attributes, null, null,
            null));
}
 
Example 9
Project: freeVM   File: ManagementFactoryTest.java   Source Code and License 6 votes vote down vote up
public void testNewPlatformMXBeanProxy_ClassLoadingMXBean()
        throws Exception {
    ClassLoadingMXBean proxy = ManagementFactory.newPlatformMXBeanProxy(
            ManagementFactory.getPlatformMBeanServer(),
            "java.lang:type=ClassLoading", ClassLoadingMXBean.class);
    assertNotNull(proxy);
    ClassLoadingMXBean classLoadingMXBean = ManagementFactory
            .getClassLoadingMXBean();
    assertEquals(proxy.getLoadedClassCount(), classLoadingMXBean
            .getLoadedClassCount());
    assertEquals(proxy.getTotalLoadedClassCount(), classLoadingMXBean
            .getTotalLoadedClassCount());
    assertEquals(proxy.getUnloadedClassCount(), classLoadingMXBean
            .getUnloadedClassCount());
    assertEquals(proxy.isVerbose(), classLoadingMXBean.isVerbose());

    boolean initialVal = proxy.isVerbose();
    proxy.setVerbose(!initialVal);
    assertTrue(proxy.isVerbose() != initialVal);
    proxy.setVerbose(initialVal);
    assertEquals(initialVal, proxy.isVerbose());
}
 
Example 10
Project: freeVM   File: Test.java   Source Code and License 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    ClassLoadingMXBean classMXBean = ManagementFactory
            .getClassLoadingMXBean();
    if (!classMXBean.isVerbose()) {
        fail();
    }
    Class.forName(args[0]);
    classMXBean.setVerbose(false);
    if (classMXBean.isVerbose()) {
        fail();
    }
    System.out.println(args[1]);
    Class.forName(args[2]);
    classMXBean.setVerbose(true);
    if (!classMXBean.isVerbose()) {
        fail();
    }
    System.out.println(args[3]);
    System.exit(77);
}
 
Example 11
Project: freeVM   File: ManagementUtils.java   Source Code and License 6 votes vote down vote up
/**
 * Creates the metadata for the {@link ClassLoadingMXBean}bean. For this
 * type of platform bean the metadata covers :
 * <ul>
 * <li>4 attributes
 * <li>0 constructors
 * <li>0 operations
 * <li>0 notifications
 * </ul>
 * 
 * @param result
 */
private static void addClassLoadingInfo(HashMap<String, MBeanInfo> result) {
    // Attributes
    MBeanAttributeInfo[] attributes = new MBeanAttributeInfo[4];
    attributes[0] = new MBeanAttributeInfo("LoadedClassCount", Integer.TYPE
            .getName(), "LoadedClassCount", true, false, false);
    attributes[1] = new MBeanAttributeInfo("TotalLoadedClassCount",
            Long.TYPE.getName(), "TotalLoadedClassCount", true, false,
            false);
    attributes[2] = new MBeanAttributeInfo("UnloadedClassCount", Long.TYPE
            .getName(), "UnloadedClassCount", true, false, false);
    attributes[3] = new MBeanAttributeInfo("Verbose", Boolean.TYPE
            .getName(), "Verbose", true, true, true);
    result.put(ClassLoadingMXBean.class.getName(), new MBeanInfo(
            ClassLoadingMXBeanImpl.class.getName(),
            ClassLoadingMXBeanImpl.class.getName(), attributes, null, null,
            null));
}
 
Example 12
Project: freeVM   File: ManagementFactoryTest.java   Source Code and License 6 votes vote down vote up
public void testNewPlatformMXBeanProxy_ClassLoadingMXBean()
        throws Exception {
    ClassLoadingMXBean proxy = ManagementFactory.newPlatformMXBeanProxy(
            ManagementFactory.getPlatformMBeanServer(),
            "java.lang:type=ClassLoading", ClassLoadingMXBean.class);
    assertNotNull(proxy);
    ClassLoadingMXBean classLoadingMXBean = ManagementFactory
            .getClassLoadingMXBean();
    assertEquals(proxy.getLoadedClassCount(), classLoadingMXBean
            .getLoadedClassCount());
    assertEquals(proxy.getTotalLoadedClassCount(), classLoadingMXBean
            .getTotalLoadedClassCount());
    assertEquals(proxy.getUnloadedClassCount(), classLoadingMXBean
            .getUnloadedClassCount());
    assertEquals(proxy.isVerbose(), classLoadingMXBean.isVerbose());

    boolean initialVal = proxy.isVerbose();
    proxy.setVerbose(!initialVal);
    assertTrue(proxy.isVerbose() != initialVal);
    proxy.setVerbose(initialVal);
    assertEquals(initialVal, proxy.isVerbose());
}
 
Example 13
Project: swage   File: ClassLoadingSensor.java   Source Code and License 5 votes vote down vote up
@Override
public void sense(final MetricRecorder.Context metricContext)
{
    ClassLoadingMXBean mxBean = ManagementFactory.getClassLoadingMXBean();

    metricContext.record(CURRENT_COUNT, mxBean.getLoadedClassCount(), Unit.NONE);
    metricContext.record(TOTAL_COUNT, mxBean.getTotalLoadedClassCount(), Unit.NONE);
    metricContext.record(UNLOADED_COUNT, mxBean.getUnloadedClassCount(), Unit.NONE);
}
 
Example 14
Project: micrometer   File: ClassLoaderMetrics.java   Source Code and License 5 votes vote down vote up
@Override
public void bindTo(MeterRegistry registry) {
    ClassLoadingMXBean classLoadingBean = ManagementFactory.getClassLoadingMXBean();

    Gauge.builder("jvm.classes.loaded", classLoadingBean, ClassLoadingMXBean::getLoadedClassCount)
        .tags(tags)
        .description("The number of classes that are currently loaded in the Java virtual machine")
        .register(registry);

    FunctionCounter.builder("jvm.classes.unloaded", classLoadingBean, ClassLoadingMXBean::getUnloadedClassCount)
        .tags(tags)
        .description("The total number of classes unloaded since the Java virtual machine has started execution")
        .register(registry);
}
 
Example 15
Project: jdk8u-jdk   File: MXBeanInteropTest1.java   Source Code and License 5 votes vote down vote up
private final int doClassLoadingMXBeanTest(MBeanServerConnection mbsc) {
    int errorCount = 0 ;
    System.out.println("---- ClassLoadingMXBean") ;

    try {
        ObjectName classLoadingName =
                new ObjectName(ManagementFactory.CLASS_LOADING_MXBEAN_NAME) ;
        MBeanInfo mbInfo = mbsc.getMBeanInfo(classLoadingName);
        errorCount += checkNonEmpty(mbInfo);
        System.out.println("getMBeanInfo\t\t"
                + mbInfo);
        ClassLoadingMXBean classLoading = null;

        classLoading = JMX.newMXBeanProxy(mbsc,
                classLoadingName,
                ClassLoadingMXBean.class) ;
        System.out.println("getLoadedClassCount\t\t"
                + classLoading.getLoadedClassCount());
        System.out.println("getTotalLoadedClassCount\t\t"
                + classLoading.getTotalLoadedClassCount());
        System.out.println("getUnloadedClassCount\t\t"
                + classLoading.getUnloadedClassCount());
        System.out.println("isVerbose\t\t"
                + classLoading.isVerbose());

        System.out.println("---- OK\n") ;

    } catch (Exception e) {
        Utils.printThrowable(e, true) ;
        errorCount++ ;
        System.out.println("---- ERROR\n") ;
    }

    return errorCount ;
}
 
Example 16
Project: uavstack   File: JVMStateCapHandler.java   Source Code and License 5 votes vote down vote up
private void readClassLoadUsage(MonitorElementInstance instance) {

        ClassLoadingMXBean clmb = ManagementFactory.getClassLoadingMXBean();

        instance.setValue("class_total", clmb.getTotalLoadedClassCount());
        instance.setValue("class_load", clmb.getLoadedClassCount());
        instance.setValue("class_unload", clmb.getUnloadedClassCount());
    }
 
Example 17
Project: openjdk-jdk10   File: MXBeanInteropTest1.java   Source Code and License 5 votes vote down vote up
private final int doClassLoadingMXBeanTest(MBeanServerConnection mbsc) {
    int errorCount = 0 ;
    System.out.println("---- ClassLoadingMXBean") ;

    try {
        ObjectName classLoadingName =
                new ObjectName(ManagementFactory.CLASS_LOADING_MXBEAN_NAME) ;
        MBeanInfo mbInfo = mbsc.getMBeanInfo(classLoadingName);
        errorCount += checkNonEmpty(mbInfo);
        System.out.println("getMBeanInfo\t\t"
                + mbInfo);
        ClassLoadingMXBean classLoading = null;

        classLoading = JMX.newMXBeanProxy(mbsc,
                classLoadingName,
                ClassLoadingMXBean.class) ;
        System.out.println("getLoadedClassCount\t\t"
                + classLoading.getLoadedClassCount());
        System.out.println("getTotalLoadedClassCount\t\t"
                + classLoading.getTotalLoadedClassCount());
        System.out.println("getUnloadedClassCount\t\t"
                + classLoading.getUnloadedClassCount());
        System.out.println("isVerbose\t\t"
                + classLoading.isVerbose());

        System.out.println("---- OK\n") ;

    } catch (Exception e) {
        Utils.printThrowable(e, true) ;
        errorCount++ ;
        System.out.println("---- ERROR\n") ;
    }

    return errorCount ;
}
 
Example 18
Project: openjdk9   File: MXBeanInteropTest1.java   Source Code and License 5 votes vote down vote up
private final int doClassLoadingMXBeanTest(MBeanServerConnection mbsc) {
    int errorCount = 0 ;
    System.out.println("---- ClassLoadingMXBean") ;

    try {
        ObjectName classLoadingName =
                new ObjectName(ManagementFactory.CLASS_LOADING_MXBEAN_NAME) ;
        MBeanInfo mbInfo = mbsc.getMBeanInfo(classLoadingName);
        errorCount += checkNonEmpty(mbInfo);
        System.out.println("getMBeanInfo\t\t"
                + mbInfo);
        ClassLoadingMXBean classLoading = null;

        classLoading = JMX.newMXBeanProxy(mbsc,
                classLoadingName,
                ClassLoadingMXBean.class) ;
        System.out.println("getLoadedClassCount\t\t"
                + classLoading.getLoadedClassCount());
        System.out.println("getTotalLoadedClassCount\t\t"
                + classLoading.getTotalLoadedClassCount());
        System.out.println("getUnloadedClassCount\t\t"
                + classLoading.getUnloadedClassCount());
        System.out.println("isVerbose\t\t"
                + classLoading.isVerbose());

        System.out.println("---- OK\n") ;

    } catch (Exception e) {
        Utils.printThrowable(e, true) ;
        errorCount++ ;
        System.out.println("---- ERROR\n") ;
    }

    return errorCount ;
}
 
Example 19
Project: https-github.com-g0t4-jenkins2-course-spring-boot   File: SystemPublicMetrics.java   Source Code and License 5 votes vote down vote up
/**
 * Add class loading metrics.
 * @param result the result
 */
protected void addClassLoadingMetrics(Collection<Metric<?>> result) {
	ClassLoadingMXBean classLoadingMxBean = ManagementFactory.getClassLoadingMXBean();
	result.add(new Metric<Long>("classes",
			(long) classLoadingMxBean.getLoadedClassCount()));
	result.add(new Metric<Long>("classes.loaded",
			classLoadingMxBean.getTotalLoadedClassCount()));
	result.add(new Metric<Long>("classes.unloaded",
			classLoadingMxBean.getUnloadedClassCount()));
}
 
Example 20
Project: jdk8u_jdk   File: MXBeanInteropTest1.java   Source Code and License 5 votes vote down vote up
private final int doClassLoadingMXBeanTest(MBeanServerConnection mbsc) {
    int errorCount = 0 ;
    System.out.println("---- ClassLoadingMXBean") ;

    try {
        ObjectName classLoadingName =
                new ObjectName(ManagementFactory.CLASS_LOADING_MXBEAN_NAME) ;
        MBeanInfo mbInfo = mbsc.getMBeanInfo(classLoadingName);
        errorCount += checkNonEmpty(mbInfo);
        System.out.println("getMBeanInfo\t\t"
                + mbInfo);
        ClassLoadingMXBean classLoading = null;

        classLoading = JMX.newMXBeanProxy(mbsc,
                classLoadingName,
                ClassLoadingMXBean.class) ;
        System.out.println("getLoadedClassCount\t\t"
                + classLoading.getLoadedClassCount());
        System.out.println("getTotalLoadedClassCount\t\t"
                + classLoading.getTotalLoadedClassCount());
        System.out.println("getUnloadedClassCount\t\t"
                + classLoading.getUnloadedClassCount());
        System.out.println("isVerbose\t\t"
                + classLoading.isVerbose());

        System.out.println("---- OK\n") ;

    } catch (Exception e) {
        Utils.printThrowable(e, true) ;
        errorCount++ ;
        System.out.println("---- ERROR\n") ;
    }

    return errorCount ;
}
 
Example 21
Project: ublu   File: JVMHelper.java   Source Code and License 5 votes vote down vote up
private String displayManagementBean(ClassLoadingMXBean mxBean) {
    StringBuilder sb = new StringBuilder();
    if (mxBean != null) {
        sb.append(mxBean.toString()).append('\n');
        sb.append(mxBean.getObjectName().toString()).append('\n');
        sb.append("Loaded Class Count:\t").append(mxBean.getLoadedClassCount()).append('\n');
        sb.append("Total Loaded Class Count:\t").append(mxBean.getTotalLoadedClassCount()).append('\n');
        sb.append("Unloaded Class Count:\t").append(mxBean.getUnloadedClassCount()).append('\n');
    }
    return sb.toString();
}
 
Example 22
Project: lookaside_java-1.8.0-openjdk   File: MXBeanInteropTest1.java   Source Code and License 5 votes vote down vote up
private final int doClassLoadingMXBeanTest(MBeanServerConnection mbsc) {
    int errorCount = 0 ;
    System.out.println("---- ClassLoadingMXBean") ;

    try {
        ObjectName classLoadingName =
                new ObjectName(ManagementFactory.CLASS_LOADING_MXBEAN_NAME) ;
        MBeanInfo mbInfo = mbsc.getMBeanInfo(classLoadingName);
        errorCount += checkNonEmpty(mbInfo);
        System.out.println("getMBeanInfo\t\t"
                + mbInfo);
        ClassLoadingMXBean classLoading = null;

        classLoading = JMX.newMXBeanProxy(mbsc,
                classLoadingName,
                ClassLoadingMXBean.class) ;
        System.out.println("getLoadedClassCount\t\t"
                + classLoading.getLoadedClassCount());
        System.out.println("getTotalLoadedClassCount\t\t"
                + classLoading.getTotalLoadedClassCount());
        System.out.println("getUnloadedClassCount\t\t"
                + classLoading.getUnloadedClassCount());
        System.out.println("isVerbose\t\t"
                + classLoading.isVerbose());

        System.out.println("---- OK\n") ;

    } catch (Exception e) {
        Utils.printThrowable(e, true) ;
        errorCount++ ;
        System.out.println("---- ERROR\n") ;
    }

    return errorCount ;
}
 
Example 23
Project: jmxmon   File: ProxyClient.java   Source Code and License 5 votes vote down vote up
public synchronized ClassLoadingMXBean getClassLoadingMXBean() throws IOException {
    if (hasPlatformMXBeans && classLoadingMBean == null) {
        classLoadingMBean =
            newPlatformMXBeanProxy(server, CLASS_LOADING_MXBEAN_NAME,
                                   ClassLoadingMXBean.class);
    }
    return classLoadingMBean;
}
 
Example 24
Project: confucius-commons   File: ClassLoaderUtilsTest.java   Source Code and License 5 votes vote down vote up
@Test
public void testClassLoadingMXBean() {
    ClassLoadingMXBean classLoadingMXBean = ClassLoaderUtils.classLoadingMXBean;
    Assert.assertEquals(classLoadingMXBean.getTotalLoadedClassCount(), ClassLoaderUtils.getTotalLoadedClassCount());
    Assert.assertEquals(classLoadingMXBean.getLoadedClassCount(), ClassLoaderUtils.getLoadedClassCount());
    Assert.assertEquals(classLoadingMXBean.getUnloadedClassCount(), ClassLoaderUtils.getUnloadedClassCount());
    Assert.assertEquals(classLoadingMXBean.isVerbose(), ClassLoaderUtils.isVerbose());

    ClassLoaderUtils.setVerbose(true);
    Assert.assertTrue(ClassLoaderUtils.isVerbose());
}
 
Example 25
Project: spring-boot-concourse   File: SystemPublicMetrics.java   Source Code and License 5 votes vote down vote up
/**
 * Add class loading metrics.
 * @param result the result
 */
protected void addClassLoadingMetrics(Collection<Metric<?>> result) {
	ClassLoadingMXBean classLoadingMxBean = ManagementFactory.getClassLoadingMXBean();
	result.add(new Metric<Long>("classes",
			(long) classLoadingMxBean.getLoadedClassCount()));
	result.add(new Metric<Long>("classes.loaded",
			classLoadingMxBean.getTotalLoadedClassCount()));
	result.add(new Metric<Long>("classes.unloaded",
			classLoadingMxBean.getUnloadedClassCount()));
}
 
Example 26
Project: LagMonitor   File: VmCommand.java   Source Code and License 5 votes vote down vote up
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
    if (!isAllowed(sender, command)) {
        sender.sendMessage(org.bukkit.ChatColor.DARK_RED + "Not whitelisted");
        return true;
    }

    RuntimeMXBean runtimeBean = ManagementFactory.getRuntimeMXBean();

    //java info
    sender.sendMessage(PRIMARY_COLOR + "Java VM: " + SECONDARY_COLOR + runtimeBean.getVmName());
    sender.sendMessage(PRIMARY_COLOR + "Java Version: " + SECONDARY_COLOR + StandardSystemProperty.JAVA_VERSION.value());
    sender.sendMessage(PRIMARY_COLOR + "Java Vendor: " + SECONDARY_COLOR
            + runtimeBean.getVmVendor() + ' ' + runtimeBean.getVmVersion());

    //vm specification
    sender.sendMessage(PRIMARY_COLOR + "Spec name: " + SECONDARY_COLOR + runtimeBean.getSpecName());
    sender.sendMessage(PRIMARY_COLOR + "Spec Vendor: " + SECONDARY_COLOR + runtimeBean.getSpecVendor());
    sender.sendMessage(PRIMARY_COLOR + "Spec Version: " + SECONDARY_COLOR + runtimeBean.getSpecVersion());

    //class loading
    ClassLoadingMXBean classBean = ManagementFactory.getClassLoadingMXBean();
    sender.sendMessage(PRIMARY_COLOR + "Loaded Classes: " + SECONDARY_COLOR + classBean.getLoadedClassCount());
    sender.sendMessage(PRIMARY_COLOR + "Total Loaded: " + SECONDARY_COLOR + classBean.getTotalLoadedClassCount());
    sender.sendMessage(PRIMARY_COLOR + "Unloaded Classes: " + SECONDARY_COLOR + classBean.getUnloadedClassCount());

    //garbage collector
    List<GarbageCollectorMXBean> gcBean = ManagementFactory.getGarbageCollectorMXBeans();
    for (GarbageCollectorMXBean collector : gcBean) {
        sender.sendMessage(PRIMARY_COLOR + "Garbage Collector: " + SECONDARY_COLOR + collector.getName());
        sender.sendMessage(PRIMARY_COLOR + "    Time: " + SECONDARY_COLOR + collector.getCollectionTime());
        sender.sendMessage(PRIMARY_COLOR + "    Count: " + SECONDARY_COLOR + collector.getCollectionCount());
    }

    return true;
}
 
Example 27
Project: contestparser   File: SystemPublicMetrics.java   Source Code and License 5 votes vote down vote up
/**
 * Add class loading metrics.
 * @param result the result
 */
protected void addClassLoadingMetrics(Collection<Metric<?>> result) {
	ClassLoadingMXBean classLoadingMxBean = ManagementFactory.getClassLoadingMXBean();
	result.add(new Metric<Long>("classes",
			(long) classLoadingMxBean.getLoadedClassCount()));
	result.add(new Metric<Long>("classes.loaded",
			classLoadingMxBean.getTotalLoadedClassCount()));
	result.add(new Metric<Long>("classes.unloaded",
			classLoadingMxBean.getUnloadedClassCount()));
}
 
Example 28
Project: jvmtop   File: ProxyClient.java   Source Code and License 5 votes vote down vote up
public synchronized ClassLoadingMXBean getClassLoadingMXBean() throws IOException {
    if (hasPlatformMXBeans && classLoadingMBean == null) {
        classLoadingMBean =
            newPlatformMXBeanProxy(server, CLASS_LOADING_MXBEAN_NAME,
                                   ClassLoadingMXBean.class);
    }
    return classLoadingMBean;
}
 
Example 29
Project: sdcct   File: ClassLoadingMetricSet.java   Source Code and License 5 votes vote down vote up
@Override
public Map<String, Metric> getMetrics() {
    Map<String, Metric> metrics = super.getMetrics();
    ClassLoadingMXBean classLoadingMxBean = ManagementFactory.getClassLoadingMXBean();

    registerGauge(metrics, CLASSES_LOADED_COUNT_METRIC_NAME, classLoadingMxBean.getLoadedClassCount());
    registerGauge(metrics, CLASSES_LOADED_TOTAL_COUNT_METRIC_NAME, classLoadingMxBean.getTotalLoadedClassCount());
    registerGauge(metrics, CLASSES_UNLOADED_COUNT_METRIC_NAME, classLoadingMxBean.getUnloadedClassCount());

    return metrics;
}
 
Example 30
Project: jmonitor   File: JMServer.java   Source Code and License 5 votes vote down vote up
@HttpMapping(url = "/loadRuntimeInfo")
public JSONObject doLoadRuntimeInfo(Map<String, Object> param) {
    try {
        String app = ((HttpServletRequest) param.get(JMDispatcher.REQ)).getParameter("app");
        RuntimeMXBean mBean = JMConnManager.getRuntimeMBean(app);
        ClassLoadingMXBean cBean = JMConnManager.getClassMbean(app);
        Map<String, String> props = mBean.getSystemProperties();
        DateFormat format = DateFormat.getInstance();
        List<String> input = mBean.getInputArguments();
        Date date = new Date(mBean.getStartTime());

        TreeMap<String, Object> data = new TreeMap<String, Object>();

        data.put("apppid", mBean.getName());
        data.put("startparam", input.toString());
        data.put("starttime", format.format(date));
        data.put("classLoadedNow", cBean.getLoadedClassCount());
        data.put("classUnloadedAll", cBean.getUnloadedClassCount());
        data.put("classLoadedAll", cBean.getTotalLoadedClassCount());
        data.putAll(props);

        JSONObject json = new JSONObject(true);
        json.putAll(data);
        return json;
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
 
Example 31
Project: watcher   File: ClassloadMetrics.java   Source Code and License 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 32
Project: LagMonitor   File: VmCommand.java   Source Code and License 5 votes vote down vote up
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
    if (!isAllowed(sender, command)) {
        sender.sendMessage(org.bukkit.ChatColor.DARK_RED + "Not whitelisted");
        return true;
    }

    RuntimeMXBean runtimeBean = ManagementFactory.getRuntimeMXBean();

    //java info
    sender.sendMessage(PRIMARY_COLOR + "Java VM: " + SECONDARY_COLOR + runtimeBean.getVmName());
    sender.sendMessage(PRIMARY_COLOR + "Java Version: " + SECONDARY_COLOR + StandardSystemProperty.JAVA_VERSION.value());
    sender.sendMessage(PRIMARY_COLOR + "Java Vendor: " + SECONDARY_COLOR
            + runtimeBean.getVmVendor() + ' ' + runtimeBean.getVmVersion());

    //vm specification
    sender.sendMessage(PRIMARY_COLOR + "Spec name: " + SECONDARY_COLOR + runtimeBean.getSpecName());
    sender.sendMessage(PRIMARY_COLOR + "Spec Vendor: " + SECONDARY_COLOR + runtimeBean.getSpecVendor());
    sender.sendMessage(PRIMARY_COLOR + "Spec Version: " + SECONDARY_COLOR + runtimeBean.getSpecVersion());

    //class loading
    ClassLoadingMXBean classBean = ManagementFactory.getClassLoadingMXBean();
    sender.sendMessage(PRIMARY_COLOR + "Loaded Classes: " + SECONDARY_COLOR + classBean.getLoadedClassCount());
    sender.sendMessage(PRIMARY_COLOR + "Total Loaded: " + SECONDARY_COLOR + classBean.getTotalLoadedClassCount());
    sender.sendMessage(PRIMARY_COLOR + "Unloaded Classes: " + SECONDARY_COLOR + classBean.getUnloadedClassCount());

    //garbage collector
    List<GarbageCollectorMXBean> gcBean = ManagementFactory.getGarbageCollectorMXBeans();
    for (GarbageCollectorMXBean collector : gcBean) {
        sender.sendMessage(PRIMARY_COLOR + "Garbage Collector: " + SECONDARY_COLOR + collector.getName());
        sender.sendMessage(PRIMARY_COLOR + "    Time: " + SECONDARY_COLOR + collector.getCollectionTime());
        sender.sendMessage(PRIMARY_COLOR + "    Count: " + SECONDARY_COLOR + collector.getCollectionCount());
    }

    return true;
}
 
Example 33
Project: ktop   File: KTop.java   Source Code and License 5 votes vote down vote up
private void KTop(RuntimeMXBean runtime, OperatingSystemMXBean os, ThreadMXBean threads, 
                  MemoryMXBean mem, ClassLoadingMXBean cl) throws InterruptedException, IOException {

    Thread.currentThread().setName("ktop");
    boolean run = true;

    // Continously update stats to console.
    while (run) {
        //Clear console, then print JVM stats
        clearScreen();
        printOperatingSystemHeader(os);
        printThreadsHeader(runtime, threads);
        printGCHeader(); 
        printClassLoaderHeader(cl);
        printJVMHeader(mem);
        System.out.println("\u001B[36m==========================================================================================\u001B[0m");
        System.out.printf("    TID THREAD NAME                                       STATE    CPU  CPU-TIME BLOCKEDBY%n");
        printTopThreads(threads, runtime);
        // Display notifications
        System.out.printf(" Note: Only top %d threads are shown!", numberOfDisplayedThreads);
        System.out.println();
        System.out.printf(" Note: Thread stats updated at  %d ms intervals", DEFAULT_REFRESH_INTERVAL);
        System.out.println();
        System.out.println(" To exit ktop: q, Sorting: < or >, Reverse sort: r");
        System.out.println();
        System.out.println("\u001B[36m==========================================================================================\u001B[0m");

        run = waitOnKeyboard();
    }
}
 
Example 34
Project: cn1   File: ManagementFactoryTest.java   Source Code and License 5 votes vote down vote up
public void testGetClassLoadingMXBean() {
    ClassLoadingMXBean mb = ManagementFactory.getClassLoadingMXBean();
    assertNotNull(mb);

    // Verify that there is only instance of the class loading bean
    ClassLoadingMXBean mb2 = ManagementFactory.getClassLoadingMXBean();
    assertNotNull(mb2);
    assertSame(mb, mb2);
}
 
Example 35
Project: commander-shell   File: JVM.java   Source Code and License 5 votes vote down vote up
@Override
public void run() {
    ClassLoadingMXBean classLoadingMXBean = ManagementFactory.getClassLoadingMXBean();
    if (classLoadingMXBean == null) {
        output.println("Couldn't get the runtime bean!");
        return;
    }
    output.println(classLoadingMXBean.isVerbose());
    output.println(classLoadingMXBean.getLoadedClassCount());
    output.println(classLoadingMXBean.getTotalLoadedClassCount());
    output.println(classLoadingMXBean.getUnloadedClassCount());
}
 
Example 36
Project: freeVM   File: ManagementFactoryTest.java   Source Code and License 5 votes vote down vote up
public void testGetClassLoadingMXBean() {
    ClassLoadingMXBean mb = ManagementFactory.getClassLoadingMXBean();
    assertNotNull(mb);

    // Verify that there is only instance of the class loading bean
    ClassLoadingMXBean mb2 = ManagementFactory.getClassLoadingMXBean();
    assertNotNull(mb2);
    assertSame(mb, mb2);
}
 
Example 37
Project: freeVM   File: ManagementFactoryTest.java   Source Code and License 5 votes vote down vote up
public void testGetClassLoadingMXBean() {
    ClassLoadingMXBean mb = ManagementFactory.getClassLoadingMXBean();
    assertNotNull(mb);

    // Verify that there is only instance of the class loading bean
    ClassLoadingMXBean mb2 = ManagementFactory.getClassLoadingMXBean();
    assertNotNull(mb2);
    assertSame(mb, mb2);
}
 
Example 38
Project: haxademic   File: JavaInfo.java   Source Code and 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 39
Project: incubator-netbeans   File: DiagnosticTask.java   Source Code and License 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 40
Project: util4j   File: TestJmx.java   Source Code and License 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 41
Project: OpenJSharp   File: JvmClassLoadingImpl.java   Source Code and License 4 votes vote down vote up
static ClassLoadingMXBean getClassLoadingMXBean() {
    return ManagementFactory.getClassLoadingMXBean();
}
 
Example 42
Project: jdk8u-jdk   File: JvmClassLoadingImpl.java   Source Code and License 4 votes vote down vote up
static ClassLoadingMXBean getClassLoadingMXBean() {
    return ManagementFactory.getClassLoadingMXBean();
}
 
Example 43
Project: java-performance   File: ClassLoading.java   Source Code and License 4 votes vote down vote up
public static void main(String[] args) {
    ClassLoadingMXBean classLoadingMXBean = ManagementFactory.getClassLoadingMXBean();
    System.out.println("Loaded classes: " + classLoadingMXBean.getLoadedClassCount());
    System.out.println("Total loaded classes: " + classLoadingMXBean.getTotalLoadedClassCount());
    System.out.println("Unloaded classes: " + classLoadingMXBean.getUnloadedClassCount());
}
 
Example 44
Project: Java-Snippets   File: VmCommand.java   Source Code and License 4 votes vote down vote up
public static void getClassInfo() {
    ClassLoadingMXBean classBean = ManagementFactory.getClassLoadingMXBean();
    long loadedClasses = classBean.getLoadedClassCount();
    long totalLoadedClasses = classBean.getTotalLoadedClassCount();
    long unloadedClasses = classBean.getUnloadedClassCount();
}
 
Example 45
Project: prometheus-client   File: ClassLoadingMetric.java   Source Code and License 4 votes vote down vote up
ClassLoadingMetric(final ClassLoadingMXBean classLoadingMXBean) {
    this.classLoadingMXBean = classLoadingMXBean;
}
 
Example 46
Project: ServerAgent   File: ClassesDataProvider.java   Source Code and License 4 votes vote down vote up
protected Class<ClassLoadingMXBean> getMXBeanClass() {
	return ClassLoadingMXBean.class;
}
 
Example 47
Project: ServerAgent   File: ClassesDataProvider.java   Source Code and License 4 votes vote down vote up
protected long getValueFromBean(Object bean) {
	return ((ClassLoadingMXBean) bean).getLoadedClassCount();
}
 
Example 48
Project: scelight   File: JavaInfoPage.java   Source Code and License 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 49
Project: jdk8u_jdk   File: JvmClassLoadingImpl.java   Source Code and License 4 votes vote down vote up
static ClassLoadingMXBean getClassLoadingMXBean() {
    return ManagementFactory.getClassLoadingMXBean();
}
 
Example 50
Project: lookaside_java-1.8.0-openjdk   File: JvmClassLoadingImpl.java   Source Code and License 4 votes vote down vote up
static ClassLoadingMXBean getClassLoadingMXBean() {
    return ManagementFactory.getClassLoadingMXBean();
}
 
Example 51
Project: javify   File: TestClassLoading.java   Source Code and License 4 votes vote down vote up
public static void main(String[] args)
  throws Exception
{
  System.out.println("Testing locally...");
  ClassLoadingMXBean bean = ManagementFactory.getClassLoadingMXBean();
  System.out.println("Bean: " + bean);
  System.out.println("Loaded classes: " + bean.getLoadedClassCount());
  System.out.println("Unloaded classes: " + bean.getUnloadedClassCount());
  System.out.println("Total loaded classes: " + bean.getTotalLoadedClassCount());
  boolean verbosity = bean.isVerbose();
  System.out.println("Verbose class output: " + (verbosity ? "yes" : "no"));
  System.out.println("Changing verbose setting...");
  bean.setVerbose(!verbosity);
  System.out.println("Verbose class output: " + (bean.isVerbose() ? "yes" : "no"));
  System.out.println("Testing via the server...");
  MBeanServer server = ManagementFactory.getPlatformMBeanServer();
  ObjectName classBean = new ObjectName(CLASS_LOADING_MXBEAN_NAME);
  System.out.println("Bean: " + classBean);
  System.out.println("Loaded classes: " + server.getAttribute(classBean, "LoadedClassCount"));
  System.out.println("Unloaded classes: " + server.getAttribute(classBean,
                                                                "UnloadedClassCount"));
  System.out.println("Total loaded classes: " + server.getAttribute(classBean,
                                                                    "TotalLoadedClassCount"));
  verbosity = (Boolean) server.getAttribute(classBean, "Verbose");
  System.out.println("Verbose class output: " + (verbosity ? "yes" : "no"));
  System.out.println("Changing verbose setting...");
  server.setAttribute(classBean, new Attribute("Verbose", !verbosity));
  System.out.println("Verbose class output: " + ((Boolean)
                                                 server.getAttribute(classBean, "Verbose") ?
                                                 "yes" : "no"));
  System.out.println("Testing via the proxy...");
  bean = ManagementFactory.newPlatformMXBeanProxy(server, CLASS_LOADING_MXBEAN_NAME,
                                                  ClassLoadingMXBean.class);
  System.out.println("Bean: " + bean);
  System.out.println("Loaded classes: " + bean.getLoadedClassCount());
  System.out.println("Unloaded classes: " + bean.getUnloadedClassCount());
  System.out.println("Total loaded classes: " + bean.getTotalLoadedClassCount());
  verbosity = bean.isVerbose();
  System.out.println("Verbose class output: " + (verbosity ? "yes" : "no"));
  System.out.println("Changing verbose setting...");
  bean.setVerbose(!verbosity);
  System.out.println("Verbose class output: " + (bean.isVerbose() ? "yes" : "no"));
}
 
Example 52
Project: jvm-stm   File: TestClassLoading.java   Source Code and License 4 votes vote down vote up
public static void main(String[] args)
  throws Exception
{
  System.out.println("Testing locally...");
  ClassLoadingMXBean bean = ManagementFactory.getClassLoadingMXBean();
  System.out.println("Bean: " + bean);
  System.out.println("Loaded classes: " + bean.getLoadedClassCount());
  System.out.println("Unloaded classes: " + bean.getUnloadedClassCount());
  System.out.println("Total loaded classes: " + bean.getTotalLoadedClassCount());
  boolean verbosity = bean.isVerbose();
  System.out.println("Verbose class output: " + (verbosity ? "yes" : "no"));
  System.out.println("Changing verbose setting...");
  bean.setVerbose(!verbosity);
  System.out.println("Verbose class output: " + (bean.isVerbose() ? "yes" : "no"));
  System.out.println("Testing via the server...");
  MBeanServer server = ManagementFactory.getPlatformMBeanServer();
  ObjectName classBean = new ObjectName(CLASS_LOADING_MXBEAN_NAME);
  System.out.println("Bean: " + classBean);
  System.out.println("Loaded classes: " + server.getAttribute(classBean, "LoadedClassCount"));
  System.out.println("Unloaded classes: " + server.getAttribute(classBean,
						  "UnloadedClassCount"));
  System.out.println("Total loaded classes: " + server.getAttribute(classBean,
						      "TotalLoadedClassCount"));
  verbosity = (Boolean) server.getAttribute(classBean, "Verbose");
  System.out.println("Verbose class output: " + (verbosity ? "yes" : "no"));
  System.out.println("Changing verbose setting...");
  server.setAttribute(classBean, new Attribute("Verbose", !verbosity));
  System.out.println("Verbose class output: " + ((Boolean)
				   server.getAttribute(classBean, "Verbose") ?
				   "yes" : "no"));
  System.out.println("Testing via the proxy...");
  bean = ManagementFactory.newPlatformMXBeanProxy(server, CLASS_LOADING_MXBEAN_NAME,
				    ClassLoadingMXBean.class);
  System.out.println("Bean: " + bean);
  System.out.println("Loaded classes: " + bean.getLoadedClassCount());
  System.out.println("Unloaded classes: " + bean.getUnloadedClassCount());
  System.out.println("Total loaded classes: " + bean.getTotalLoadedClassCount());
  verbosity = bean.isVerbose();
  System.out.println("Verbose class output: " + (verbosity ? "yes" : "no"));
  System.out.println("Changing verbose setting...");
  bean.setVerbose(!verbosity);
  System.out.println("Verbose class output: " + (bean.isVerbose() ? "yes" : "no"));
}
 
Example 53
Project: carbon-metrics   File: ClassLoadingGaugeSet.java   Source Code and License 4 votes vote down vote up
public ClassLoadingGaugeSet(ClassLoadingMXBean mxBean) {
    this.mxBean = mxBean;
}
 
Example 54
Project: jmonitor   File: JMConnManager.java   Source Code and License 4 votes vote down vote up
public static ClassLoadingMXBean getClassMbean(String app) throws IOException {
    return getServer(app, CLSBEANAME, ClassLoadingMXBean.class);
}
 
Example 55
Project: infobip-open-jdk-8   File: JvmClassLoadingImpl.java   Source Code and License 4 votes vote down vote up
static ClassLoadingMXBean getClassLoadingMXBean() {
    return ManagementFactory.getClassLoadingMXBean();
}
 
Example 56
Project: jdk8u-dev-jdk   File: JvmClassLoadingImpl.java   Source Code and License 4 votes vote down vote up
static ClassLoadingMXBean getClassLoadingMXBean() {
    return ManagementFactory.getClassLoadingMXBean();
}
 
Example 57
Project: purej-vminspect   File: SystemData.java   Source Code and License 4 votes vote down vote up
/**
 * Creates a new instance of this class.
 */
public SystemData() {
  // Store runtime-infos:
  _rtInfo = System.getProperty("java.runtime.name") + ", " + System.getProperty("java.runtime.version");
  _rtb = ManagementFactory.getRuntimeMXBean();

  // Store thread-infos:
  ThreadMXBean tb = ManagementFactory.getThreadMXBean();
  _threadCurrentCount = tb.getThreadCount();

  // Get class-loader stuff:
  ClassLoadingMXBean clb = ManagementFactory.getClassLoadingMXBean();
  _clLoadedClassCount = clb.getLoadedClassCount();
  _clTotalLoadedClassCount = clb.getTotalLoadedClassCount();

  // Build gc collection time:
  long tmpGcCollectionCount = 0;
  long tmpGcCollectionTimeMillis = 0;
  for (GarbageCollectorMXBean garbageCollector : ManagementFactory.getGarbageCollectorMXBeans()) {
    tmpGcCollectionCount += garbageCollector.getCollectionCount();
    tmpGcCollectionTimeMillis += garbageCollector.getCollectionTime();
  }
  _gcCollectionCount = tmpGcCollectionCount;
  _gcCollectionTimeMillis = tmpGcCollectionTimeMillis;

  // Get heap / none heap memory:
  MemoryMXBean mb = ManagementFactory.getMemoryMXBean();
  _memoryHeap = new MemoryData(mb.getHeapMemoryUsage());
  _memoryNonHeap = new MemoryData(mb.getNonHeapMemoryUsage());

  // Physical / swap memory - is hidden, type is long (eg. bytes):
  _osb = ManagementFactory.getOperatingSystemMXBean();
  long memPhysTotal = getHiddenInfoLong(_osb, "getTotalPhysicalMemorySize");
  long memPhysFree = getHiddenInfoLong(_osb, "getFreePhysicalMemorySize");
  _memoryPhysical = new MemoryData(memPhysTotal != -1 ? memPhysTotal - memPhysFree : -1, -1, memPhysTotal);
  long memSwapTotal = getHiddenInfoLong(_osb, "getTotalSwapSpaceSize");
  long memSwapFree = getHiddenInfoLong(_osb, "getFreeSwapSpaceSize");
  _memorySwap = new MemoryData(memSwapTotal != -1 ? memSwapTotal - memSwapFree : -1, -1, memSwapTotal);

  // Process Cpu time is hidden - value is in nanoseconds:
  Object cpuTime = getHiddenInfo(_osb, "getProcessCpuTime");
  _processCpuTimeMillis = cpuTime != null ? ((Long) cpuTime).longValue() / 1000000 : -1;

  // Process Cpu load is hidden - value is a double between 0..1:
  Object cpuLoad = getHiddenInfo(_osb, "getProcessCpuLoad");
  double processCpuLoadPct = cpuLoad != null ? ((Double) cpuLoad).doubleValue() : -1;
  _processCpuLoadPct = processCpuLoadPct < 0 ? processCpuLoadPct : processCpuLoadPct * 100;

  // System Cpu load is hidden - value is a double between 0..1:
  Object systemLoad = getHiddenInfo(_osb, "getSystemCpuLoad");
  double systemCpuLoadPct = systemLoad != null ? ((Double) systemLoad).doubleValue() : -1;
  _systemCpuLoadPct = systemCpuLoadPct < 0 ? systemCpuLoadPct : systemCpuLoadPct * 100;

  // Open/Max file descriptor count:
  _openFileDescriptorCount = getHiddenInfoLong(_osb, "getOpenFileDescriptorCount");
  _maxFileDescriptorCount = getHiddenInfoLong(_osb, "getMaxFileDescriptorCount");
}
 
Example 58
Project: jdk7-jdk   File: JvmClassLoadingImpl.java   Source Code and License 4 votes vote down vote up
static ClassLoadingMXBean getClassLoadingMXBean() {
    return ManagementFactory.getClassLoadingMXBean();
}
 
Example 59
Project: ktop   File: KTop.java   Source Code and License 4 votes vote down vote up
private void printClassLoaderHeader(ClassLoadingMXBean cl) {
    System.out.printf(" #CurrentClassesLoaded: %-8d #TotalClassesLoaded: %-8d #TotalClassesUnloaded: %-8d %n",
                      cl.getLoadedClassCount(), cl.getTotalLoadedClassCount(), cl.getUnloadedClassCount());
}
 
Example 60
Project: openjdk-source-code-learn   File: JvmClassLoadingImpl.java   Source Code and License 4 votes vote down vote up
static ClassLoadingMXBean getClassLoadingMXBean() {
    return ManagementFactory.getClassLoadingMXBean();
}