Package java.lang.management

Examples of java.lang.management.OperatingSystemMXBean


  }
  private void logPlatformInfo(String serviceName) {
    if (ManagementFactory.getPlatformMBeanServer() != null) {
      RuntimeMXBean bean = ManagementFactory.getRuntimeMXBean();
      // MemoryMXBean memoryBean = ManagementFactory.getMemoryMXBean();
      OperatingSystemMXBean osBean = ManagementFactory.getOperatingSystemMXBean();
      // bean.getName() should return a string that looks like this: PID@HOSTNAME
      // where PID is the process id and the HOSTNAME is the name of the machine
      processPid = bean.getName();
      if (processPid != null && processPid.trim().length() > 0) {
        int endPos = processPid.indexOf("@"); // find the position where the PID ends
        if (endPos > -1) {
          processPid = processPid.substring(0, endPos);
        }
      }
   
      String loadedJars = getLoadedJars()
      DateFormat df = new SimpleDateFormat("dd MMM yyyy HH:mm:ss ");

      StringBuffer platformInfo = new StringBuffer();
      platformInfo.append("\n+------------------------------------------------------------------");
      platformInfo.append("\n                   Starting UIMA AS Service - PID:" + processPid);
      platformInfo.append("\n+------------------------------------------------------------------");
      platformInfo.append("\n+ Service Name:" + serviceName);
      platformInfo.append("\n+ Service Queue Name:" + endpointName);
      platformInfo.append("\n+ Service Start Time:" + df.format(bean.getStartTime()));
      platformInfo.append("\n+ UIMA AS Version:" + uimaAsVersion.getVersionString());
      platformInfo.append("\n+ UIMA Core Version:" + UIMAFramework.getVersionString());
      platformInfo.append("\n+ OS Name:" + osBean.getName());
      platformInfo.append("\n+ OS Version:" + osBean.getVersion());
      platformInfo.append("\n+ OS Architecture:" + osBean.getArch());
      platformInfo.append("\n+ OS CPU Count:" + osBean.getAvailableProcessors());
      platformInfo.append("\n+ JVM Vendor:" + bean.getVmVendor());
      platformInfo.append("\n+ JVM Name:" + bean.getVmName());
      platformInfo.append("\n+ JVM Version:" + bean.getVmVersion());
      platformInfo.append("\n+ JVM Input Args:" + bean.getInputArguments());
      platformInfo.append("\n+ JVM Classpath:" + bean.getClassPath());
View Full Code Here


        int maxNameLen;
        String name;
        Map<String, String> props = new HashMap<String, String>();

        RuntimeMXBean         runtime = ManagementFactory.getRuntimeMXBean();
        OperatingSystemMXBean os = ManagementFactory.getOperatingSystemMXBean();
        ThreadMXBean          threads = ManagementFactory.getThreadMXBean();
        MemoryMXBean          mem = ManagementFactory.getMemoryMXBean();
        ClassLoadingMXBean    cl = ManagementFactory.getClassLoadingMXBean();

        //
        // print ServiceMix informations
        //
        maxNameLen = 25;
        io.out.println("ServiceMix");
        printValue("ServiceMix home", maxNameLen, System.getProperty("servicemix.home"));
        printValue("ServiceMix base", maxNameLen, System.getProperty("servicemix.base"));
        printValue("ServiceMix version", maxNameLen, branding.getVersion());
        io.out.println();

        io.out.println("JVM");
        printValue("Java Virtual Machine", maxNameLen, runtime.getVmName() + " version " + runtime.getVmVersion());
        printValue("Vendor", maxNameLen, runtime.getVmVendor());
        printValue("Uptime", maxNameLen, printDuration(runtime.getUptime()));
        try {
            printValue("Process CPU time", maxNameLen, printDuration(getSunOsValueAsLong(os, "getProcessCpuTime") / 1000000));
        } catch (Throwable t) {}
        printValue("Total compile time", maxNameLen, printDuration(ManagementFactory.getCompilationMXBean().getTotalCompilationTime()));

        io.out.println("Threads");
        printValue("Live threads", maxNameLen, Integer.toString(threads.getThreadCount()));
        printValue("Daemon threads", maxNameLen, Integer.toString(threads.getDaemonThreadCount()));
        printValue("Peak", maxNameLen, Integer.toString(threads.getPeakThreadCount()));
        printValue("Total started", maxNameLen, Long.toString(threads.getTotalStartedThreadCount()));

        io.out.println("Memory");
        printValue("Current heap size", maxNameLen, printSizeInKb(mem.getHeapMemoryUsage().getUsed()));
        printValue("Maximum heap size", maxNameLen, printSizeInKb(mem.getHeapMemoryUsage().getMax()));
        printValue("Committed heap size", maxNameLen, printSizeInKb(mem.getHeapMemoryUsage().getCommitted()));
        printValue("Pending objects", maxNameLen, Integer.toString(mem.getObjectPendingFinalizationCount()));
        for (GarbageCollectorMXBean gc : ManagementFactory.getGarbageCollectorMXBeans()) {
            String val = "Name = '" + gc.getName() + "', Collections = " + gc.getCollectionCount() + ", Time = " + printDuration(gc.getCollectionTime());
            printValue("Garbage collector", maxNameLen, val);
        }

        io.out.println("Classes");
        printValue("Current classes loaded", maxNameLen, printLong(cl.getLoadedClassCount()));
        printValue("Total classes loaded", maxNameLen, printLong(cl.getTotalLoadedClassCount()));
        printValue("Total classes unloaded", maxNameLen, printLong(cl.getUnloadedClassCount()));

        io.out.println("Operating system");
        printValue("Name", maxNameLen, os.getName() + " version " + os.getVersion());
        printValue("Architecture", maxNameLen, os.getArch());
        printValue("Processors", maxNameLen, Integer.toString(os.getAvailableProcessors()));
        try {
            printValue("Total physical memory", maxNameLen, printSizeInKb(getSunOsValueAsLong(os, "getTotalPhysicalMemorySize")));
            printValue("Free physical memory", maxNameLen, printSizeInKb(getSunOsValueAsLong(os, "getFreePhysicalMemorySize")));
            printValue("Committed virtual memory", maxNameLen, printSizeInKb(getSunOsValueAsLong(os, "getCommittedVirtualMemorySize")));
            printValue("Total swap space", maxNameLen, printSizeInKb(getSunOsValueAsLong(os, "getTotalSwapSpaceSize")));
View Full Code Here

    /*
     * Test method for
     * 'java.lang.management.ManagementFactory.getOperatingSystemMXBean()'
     */
    public void testGetOperatingSystemMXBean() {
        OperatingSystemMXBean mb = ManagementFactory.getOperatingSystemMXBean();
        assertNotNull(mb);

        // Verify that there is only instance of this bean
        OperatingSystemMXBean mb2 = ManagementFactory
                .getOperatingSystemMXBean();
        assertNotNull(mb2);
        assertSame(mb, mb2);
    }
View Full Code Here

     * 'java.lang.management.ManagementFactory.newPlatformMXBeanProxy(MBeanServerConnection,
     * String, Class<T>) <T>'
     */
    public void testNewPlatformMXBeanProxy_OperatingSystemMXBean()
            throws Exception {
        OperatingSystemMXBean proxy = ManagementFactory.newPlatformMXBeanProxy(
                ManagementFactory.getPlatformMBeanServer(),
                "java.lang:type=OperatingSystem", OperatingSystemMXBean.class);
        assertNotNull(proxy);
        OperatingSystemMXBean mb = ManagementFactory.getOperatingSystemMXBean();
        assertEquals(mb.getArch(), proxy.getArch());
        assertEquals(mb.getAvailableProcessors(), proxy
                .getAvailableProcessors());
        assertEquals(mb.getVersion(), proxy.getVersion());
        assertEquals(mb.getName(), proxy.getName());
    }
View Full Code Here

    private Method method_getProcessCpuLoad;
  private Method method_getSystemCpuLoad;
  private Method method_getFreePhysicalMemorySize;
 
  public PerformanceMonitor(){
    OperatingSystemMXBean operatingSystemMXBean= ManagementFactory.getOperatingSystemMXBean();
    try {
      method_getProcessCpuLoad = operatingSystemMXBean.getClass().getMethod("getProcessCpuLoad");
      method_getSystemCpuLoad = operatingSystemMXBean.getClass().getMethod("getSystemCpuLoad");
      method_getFreePhysicalMemorySize = operatingSystemMXBean.getClass().getMethod("getFreePhysicalMemorySize");
      method_getProcessCpuLoad.setAccessible(true);
      method_getSystemCpuLoad.setAccessible(true);
      method_getFreePhysicalMemorySize.setAccessible(true);
    } catch (Exception e) {
        //workaround to support legacy java versions the
View Full Code Here

      return Math.max(value, 0);
    }
   
    //http://docs.oracle.com/javase/7/docs/jre/api/management/extension/com/sun/management/OperatingSystemMXBean.html
    public SystemResourcesInfo createRessourcenInfo(){
      OperatingSystemMXBean operatingSystemMXBean= ManagementFactory.getOperatingSystemMXBean();
      MemoryMXBean memoryMXBean = ManagementFactory.getMemoryMXBean();
      java.lang.management.ThreadMXBean threadMXBean = ManagementFactory.getThreadMXBean();
      ClassLoadingMXBean classLoadingMXBean  = ManagementFactory.getClassLoadingMXBean();
     
      double processCpuLoad=0;
View Full Code Here

        /* some useful information - log the number of fds used before
         * and after a test is run. Helps to verify we are freeing resources
         * correctly. Unfortunately this only works on unix systems (the
         * only place sun has implemented as part of the mgmt bean api.
         */
        OperatingSystemMXBean osMbean =
            ManagementFactory.getOperatingSystemMXBean();
        if (osMbean != null && osMbean instanceof UnixOperatingSystemMXBean) {
            UnixOperatingSystemMXBean unixos =
                (UnixOperatingSystemMXBean)osMbean;
            LOG.info("Initial fdcount is: "
View Full Code Here

        /* some useful information - log the number of fds used before
         * and after a test is run. Helps to verify we are freeing resources
         * correctly. Unfortunately this only works on unix systems (the
         * only place sun has implemented as part of the mgmt bean api.
         */
        OperatingSystemMXBean osMbean =
            ManagementFactory.getOperatingSystemMXBean();
        if (osMbean != null && osMbean instanceof UnixOperatingSystemMXBean) {
            UnixOperatingSystemMXBean unixos =
                (UnixOperatingSystemMXBean)osMbean;
            LOG.info("fdcount after test is: "
View Full Code Here

     * @return The amount of RAM in the system
     */
    public static int getSystemRam() {
        long ramm = 0;
        int ram = 0;
        OperatingSystemMXBean operatingSystemMXBean = ManagementFactory.getOperatingSystemMXBean();
        try {
            Method m = operatingSystemMXBean.getClass().getDeclaredMethod("getTotalPhysicalMemorySize");
            m.setAccessible(true);
            Object value = m.invoke(operatingSystemMXBean);
            if (value != null) {
                ramm = Long.parseLong(value.toString());
                ram = (int) (ramm / 1048576);
View Full Code Here

         if (connection == null) {
            log.warn("MBean connection is not open, cannot read GC stats");
            return;
         }

         OperatingSystemMXBean os = ManagementFactory.newPlatformMXBeanProxy(connection,
               ManagementFactory.OPERATING_SYSTEM_MXBEAN_NAME, OperatingSystemMXBean.class);
         int procCount = os.getAvailableProcessors();

         List<GarbageCollectorMXBean> gcMbeans = getGarbageCollectorMXBeans(connection);
         long gcTime = 0;
         for (GarbageCollectorMXBean gcBean : gcMbeans)
            gcTime += gcBean.getCollectionTime();
View Full Code Here

TOP

Related Classes of java.lang.management.OperatingSystemMXBean

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.