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