Search in sources :

Example 71 with RuntimeMXBean

use of java.lang.management.RuntimeMXBean in project asterixdb by apache.

the class LangExecutionUtil method checkOpenRunFileLeaks.

private static void checkOpenRunFileLeaks() throws IOException {
    if (SystemUtils.IS_OS_WINDOWS) {
        return;
    }
    // Only run the check on Linux and MacOS.
    RuntimeMXBean runtimeMXBean = ManagementFactory.getRuntimeMXBean();
    String processName = runtimeMXBean.getName();
    String processId = processName.split("@")[0];
    // Checks whether there are leaked run files from operators.
    Process process = Runtime.getRuntime().exec(new String[] { "bash", "-c", "lsof -p " + processId + "|grep waf|wc -l" });
    try (BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()))) {
        int runFileCount = Integer.parseInt(reader.readLine().trim());
        if (runFileCount != 0) {
            System.out.print(takeDumpJSON(ManagementFactory.getThreadMXBean()));
            outputLeakedOpenFiles(processId);
            throw new AssertionError("There are " + runFileCount + " leaked run files.");
        }
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) BufferedReader(java.io.BufferedReader) RuntimeMXBean(java.lang.management.RuntimeMXBean)

Example 72 with RuntimeMXBean

use of java.lang.management.RuntimeMXBean in project gcontracts by andresteingress.

the class Configurator method initAssertionConfiguration.

private static void initAssertionConfiguration() {
    assertionConfiguration = new HashMap<String, Boolean>();
    // per default assertion are enabled (Groovy like)
    assertionConfiguration.put(null, Boolean.TRUE);
    RuntimeMXBean runtimemxBean = ManagementFactory.getRuntimeMXBean();
    for (String arg : runtimemxBean.getInputArguments()) {
        if (DISABLED_ASSERTIONS.equals(arg)) {
            assertionConfiguration.put(null, Boolean.FALSE);
        } else if (arg.startsWith(ENABLE_PACKAGE_ASSERTIONS) && arg.endsWith(PACKAGE_POSTFIX)) {
            final String packageName = arg.substring(ENABLE_PACKAGE_ASSERTIONS.length(), arg.length() - PACKAGE_POSTFIX.length());
            assertionConfiguration.put(packageName, Boolean.TRUE);
        } else if (arg.startsWith(DISABLE_PACKAGE_ASSERTIONS) && arg.endsWith(PACKAGE_POSTFIX)) {
            final String packageName = arg.substring(DISABLE_PACKAGE_ASSERTIONS.length(), arg.length() - PACKAGE_POSTFIX.length());
            assertionConfiguration.put(packageName, Boolean.FALSE);
        } else if (arg.startsWith(ENABLE_PACKAGE_ASSERTIONS)) {
            final String className = arg.substring(ENABLE_PACKAGE_ASSERTIONS.length(), arg.length());
            assertionConfiguration.put(className, Boolean.TRUE);
        } else if (arg.startsWith(DISABLE_PACKAGE_ASSERTIONS)) {
            final String className = arg.substring(DISABLE_PACKAGE_ASSERTIONS.length(), arg.length());
            assertionConfiguration.put(className, Boolean.FALSE);
        }
    }
}
Also used : RuntimeMXBean(java.lang.management.RuntimeMXBean)

Example 73 with RuntimeMXBean

use of java.lang.management.RuntimeMXBean in project phoenix by apache.

the class QueryServer method logJVMInfo.

/**
   * Log information about the currently running JVM.
   */
public static void logJVMInfo() {
    // Print out vm stats before starting up.
    RuntimeMXBean runtime = ManagementFactory.getRuntimeMXBean();
    if (runtime != null) {
        LOG.info("vmName=" + runtime.getVmName() + ", vmVendor=" + runtime.getVmVendor() + ", vmVersion=" + runtime.getVmVersion());
        LOG.info("vmInputArguments=" + runtime.getInputArguments());
    }
}
Also used : RuntimeMXBean(java.lang.management.RuntimeMXBean)

Example 74 with RuntimeMXBean

use of java.lang.management.RuntimeMXBean in project Glowstone by GlowstoneMC.

the class GlowstoneCommand method execute.

