Search in sources :

Example 6 with MonitoredHost

use of sun.jvmstat.monitor.MonitoredHost in project rest.li by linkedin.

the class LoadBalancerClientCli method resetTogglingStores.

public static void resetTogglingStores(String host, boolean enabled) throws Exception {
    MonitoredHost _host = MonitoredHost.getMonitoredHost(new HostIdentifier(host));
    for (Object pidObj : _host.activeVms()) {
        int pid = (Integer) pidObj;
        System.out.println("checking pid: " + pid);
        JMXServiceURL jmxUrl = null;
        com.sun.tools.attach.VirtualMachine vm = com.sun.tools.attach.VirtualMachine.attach(pid + "");
        try {
            // get the connector address
            String connectorAddress = vm.getAgentProperties().getProperty(CONNECTOR_ADDRESS);
            // establish connection to connector server
            if (connectorAddress != null) {
                jmxUrl = new JMXServiceURL(connectorAddress);
            }
        } finally {
            vm.detach();
        }
        if (jmxUrl != null) {
            System.out.println("got jmx url: " + jmxUrl);
            // connect to jmx
            JMXConnector connector = JMXConnectorFactory.connect(jmxUrl);
            connector.connect();
            MBeanServerConnection mbeanServer = connector.getMBeanServerConnection();
            // look for all beans in the d2 name space
            Set<ObjectInstance> objectInstances = mbeanServer.queryMBeans(new ObjectName("com.linkedin.d2:*"), null);
            for (ObjectInstance objectInstance : objectInstances) {
                System.err.println("checking object: " + objectInstance.getObjectName());
                // if we've found a toggling store, then toggle it
                if (objectInstance.getObjectName().toString().endsWith("TogglingStore")) {
                    System.out.println("found toggling zk store, so toggling to: " + enabled);
                    mbeanServer.invoke(objectInstance.getObjectName(), "setEnabled", new Object[] { enabled }, new String[] { "boolean" });
                }
            }
        } else {
            System.out.println("pid is not a jmx process: " + pid);
        }
    }
}
Also used : JMXServiceURL(javax.management.remote.JMXServiceURL) HostIdentifier(sun.jvmstat.monitor.HostIdentifier) ObjectInstance(javax.management.ObjectInstance) ObjectName(javax.management.ObjectName) JMXConnector(javax.management.remote.JMXConnector) MonitoredHost(sun.jvmstat.monitor.MonitoredHost) MBeanServerConnection(javax.management.MBeanServerConnection)

Example 7 with MonitoredHost

use of sun.jvmstat.monitor.MonitoredHost in project ignite by apache.

the class IgniteNodeRunner method killAll.

/**
 * Kill all Jvm runned by {#link IgniteNodeRunner}. Works based on jps command.
 *
 * @return List of killed process ids.
 * @throws Exception If exception.
 */
public static List<Integer> killAll() throws Exception {
    MonitoredHost monitoredHost = MonitoredHost.getMonitoredHost(new HostIdentifier("localhost"));
    Set<Integer> jvms = monitoredHost.activeVms();
    List<Integer> res = new ArrayList<>();
    for (Integer jvmId : jvms) {
        try {
            MonitoredVm vm = monitoredHost.getMonitoredVm(new VmIdentifier("//" + jvmId + "?mode=r"), 0);
            if (IgniteNodeRunner.class.getName().equals(MonitoredVmUtil.mainClass(vm, true))) {
                Process killProc = Runtime.getRuntime().exec(U.isWindows() ? new String[] { "taskkill", "/pid", jvmId.toString(), "/f", "/t" } : new String[] { "kill", "-9", jvmId.toString() });
                killProc.waitFor();
                res.add(jvmId);
            }
        } catch (Exception e) {
            // Print stack trace just for information.
            X.printerrln("Could not kill IgniteNodeRunner java processes. Jvm pid = " + jvmId, e);
        }
    }
    return res;
}
Also used : MonitoredVm(sun.jvmstat.monitor.MonitoredVm) HostIdentifier(sun.jvmstat.monitor.HostIdentifier) ArrayList(java.util.ArrayList) VmIdentifier(sun.jvmstat.monitor.VmIdentifier) GridJavaProcess(org.apache.ignite.internal.util.GridJavaProcess) MonitoredHost(sun.jvmstat.monitor.MonitoredHost) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IOException(java.io.IOException)

Example 8 with MonitoredHost

use of sun.jvmstat.monitor.MonitoredHost in project jdk8u_jdk by JetBrains.

the class HotSpotAttachProvider method listVirtualMachines.

/*
     * This listVirtualMachines implementation is based on jvmstat. Can override
     * this in platform implementations when there is a more efficient mechanism
     * available.
     */
