Search in sources :

Example 56 with RuntimeMXBean

use of java.lang.management.RuntimeMXBean in project Mycat-Server by MyCATApache.

the class EnvironmentInformation method getJvmStartupOptionsArray.

/**
	 * Gets the system parameters and environment parameters that were passed to the JVM on startup.
	 *
	 * @return The options passed to the JVM on startup.
	 */
public static String[] getJvmStartupOptionsArray() {
    try {
        RuntimeMXBean bean = ManagementFactory.getRuntimeMXBean();
        List<String> options = bean.getInputArguments();
        return options.toArray(new String[options.size()]);
    } catch (Throwable t) {
        return new String[0];
    }
}
Also used : RuntimeMXBean(java.lang.management.RuntimeMXBean)

Example 57 with RuntimeMXBean

use of java.lang.management.RuntimeMXBean in project redisson by redisson.

the class RedissonTestRunListener method testRunStarted.

@Override
public void testRunStarted(Description description) throws Exception {
    super.testRunStarted(description);
    Runtime.getRuntime().addShutdownHook(new Thread(() -> {
        running.set(Boolean.FALSE);
    }));
    new Thread(() -> {
        final RuntimeMXBean runtimeBean = ManagementFactory.getRuntimeMXBean();
        final AtomicLong u = new AtomicLong(runtimeBean.getUptime());
        while (running.get()) {
            try {
                long upTime = runtimeBean.getUptime();
                if (upTime >= u.get() + 10000) {
                    u.set(upTime);
                    System.out.printf("Test Up Time    = %.3f (s)%n", upTime / 1000d);
                    System.out.printf("Heap Usage      = %.3f (MB)%n", ManagementFactory.getMemoryMXBean().getHeapMemoryUsage().getUsed() / 1024d / 1024d);
                    System.out.printf("None Heap Usage = %.3f (MB)%n", ManagementFactory.getMemoryMXBean().getNonHeapMemoryUsage().getUsed() / 1024d / 1024d);
                    System.out.println("=============================");
                }
                Thread.currentThread().sleep(10000l);
            } catch (InterruptedException ex) {
                Logger.getLogger(RedissonTestRunListener.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }).start();
}
Also used : AtomicLong(java.util.concurrent.atomic.AtomicLong) RuntimeMXBean(java.lang.management.RuntimeMXBean)

Example 58 with RuntimeMXBean

use of java.lang.management.RuntimeMXBean in project commons by twitter.

the class JvmStats method export.

/**
   * Exports stats related to the JVM and runtime environment.
   */
public static void export() {
    final OperatingSystemMXBean osMbean = ManagementFactory.getOperatingSystemMXBean();
    if (osMbean instanceof com.sun.management.OperatingSystemMXBean) {
        final com.sun.management.OperatingSystemMXBean sunOsMbean = (com.sun.management.OperatingSystemMXBean) osMbean;
        Stats.exportAll(ImmutableList.<Stat<? extends Number>>builder().add(new StatImpl<Long>("system_free_physical_memory_mb") {

            @Override
            public Long read() {
                return sunOsMbean.getFreePhysicalMemorySize() / BYTES_PER_MB;
            }
        }).add(new StatImpl<Long>("system_free_swap_mb") {

            @Override
            public Long read() {
                return sunOsMbean.getFreeSwapSpaceSize() / BYTES_PER_MB;
            }
        }).add(Rate.of(new StatImpl<Long>("process_cpu_time_nanos") {

            @Override
            public Long read() {
                return sunOsMbean.getProcessCpuTime();
            }
        }).withName("process_cpu_cores_utilized").withScaleFactor(SECS_PER_NANO).build()).build());
    }
    if (osMbean instanceof com.sun.management.UnixOperatingSystemMXBean) {
        final com.sun.management.UnixOperatingSystemMXBean unixOsMbean = (com.sun.management.UnixOperatingSystemMXBean) osMbean;
        Stats.exportAll(ImmutableList.<Stat<? extends Number>>builder().add(new StatImpl<Long>("process_max_fd_count") {

            @Override
            public Long read() {
                return unixOsMbean.getMaxFileDescriptorCount();
            }
        }).add(new StatImpl<Long>("process_open_fd_count") {

            @Override
            public Long read() {
                return unixOsMbean.getOpenFileDescriptorCount();
            }
        }).build());
    }
    final Runtime runtime = Runtime.getRuntime();
    final ClassLoadingMXBean classLoadingBean = ManagementFactory.getClassLoadingMXBean();
    final MemoryMXBean memoryBean = ManagementFactory.getMemoryMXBean();
    final ThreadMXBean threads = ManagementFactory.getThreadMXBean();
    final RuntimeMXBean runtimeMXBean = ManagementFactory.getRuntimeMXBean();
    Stats.exportAll(ImmutableList.<Stat<? extends Number>>builder().add(new StatImpl<Long>("jvm_time_ms") {

        @Override
        public Long read() {
            return System.currentTimeMillis();
        }
    }).add(new StatImpl<Integer>("jvm_available_processors") {

        @Override
        public Integer read() {
            return runtime.availableProcessors();
        }
    }).add(new StatImpl<Long>("jvm_memory_free_mb") {

        @Override
        public Long read() {
            return runtime.freeMemory() / BYTES_PER_MB;
        }
    }).add(new StatImpl<Long>("jvm_memory_max_mb") {

        @Override
        public Long read() {
            return runtime.maxMemory() / BYTES_PER_MB;
        }
    }).add(new StatImpl<Long>("jvm_memory_mb_total") {

        @Override
        public Long read() {
            return runtime.totalMemory() / BYTES_PER_MB;
        }
    }).add(new StatImpl<Integer>("jvm_class_loaded_count") {

        @Override
        public Integer read() {
            return classLoadingBean.getLoadedClassCount();
        }
    }).add(new StatImpl<Long>("jvm_class_total_loaded_count") {

        @Override
        public Long read() {
            return classLoadingBean.getTotalLoadedClassCount();
        }
    }).add(new StatImpl<Long>("jvm_class_unloaded_count") {

        @Override
        public Long read() {
            return classLoadingBean.getUnloadedClassCount();
        }
    }).add(new StatImpl<Long>("jvm_gc_collection_time_ms") {

        @Override
        public Long read() {
            long collectionTimeMs = 0;
            for (GarbageCollectorMXBean bean : ManagementFactory.getGarbageCollectorMXBeans()) {
                collectionTimeMs += bean.getCollectionTime();
            }
            return collectionTimeMs;
        }
    }).add(new StatImpl<Long>("jvm_gc_collection_count") {

        @Override
        public Long read() {
            long collections = 0;
            for (GarbageCollectorMXBean bean : ManagementFactory.getGarbageCollectorMXBeans()) {
                collections += bean.getCollectionCount();
            }
            return collections;
        }
    }).add(new StatImpl<Long>("jvm_memory_heap_mb_used") {

        @Override
        public Long read() {
            return memoryBean.getHeapMemoryUsage().getUsed() / BYTES_PER_MB;
        }
    }).add(new StatImpl<Long>("jvm_memory_heap_mb_committed") {

        @Override
        public Long read() {
            return memoryBean.getHeapMemoryUsage().getCommitted() / BYTES_PER_MB;
        }
    }).add(new StatImpl<Long>("jvm_memory_heap_mb_max") {

        @Override
        public Long read() {
            return memoryBean.getHeapMemoryUsage().getMax() / BYTES_PER_MB;
        }
    }).add(new StatImpl<Long>("jvm_memory_non_heap_mb_used") {

        @Override
        public Long read() {
            return memoryBean.getNonHeapMemoryUsage().getUsed() / BYTES_PER_MB;
        }
    }).add(new StatImpl<Long>("jvm_memory_non_heap_mb_committed") {

        @Override
        public Long read() {
            return memoryBean.getNonHeapMemoryUsage().getCommitted() / BYTES_PER_MB;
        }
    }).add(new StatImpl<Long>("jvm_memory_non_heap_mb_max") {

        @Override
        public Long read() {
            return memoryBean.getNonHeapMemoryUsage().getMax() / BYTES_PER_MB;
        }
    }).add(new StatImpl<Long>("jvm_uptime_secs") {

        @Override
        public Long read() {
            return runtimeMXBean.getUptime() / 1000;
        }
    }).add(new StatImpl<Double>("system_load_avg") {

        @Override
        public Double read() {
            return osMbean.getSystemLoadAverage();
        }
    }).add(new StatImpl<Integer>("jvm_threads_peak") {

        @Override
        public Integer read() {
            return threads.getPeakThreadCount();
        }
    }).add(new StatImpl<Long>("jvm_threads_started") {

        @Override
        public Long read() {
            return threads.getTotalStartedThreadCount();
        }
    }).add(new StatImpl<Integer>("jvm_threads_daemon") {

        @Override
        public Integer read() {
            return threads.getDaemonThreadCount();
        }
    }).add(new StatImpl<Integer>("jvm_threads_active") {

        @Override
        public Integer read() {
            return threads.getThreadCount();
        }
    }).build());
    // Export per memory pool gc time and cycle count like Ostrich
    // This is based on code in Bridcage: https://cgit.twitter.biz/birdcage/tree/ \
    // ostrich/src/main/scala/com/twitter/ostrich/stats/StatsCollection.scala
    Stats.exportAll(Iterables.transform(ManagementFactory.getGarbageCollectorMXBeans(), new Function<GarbageCollectorMXBean, Stat<? extends Number>>() {

        @Override
        public Stat<? extends Number> apply(final GarbageCollectorMXBean gcMXBean) {
            return new StatImpl<Long>("jvm_gc_" + Stats.normalizeName(gcMXBean.getName()) + "_collection_count") {

                @Override
                public Long read() {
                    return gcMXBean.getCollectionCount();
                }
            };
        }
    }));
    Stats.exportAll(Iterables.transform(ManagementFactory.getGarbageCollectorMXBeans(), new Function<GarbageCollectorMXBean, Stat<? extends Number>>() {

        @Override
        public Stat<? extends Number> apply(final GarbageCollectorMXBean gcMXBean) {
            return new StatImpl<Long>("jvm_gc_" + Stats.normalizeName(gcMXBean.getName()) + "_collection_time_ms") {

                @Override
                public Long read() {
                    return gcMXBean.getCollectionTime();
                }
            };
        }
    }));
    Stats.exportString(new StatImpl<String>("jvm_input_arguments") {

        @Override
        public String read() {
            return runtimeMXBean.getInputArguments().toString();
        }
    });
    for (final String property : System.getProperties().stringPropertyNames()) {
        Stats.exportString(new StatImpl<String>("jvm_prop_" + Stats.normalizeName(property)) {

            @Override
            public String read() {
                return System.getProperty(property);
            }
        });
    }
    for (final Map.Entry<String, String> environmentVariable : System.getenv().entrySet()) {
        Stats.exportString(new StatImpl<String>("system_env_" + Stats.normalizeName(environmentVariable.getKey())) {

            @Override
            public String read() {
                return environmentVariable.getValue();
            }
        });
    }
}
Also used : GarbageCollectorMXBean(java.lang.management.GarbageCollectorMXBean) Function(com.google.common.base.Function) MemoryMXBean(java.lang.management.MemoryMXBean) ClassLoadingMXBean(java.lang.management.ClassLoadingMXBean) ThreadMXBean(java.lang.management.ThreadMXBean) RuntimeMXBean(java.lang.management.RuntimeMXBean) Map(java.util.Map) OperatingSystemMXBean(java.lang.management.OperatingSystemMXBean)

Example 59 with RuntimeMXBean

use of java.lang.management.RuntimeMXBean in project mc-dev by Bukkit.

the class CrashReportJVMFlags method a.

public String a() {
    RuntimeMXBean runtimemxbean = ManagementFactory.getRuntimeMXBean();
    List list = runtimemxbean.getInputArguments();
    int i = 0;
    StringBuilder stringbuilder = new StringBuilder();
    Iterator iterator = list.iterator();
    while (iterator.hasNext()) {
        String s = (String) iterator.next();
        if (s.startsWith("-X")) {
            if (i++ > 0) {
                stringbuilder.append(" ");
            }
            stringbuilder.append(s);
        }
    }
    return String.format("%d total; %s", new Object[] { Integer.valueOf(i), stringbuilder.toString() });
}
Also used : Iterator(java.util.Iterator) List(java.util.List) RuntimeMXBean(java.lang.management.RuntimeMXBean)

Example 60 with RuntimeMXBean

use of java.lang.management.RuntimeMXBean in project android by JetBrains.

the class GoogleCrash method getDefaultParameters.

@NotNull
private static Map<String, String> getDefaultParameters() {
    Map<String, String> map = new HashMap<>();
    ApplicationInfo applicationInfo = getApplicationInfo();
    if (ANONYMIZED_UID != null) {
        map.put("guid", ANONYMIZED_UID);
    }
    RuntimeMXBean runtimeMXBean = ManagementFactory.getRuntimeMXBean();
    map.put("ptime", Long.toString(runtimeMXBean.getUptime()));
    // product specific key value pairs
    map.put(KEY_VERSION, applicationInfo == null ? "0.0.0.0" : applicationInfo.getStrictVersion());
    // must match registration with Crash
    map.put(KEY_PRODUCT_ID, CrashReport.PRODUCT_ANDROID_STUDIO);
    map.put("fullVersion", applicationInfo == null ? "0.0.0.0" : applicationInfo.getFullVersion());
    map.put("osName", StringUtil.notNullize(SystemInfo.OS_NAME));
    map.put("osVersion", StringUtil.notNullize(SystemInfo.OS_VERSION));
    map.put("osArch", StringUtil.notNullize(SystemInfo.OS_ARCH));
    map.put("locale", StringUtil.notNullize(LOCALE));
    map.put("vmName", StringUtil.notNullize(runtimeMXBean.getVmName()));
    map.put("vmVendor", StringUtil.notNullize(runtimeMXBean.getVmVendor()));
    map.put("vmVersion", StringUtil.notNullize(runtimeMXBean.getVmVersion()));
    MemoryUsage usage = ManagementFactory.getMemoryMXBean().getHeapMemoryUsage();
    map.put("heapUsed", Long.toString(usage.getUsed()));
    map.put("heapCommitted", Long.toString(usage.getCommitted()));
    map.put("heapMax", Long.toString(usage.getMax()));
    return map;
}
Also used : HashMap(com.intellij.util.containers.HashMap) ApplicationInfo(com.intellij.openapi.application.ApplicationInfo) RuntimeMXBean(java.lang.management.RuntimeMXBean) MemoryUsage(java.lang.management.MemoryUsage) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

RuntimeMXBean (java.lang.management.RuntimeMXBean)92 OperatingSystemMXBean (java.lang.management.OperatingSystemMXBean)16 MemoryMXBean (java.lang.management.MemoryMXBean)11 IOException (java.io.IOException)9 GarbageCollectorMXBean (java.lang.management.GarbageCollectorMXBean)9 ThreadMXBean (java.lang.management.ThreadMXBean)8 MemoryUsage (java.lang.management.MemoryUsage)6 Method (java.lang.reflect.Method)6 ArrayList (java.util.ArrayList)6 ClassLoadingMXBean (java.lang.management.ClassLoadingMXBean)5 HashMap (java.util.HashMap)5 Map (java.util.Map)5 Properties (java.util.Properties)5 InputStream (java.io.InputStream)4 MemoryPoolMXBean (java.lang.management.MemoryPoolMXBean)4 Field (java.lang.reflect.Field)4 Date (java.util.Date)4 BufferedReader (java.io.BufferedReader)3 File (java.io.File)3 InputStreamReader (java.io.InputStreamReader)3