diff --git a/src/test/java/TestJvm.java b/src/test/java/TestJvm.java index cbb82f2774ffe26fb137f1b425b5d0828167321f..53c8d43f461d253f34cffd37633daa4288a80135 100644 --- a/src/test/java/TestJvm.java +++ b/src/test/java/TestJvm.java @@ -13,7 +13,26 @@ import java.util.Set; * Created by jiangzeyin on 2019/4/4. */ public class TestJvm { + public static void main(String[] args) throws IOException, AttachNotSupportedException, MonitorException, URISyntaxException { + System.out.println(SystemUtil.getJavaRuntimeInfo().getVersion()); + // 获取监控主机 + MonitoredHost local = MonitoredHost.getMonitoredHost("localhost"); + // 取得所有在活动的虚拟机集合 + Set vmlist = new HashSet(local.activeVms()); + // 遍历集合,输出PID和进程名 + for (Object process : vmlist) { + MonitoredVm vm = local.getMonitoredVm(new VmIdentifier("//" + process)); + // 获取类名 + String processname = MonitoredVmUtil.mainClass(vm, true); + System.out.println(processname); + if (!"io.jpom.JpomAgentApplication".equals(processname)) { + continue; + } + System.out.println(vm.getVmIdentifier().getUserInfo()); + System.out.println(vm.getVmIdentifier().toString()); + } + } }