Search in sources :

Example 11 with MBeanInfo

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;
}
Also used : MBeanInfo(javax.management.MBeanInfo) MBeanAttributeInfo(javax.management.MBeanAttributeInfo)

Example 12 with MBeanInfo

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);
        }
    }
}
Also used : MBeanInfo(javax.management.MBeanInfo) Attribute(javax.management.Attribute) AttributeList(javax.management.AttributeList) MBeanAttributeInfo(javax.management.MBeanAttributeInfo) IOException(java.io.IOException) ObjectName(javax.management.ObjectName)

Example 13 with MBeanInfo

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("-----------------------------------------");
    }
}
Also used : AttributeNotFoundException(javax.management.AttributeNotFoundException) MBeanInfo(javax.management.MBeanInfo) Query(com.googlecode.jmxtrans.model.Query) MBeanAttributeInfo(javax.management.MBeanAttributeInfo) ObjectName(javax.management.ObjectName) Result(com.googlecode.jmxtrans.model.Result)

Example 14 with MBeanInfo

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;
}
Also used : RuntimeMBeanException(javax.management.RuntimeMBeanException) ReflectionException(javax.management.ReflectionException) AttributeNotFoundException(javax.management.AttributeNotFoundException) MBeanInfo(javax.management.MBeanInfo) InstanceNotFoundException(javax.management.InstanceNotFoundException) IntrospectionException(javax.management.IntrospectionException) MBeanAttributeInfo(javax.management.MBeanAttributeInfo) ObjectName(javax.management.ObjectName) RuntimeMBeanException(javax.management.RuntimeMBeanException) MBeanException(javax.management.MBeanException)

Example 15 with MBeanInfo

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);
}
Also used : MBeanInfo(javax.management.MBeanInfo) AbstractMetric(org.apache.hadoop.metrics2.AbstractMetric) MetricsTag(org.apache.hadoop.metrics2.MetricsTag) MBeanAttributeInfo(javax.management.MBeanAttributeInfo)

Aggregations

MBeanInfo (javax.management.MBeanInfo)154 MBeanAttributeInfo (javax.management.MBeanAttributeInfo)87 ObjectName (javax.management.ObjectName)79 MBeanOperationInfo (javax.management.MBeanOperationInfo)38 MBeanServer (javax.management.MBeanServer)27 Test (org.junit.Test)27 Attribute (javax.management.Attribute)19 ArrayList (java.util.ArrayList)17 IntrospectionException (javax.management.IntrospectionException)16 ReflectionException (javax.management.ReflectionException)16 HashMap (java.util.HashMap)15 InstanceNotFoundException (javax.management.InstanceNotFoundException)15 IOException (java.io.IOException)12 MBeanNotificationInfo (javax.management.MBeanNotificationInfo)12 MBeanParameterInfo (javax.management.MBeanParameterInfo)12 MBeanServerConnection (javax.management.MBeanServerConnection)10 MalformedObjectNameException (javax.management.MalformedObjectNameException)10 AttributeList (javax.management.AttributeList)9 AttributeNotFoundException (javax.management.AttributeNotFoundException)9 Descriptor (javax.management.Descriptor)8