本文整理汇总了Java中sun.jvmstat.monitor.MonitoredHost.getMonitoredVm方法的典型用法代码示例。如果您正苦于以下问题:Java MonitoredHost.getMonitoredVm方法的具体用法?Java MonitoredHost.getMonitoredVm怎么用?Java MonitoredHost.getMonitoredVm使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sun.jvmstat.monitor.MonitoredHost
的用法示例。
在下文中一共展示了MonitoredHost.getMonitoredVm方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getMainClass
import sun.jvmstat.monitor.MonitoredHost; //导入方法依赖的package包/类
private static String getMainClass(VirtualMachineDescriptor vmd)
throws URISyntaxException, MonitorException {
try {
String mainClass = null;
VmIdentifier vmId = new VmIdentifier(vmd.id());
MonitoredHost monitoredHost = MonitoredHost.getMonitoredHost(vmId);
MonitoredVm monitoredVm = monitoredHost.getMonitoredVm(vmId, -1);
mainClass = MonitoredVmUtil.mainClass(monitoredVm, true);
monitoredHost.detach(monitoredVm);
return mainClass;
} catch(NullPointerException e) {
// There is a potential race, where a running java app is being
// queried, unfortunately the java app has shutdown after this
// method is started but before getMonitoredVM is called.
// If this is the case, then the /tmp/hsperfdata_xxx/pid file
// will have disappeared and we will get a NullPointerException.
// Handle this gracefully....
return null;
}
}
示例2: getThisVm
import sun.jvmstat.monitor.MonitoredHost; //导入方法依赖的package包/类
private MonitoredVm getThisVm() {
if (thisVm == null) {
synchronized (this) {
if (thisVm == null) {
try {
MonitoredHost localHost = MonitoredHost.getMonitoredHost("localhost");
VmIdentifier vmIdent = new VmIdentifier("0");
thisVm = localHost.getMonitoredVm(vmIdent);
} catch (MonitorException me) {
throw new IllegalArgumentException("jvmstat perf counters not available: " + me);
} catch (URISyntaxException use) {
throw new IllegalArgumentException("jvmstat perf counters not available: " + use);
}
}
}
}
return thisVm;
}
示例3: main
import sun.jvmstat.monitor.MonitoredHost; //导入方法依赖的package包/类
public static void main(String[] args) throws IOException,
MonitorException, URISyntaxException {
LingeredApp app = null;
try {
List<String> vmArgs = new ArrayList<String>();
vmArgs.add("-XX:+UsePerfData");
vmArgs.addAll(Utils.getVmOptions());
app = LingeredApp.startApp(vmArgs);
MonitoredHost localHost = MonitoredHost.getMonitoredHost("localhost");
String uriString = "//" + app.getPid() + "?mode=r"; // NOI18N
VmIdentifier vmId = new VmIdentifier(uriString);
MonitoredVm vm = localHost.getMonitoredVm(vmId);
System.out.println("Monitored vm command line: " + MonitoredVmUtil.commandLine(vm));
vm.setInterval(INTERVAL);
localHost.setInterval(INTERVAL);
Asserts.assertEquals(vm.getInterval(), INTERVAL, "Monitored vm interval should be equal the test value");
Asserts.assertEquals(localHost.getInterval(), INTERVAL, "Monitored host interval should be equal the test value");
} finally {
LingeredApp.stopApp(app);
}
}
示例4: findList
import sun.jvmstat.monitor.MonitoredHost; //导入方法依赖的package包/类
public List<MonitoredVm> findList() throws Exception
{
List<MonitoredVm> list = new ArrayList<MonitoredVm>();
MonitoredHost local = MonitoredHost.getMonitoredHost("localhost");
Set<Integer> vmlist = new HashSet<Integer>(local.activeVms());
for (int id : vmlist)
{
MonitoredVm vm = local.getMonitoredVm(new VmIdentifier("//" + id));
String processname = MonitoredVmUtil.mainClass(vm, true);
System.out.println(id + " [" + processname + "]");
list.add(vm);
}
return list;
}
示例5: main
import sun.jvmstat.monitor.MonitoredHost; //导入方法依赖的package包/类
public static void main(String[] args) {
int vmInterval;
int hostInterval;
try {
MonitoredHost localHost = MonitoredHost.getMonitoredHost("localhost");
Set vms = localHost.activeVms();
Integer vmInt = (Integer) vms.iterator().next();
String uriString = "//" + vmInt + "?mode=r"; // NOI18N
VmIdentifier vmId = new VmIdentifier(uriString);
MonitoredVm vm = localHost.getMonitoredVm(vmId);
vm.setInterval(INTERVAL);
localHost.setInterval(INTERVAL);
vmInterval = vm.getInterval();
hostInterval = localHost.getInterval();
} catch (Exception ex) {
throw new Error ("Test failed",ex);
}
System.out.println("VM "+vmInterval);
if (vmInterval != INTERVAL) {
throw new Error("Test failed");
}
System.out.println("Host "+hostInterval);
if (hostInterval != INTERVAL) {
throw new Error("Test failed");
}
}
示例6: attachToMonitoredVm
import sun.jvmstat.monitor.MonitoredHost; //导入方法依赖的package包/类
private static MonitoredVm attachToMonitoredVm(MonitoredHost host, long pid) throws MonitorException, URISyntaxException {
final Set vmIds = host.activeVms();
for (Object vmId : vmIds) {
if (vmId instanceof Integer &&
((Integer)vmId).longValue() == pid) {
return host.getMonitoredVm(new VmIdentifier(vmId.toString()));
}
}
return null;
}
示例7: testAttachable
import sun.jvmstat.monitor.MonitoredHost; //导入方法依赖的package包/类
/**
* Test if a VM is attachable. If it's not attachable,
* an AttachNotSupportedException will be thrown. For example,
* 1.4.2 or 5.0 VM are not attachable. There are cases that
* we can't determine if a VM is attachable or not and this method
* will just return.
*
* This method uses the jvmstat counter to determine if a VM
* is attachable. If the target VM does not have a jvmstat
* share memory buffer, this method returns.
*
* @exception AttachNotSupportedException if it's not attachable
*/
void testAttachable(String id) throws AttachNotSupportedException {
MonitoredVm mvm = null;
try {
VmIdentifier vmid = new VmIdentifier(id);
MonitoredHost host = MonitoredHost.getMonitoredHost(vmid);
mvm = host.getMonitoredVm(vmid);
if (MonitoredVmUtil.isAttachable(mvm)) {
// it's attachable; so return false
return;
}
} catch (Throwable t) {
if (t instanceof ThreadDeath) {
ThreadDeath td = (ThreadDeath)t;
throw td;
}
// we do not know what this id is
return;
} finally {
if (mvm != null) {
mvm.detach();
}
}
// we're sure it's not attachable; throw exception
throw new AttachNotSupportedException(
"The VM does not support the attach mechanism");
}
示例8: check
import sun.jvmstat.monitor.MonitoredHost; //导入方法依赖的package包/类
private static boolean check(VirtualMachineDescriptor vmd, String excludeClass, String partialMatch) {
String mainClass = null;
try {
VmIdentifier vmId = new VmIdentifier(vmd.id());
MonitoredHost monitoredHost = MonitoredHost.getMonitoredHost(vmId);
MonitoredVm monitoredVm = monitoredHost.getMonitoredVm(vmId, -1);
mainClass = MonitoredVmUtil.mainClass(monitoredVm, true);
monitoredHost.detach(monitoredVm);
} catch (NullPointerException npe) {
// There is a potential race, where a running java app is being
// queried, unfortunately the java app has shutdown after this
// method is started but before getMonitoredVM is called.
// If this is the case, then the /tmp/hsperfdata_xxx/pid file
// will have disappeared and we will get a NullPointerException.
// Handle this gracefully....
return false;
} catch (MonitorException | URISyntaxException e) {
return false;
}
if (excludeClass != null && mainClass.equals(excludeClass)) {
return false;
}
if (partialMatch != null && mainClass.indexOf(partialMatch) == -1) {
return false;
}
return true;
}
示例9: check
import sun.jvmstat.monitor.MonitoredHost; //导入方法依赖的package包/类
private boolean check(VirtualMachineDescriptor vmd) {
String mainClass = null;
try {
VmIdentifier vmId = new VmIdentifier(vmd.id());
MonitoredHost monitoredHost = MonitoredHost.getMonitoredHost(vmId);
MonitoredVm monitoredVm = monitoredHost.getMonitoredVm(vmId, -1);
mainClass = MonitoredVmUtil.mainClass(monitoredVm, true);
monitoredHost.detach(monitoredVm);
} catch (NullPointerException npe) {
// There is a potential race, where a running java app is being
// queried, unfortunately the java app has shutdown after this
// method is started but before getMonitoredVM is called.
// If this is the case, then the /tmp/hsperfdata_xxx/pid file
// will have disappeared and we will get a NullPointerException.
// Handle this gracefully....
return false;
} 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();
}
}
return false;
}
if (mainClass.equals(excludeCls)) {
return false;
}
if (matchAll || mainClass.indexOf(matchClass) != -1) {
return true;
}
return false;
}
示例10: logNames
import sun.jvmstat.monitor.MonitoredHost; //导入方法依赖的package包/类
static void logNames() throws MonitorException {
VmIdentifier vmId = arguments.vmId();
int interval = arguments.sampleInterval();
MonitoredHost monitoredHost = MonitoredHost.getMonitoredHost(vmId);
MonitoredVm monitoredVm = monitoredHost.getMonitoredVm(vmId, interval);
JStatLogger logger = new JStatLogger(monitoredVm);
logger.printNames(arguments.counterNames(), arguments.comparator(), arguments.showUnsupported(), System.out);
monitoredHost.detach(monitoredVm);
}
示例11: logSnapShot
import sun.jvmstat.monitor.MonitoredHost; //导入方法依赖的package包/类
static void logSnapShot() throws MonitorException {
VmIdentifier vmId = arguments.vmId();
int interval = arguments.sampleInterval();
MonitoredHost monitoredHost = MonitoredHost.getMonitoredHost(vmId);
MonitoredVm monitoredVm = monitoredHost.getMonitoredVm(vmId, interval);
JStatLogger logger = new JStatLogger(monitoredVm);
logger.printSnapShot(arguments.counterNames(), arguments.comparator(), arguments.isVerbose(), arguments.showUnsupported(),
System.out);
monitoredHost.detach(monitoredVm);
}
示例12: getMonitoredVMs
import sun.jvmstat.monitor.MonitoredHost; //导入方法依赖的package包/类
private static void getMonitoredVMs(Map<Integer, LocalVirtualMachine> map) {
MonitoredHost host;
Set vms;
try {
host = MonitoredHost.getMonitoredHost(new HostIdentifier((String)null));
vms = host.activeVms();
} catch (java.net.URISyntaxException sx) {
throw new InternalError(sx.getMessage());
} catch (MonitorException mx) {
throw new InternalError(mx.getMessage());
}
for (Object vmid: vms) {
if (vmid instanceof Integer) {
int pid = ((Integer) vmid).intValue();
String name = vmid.toString(); // default to pid if name not available
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));
}
}
}
示例13: killAll
import sun.jvmstat.monitor.MonitoredHost; //导入方法依赖的package包/类
/**
* 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;
}
示例14: getMonitoredVMs
import sun.jvmstat.monitor.MonitoredHost; //导入方法依赖的package包/类
private static void getMonitoredVMs(Map<Integer, LocalVirtualMachine> map) {
MonitoredHost host;
Set vms;
try {
host = MonitoredHost.getMonitoredHost(new HostIdentifier((String)null));
vms = host.activeVms();
} catch (java.net.URISyntaxException sx) {
throw new InternalError(sx.getMessage());
} catch (MonitorException mx) {
throw new InternalError(mx.getMessage());
}
for (Object vmid: vms) {
if (vmid instanceof Integer) {
int pid = ((Integer) vmid).intValue();
String name = vmid.toString(); // default to pid if name not available
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));
}
}
}
示例15: getMonitoredVMs
import sun.jvmstat.monitor.MonitoredHost; //导入方法依赖的package包/类
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 sx) {
throw new InternalError(sx.getMessage());
} catch (MonitorException mx) {
throw new InternalError(mx.getMessage());
}
for (Object vmid: vms) {
if (vmid instanceof Integer) {
int pid = ((Integer) vmid).intValue();
String name = vmid.toString(); // default to pid if name not available
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));
}
}
}