add mx -jconsole option

This commit is contained in:
Doug MacEachern 2009-04-29 12:19:40 -07:00
parent 6ef73dcbcb
commit 0eb3672642
1 changed files with 29 additions and 6 deletions

View File

@ -79,18 +79,38 @@ public class Mx extends SigarCommandBase {
} }
} }
private void jconsole() {
String pid = String.valueOf(this.sigar.getPid());
String[] argv = { "jconsole", pid };
println("exec(jconsole, " + pid + ")");
try {
Process p = Runtime.getRuntime().exec(argv);
p.waitFor();
println("jconsole exited");
} catch (Exception e) {
println(e.getMessage());
}
}
public void output(String[] args) throws SigarException { public void output(String[] args) throws SigarException {
MBeanServer server = getMBeanServer(); MBeanServer server = getMBeanServer();
register(server); register(server);
boolean hasQuery = args.length != 0; boolean hasQuery = false;
try { boolean launchJconsole = false;
String query; String query = "sigar:*";
if (hasQuery) {
query = args[0]; for (int i=0; i<args.length; i++) {
String arg = args[i];
if (arg.equals("-jconsole")) {
launchJconsole = true;
} }
else { else {
query = "sigar:*"; query = arg;
hasQuery = true;
} }
}
try {
Set beans = Set beans =
server.queryNames(new ObjectName(query), null); server.queryNames(new ObjectName(query), null);
println(beans.size() + " MBeans are registered..."); println(beans.size() + " MBeans are registered...");
@ -112,6 +132,9 @@ public class Mx extends SigarCommandBase {
} catch (Exception e) { } catch (Exception e) {
throw new SigarException(e.getMessage()); throw new SigarException(e.getMessage());
} }
if (launchJconsole) {
jconsole();
}
} }
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {