Java Code Examples for java.lang.management.ClassLoadingMXBean

The following examples show how to use java.lang.management.ClassLoadingMXBean. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: micrometer   Source File: ClassLoaderMetrics.java    License: Apache License 2.0 8 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")
            .baseUnit(BaseUnits.CLASSES)
            .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")
            .baseUnit(BaseUnits.CLASSES)
            .register(registry);
}
 
Example 2
Source Project: DeconvolutionLab2   Source File: FileMeter.java    License: GNU General Public License v3.0 6 votes vote down vote up
@Override
public void setDetail() {
	File[] roots = File.listRoots();
	int i=0;
	add(i++, new String[] { "Properties", "java.class.path", System.getProperty("java.class.path") });
	add(i++, new String[] { "Properties", "java.home", System.getProperty("java.home") });
	add(i++, new String[] { "Properties", "user.dir", System.getProperty("user.dir") });
	add(i++, new String[] { "Properties", "user.home", System.getProperty("user.home") });
	add(i++, new String[] { "Properties", "user.name", System.getProperty("user.name") });

	for (File root : roots) {
		add(i++, new String[] { "FileSystem", "Root Path", root.getAbsolutePath() });
		add(i++, new String[] { "FileSystem", "Total Space", NumFormat.bytes(root.getTotalSpace()) });
		add(i++, new String[] { "FileSystem", "Usable Space", NumFormat.bytes(root.getUsableSpace()) });
	}		
	ClassLoadingMXBean loader = ManagementFactory.getClassLoadingMXBean();
	add(i++, new String[] { "ClassLoading", "Loaded Class", "" + loader.getLoadedClassCount() });
}
 
Example 3
@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 4
Source Project: Deta_Cache   Source File: OperatingSystemInfoUtil.java    License: Apache License 2.0 5 votes vote down vote up
/**
	 * Java ������������ϵͳ
	 */
	public static Map<String, String> showClassLoading(){
		Map<String, String> map = new HashMap<>();
		ClassLoadingMXBean cl = ManagementFactory.getClassLoadingMXBean();
		map.put("TotalLoadedClassCount: ", "" +cl.getTotalLoadedClassCount());
		map.put("LoadedClassCount", "" + cl.getLoadedClassCount());
		map.put("UnloadedClassCount:" , "" + cl.getTotalLoadedClassCount());	
		return map;	
//		System.out.println("TotalLoadedClassCount: " + cl.getTotalLoadedClassCount());
//		System.out.println("LoadedClassCount" + cl.getLoadedClassCount());
//		System.out.println("UnloadedClassCount:" + cl.getUnloadedClassCount());
	}
 
Example 5
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 6
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 7
Source Project: vjtools   Source File: JmxClient.java    License: Apache License 2.0 5 votes vote down vote up
public synchronized ClassLoadingMXBean getClassLoadingMXBean() throws IOException {
	if (hasPlatformMXBeans && classLoadingMBean == null) {
		classLoadingMBean = ManagementFactory.newPlatformMXBeanProxy(server,
				ManagementFactory.CLASS_LOADING_MXBEAN_NAME, ClassLoadingMXBean.class);
	}
	return classLoadingMBean;
}
 
Example 8
Source Project: hugegraph   Source File: SystemMetrics.java    License: Apache License 2.0 5 votes vote down vote up
private Map<String, Object> getClassLoadingMetrics() {
    Map<String, Object> metrics = new LinkedHashMap<>();
    ClassLoadingMXBean classLoadingMxBean = ManagementFactory
                                            .getClassLoadingMXBean();
    metrics.put("count", classLoadingMxBean.getLoadedClassCount());
    metrics.put("loaded", classLoadingMxBean.getTotalLoadedClassCount());
    metrics.put("unloaded", classLoadingMxBean.getUnloadedClassCount());
    return metrics;
}
 
Example 9
Source Project: vjtools   Source File: JmxClient.java    License: Apache License 2.0 5 votes vote down vote up
public synchronized ClassLoadingMXBean getClassLoadingMXBean() throws IOException {
	if (hasPlatformMXBeans && classLoadingMBean == null) {
		classLoadingMBean = ManagementFactory.newPlatformMXBeanProxy(server,
				ManagementFactory.CLASS_LOADING_MXBEAN_NAME, ClassLoadingMXBean.class);
	}
	return classLoadingMBean;
}
 
Example 10
Source Project: quarkus   Source File: SmallRyeMetricsRecorder.java    License: Apache License 2.0 5 votes vote down vote up
private void micrometerJvmClassLoaderMetrics(MetricRegistry registry) {
    // The ClassLoadingMXBean can be used in native mode, but it only returns zeroes, so there's no point in including such metrics.
    if (!ImageInfo.inImageCode()) {
        ClassLoadingMXBean classLoadingBean = ManagementFactory.getClassLoadingMXBean();

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

        registry.register(
                new ExtendedMetadataBuilder()
                        .withName("jvm.classes.unloaded")
                        .withType(MetricType.COUNTER)
                        .withUnit("classes")
                        .withDescription(
                                "The total number of classes unloaded since the Java virtual machine has started execution")
                        .withOpenMetricsKeyOverride("jvm_classes_unloaded_classes_total")
                        .build(),
                new GetCountOnlyCounter() {
                    @Override
                    public long getCount() {
                        return classLoadingBean.getUnloadedClassCount();
                    }
                });
    }
}
 
Example 11
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 12
Source Project: game-server   Source File: SysUtil.java    License: MIT License 5 votes vote down vote up
/**
 * 类加载信息
 * 
 * @author JiangZhiYong
 * @QQ 359135103 2017年10月12日 下午3:39:22
 * @param spliteStr
 * @return
 */
public static String classLoadInfo(String spliteStr) {
	ClassLoadingMXBean bean = ManagementFactory.getClassLoadingMXBean();
	StringBuilder sb = new StringBuilder();
	sb.append("类加载数:   " + bean.getLoadedClassCount()).append(spliteStr);
	sb.append("类加载总数:   " + bean.getTotalLoadedClassCount()).append(spliteStr);
	sb.append("类卸载数:   " + bean.getUnloadedClassCount()).append(spliteStr);
	return sb.toString();
}
 
