Refine search
private ImmutableMap<String, Optional<Object>> getAttributes(Set<String> uniqueColumnNames, String name) throws JMException { ObjectName objectName = new ObjectName(name); String[] columnNamesArray = uniqueColumnNames.toArray(new String[uniqueColumnNames.size()]); ImmutableMap.Builder<String, Optional<Object>> attributes = ImmutableMap.builder(); for (Attribute attribute : mbeanServer.getAttributes(objectName, columnNamesArray).asList()) { attributes.put(attribute.getName(), Optional.ofNullable(attribute.getValue())); } return attributes.build(); }
@Override public void sendAttributeChangeNotification(Attribute oldAttribute, Attribute newAttribute) throws MBeanException, RuntimeOperationsException { if (oldAttribute == null || newAttribute == null) throw new RuntimeOperationsException(new IllegalArgumentException( "Attribute cannot be null.")); if (!oldAttribute.getName().equals(newAttribute.getName())) throw new RuntimeOperationsException(new IllegalArgumentException( "Attribute names cannot be different.")); // TODO: the source must be the object name of the MBean if the listener was registered through // MBeanServer Object oldValue = oldAttribute.getValue(); AttributeChangeNotification n = new AttributeChangeNotification(this, 1, System.currentTimeMillis(), "Attribute value changed", oldAttribute.getName(), oldValue == null ? null : oldValue.getClass().getName(), oldValue, newAttribute.getValue()); sendAttributeChangeNotification(n); }
private synchronized NameValueMap getCachedAttributes(ObjectName objName, Set<String> attrNames) throws InstanceNotFoundException, ReflectionException, IOException { NameValueMap values = cachedValues.get(objName); if (values != null && values.keySet().containsAll(attrNames)) { return values; } attrNames = new TreeSet<String>(attrNames); Set<String> oldNames = cachedNames.get(objName); if (oldNames != null) { attrNames.addAll(oldNames); } values = new NameValueMap(); final AttributeList attrs = conn.getAttributes(objName, attrNames.toArray(new String[attrNames.size()])); for (Attribute attr : attrs.asList()) { values.put(attr.getName(), attr.getValue()); } cachedValues.put(objName, values); cachedNames.put(objName, attrNames); return values; }
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; }
public AttributeList setAttributes(AttributeList list) { AttributeList results=new AttributeList(); for(int i=0;i < list.size();i++) { Attribute attr=(Attribute)list.get(i); if(setNamedAttribute(attr)) results.add(attr); else { if(log.isWarnEnabled()) log.warn("Failed to update attribute name " + attr.getName() + " with value " + attr.getValue()); } } return results; }
protected boolean setNamedAttribute(Attribute attribute) { AttributeEntry entry=atts.get(attribute.getName()); if(entry != null) { try { entry.setter.invoke(attribute.getValue()); return true; } catch(Throwable e) { log.warn(Util.getMessage("AttrWriteFailure"), attribute.getName(), e); } } else { log.warn(Util.getMessage("MissingAttribute"), attribute.getName()); } return false; }
private static Metric toMetric(long t, ObjectName name, Attribute attribute, Tag dsType) { Tag id = Tags.newTag("id", name.getKeyProperty("name")); Tag clazz = Tags.newTag("class", name.getKeyProperty("type")); TagList list = BasicTagList.of(id, clazz, dsType); return new Metric(normalizeName(attribute.getName()), list, t, attribute.getValue()); }
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); } } }
private synchronized NameValueMap getCachedAttributes( ObjectName objName, Set<String> attrNames) throws InstanceNotFoundException, ReflectionException, IOException { NameValueMap values = cachedValues.get(objName); if (values != null && values.keySet().containsAll(attrNames)) { return values; } attrNames = new TreeSet<String>(attrNames); Set<String> oldNames = cachedNames.get(objName); if (oldNames != null) { attrNames.addAll(oldNames); } values = new NameValueMap(); final AttributeList attrs = conn.getAttributes( objName, attrNames.toArray(new String[attrNames.size()])); for (Attribute attr : attrs.asList()) { values.put(attr.getName(), attr.getValue()); } cachedValues.put(objName, values); cachedNames.put(objName, attrNames); return values; }
for (final Object object : attributes) { final Attribute attribute = (Attribute) object; final Object value = convertValueIfNeeded(attribute.getValue()); final String attributeDescription = getAttributeDescription(attribute.getName(), attributeInfos); final String formattedAttributeValue = formatAttributeValue(value); final MBeanAttribute mbeanAttribute = new MBeanAttribute(attribute.getName(), attributeDescription, formattedAttributeValue); result.add(mbeanAttribute);
private static void fetchThreadPoolMetrics(long now, MBeanServer mbs, List<Metric> metrics) throws JMException { final ObjectName threadPoolName = new ObjectName("Catalina:type=ThreadPool,*"); final Set<ObjectName> names = mbs.queryNames(threadPoolName, null); if (names == null) { return; } for (ObjectName name : names) { AttributeList list = mbs.getAttributes(name, THREAD_POOL_ATTRS); // determine whether the shared threadPool is used boolean isUsed = true; for (Attribute a : list.asList()) { if (a.getName().equals("maxThreads")) { Number v = (Number) a.getValue(); isUsed = v.doubleValue() >= 0.0; break; } } if (isUsed) { // only add the attributes if the metric is used. for (Attribute a : list.asList()) { addMetric(metrics, toGauge(now, name, a)); } } } }