Refine search
private MBeanAttributeInfo attrInfo(MBeanInfo mbinfo, String attr) { for(MBeanAttributeInfo ai: mbinfo.getAttributes()) { if (ai.getName().equals(attr)) { return ai; } } return null; }
private Stream<JmxColumnHandle> getColumnHandles(MBeanInfo mbeanInfo) { return Arrays.stream(mbeanInfo.getAttributes()) .filter(MBeanAttributeInfo::isReadable) .map(attribute -> new JmxColumnHandle(attribute.getName(), getColumnType(attribute))); }
private static Set<String> getAttributesNames(ObjectName name) { try { final Set<String> result = new HashSet<String>(); final MBeanInfo mBeanInfo = MBEAN_SERVER.getMBeanInfo(name); final MBeanAttributeInfo[] attributes = mBeanInfo.getAttributes(); for (final MBeanAttributeInfo attribute : attributes) { if (attribute.isReadable()) { result.add(attribute.getName()); } } return result; } catch (final JMException e) { return Collections.emptySet(); } } }
/** * List of the names of each of the attributes on the MBean * * @return list of attribute names */ public Collection<String> listAttributeNames() { List<String> list = new ArrayList<String>(); try { MBeanAttributeInfo[] attrs = beanInfo.getAttributes(); for (MBeanAttributeInfo attr : attrs) { list.add(attr.getName()); } } catch (Exception e) { throwException("Could not list attribute names. Reason: ", e); } return list; }
public static List<MbeanAttributeValue> getMBeanAttributeValues(String mbeanExpr, String attributeExpr) { List<MbeanAttributeValue> values = new ArrayList<>(); MBeanServer server = ManagementFactory.getPlatformMBeanServer(); try { Set<ObjectName> mbeanNames = server.queryNames(new ObjectName(mbeanExpr), null); for (ObjectName mbeanName: mbeanNames) { MBeanInfo mBeanInfo = server.getMBeanInfo(mbeanName); MBeanAttributeInfo[] attributeInfos = mBeanInfo.getAttributes(); for (MBeanAttributeInfo attributeInfo: attributeInfos) { if (attributeInfo.getName().equals(attributeExpr) || attributeExpr.length() == 0 || attributeExpr.equals("*")) { double value = (Double) server.getAttribute(mbeanName, attributeInfo.getName()); values.add(new MbeanAttributeValue(mbeanName.getCanonicalName(), attributeInfo.getName(), value)); } } } } catch (Exception e) { LOG.error("fail to retrieve value for " + mbeanExpr + ":" + attributeExpr, e); } return values; }
private static void printJMXStats() { MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer(); ObjectName groupMulticast = getGroupMulticastObjectName(mBeanServer); if (groupMulticast == null) { System.err.println("Unable to find the GROUP_MULTICAST protocol"); return ; } try { System.out.println("======== JMX STATS ========="); for (MBeanAttributeInfo mBeanAttributeInfo : mBeanServer.getMBeanInfo(groupMulticast).getAttributes()) { String attribute = mBeanAttributeInfo.getName(); String type = mBeanAttributeInfo.getType(); if (!type.equals("double") && !type.equals("int")) { continue; } System.out.println(attribute + "=" + mBeanServer.getAttribute(groupMulticast, attribute)); } System.out.println("======== JMX STATS ========="); } catch (Exception e) { System.err.println("Error collecting stats" + e.getLocalizedMessage()); } }
private Map<String, String> getMBeanValues(MBeanServerConnection cnx, ObjectName on, String ... attributeNames) throws InstanceNotFoundException, IOException, ReflectionException, IntrospectionException { if (attributeNames == null) { MBeanInfo info = cnx.getMBeanInfo( on ); MBeanAttributeInfo[] attributeArray = info.getAttributes(); int i = 0; attributeNames = new String[attributeArray.length]; for (MBeanAttributeInfo ai : attributeArray) attributeNames[i++] = ai.getName(); } AttributeList attributes = cnx.getAttributes(on, attributeNames); Map<String, String> values = new HashMap<String, String>(); for (javax.management.Attribute attribute : attributes.asList()) { Object value = attribute.getValue(); values.put(attribute.getName(), value == null ? "" : value.toString()); } return values; }
/** * Description of the specified attribute name. * * @param attributeName - stringified name of the attribute * @return the description */ public String describeAttribute(String attributeName) { String ret = "Attribute not found"; try { MBeanAttributeInfo[] attributes = beanInfo.getAttributes(); for (MBeanAttributeInfo attribute : attributes) { if (attribute.getName().equals(attributeName)) { return describeAttribute(attribute); } } } catch (Exception e) { throwException("Could not describe attribute '" + attributeName + "'. Reason: ", e); } return ret; }
continue; MBeanAttributeInfo[] attrs = mbeanServer.getMBeanInfo(obj.getObjectName()).getAttributes(); String[] strAtts = new String[attrs.length]; for (int i = 0; i < strAtts.length; i++) { strAtts[i] = attrs[i].getName();
); final MBeanAttributeInfo[] attributes = info.getAttributes(); for (final MBeanAttributeInfo attributeInfo : attributes) { final Object attribute; try { attribute = connection.getAttribute(n, attributeInfo.getName()); } catch (final Exception error) { throw new PrintMetricsException( ); System.out.println(attributeInfo.getName() + ": " + attribute);
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); } } }
StringBuffer result = new StringBuffer(); MBeanInfo info = mbsc.getMBeanInfo(instance.getObjectName()); MBeanAttributeInfo[] attributes = info.getAttributes(); if (attributes.length > 0) { result.append("Attributes:"); result.append("\n"); for (int i = 0; i < attributes.length; i++) { result.append(' ' + attributes[i].getName() + ": " + attributes[i].getDescription() + " (type=" + attributes[i].getType() + ")"); result.append("\n");
sb.append(" - " + mbinfo.getDescription()); sb.append('\n'); for(MBeanAttributeInfo ai: mbinfo.getAttributes()) { sb.append(" (A) "); sb.append(ai.getName()).append(" : ").append(toPrintableType(ai.getType())).append(""); if (!ai.isReadable()) { sb.append(" - WRITEONLY"); if (!ai.getName().equals(ai.getDescription())) { sb.append(" - " + ai.getDescription()); sb.append('\n');
MBeanInfo info = server.getMBeanInfo(this.objectName); MBeanAttributeInfo[] attributeInfo = info.getAttributes(); this.allowedAttributes = new HashMap<>(attributeInfo.length); for (MBeanAttributeInfo infoEle : attributeInfo) { this.allowedAttributes.put(infoEle.getName(), infoEle);
public Iterable<Result> fetchResults(MBeanServerConnection mbeanServer, ObjectName queryName) throws InstanceNotFoundException, IntrospectionException, ReflectionException, IOException { ObjectInstance oi = mbeanServer.getObjectInstance(queryName); List<String> attributes; if (attr.isEmpty()) { attributes = new ArrayList<>(); MBeanInfo info = mbeanServer.getMBeanInfo(queryName); for (MBeanAttributeInfo attrInfo : info.getAttributes()) { attributes.add(attrInfo.getName()); } } else { attributes = attr; } try { if (!attributes.isEmpty()) { logger.debug("Executing queryName [{}] from query [{}]", queryName.getCanonicalName(), this); AttributeList al = mbeanServer.getAttributes(queryName, attributes.toArray(new String[attributes.size()])); return new JmxResultProcessor(this, oi, al.asList(), oi.getClassName(), queryName.getDomain()).getResults(); } } catch (UnmarshalException ue) { if ((ue.getCause() != null) && (ue.getCause() instanceof ClassNotFoundException)) { logger.debug("Bad unmarshall, continuing. This is probably ok and due to something like this: " + "http://ehcache.org/xref/net/sf/ehcache/distribution/RMICacheManagerPeerListener.html#52", ue.getMessage()); } else { throw ue; } } return ImmutableList.of(); }
fail("Could not obtain Sender Proxy Details"); attributeInfos = info.getAttributes(); for (MBeanAttributeInfo attributeInfo : attributeInfos) { propertyName = attributeInfo.getName(); propertyValue = mbeanServer.getAttribute(objName, propertyName); LogWriterUtils.getLogWriter().info(
log.info("DESCRIPTION: \t" + info.getDescription()); log.info("ATTRIBUTES"); MBeanAttributeInfo[] attrInfo = info.getAttributes(); if (attrInfo.length > 0) { for (int i = 0; i < attrInfo.length; i++) { log.info(" ** NAME: \t" + attrInfo[i].getName()); log.info(" DESCR: \t" + attrInfo[i].getDescription()); log.info(" TYPE: \t" + attrInfo[i].getType() + "\tREAD: " + attrInfo[i].isReadable() + "\tWRITE: " + attrInfo[i].isWritable());
MBeanAttributeInfo[] attrs = info.getAttributes(); queryBuilder.addAttr(attrInfo.getName());
final ObjectName name = new ObjectName(mbeanName); final MBeanInfo info = this.server.getMBeanInfo(name); ret.put("attributes", info.getAttributes()); ret.put("description", info.getDescription()); } catch (final Exception e) { final MBeanInfo info = this.server.getMBeanInfo(name); final MBeanAttributeInfo[] mbeanAttrs = info.getAttributes(); final Map<String, Object> attributes = new TreeMap<>(); final Object obj = this.server.getMBeanAttribute(name, attrInfo.getName()); attributes.put(attrInfo.getName(), obj);
public void walkTree(MBeanServerConnection connection, Server server) 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(); Query.Builder queryBuilder = Query.builder() .setObj(name.getCanonicalName()) .addOutputWriterFactory(new StdOutWriter(ImmutableList.<String>of(), false, false, null, Collections.<String, Object>emptyMap())); 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); } } } }