@Override
public boolean execute(CommandSender sender, String label, String[] args) {
    if (!testPermission(sender)) {
        return true;
    }
    if (args.length == 0 || (args.length > 0 && args[0].equalsIgnoreCase("about"))) {
        // some info about this Glowstone server
        sender.sendMessage("Information about this server:");
        sender.sendMessage(" - " + ChatColor.GOLD + "Server brand: " + ChatColor.AQUA + Bukkit.getName() + ChatColor.RESET + ".");
        sender.sendMessage(" - " + ChatColor.GOLD + "Server name: " + ChatColor.AQUA + Bukkit.getServerName() + ChatColor.RESET + ".");
        sender.sendMessage(" - " + ChatColor.GOLD + "Glowstone version: " + ChatColor.AQUA + Bukkit.getVersion() + ChatColor.RESET + ".");
        sender.sendMessage(" - " + ChatColor.GOLD + "API version: " + ChatColor.AQUA + Bukkit.getBukkitVersion() + ChatColor.RESET + ".");
        sender.sendMessage(" - " + ChatColor.GOLD + "Players: " + ChatColor.AQUA + Bukkit.getOnlinePlayers().size() + ChatColor.RESET + ".");
        sender.sendMessage(" - " + ChatColor.GOLD + "Worlds: " + ChatColor.AQUA + Bukkit.getWorlds().size() + ChatColor.RESET + ".");
        sender.sendMessage(" - " + ChatColor.GOLD + "Plugins: " + ChatColor.AQUA + Bukkit.getPluginManager().getPlugins().length + ChatColor.RESET + ".");
        // thread count
        int threadCount = 0;
        Set<Thread> threads = Thread.getAllStackTraces().keySet();
        for (Thread t : threads) {
            if (t.getThreadGroup() == Thread.currentThread().getThreadGroup()) {
                threadCount++;
            }
        }
        sender.sendMessage(" - " + ChatColor.GOLD + "Threads: " + ChatColor.AQUA + threadCount + ChatColor.RESET + ".");
        return false;
    }
    if (args[0].equalsIgnoreCase("help")) {
        // some help
        return false;
    }
    if (args[0].equalsIgnoreCase("property")) {
        if (args.length == 1) {
            // list all
            System.getProperties().forEach((key, value) -> sender.sendMessage("Property '" + ChatColor.AQUA + key + ChatColor.RESET + "' = \"" + ChatColor.GOLD + value + ChatColor.RESET + "\"."));
        } else {
            // get a property
            String key = args[1].toLowerCase();
            String value = System.getProperty(key);
            if (value == null) {
                sender.sendMessage(ChatColor.RED + "Unknown system property '" + key + "'.");
            } else {
                sender.sendMessage("Property '" + ChatColor.AQUA + key + ChatColor.RESET + "' = \"" + ChatColor.GOLD + value + ChatColor.RESET + "\".");
            }
        }
        return false;
    }
    if (args[0].equalsIgnoreCase("vm")) {
        RuntimeMXBean runtimeMxBean = ManagementFactory.getRuntimeMXBean();
        List<String> arguments = runtimeMxBean.getInputArguments();
        if (arguments.size() == 0) {
            sender.sendMessage("There are no VM arguments.");
        } else {
            sender.sendMessage("Glowstone VM arguments (" + arguments.size() + "):");
            for (String argument : arguments) {
                sender.sendMessage(" - '" + ChatColor.AQUA + argument + ChatColor.RESET + "'.");
            }
        }
        return false;
    }
    if (args[0].equals("eval")) {
        if (args.length == 1) {
            // no args, send usage
            sender.sendMessage(ChatColor.RED + "Usage: /" + label + " eval <eval>");
            return false;
        }
        StringBuilder builder = new StringBuilder();
        for (int i = 1; i < args.length; i++) {
            builder.append(args[i] + (i == args.length - 1 ? "" : " "));
        }
        ReflectionProcessor processor = new ReflectionProcessor(builder.toString(), sender instanceof Entity ? sender : Bukkit.getServer());
        Object result = processor.process();
        sender.sendMessage(ChatColor.GOLD + "Eval returned: " + (result == null ? ChatColor.RED + "<no value>" : ChatColor.AQUA + result.toString()));
    }
    return false;
}
Also used : Entity(org.bukkit.entity.Entity) ReflectionProcessor(net.glowstone.util.ReflectionProcessor) RuntimeMXBean(java.lang.management.RuntimeMXBean)

Example 75 with RuntimeMXBean

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

the class MXBeanInteropTest1 method doRuntimeMXBeanTest.

private final int doRuntimeMXBeanTest(MBeanServerConnection mbsc) {
    int errorCount = 0;
    System.out.println("---- RuntimeMXBean");
    try {
        ObjectName runtimeName = new ObjectName(ManagementFactory.RUNTIME_MXBEAN_NAME);
        MBeanInfo mbInfo = mbsc.getMBeanInfo(runtimeName);
        errorCount += checkNonEmpty(mbInfo);
        System.out.println("getMBeanInfo\t\t" + mbInfo);
        RuntimeMXBean runtime = null;
        runtime = JMX.newMXBeanProxy(mbsc, runtimeName, RuntimeMXBean.class);
        System.out.println("getClassPath\t\t" + runtime.getClassPath());
        System.out.println("getInputArguments\t\t" + runtime.getInputArguments());
        System.out.println("getLibraryPath\t\t" + runtime.getLibraryPath());
        System.out.println("getManagementSpecVersion\t\t" + runtime.getManagementSpecVersion());
        System.out.println("getName\t\t" + runtime.getName());
        System.out.println("getSpecName\t\t" + runtime.getSpecName());
        System.out.println("getSpecVendor\t\t" + runtime.getSpecVendor());
        System.out.println("getSpecVersion\t\t" + runtime.getSpecVersion());
        System.out.println("getStartTime\t\t" + runtime.getStartTime());
        System.out.println("getSystemProperties\t\t" + runtime.getSystemProperties());
        System.out.println("getUptime\t\t" + runtime.getUptime());
        System.out.println("getVmName\t\t" + runtime.getVmName());
        System.out.println("getVmVendor\t\t" + runtime.getVmVendor());
        System.out.println("getVmVersion\t\t" + runtime.getVmVersion());
        boolean supported = runtime.isBootClassPathSupported();
        System.out.println("isBootClassPathSupported\t\t" + supported);
        if (supported) {
            System.out.println("getBootClassPath\t\t" + runtime.getBootClassPath());
        }
        System.out.println("---- OK\n");
    } catch (Exception e) {
        Utils.printThrowable(e, true);
        errorCount++;
        System.out.println("---- ERROR\n");
    }
    return errorCount;
}
Also used : MBeanInfo(javax.management.MBeanInfo) RuntimeMXBean(java.lang.management.RuntimeMXBean) ObjectName(javax.management.ObjectName)

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