add query support
This commit is contained in:
parent
63478f28ff
commit
c7b398b53a
|
@ -21,6 +21,8 @@ import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
|
import javax.management.MBeanAttributeInfo;
|
||||||
|
import javax.management.MBeanInfo;
|
||||||
import javax.management.MBeanServer;
|
import javax.management.MBeanServer;
|
||||||
import javax.management.MBeanServerFactory;
|
import javax.management.MBeanServerFactory;
|
||||||
import javax.management.ObjectName;
|
import javax.management.ObjectName;
|
||||||
|
@ -44,6 +46,10 @@ public class Mx extends SigarCommandBase {
|
||||||
return "Register MBeans for use via jconsole, etc.";
|
return "Register MBeans for use via jconsole, etc.";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected boolean validateArgs(String[] args) {
|
||||||
|
return args.length <= 1;
|
||||||
|
}
|
||||||
|
|
||||||
public static MBeanServer getMBeanServer()
|
public static MBeanServer getMBeanServer()
|
||||||
throws SigarException {
|
throws SigarException {
|
||||||
List servers =
|
List servers =
|
||||||
|
@ -73,12 +79,32 @@ public class Mx extends SigarCommandBase {
|
||||||
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;
|
||||||
try {
|
try {
|
||||||
|
String query;
|
||||||
|
if (hasQuery) {
|
||||||
|
query = args[0];
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
query = "sigar:*";
|
||||||
|
}
|
||||||
Set beans =
|
Set beans =
|
||||||
server.queryNames(new ObjectName("sigar:*"), null);
|
server.queryNames(new ObjectName(query), null);
|
||||||
println(beans.size() + " MBeans are registered...");
|
println(beans.size() + " MBeans are registered...");
|
||||||
for (Iterator it=beans.iterator(); it.hasNext();) {
|
for (Iterator it=beans.iterator(); it.hasNext();) {
|
||||||
println(it.next().toString());
|
ObjectName name = (ObjectName)it.next();
|
||||||
|
if (hasQuery) {
|
||||||
|
MBeanInfo info = server.getMBeanInfo(name);
|
||||||
|
MBeanAttributeInfo[] attrs = info.getAttributes();
|
||||||
|
for (int i=0; i<attrs.length; i++) {
|
||||||
|
String attr = attrs[i].getName();
|
||||||
|
Object val = server.getAttribute(name, attr);
|
||||||
|
println(name + ":" + attr + "=" + val);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
println(name.toString());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new SigarException(e.getMessage());
|
throw new SigarException(e.getMessage());
|
||||||
|
|
Loading…
Reference in New Issue