Search in sources :

Example 1 with RuntimeMXBean

use of java.lang.management.RuntimeMXBean in project tdi-studio-se by Talend.

the class Agent method getAgentJar.

/**
     * Gets the agent jar file from input arguments.
     * 
     * @return The agent jar file
     */
private static String getAgentJar() {
    RuntimeMXBean runtimeMXBean = ManagementFactory.getRuntimeMXBean();
    List<String> arguments = runtimeMXBean.getInputArguments();
    for (String argument : arguments) {
        if (argument.contains(Constants.JAVA_AGENT_OPTION)) {
            return argument.replace(Constants.JAVA_AGENT_OPTION, "");
        }
    }
    throw new IllegalStateException();
}
Also used : RuntimeMXBean(java.lang.management.RuntimeMXBean)

Example 2 with RuntimeMXBean

use of java.lang.management.RuntimeMXBean in project voltdb by VoltDB.

the class DirectMemoryUtils method getDirectMemorySize.

/**
   * @return the setting of -XX:MaxDirectMemorySize as a long. Returns 0 if
   *         -XX:MaxDirectMemorySize is not set.
   */
public static long getDirectMemorySize() {
    RuntimeMXBean RuntimemxBean = ManagementFactory.getRuntimeMXBean();
    List<String> arguments = RuntimemxBean.getInputArguments();
    //for the byte case.
    long multiplier = 1;
    for (String s : arguments) {
        if (s.contains("-XX:MaxDirectMemorySize=")) {
            String memSize = s.toLowerCase().replace("-xx:maxdirectmemorysize=", "").trim();
            if (memSize.contains("k")) {
                multiplier = 1024;
            } else if (memSize.contains("m")) {
                multiplier = 1048576;
            } else if (memSize.contains("g")) {
                multiplier = 1073741824;
            }
            memSize = memSize.replaceAll("[^\\d]", "");
            long retValue = Long.parseLong(memSize);
            return retValue * multiplier;
        }
    }
    return 0;
}
Also used : RuntimeMXBean(java.lang.management.RuntimeMXBean)

Example 3 with RuntimeMXBean

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

the class TestManager method connect.

private static void connect(String pid, String address) throws Exception {
    if (address == null) {
        throw new RuntimeException("Local connector address for " + pid + " is null");
    }
    System.out.println("Connect to process " + pid + " via: " + address);
    JMXServiceURL url = new JMXServiceURL(address);
    JMXConnector c = JMXConnectorFactory.connect(url);
    MBeanServerConnection server = c.getMBeanServerConnection();
    System.out.println("Connected.");
    RuntimeMXBean rt = newPlatformMXBeanProxy(server, RUNTIME_MXBEAN_NAME, RuntimeMXBean.class);
    System.out.println(rt.getName());
    // close the connection
    c.close();
}
Also used : JMXServiceURL(javax.management.remote.JMXServiceURL) JMXConnector(javax.management.remote.JMXConnector) RuntimeMXBean(java.lang.management.RuntimeMXBean) MBeanServerConnection(javax.management.MBeanServerConnection)

Example 4 with RuntimeMXBean

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

the class MXBeanProxyTest method main.

public static void main(String[] argv) throws Exception {
    boolean iae = false;
    try {
        // Get a MXBean proxy with invalid name
        newPlatformMXBeanProxy(server, "Invalid ObjectName", RuntimeMXBean.class);
    } catch (IllegalArgumentException e) {
        // Expected exception
        System.out.println("EXPECTED: " + e);
        iae = true;
    }
    if (!iae) {
        throw new RuntimeException("Invalid ObjectName " + " was not detected");
    }
    try {
        // Get a MXBean proxy with non existent MXBean
        newPlatformMXBeanProxy(server, "java.lang:type=Foo", RuntimeMXBean.class);
        iae = false;
    } catch (IllegalArgumentException e) {
        // Expected exception
        System.out.println("EXPECTED: " + e);
        iae = true;
    }
    if (!iae) {
        throw new RuntimeException("Non existent MXBean " + " was not detected");
    }
    try {
        // Mismatch MXBean interface
        newPlatformMXBeanProxy(server, RUNTIME_MXBEAN_NAME, ClassLoadingMXBean.class);
        iae = false;
    } catch (IllegalArgumentException e) {
        // Expected exception
        System.out.println("EXPECTED: " + e);
        iae = true;
    }
    if (!iae) {
        throw new RuntimeException("Mismatched MXBean interface " + " was not detected");
    }
    final FooMBean foo = new Foo();
    final ObjectName objName = new ObjectName("java.lang:type=Foo");
    server.registerMBean(foo, objName);
    try {
        // non-platform MXBean
        newPlatformMXBeanProxy(server, "java.lang:type=Foo", FooMBean.class);
        iae = false;
    } catch (IllegalArgumentException e) {
        // Expected exception
        System.out.println("EXPECTED: " + e);
        iae = true;
    }
    if (!iae) {
        throw new RuntimeException("Non-platform MXBean " + " was not detected");
    }
    // Successfully get MXBean
    RuntimeMXBean rm = newPlatformMXBeanProxy(server, RUNTIME_MXBEAN_NAME, RuntimeMXBean.class);
    System.out.println("VM uptime = " + rm.getUptime());
    System.out.println("Test passed.");
}
Also used : RuntimeMXBean(java.lang.management.RuntimeMXBean)

Example 5 with RuntimeMXBean

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

the class ProcessTools method getProcessId.

/**
     * Get the process id of the current running Java process
     *
     * @return Process id
     */
public static int getProcessId() throws Exception {
    // Get the current process id using a reflection hack
    RuntimeMXBean runtime = ManagementFactory.getRuntimeMXBean();
    Field jvm = runtime.getClass().getDeclaredField("jvm");
    jvm.setAccessible(true);
    VMManagement mgmt = (sun.management.VMManagement) jvm.get(runtime);
    Method pid_method = mgmt.getClass().getDeclaredMethod("getProcessId");
    pid_method.setAccessible(true);
    int pid = (Integer) pid_method.invoke(mgmt);
    return pid;
}
Also used : Field(java.lang.reflect.Field) VMManagement(sun.management.VMManagement) RuntimeMXBean(java.lang.management.RuntimeMXBean) Method(java.lang.reflect.Method)

Aggregations

RuntimeMXBean (java.lang.management.RuntimeMXBean)164 OperatingSystemMXBean (java.lang.management.OperatingSystemMXBean)27 IOException (java.io.IOException)17 MemoryMXBean (java.lang.management.MemoryMXBean)16 ThreadMXBean (java.lang.management.ThreadMXBean)13 GarbageCollectorMXBean (java.lang.management.GarbageCollectorMXBean)11 Date (java.util.Date)10 ArrayList (java.util.ArrayList)9 HashMap (java.util.HashMap)9 MemoryUsage (java.lang.management.MemoryUsage)8 Method (java.lang.reflect.Method)8 Map (java.util.Map)8 Properties (java.util.Properties)6 InputStream (java.io.InputStream)5 ClassLoadingMXBean (java.lang.management.ClassLoadingMXBean)5 Iterator (java.util.Iterator)5 File (java.io.File)4 MemoryPoolMXBean (java.lang.management.MemoryPoolMXBean)4 Field (java.lang.reflect.Field)4 UnknownHostException (java.net.UnknownHostException)4