Search in sources :

Example 6 with VmIdentifier

use of sun.jvmstat.monitor.VmIdentifier 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 7 with VmIdentifier

use of sun.jvmstat.monitor.VmIdentifier 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 8 with VmIdentifier

use of sun.jvmstat.monitor.VmIdentifier 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 9 with VmIdentifier

use of sun.jvmstat.monitor.VmIdentifier in project Gargoyle by callakrsos.

the class Monitors method actived.

/**
	 * @작성자 : KYJ
	 * @작성일 : 2017. 1. 20.
	 * @param string
	 * @param v
	 * @return
	 */
private static void actived(String status, Integer lvmid) {
    try {
        String vmidString = "//" + lvmid + "?mode=r";
        VmIdentifier id = new VmIdentifier(vmidString);
        MonitoredVm vm = monitoredHost.getMonitoredVm(id, 0);
        String mainArgs = MonitoredVmUtil.mainArgs(vm);
        String mainClassName = MonitoredVmUtil.mainClass(vm, true);
        String jvmArgs = MonitoredVmUtil.jvmArgs(vm);
        String vmVersion = MonitoredVmUtil.vmVersion(vm);
        String jvmFlags = MonitoredVmUtil.jvmFlags(vm);
        String commandLine = MonitoredVmUtil.commandLine(vm);
        ApplicationModel model = new ApplicationModel();
        model.setProcessId(lvmid);
        model.setApplicationName(mainClassName);
        model.setArgument(mainArgs);
        model.setJvmArgs(jvmArgs);
        model.setVmVersion(vmVersion);
        model.setJvmFlags(jvmFlags);
        model.setCommandLine(commandLine);
        cache.put(lvmid.toString(), model);
        notifyMessage(Status.actived, cache.get(lvmid.toString()));
        LOGGER.debug("status[{}] V PID : {} mainClassName : {} vmVersion : {}  jvmFlags : {} commandLine : {}", status, lvmid, mainClassName, vmVersion, jvmFlags, commandLine);
        monitoredHost.detach(vm);
    }/*
		 * 수행이 빠른 프로그램인경우 모니터링이되지않고 중간에 에러가 발생하는 케이스가 있다.
		 */
     catch (sun.jvmstat.monitor.MonitorException e) {
        LOGGER.warn(ValueUtil.toString(e));
    } catch (Exception e) {
        LOGGER.error(ValueUtil.toString(e));
    }
}
Also used : MonitorException(sun.jvmstat.monitor.MonitorException) MonitoredVm(sun.jvmstat.monitor.MonitoredVm) VmIdentifier(sun.jvmstat.monitor.VmIdentifier) MonitorException(sun.jvmstat.monitor.MonitorException)

Aggregations

MonitoredVm (sun.jvmstat.monitor.MonitoredVm)9 VmIdentifier (sun.jvmstat.monitor.VmIdentifier)9 MonitoredHost (sun.jvmstat.monitor.MonitoredHost)7 MonitorException (sun.jvmstat.monitor.MonitorException)6 AttachNotSupportedException (com.sun.tools.attach.AttachNotSupportedException)3 IOException (java.io.IOException)3 URISyntaxException (java.net.URISyntaxException)3 HostIdentifier (sun.jvmstat.monitor.HostIdentifier)3 ArrayList (java.util.ArrayList)2 VirtualMachineDescriptor (com.sun.tools.attach.VirtualMachineDescriptor)1 Set (java.util.Set)1 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)1 GridJavaProcess (org.apache.ignite.internal.util.GridJavaProcess)1 JStatLogger (sun.tools.jstat.JStatLogger)1