Search in sources :

Example 1 with MonitorException

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

the class JCmd method listCounters.

private static void listCounters(String pid) {
    // Code from JStat (can't call it directly since it does System.exit)
    VmIdentifier vmId = null;
    try {
        vmId = new VmIdentifier(pid);
    } catch (URISyntaxException e) {
        System.err.println("Malformed VM Identifier: " + pid);
        return;
    }
    try {
        MonitoredHost monitoredHost = MonitoredHost.getMonitoredHost(vmId);
        MonitoredVm monitoredVm = monitoredHost.getMonitoredVm(vmId, -1);
        JStatLogger logger = new JStatLogger(monitoredVm);
        // all names
        logger.printSnapShot(// all names
        "\\w*", // comparator
        new AscendingMonitorComparator(), // not verbose
        false, // show unsupported
        true, System.out);
        monitoredHost.detach(monitoredVm);
    } catch (MonitorException ex) {
        ex.printStackTrace();
    }
}
Also used : JStatLogger(sun.tools.jstat.JStatLogger) MonitoredVm(sun.jvmstat.monitor.MonitoredVm) VmIdentifier(sun.jvmstat.monitor.VmIdentifier) URISyntaxException(java.net.URISyntaxException) MonitoredHost(sun.jvmstat.monitor.MonitoredHost) MonitorException(sun.jvmstat.monitor.MonitorException)

Example 2 with MonitorException

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

the class JCmd method main.

public static void main(String[] args) {
    Arguments arg = null;
    try {
        arg = new Arguments(args);
    } catch (IllegalArgumentException ex) {
        System.err.println("Error parsing arguments: " + ex.getMessage() + "\n");
        Arguments.usage();
        System.exit(1);
    }
    if (arg.isShowUsage()) {
        Arguments.usage();
        System.exit(1);
    }
    if (arg.isListProcesses()) {
        List<VirtualMachineDescriptor> vmds = VirtualMachine.list();
        for (VirtualMachineDescriptor vmd : vmds) {
            System.out.println(vmd.id() + " " + vmd.displayName());
        }
        System.exit(0);
    }
    List<String> pids = new ArrayList<String>();
    if (arg.getPid() == 0) {
        // find all VMs
        List<VirtualMachineDescriptor> vmds = VirtualMachine.list();
        for (VirtualMachineDescriptor vmd : vmds) {
            if (!isJCmdProcess(vmd)) {
                pids.add(vmd.id());
            }
        }
    } else if (arg.getProcessSubstring() != null) {
        // use the partial class-name match
        List<VirtualMachineDescriptor> vmds = VirtualMachine.list();
        for (VirtualMachineDescriptor vmd : vmds) {
            if (isJCmdProcess(vmd)) {
                continue;
            }
            try {
                String mainClass = getMainClass(vmd);
                if (mainClass != null && mainClass.indexOf(arg.getProcessSubstring()) != -1) {
                    pids.add(vmd.id());
                }
            } catch (MonitorException | URISyntaxException e) {
                if (e.getMessage() != null) {
                    System.err.println(e.getMessage());
                } else {
                    Throwable cause = e.getCause();
                    if ((cause != null) && (cause.getMessage() != null)) {
                        System.err.println(cause.getMessage());
                    } else {
                        e.printStackTrace();
                    }
                }
            }
        }
        if (pids.isEmpty()) {
            System.err.println("Could not find any processes matching : '" + arg.getProcessSubstring() + "'");
            System.exit(1);
        }
    } else if (arg.getPid() == -1) {
        System.err.println("Invalid pid specified");
        System.exit(1);
    } else {
        // Use the found pid
        pids.add(arg.getPid() + "");
    }
    boolean success = true;
    for (String pid : pids) {
        System.out.println(pid + ":");
        if (arg.isListCounters()) {
            listCounters(pid);
        } else {
            try {
                executeCommandForPid(pid, arg.getCommand());
            } catch (AttachOperationFailedException ex) {
                System.err.println(ex.getMessage());
                success = false;
            } catch (Exception ex) {
                ex.printStackTrace();
                success = false;
            }
        }
    }
    System.exit(success ? 0 : 1);
}
Also used : AttachOperationFailedException(com.sun.tools.attach.AttachOperationFailedException) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) VirtualMachineDescriptor(com.sun.tools.attach.VirtualMachineDescriptor) AttachNotSupportedException(com.sun.tools.attach.AttachNotSupportedException) AgentLoadException(com.sun.tools.attach.AgentLoadException) MonitorException(sun.jvmstat.monitor.MonitorException) URISyntaxException(java.net.URISyntaxException) AttachOperationFailedException(com.sun.tools.attach.AttachOperationFailedException) IOException(java.io.IOException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 3 with MonitorException

use of sun.jvmstat.monitor.MonitorException 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)

Aggregations

MonitorException (sun.jvmstat.monitor.MonitorException)3 AttachNotSupportedException (com.sun.tools.attach.AttachNotSupportedException)2 IOException (java.io.IOException)2 URISyntaxException (java.net.URISyntaxException)2 MonitoredHost (sun.jvmstat.monitor.MonitoredHost)2 MonitoredVm (sun.jvmstat.monitor.MonitoredVm)2 VmIdentifier (sun.jvmstat.monitor.VmIdentifier)2 AgentLoadException (com.sun.tools.attach.AgentLoadException)1 AttachOperationFailedException (com.sun.tools.attach.AttachOperationFailedException)1 VirtualMachineDescriptor (com.sun.tools.attach.VirtualMachineDescriptor)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 HostIdentifier (sun.jvmstat.monitor.HostIdentifier)1 JStatLogger (sun.tools.jstat.JStatLogger)1