use of javax.management.MBeanInfo in project jcollectd by collectd.
the class MBeanCollector method queryAll.
private MBeanQuery queryAll(ObjectName name) throws Exception {
MBeanQuery query = new MBeanQuery(name);
MBeanInfo info = _sender.getMBeanServerConnection().getMBeanInfo(name);
MBeanAttributeInfo[] attrs = info.getAttributes();
for (int i = 0; i < attrs.length; i++) {
query.addAttribute(new MBeanAttribute(attrs[i].getName()));
}
return query;
}
use of javax.management.MBeanInfo in project jmxtrans by jmxtrans.
the class TreeWalker method walkTree.
public void walkTree(MBeanServerConnection connection) throws Exception {
// key here is null, null returns everything!
Set<ObjectName> mbeans = connection.queryNames(null, null);
for (ObjectName name : mbeans) {
MBeanInfo info = connection.getMBeanInfo(name);
MBeanAttributeInfo[] attrs = info.getAttributes();
String[] attrNames = new String[attrs.length];
for (int i = 0; i < attrs.length; i++) {
attrNames[i] = attrs[i].getName();
}
try {
AttributeList attributes = connection.getAttributes(name, attrNames);
for (Attribute attribute : attributes.asList()) {
output(name.getCanonicalName() + "%" + attribute.getName(), attribute.getValue());
}
} catch (Exception e) {
log.error("error getting " + name + ":" + e.getMessage(), e);
}
}
}
use of javax.management.MBeanInfo in project jmxtrans by jmxtrans.
the class TreeWalker3 method walkTree.
public void walkTree(MBeanServerConnection connection, Server server) throws Exception {
// key here is null, null returns everything!
Set<ObjectName> mbeans = connection.queryNames(null, null);
Map<String, String> output = newHashMap();
for (ObjectName name : mbeans) {
MBeanInfo info = connection.getMBeanInfo(name);
MBeanAttributeInfo[] attrs = info.getAttributes();
Query.Builder queryBuilder = Query.builder().setObj(name.getCanonicalName());
ResultCapture resultCapture = new ResultCapture();
queryBuilder.addOutputWriterFactory(resultCapture);
for (MBeanAttributeInfo attrInfo : attrs) {
queryBuilder.addAttr(attrInfo.getName());
}
Query query = queryBuilder.build();
try {
Iterable<Result> results = server.execute(query);
query.runOutputWritersForQuery(server, results);
} catch (AttributeNotFoundException anfe) {
log.error("Error", anfe);
}
for (Result result : resultCapture.results) {
output.put(result.getTypeName(), query.getAttr().toString());
}
}
for (Entry<String, String> entry : output.entrySet()) {
log.debug(entry.getKey());
log.debug(entry.getValue());
log.debug("-----------------------------------------");
}
}
use of javax.management.MBeanInfo in project hbase by apache.
the class JSONBean method write.
/**
* @param mBeanServer
* @param qry
* @param attribute
* @param description
* @return Return non-zero if failed to find bean. 0
* @throws IOException
*/
private static int write(final JsonGenerator jg, final MBeanServer mBeanServer, ObjectName qry, String attribute, final boolean description) throws IOException {
LOG.trace("Listing beans for " + qry);
Set<ObjectName> names = null;
names = mBeanServer.queryNames(qry, null);
jg.writeArrayFieldStart("beans");
Iterator<ObjectName> it = names.iterator();
while (it.hasNext()) {
ObjectName oname = it.next();
MBeanInfo minfo;
String code = "";
String descriptionStr = null;
Object attributeinfo = null;
try {
minfo = mBeanServer.getMBeanInfo(oname);
code = minfo.getClassName();
if (description)
descriptionStr = minfo.getDescription();
String prs = "";
try {
if ("org.apache.commons.modeler.BaseModelMBean".equals(code)) {
prs = "modelerType";
code = (String) mBeanServer.getAttribute(oname, prs);
}
if (attribute != null) {
prs = attribute;
attributeinfo = mBeanServer.getAttribute(oname, prs);
}
} catch (RuntimeMBeanException e) {
// so no need to log them as errors all the time.
if (e.getCause() instanceof UnsupportedOperationException) {
if (LOG.isTraceEnabled()) {
LOG.trace("Getting attribute " + prs + " of " + oname + " threw " + e);
}
} else {
LOG.error("Getting attribute " + prs + " of " + oname + " threw an exception", e);
}
return 0;
} catch (AttributeNotFoundException e) {
// If the modelerType attribute was not found, the class name is used
// instead.
LOG.error("getting attribute " + prs + " of " + oname + " threw an exception", e);
} catch (MBeanException e) {
// The code inside the attribute getter threw an exception so log it,
// and fall back on the class name
LOG.error("getting attribute " + prs + " of " + oname + " threw an exception", e);
} catch (RuntimeException e) {
// For some reason even with an MBeanException available to them
// Runtime exceptionscan still find their way through, so treat them
// the same as MBeanException
LOG.error("getting attribute " + prs + " of " + oname + " threw an exception", e);
} catch (ReflectionException e) {
// This happens when the code inside the JMX bean (setter?? from the
// java docs) threw an exception, so log it and fall back on the
// class name
LOG.error("getting attribute " + prs + " of " + oname + " threw an exception", e);
}
} catch (InstanceNotFoundException e) {
//Ignored for some reason the bean was not found so don't output it
continue;
} catch (IntrospectionException e) {
// This is an internal error, something odd happened with reflection so
// log it and don't output the bean.
LOG.error("Problem while trying to process JMX query: " + qry + " with MBean " + oname, e);
continue;
} catch (ReflectionException e) {
// This happens when the code inside the JMX bean threw an exception, so
// log it and don't output the bean.
LOG.error("Problem while trying to process JMX query: " + qry + " with MBean " + oname, e);
continue;
}
jg.writeStartObject();
jg.writeStringField("name", oname.toString());
if (description && descriptionStr != null && descriptionStr.length() > 0) {
jg.writeStringField("description", descriptionStr);
}
jg.writeStringField("modelerType", code);
if (attribute != null && attributeinfo == null) {
jg.writeStringField("result", "ERROR");
jg.writeStringField("message", "No attribute with name " + attribute + " was found.");
jg.writeEndObject();
jg.writeEndArray();
jg.close();
return -1;
}
if (attribute != null) {
writeAttribute(jg, attribute, descriptionStr, attributeinfo);
} else {
MBeanAttributeInfo[] attrs = minfo.getAttributes();
for (int i = 0; i < attrs.length; i++) {
writeAttribute(jg, mBeanServer, oname, description, attrs[i]);
}
}
jg.writeEndObject();
}
jg.writeEndArray();
return 0;
}
use of javax.management.MBeanInfo in project hadoop by apache.
the class MBeanInfoBuilder method get.
MBeanInfo get() {
curRecNo = 0;
for (MetricsRecordImpl rec : recs) {
for (MetricsTag t : rec.tags()) {
attrs.add(newAttrInfo("tag." + t.name(), t.description(), "java.lang.String"));
}
for (AbstractMetric m : rec.metrics()) {
m.visit(this);
}
++curRecNo;
}
MetricsSystemImpl.LOG.debug(attrs);
MBeanAttributeInfo[] attrsArray = new MBeanAttributeInfo[attrs.size()];
return new MBeanInfo(name, description, attrs.toArray(attrsArray), null, null, // no ops/ctors/notifications
null);
}
Aggregations