Java 类java.lang.management.ClassLoadingMXBean 实例源码

项目:flink    文件:MetricUtils.java   
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();
        }
    });
}
项目:flink    文件:TaskExecutorMetricsInitializer.java   
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();
        }
    });
}
项目:ktop    文件:KTop.java   
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;
}
项目:cn1    文件:Test.java   
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);
}
项目:cn1    文件:ManagementUtils.java   
/**
 * 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));
}
项目:cn1    文件:ManagementFactoryTest.java   
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());
}
项目:wildfly-core    文件:PlatformMBeanResourceUnitTestCase.java   
@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);
}
项目:freeVM    文件:ManagementUtils.java   
/**
 * 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));
}
项目:freeVM    文件:ManagementFactoryTest.java   
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());
}
项目:freeVM    文件:Test.java   
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);
}
项目:freeVM    文件:ManagementUtils.java   
/**
 * 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));
}
项目:freeVM    文件:ManagementFactoryTest.java   
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());
}
项目:swage    文件:ClassLoadingSensor.java   
@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);
}
项目:micrometer    文件:ClassLoaderMetrics.java   
@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);
}
项目:jdk8u-jdk    文件:MXBeanInteropTest1.java   
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 ;
}
项目:uavstack    文件:JVMStateCapHandler.java   
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());
    }
项目:openjdk-jdk10    文件:MXBeanInteropTest1.java   
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 ;
}
项目:openjdk9    文件:MXBeanInteropTest1.java   
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 ;
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:SystemPublicMetrics.java   
/**
 * 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()));
}
项目:jdk8u_jdk    文件:MXBeanInteropTest1.java   
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 ;
}
项目:ublu    文件:JVMHelper.java   
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();
}
项目:lookaside_java-1.8.0-openjdk    文件:MXBeanInteropTest1.java   
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 ;
}
项目:jmxmon    文件:ProxyClient.java   
public synchronized ClassLoadingMXBean getClassLoadingMXBean() throws IOException {
    if (hasPlatformMXBeans && classLoadingMBean == null) {
        classLoadingMBean =
            newPlatformMXBeanProxy(server, CLASS_LOADING_MXBEAN_NAME,
                                   ClassLoadingMXBean.class);
    }
    return classLoadingMBean;
}
项目:confucius-commons    文件:ClassLoaderUtilsTest.java   
@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());
}
项目:spring-boot-concourse    文件:SystemPublicMetrics.java   
/**
 * 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()));
}
项目:LagMonitor    文件:VmCommand.java   
@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;
}
项目:contestparser    文件:SystemPublicMetrics.java   
/**
 * 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()));
}
项目:jvmtop    文件:ProxyClient.java   
public synchronized ClassLoadingMXBean getClassLoadingMXBean() throws IOException {
    if (hasPlatformMXBeans && classLoadingMBean == null) {
        classLoadingMBean =
            newPlatformMXBeanProxy(server, CLASS_LOADING_MXBEAN_NAME,
                                   ClassLoadingMXBean.class);
    }
    return classLoadingMBean;
}
项目:sdcct    文件:ClassLoadingMetricSet.java   
@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;
}
项目:jmonitor    文件:JMServer.java   
@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);
    }
}
项目:watcher    文件:ClassloadMetrics.java   
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;
}
项目:LagMonitor    文件:VmCommand.java   
@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;
}
项目:ktop    文件:KTop.java   
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();
    }
}
项目:cn1    文件:ManagementFactoryTest.java   
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);
}
项目:commander-shell    文件:JVM.java   
@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());
}
项目:freeVM    文件:ManagementFactoryTest.java   
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);
}
项目:freeVM    文件:ManagementFactoryTest.java   
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);
}
项目:haxademic    文件:JavaInfo.java   
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());
}
项目:incubator-netbeans    文件:DiagnosticTask.java   
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();
    }
项目:util4j    文件:TestJmx.java   
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**********************");
}