public List<VirtualMachineDescriptor> listVirtualMachines() {
    ArrayList<VirtualMachineDescriptor> result = new ArrayList<VirtualMachineDescriptor>();
    MonitoredHost host;
    Set<Integer> vms;
    try {
        host = MonitoredHost.getMonitoredHost(new HostIdentifier((String) null));
        vms = host.activeVms();
    } catch (Throwable t) {
        if (t instanceof ExceptionInInitializerError) {
            t = t.getCause();
        }
        if (t instanceof ThreadDeath) {
            throw (ThreadDeath) t;
        }
        if (t instanceof SecurityException) {
            return result;
        }
        // shouldn't happen
        throw new InternalError(t);
    }
    for (Integer vmid : vms) {
        String pid = vmid.toString();
        // default to pid if name not available
        String name = pid;
        boolean isAttachable = false;
        MonitoredVm mvm = null;
        try {
            mvm = host.getMonitoredVm(new VmIdentifier(pid));
            try {
                isAttachable = MonitoredVmUtil.isAttachable(mvm);
                // use the command line as the display name
                name = MonitoredVmUtil.commandLine(mvm);
            } catch (Exception e) {
            }
            if (isAttachable) {
                result.add(new HotSpotVirtualMachineDescriptor(this, pid, name));
            }
        } catch (Throwable t) {
            if (t instanceof ThreadDeath) {
                throw (ThreadDeath) t;
            }
        } finally {
            if (mvm != null) {
                mvm.detach();
            }
        }
    }
    return result;
}
Also used : MonitoredVm(sun.jvmstat.monitor.MonitoredVm) ArrayList(java.util.ArrayList) HostIdentifier(sun.jvmstat.monitor.HostIdentifier) VmIdentifier(sun.jvmstat.monitor.VmIdentifier) VirtualMachineDescriptor(com.sun.tools.attach.VirtualMachineDescriptor) AttachNotSupportedException(com.sun.tools.attach.AttachNotSupportedException) MonitorException(sun.jvmstat.monitor.MonitorException) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) MonitoredHost(sun.jvmstat.monitor.MonitoredHost)

Example 9 with MonitoredHost

use of sun.jvmstat.monitor.MonitoredHost in project jdk8u_jdk by JetBrains.

the class LocalVirtualMachine method getMonitoredVMs.

private static void getMonitoredVMs(Map<Integer, LocalVirtualMachine> map) {
    MonitoredHost host;
    Set<Integer> vms;
    try {
        host = MonitoredHost.getMonitoredHost(new HostIdentifier((String) null));
        vms = host.activeVms();
    } catch (java.net.URISyntaxException | MonitorException x) {
        throw new InternalError(x.getMessage(), x);
    }
    for (Object vmid : vms) {
        if (vmid instanceof Integer) {
            int pid = ((Integer) vmid).intValue();
            // default to pid if name not available
            String name = vmid.toString();
            boolean attachable = false;
            String address = null;
            try {
                MonitoredVm mvm = host.getMonitoredVm(new VmIdentifier(name));
                // use the command line as the display name
                name = MonitoredVmUtil.commandLine(mvm);
                attachable = MonitoredVmUtil.isAttachable(mvm);
                address = ConnectorAddressLink.importFrom(pid);
                mvm.detach();
            } catch (Exception x) {
            // ignore
            }
            map.put((Integer) vmid, new LocalVirtualMachine(pid, name, attachable, address));
        }
    }
}
Also used : MonitoredVm(sun.jvmstat.monitor.MonitoredVm) HostIdentifier(sun.jvmstat.monitor.HostIdentifier) VmIdentifier(sun.jvmstat.monitor.VmIdentifier) AttachNotSupportedException(com.sun.tools.attach.AttachNotSupportedException) MonitorException(sun.jvmstat.monitor.MonitorException) IOException(java.io.IOException) MonitoredHost(sun.jvmstat.monitor.MonitoredHost) MonitorException(sun.jvmstat.monitor.MonitorException)

Example 10 with MonitoredHost

use of sun.jvmstat.monitor.MonitoredHost in project jdk8u_jdk by JetBrains.

the class MonitorVmStartTerminate method main.

public static void main(String... args) throws Exception {
    MonitoredHost host = MonitoredHost.getMonitoredHost("localhost");
    // 1 ms
    host.setInterval(1);
    String id = UUID.randomUUID().toString();
    List<JavaProcess> javaProcesses = new ArrayList<>();
    for (int i = 0; i < PROCESS_COUNT; i++) {
        javaProcesses.add(new JavaProcess(id + "_" + i));
    }
    Listener listener = new Listener(host, javaProcesses);
    host.addHostListener(listener);
    for (JavaProcess javaProcess : javaProcesses) {
        javaProcess.start();
    }
    // Wait for all processes to start before terminating
    // them, so pids are not reused within a poll interval.
    System.out.println("Waiting for all processes to get started notification");
    listener.started.acquire(PROCESS_COUNT);
    for (JavaProcess javaProcess : javaProcesses) {
        javaProcess.terminate();
    }
    System.out.println("Waiting for all processes to get terminated notification");
    listener.terminated.acquire(PROCESS_COUNT);
    host.removeHostListener(listener);
}
Also used : HostListener(sun.jvmstat.monitor.event.HostListener) ArrayList(java.util.ArrayList) MonitoredHost(sun.jvmstat.monitor.MonitoredHost)

Aggregations

MonitoredHost (sun.jvmstat.monitor.MonitoredHost)10 VmIdentifier (sun.jvmstat.monitor.VmIdentifier)8 MonitoredVm (sun.jvmstat.monitor.MonitoredVm)7 MonitorException (sun.jvmstat.monitor.MonitorException)5 URISyntaxException (java.net.URISyntaxException)4 HostIdentifier (sun.jvmstat.monitor.HostIdentifier)4 AttachNotSupportedException (com.sun.tools.attach.AttachNotSupportedException)3 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 VirtualMachineDescriptor (com.sun.tools.attach.VirtualMachineDescriptor)1 Set (java.util.Set)1 MBeanServerConnection (javax.management.MBeanServerConnection)1 ObjectInstance (javax.management.ObjectInstance)1 ObjectName (javax.management.ObjectName)1 JMXConnector (javax.management.remote.JMXConnector)1 JMXServiceURL (javax.management.remote.JMXServiceURL)1 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)1 GridJavaProcess (org.apache.ignite.internal.util.GridJavaProcess)1 HostListener (sun.jvmstat.monitor.event.HostListener)1 JStatLogger (sun.tools.jstat.JStatLogger)1