Example 13
Source Project: swage   Source File: ClassLoadingSensor.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void sense(final MetricContext 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
Source Project: openjdk-systemtest   Source File: ClassProfiler.java    License: Apache License 2.0 5 votes vote down vote up
private void recordClassStats(RuntimeMXBean rb, ClassLoadingMXBean cb) {
	// Print out time in 2 d.p.
	DecimalFormat df = new DecimalFormat("#0.00"); 
	// Write stats to file
	this.csv.println(df.format(rb.getUptime() / 1000) + "," + cb.getLoadedClassCount() + ","
			+ cb.getTotalLoadedClassCount() + "," + cb.getUnloadedClassCount());
}
 
Example 15
Source Project: ClusterDeviceControlPlatform   Source File: Test.java    License: MIT License 5 votes vote down vote up
private static void printClassLoadingInfo() {
    ClassLoadingMXBean classLoad = ManagementFactory.getClassLoadingMXBean();
    System.out.println("已加载类总数:" + classLoad.getTotalLoadedClassCount());
    System.out.println("已加载当前类:" + classLoad.getLoadedClassCount());
    System.out.println("已卸载类总数:" + classLoad.getUnloadedClassCount());

}
 
Example 16
Source Project: ClusterDeviceControlPlatform   Source File: Test.java    License: MIT License 5 votes vote down vote up
private static void printClassLoadingInfo() {
    ClassLoadingMXBean classLoad = ManagementFactory.getClassLoadingMXBean();
    System.out.println("已加载类总数:" + classLoad.getTotalLoadedClassCount());
    System.out.println("已加载当前类:" + classLoad.getLoadedClassCount());
    System.out.println("已卸载类总数:" + classLoad.getUnloadedClassCount());

}
 
Example 17
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
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
Source Project: jdk8u-jdk   Source File: MXBeanInteropTest1.java    License: GNU General Public License v2.0 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 20
Source Project: uavstack   Source File: JVMStateCapHandler.java    License: Apache License 2.0 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 21
Source Project: visualvm   Source File: MonitoredDataImpl.java    License: GNU General Public License v2.0 5 votes vote down vote up
MonitoredDataImpl(JmxSupport jmxSupport,JvmMXBeans jmxModel) {
  this(jmxSupport);
  RuntimeMXBean runtimeBean = jmxModel.getRuntimeMXBean();
  upTime = runtimeBean.getUptime();
  ClassLoadingMXBean classBean = jmxModel.getClassLoadingMXBean();
  ThreadMXBean threadBean = jmxModel.getThreadMXBean();
  MemoryUsage mem = jmxModel.getMemoryMXBean().getHeapMemoryUsage();
  MemoryPoolMXBean permBean = jmxSupport.getPermGenPool();
  unloadedClasses = classBean.getUnloadedClassCount();
  loadedClasses = classBean.getLoadedClassCount() + unloadedClasses;
  sharedLoadedClasses = 0;
  sharedUnloadedClasses = 0;
  threadsDaemon = threadBean.getDaemonThreadCount();
  threadsLive = threadBean.getThreadCount();
  threadsLivePeak = threadBean.getPeakThreadCount();
  threadsStarted = threadBean.getTotalStartedThreadCount();
  applicationTime = 0;
  genCapacity = new long[2];
  genUsed = new long[2];
  genMaxCapacity = new long[2];
  genCapacity[0] = mem.getCommitted();
  genUsed[0] = mem.getUsed();
  genMaxCapacity[0] = mem.getMax();
  if (permBean != null) {
      MemoryUsage perm = permBean.getUsage();
      genCapacity[1] = perm.getCommitted();
      genUsed[1] = perm.getUsed();
      genMaxCapacity[1] = perm.getMax();
  }
}
 
Example 22
Source Project: visualvm   Source File: JvmMXBeansFactory.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns an MXBean proxy for the class loading system of the JVM.
 */
public synchronized ClassLoadingMXBean getClassLoadingMXBean() {
    if (mbsc != null && classLoadingMXBean == null) {
        classLoadingMXBean = getMXBean(CLASS_LOADING_MXBEAN_NAME, ClassLoadingMXBean.class);
    }
    return classLoadingMXBean;
}
 
Example 23
Source Project: jdk8u_jdk   Source File: MXBeanInteropTest1.java    License: GNU General Public License v2.0 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 24
Source Project: jmxmon   Source File: ProxyClient.java    License: Apache License 2.0 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 25
Source Project: confucius-commons   Source File: ClassLoaderUtilsTest.java    License: Apache License 2.0 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 26
Source Project: watcher   Source File: ClassloadMetrics.java    License: Apache License 2.0 5 votes vote down vote up
public Object doMonitor(Map<String, Object> params) {
	Map<String, Object> map = Maps.newHashMap();
	ClassLoadingMXBean mxBean = ManagementFactory.getClassLoadingMXBean();
	map.put("totalLoadedClassCount", mxBean.getTotalLoadedClassCount());
	map.put("loadedClassCount", mxBean.getLoadedClassCount());
	map.put("unloadedClassCount", mxBean.getUnloadedClassCount());
	return map;
}
 
Example 27
Source Project: jvmtop   Source File: ProxyClient.java    License: GNU General Public License v2.0 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 28
Source Project: jmonitor   Source File: JMServer.java    License: GNU General Public License v2.0 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 29
Source Project: kieker   Source File: ClassLoadingSampler.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected IMonitoringRecord[] createNewMonitoringRecords(final long timestamp, final String hostname, final String vmName,
		final IMonitoringController monitoringCtr) {
	if (!monitoringCtr.isProbeActivated(SignatureFactory.createJVMClassLoadSignature())) {
		return new IMonitoringRecord[] {};
	}

	final ClassLoadingMXBean classLoadingBean = ManagementFactory.getClassLoadingMXBean();
	return new IMonitoringRecord[] { new ClassLoadingRecord(timestamp, hostname, vmName, classLoadingBean.getTotalLoadedClassCount(),
			classLoadingBean.getLoadedClassCount(), classLoadingBean.getUnloadedClassCount()), };
}
 
Example 30
Source Project: nifi   Source File: JVMDiagnosticTask.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public DiagnosticsDumpElement captureDump(final boolean verbose) {
    final MemoryMXBean memory = ManagementFactory.getMemoryMXBean();
    final ClassLoadingMXBean classLoading = ManagementFactory.getClassLoadingMXBean();
    final MemoryUsage heap = memory.getHeapMemoryUsage();
    final ThreadMXBean threads = ManagementFactory.getThreadMXBean();
    final RuntimeMXBean runtime = ManagementFactory.getRuntimeMXBean();

    final List<String> details = new ArrayList<>();
    final NumberFormat numberFormat = NumberFormat.getInstance();

    details.add("Total Thread Count: " + numberFormat.format(threads.getThreadCount()));
    details.add("Daemon Thread Count: " + numberFormat.format(threads.getDaemonThreadCount()));

    details.add("Max Heap: " + FormatUtils.formatDataSize(heap.getMax()));
    details.add("Heap Used: " + FormatUtils.formatDataSize(heap.getUsed()));
    details.add("Heap Committed: " + FormatUtils.formatDataSize(heap.getCommitted()));

    details.add("JVM Uptime: " + FormatUtils.formatHoursMinutesSeconds(runtime.getUptime(), TimeUnit.MILLISECONDS));

    details.add("JVM Spec Name: " + runtime.getSpecName());
    details.add("JVM Spec Vendor: " + runtime.getSpecVendor());
    details.add("JVM Spec Version: " + runtime.getSpecVersion());

    details.add("JVM Vendor: " + runtime.getVmVendor());
    details.add("JVM Version: " + runtime.getVmVersion());
    details.add("Classes Loaded: " + numberFormat.format(classLoading.getLoadedClassCount()));
    details.add("Classes Loaded Since Start: " + numberFormat.format(classLoading.getTotalLoadedClassCount()));
    details.add("Working Directory: " + new File(".").getAbsolutePath());

    return new StandardDiagnosticsDumpElement("Java Virtual Machine", details);
}