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();
}
}
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);
}
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));
}
}
}
Aggregations