@Test public void collectSingleMbeanWithOneCompAttribWithAllItsCompMembers() { String collectionName = "collectSingleMbeanWithOneCompAttribWithAllItsCompMembers"; jmxNodeInfo.setMBeans(jmxConfigFactory.getMBeanInfo(collectionName)); jmxNodeInfo.setDsMap(generateDataSourceMap(jmxConfigFactory.getAttributeMap(collectionName, "", ""))); CollectionSet collectionSet = jmxCollector.collect(collectionAgent, null, null); JMXCollectionSet jmxCollectionSet = (JMXCollectionSet) collectionSet; JMXCollectionResource jmxCollectionResource = jmxCollectionSet.getResource(); AttributeGroup group = jmxCollectionResource.getGroup(new AttributeGroupType("java_lang_type_Memory", "all")); assertEquals(4, group.getAttributes().size()); printDebugAttributeGroup(group); assertEquals("Collection: " + collectionName + " run successfully", 1, collectionSet.getStatus()); }
@Override public CollectionSet collect(CollectionAgent agent, EventProxy eproxy, Map<String, Object> map) { InetAddress ipaddr = agent.getAddress(); JMXNodeInfo nodeInfo = agent.getAttribute(NODE_INFO_KEY); Map<String, BeanInfo> mbeans = nodeInfo.getMBeans(); String collDir = serviceName; boolean useMbeanForRrds = ParameterMap.getKeyedBoolean(map, "use-mbean-name-for-rrds", false); String port = ParameterMap.getKeyedString(map, "port", null); String friendlyName = ParameterMap.getKeyedString(map,"friendly-name", port); if (useFriendlyName) { collDir = friendlyName; } JMXCollectionSet collectionSet=new JMXCollectionSet(agent,collDir); collectionSet.setCollectionTimestamp(new Date()); JMXCollectionResource collectionResource=collectionSet.getResource(); ConnectionWrapper connection = null; LogUtils.debugf(this, "collecting %s on node ID %d", InetAddressUtils.str(ipaddr), nodeInfo.getNodeId()); try { connection = getMBeanServerConnection(map, ipaddr); if (connection == null) { return collectionSet; } MBeanServerConnection mbeanServer = connection.getMBeanServer(); int retry = ParameterMap.getKeyedInteger(map, "retry", 3); for (int attempts = 0; attempts <= retry; attempts++) { try { for (Iterator<BeanInfo> iter = mbeans.values().iterator(); iter.hasNext();) { BeanInfo beanInfo = iter.next(); String mbeanName = beanInfo.getMbeanName(); String objectName = beanInfo.getObjectName(); String excludeList = beanInfo.getExcludes(); String obj = useMbeanForRrds ? mbeanName : objectName; AttributeGroupType attribGroupType=new AttributeGroupType(fixGroupName(obj),"all"); List<String> attribNames = beanInfo.getAttributeNames(); List<String> compAttribNames = beanInfo.getCompositeAttributeNames(); for (String compAttribName : compAttribNames) { if (attribNames.contains(compAttribName) ) { attribNames.remove(compAttribName); String[] ac = compAttribName.split("\\|", -1); String attrName = ac[0]; if (!attribNames.contains(attrName)) { attribNames.add(attrName); } } } String[] attrNames = attribNames.toArray(new String[attribNames.size()]); if (objectName.indexOf("*") == -1) { LogUtils.debugf(this, "%s Collector - getAttributes: %s, # attributes: %d, # composite attribute members: %d", serviceName, objectName, attrNames.length, compAttribNames.size()); try { ObjectName oName = new ObjectName(objectName); if (mbeanServer.isRegistered(oName)) { AttributeList attrList = mbeanServer.getAttributes(oName, attrNames); Map<String, JMXDataSource> dsMap = nodeInfo.getDsMap(); for(Object attribute : attrList) { List<String> compositeMemberKeys = new ArrayList<String>(); Boolean isComposite = false; Attribute attrib=(Attribute)attribute; for (String compAttrName : compAttribNames ) { String[] attribKeys = compAttrName.split("\\|", -1); if (attrib.getName().equals(attribKeys[0])) { compositeMemberKeys.add(attribKeys[1]); isComposite = true; } } if (isComposite) { try { CompositeData cd = (CompositeData)attrib.getValue(); for (String key : compositeMemberKeys) { JMXDataSource ds = dsMap.get(objectName + "|" + attrib.getName() + "|" + key); JMXCollectionAttributeType attribType=new JMXCollectionAttributeType(ds, null, null, attribGroupType); collectionResource.setAttributeValue(attribType, cd.get(key).toString()); } } catch (final ClassCastException cce) { LogUtils.debugf(this, cce, "%s Collection - getAttributes (try CompositeData) - ERROR: Failed to cast attribute value to type CompositeData!", serviceName); } } else { JMXDataSource ds = dsMap.get(objectName + "|" + attrib.getName()); JMXCollectionAttributeType attribType=new JMXCollectionAttributeType(ds, null, null, attribGroupType); collectionResource.setAttributeValue(attribType, attrib.getValue().toString()); } } } } catch (final InstanceNotFoundException e) { LogUtils.errorf(this, e, "Unable to retrieve attributes from %s", objectName); } } else { Set<ObjectName> mbeanSet = getObjectNames(mbeanServer, objectName); for (Iterator<ObjectName> objectNameIter = mbeanSet.iterator(); objectNameIter.hasNext(); ) { ObjectName oName = objectNameIter.next(); LogUtils.debugf(this, "%s Collector - getAttributesWC: %s, # attributes: %d, alias: %s", serviceName, oName, attrNames.length, beanInfo.getKeyAlias()); try { if (excludeList == null) { if (mbeanServer.isRegistered(oName)) { AttributeList attrList = mbeanServer.getAttributes(oName, attrNames); Map<String, JMXDataSource> dsMap = nodeInfo.getDsMap(); for(Object attribute : attrList) { Attribute attrib=(Attribute)attribute; JMXDataSource ds = dsMap.get(objectName + "|" + attrib.getName()); JMXCollectionAttributeType attribType= new JMXCollectionAttributeType(ds, oName.getKeyProperty(beanInfo.getKeyField()), beanInfo.getKeyAlias(), attribGroupType); collectionResource.setAttributeValue(attribType, attrib.getValue().toString()); } } } else { String keyName = oName.getKeyProperty(beanInfo.getKeyField()); boolean found = false; StringTokenizer st = new StringTokenizer( excludeList, ","); while (st.hasMoreTokens()) { if (keyName.equals(st.nextToken())) { found = true; break; } } if (!found) { if (mbeanServer.isRegistered(oName)) { AttributeList attrList = mbeanServer.getAttributes(oName, attrNames); Map<String, JMXDataSource> dsMap = nodeInfo.getDsMap(); for(Object attribute : attrList) { Attribute attrib=(Attribute)attribute; JMXDataSource ds = dsMap.get(objectName + "|" + attrib.getName()); JMXCollectionAttributeType attribType = new JMXCollectionAttributeType(ds, oName.getKeyProperty(beanInfo.getKeyField()), beanInfo.getKeyAlias(), attribGroupType); collectionResource.setAttributeValue(attribType, attrib.getValue().toString()); } } } } } catch (final InstanceNotFoundException e) { LogUtils.errorf(this, e, "Error retrieving attributes for %s", oName); } } } } break; } catch (final Exception e) { LogUtils.debugf(this, e, "%s Collector.collect: IOException while collecting address: %s", serviceName, agent.getAddress()); } } } catch (final Exception e) { LogUtils.errorf(this, e, "Error getting MBeanServer"); } finally { if (connection != null) { connection.close(); } } collectionSet.setStatus(ServiceCollector.COLLECTION_SUCCEEDED); return collectionSet; }
JMXCollector implements ServiceCollector { @Override public CollectionSet collect(CollectionAgent agent, EventProxy eproxy, Map<String, Object> map) { InetAddress ipaddr = agent.getAddress(); JMXNodeInfo nodeInfo = agent.getAttribute(NODE_INFO_KEY); Map<String, BeanInfo> mbeans = nodeInfo.getMBeans(); String collDir = serviceName; boolean useMbeanForRrds = ParameterMap.getKeyedBoolean(map, "use-mbean-name-for-rrds", false); String port = ParameterMap.getKeyedString(map, "port", null); String friendlyName = ParameterMap.getKeyedString(map,"friendly-name", port); if (useFriendlyName) { collDir = friendlyName; } JMXCollectionSet collectionSet=new JMXCollectionSet(agent,collDir); collectionSet.setCollectionTimestamp(new Date()); JMXCollectionResource collectionResource=collectionSet.getResource(); ConnectionWrapper connection = null; LogUtils.debugf(this, "collecting %s on node ID %d", InetAddressUtils.str(ipaddr), nodeInfo.getNodeId()); try { connection = getMBeanServerConnection(map, ipaddr); if (connection == null) { return collectionSet; } MBeanServerConnection mbeanServer = connection.getMBeanServer(); int retry = ParameterMap.getKeyedInteger(map, "retry", 3); for (int attempts = 0; attempts <= retry; attempts++) { try { for (Iterator<BeanInfo> iter = mbeans.values().iterator(); iter.hasNext();) { BeanInfo beanInfo = iter.next(); String mbeanName = beanInfo.getMbeanName(); String objectName = beanInfo.getObjectName(); String excludeList = beanInfo.getExcludes(); String obj = useMbeanForRrds ? mbeanName : objectName; AttributeGroupType attribGroupType=new AttributeGroupType(fixGroupName(obj),"all"); List<String> attribNames = beanInfo.getAttributeNames(); List<String> compAttribNames = beanInfo.getCompositeAttributeNames(); for (String compAttribName : compAttribNames) { if (attribNames.contains(compAttribName) ) { attribNames.remove(compAttribName); String[] ac = compAttribName.split("\\|", -1); String attrName = ac[0]; if (!attribNames.contains(attrName)) { attribNames.add(attrName); } } } String[] attrNames = attribNames.toArray(new String[attribNames.size()]); if (objectName.indexOf("*") == -1) { LogUtils.debugf(this, "%s Collector - getAttributes: %s, # attributes: %d, # composite attribute members: %d", serviceName, objectName, attrNames.length, compAttribNames.size()); try { ObjectName oName = new ObjectName(objectName); if (mbeanServer.isRegistered(oName)) { AttributeList attrList = mbeanServer.getAttributes(oName, attrNames); Map<String, JMXDataSource> dsMap = nodeInfo.getDsMap(); for(Object attribute : attrList) { List<String> compositeMemberKeys = new ArrayList<String>(); Boolean isComposite = false; Attribute attrib=(Attribute)attribute; for (String compAttrName : compAttribNames ) { String[] attribKeys = compAttrName.split("\\|", -1); if (attrib.getName().equals(attribKeys[0])) { compositeMemberKeys.add(attribKeys[1]); isComposite = true; } } if (isComposite) { try { CompositeData cd = (CompositeData)attrib.getValue(); for (String key : compositeMemberKeys) { JMXDataSource ds = dsMap.get(objectName + "|" + attrib.getName() + "|" + key); JMXCollectionAttributeType attribType=new JMXCollectionAttributeType(ds, null, null, attribGroupType); collectionResource.setAttributeValue(attribType, cd.get(key).toString()); } } catch (final ClassCastException cce) { LogUtils.debugf(this, cce, "%s Collection - getAttributes (try CompositeData) - ERROR: Failed to cast attribute value to type CompositeData!", serviceName); } } else { JMXDataSource ds = dsMap.get(objectName + "|" + attrib.getName()); JMXCollectionAttributeType attribType=new JMXCollectionAttributeType(ds, null, null, attribGroupType); collectionResource.setAttributeValue(attribType, attrib.getValue().toString()); } } } } catch (final InstanceNotFoundException e) { LogUtils.errorf(this, e, "Unable to retrieve attributes from %s", objectName); } } else { Set<ObjectName> mbeanSet = getObjectNames(mbeanServer, objectName); for (Iterator<ObjectName> objectNameIter = mbeanSet.iterator(); objectNameIter.hasNext(); ) { ObjectName oName = objectNameIter.next(); LogUtils.debugf(this, "%s Collector - getAttributesWC: %s, # attributes: %d, alias: %s", serviceName, oName, attrNames.length, beanInfo.getKeyAlias()); try { if (excludeList == null) { if (mbeanServer.isRegistered(oName)) { AttributeList attrList = mbeanServer.getAttributes(oName, attrNames); Map<String, JMXDataSource> dsMap = nodeInfo.getDsMap(); for(Object attribute : attrList) { Attribute attrib=(Attribute)attribute; JMXDataSource ds = dsMap.get(objectName + "|" + attrib.getName()); JMXCollectionAttributeType attribType= new JMXCollectionAttributeType(ds, oName.getKeyProperty(beanInfo.getKeyField()), beanInfo.getKeyAlias(), attribGroupType); collectionResource.setAttributeValue(attribType, attrib.getValue().toString()); } } } else { String keyName = oName.getKeyProperty(beanInfo.getKeyField()); boolean found = false; StringTokenizer st = new StringTokenizer( excludeList, ","); while (st.hasMoreTokens()) { if (keyName.equals(st.nextToken())) { found = true; break; } } if (!found) { if (mbeanServer.isRegistered(oName)) { AttributeList attrList = mbeanServer.getAttributes(oName, attrNames); Map<String, JMXDataSource> dsMap = nodeInfo.getDsMap(); for(Object attribute : attrList) { Attribute attrib=(Attribute)attribute; JMXDataSource ds = dsMap.get(objectName + "|" + attrib.getName()); JMXCollectionAttributeType attribType = new JMXCollectionAttributeType(ds, oName.getKeyProperty(beanInfo.getKeyField()), beanInfo.getKeyAlias(), attribGroupType); collectionResource.setAttributeValue(attribType, attrib.getValue().toString()); } } } } } catch (final InstanceNotFoundException e) { LogUtils.errorf(this, e, "Error retrieving attributes for %s", oName); } } } } break; } catch (final Exception e) { LogUtils.debugf(this, e, "%s Collector.collect: IOException while collecting address: %s", serviceName, agent.getAddress()); } } } catch (final Exception e) { LogUtils.errorf(this, e, "Error getting MBeanServer"); } finally { if (connection != null) { connection.close(); } } collectionSet.setStatus(ServiceCollector.COLLECTION_SUCCEEDED); return collectionSet; } }
JMXCollector implements ServiceCollector { @Override public CollectionSet collect(CollectionAgent agent, EventProxy eproxy, Map<String, Object> map) { InetAddress ipaddr = agent.getAddress(); JMXNodeInfo nodeInfo = agent.getAttribute(NODE_INFO_KEY); Map<String, BeanInfo> mbeans = nodeInfo.getMBeans(); String collDir = serviceName; boolean useMbeanForRrds = ParameterMap.getKeyedBoolean(map, "use-mbean-name-for-rrds", false); String port = ParameterMap.getKeyedString(map, "port", null); String friendlyName = ParameterMap.getKeyedString(map,"friendly-name", port); if (useFriendlyName) { collDir = friendlyName; } JMXCollectionSet collectionSet=new JMXCollectionSet(agent,collDir); collectionSet.setCollectionTimestamp(new Date()); JMXCollectionResource collectionResource=collectionSet.getResource(); ConnectionWrapper connection = null; LogUtils.debugf(this, "collecting %s on node ID %d", InetAddressUtils.str(ipaddr), nodeInfo.getNodeId()); try { connection = getMBeanServerConnection(map, ipaddr); if (connection == null) { return collectionSet; } MBeanServerConnection mbeanServer = connection.getMBeanServer(); int retry = ParameterMap.getKeyedInteger(map, "retry", 3); for (int attempts = 0; attempts <= retry; attempts++) { try { for (Iterator<BeanInfo> iter = mbeans.values().iterator(); iter.hasNext();) { BeanInfo beanInfo = iter.next(); String mbeanName = beanInfo.getMbeanName(); String objectName = beanInfo.getObjectName(); String excludeList = beanInfo.getExcludes(); String obj = useMbeanForRrds ? mbeanName : objectName; AttributeGroupType attribGroupType=new AttributeGroupType(fixGroupName(obj),"all"); List<String> attribNames = beanInfo.getAttributeNames(); List<String> compAttribNames = beanInfo.getCompositeAttributeNames(); for (String compAttribName : compAttribNames) { if (attribNames.contains(compAttribName) ) { attribNames.remove(compAttribName); String[] ac = compAttribName.split("\\|", -1); String attrName = ac[0]; if (!attribNames.contains(attrName)) { attribNames.add(attrName); } } } String[] attrNames = attribNames.toArray(new String[attribNames.size()]); if (objectName.indexOf("*") == -1) { LogUtils.debugf(this, "%s Collector - getAttributes: %s, # attributes: %d, # composite attribute members: %d", serviceName, objectName, attrNames.length, compAttribNames.size()); try { ObjectName oName = new ObjectName(objectName); if (mbeanServer.isRegistered(oName)) { AttributeList attrList = mbeanServer.getAttributes(oName, attrNames); Map<String, JMXDataSource> dsMap = nodeInfo.getDsMap(); for(Object attribute : attrList) { List<String> compositeMemberKeys = new ArrayList<String>(); Boolean isComposite = false; Attribute attrib=(Attribute)attribute; for (String compAttrName : compAttribNames ) { String[] attribKeys = compAttrName.split("\\|", -1); if (attrib.getName().equals(attribKeys[0])) { compositeMemberKeys.add(attribKeys[1]); isComposite = true; } } if (isComposite) { try { CompositeData cd = (CompositeData)attrib.getValue(); for (String key : compositeMemberKeys) { JMXDataSource ds = dsMap.get(objectName + "|" + attrib.getName() + "|" + key); JMXCollectionAttributeType attribType=new JMXCollectionAttributeType(ds, null, null, attribGroupType); collectionResource.setAttributeValue(attribType, cd.get(key).toString()); } } catch (final ClassCastException cce) { LogUtils.debugf(this, cce, "%s Collection - getAttributes (try CompositeData) - ERROR: Failed to cast attribute value to type CompositeData!", serviceName); } } else { JMXDataSource ds = dsMap.get(objectName + "|" + attrib.getName()); JMXCollectionAttributeType attribType=new JMXCollectionAttributeType(ds, null, null, attribGroupType); collectionResource.setAttributeValue(attribType, attrib.getValue().toString()); } } } } catch (final InstanceNotFoundException e) { LogUtils.errorf(this, e, "Unable to retrieve attributes from %s", objectName); } } else { Set<ObjectName> mbeanSet = getObjectNames(mbeanServer, objectName); for (Iterator<ObjectName> objectNameIter = mbeanSet.iterator(); objectNameIter.hasNext(); ) { ObjectName oName = objectNameIter.next(); LogUtils.debugf(this, "%s Collector - getAttributesWC: %s, # attributes: %d, alias: %s", serviceName, oName, attrNames.length, beanInfo.getKeyAlias()); try { if (excludeList == null) { if (mbeanServer.isRegistered(oName)) { AttributeList attrList = mbeanServer.getAttributes(oName, attrNames); Map<String, JMXDataSource> dsMap = nodeInfo.getDsMap(); for(Object attribute : attrList) { Attribute attrib=(Attribute)attribute; JMXDataSource ds = dsMap.get(objectName + "|" + attrib.getName()); JMXCollectionAttributeType attribType= new JMXCollectionAttributeType(ds, oName.getKeyProperty(beanInfo.getKeyField()), beanInfo.getKeyAlias(), attribGroupType); collectionResource.setAttributeValue(attribType, attrib.getValue().toString()); } } } else { String keyName = oName.getKeyProperty(beanInfo.getKeyField()); boolean found = false; StringTokenizer st = new StringTokenizer( excludeList, ","); while (st.hasMoreTokens()) { if (keyName.equals(st.nextToken())) { found = true; break; } } if (!found) { if (mbeanServer.isRegistered(oName)) { AttributeList attrList = mbeanServer.getAttributes(oName, attrNames); Map<String, JMXDataSource> dsMap = nodeInfo.getDsMap(); for(Object attribute : attrList) { Attribute attrib=(Attribute)attribute; JMXDataSource ds = dsMap.get(objectName + "|" + attrib.getName()); JMXCollectionAttributeType attribType = new JMXCollectionAttributeType(ds, oName.getKeyProperty(beanInfo.getKeyField()), beanInfo.getKeyAlias(), attribGroupType); collectionResource.setAttributeValue(attribType, attrib.getValue().toString()); } } } } } catch (final InstanceNotFoundException e) { LogUtils.errorf(this, e, "Error retrieving attributes for %s", oName); } } } } break; } catch (final Exception e) { LogUtils.debugf(this, e, "%s Collector.collect: IOException while collecting address: %s", serviceName, agent.getAddress()); } } } catch (final Exception e) { LogUtils.errorf(this, e, "Error getting MBeanServer"); } finally { if (connection != null) { connection.close(); } } collectionSet.setStatus(ServiceCollector.COLLECTION_SUCCEEDED); return collectionSet; }  }
JMXCollector implements ServiceCollector { @Override public CollectionSet collect(CollectionAgent agent, EventProxy eproxy, Map<String, Object> map) { InetAddress ipaddr = agent.getAddress(); JMXNodeInfo nodeInfo = agent.getAttribute(NODE_INFO_KEY); Map<String, BeanInfo> mbeans = nodeInfo.getMBeans(); String collDir = serviceName; boolean useMbeanForRrds = ParameterMap.getKeyedBoolean(map, "use-mbean-name-for-rrds", false); String port = ParameterMap.getKeyedString(map, "port", null); String friendlyName = ParameterMap.getKeyedString(map,"friendly-name", port); if (useFriendlyName) { collDir = friendlyName; } JMXCollectionSet collectionSet=new JMXCollectionSet(agent,collDir); collectionSet.setCollectionTimestamp(new Date()); JMXCollectionResource collectionResource=collectionSet.getResource(); ConnectionWrapper connection = null; LogUtils.debugf(this, "collecting %s on node ID %d", InetAddressUtils.str(ipaddr), nodeInfo.getNodeId()); try { connection = getMBeanServerConnection(map, ipaddr); if (connection == null) { return collectionSet; } MBeanServerConnection mbeanServer = connection.getMBeanServer(); int retry = ParameterMap.getKeyedInteger(map, "retry", 3); for (int attempts = 0; attempts <= retry; attempts++) { try { for (Iterator<BeanInfo> iter = mbeans.values().iterator(); iter.hasNext();) { BeanInfo beanInfo = iter.next(); String mbeanName = beanInfo.getMbeanName(); String objectName = beanInfo.getObjectName(); String excludeList = beanInfo.getExcludes(); String obj = useMbeanForRrds ? mbeanName : objectName; AttributeGroupType attribGroupType=new AttributeGroupType(fixGroupName(obj),"all"); List<String> attribNames = beanInfo.getAttributeNames(); List<String> compAttribNames = beanInfo.getCompositeAttributeNames(); for (String compAttribName : compAttribNames) { if (attribNames.contains(compAttribName) ) { attribNames.remove(compAttribName); String[] ac = compAttribName.split("\\|", -1); String attrName = ac[0]; if (!attribNames.contains(attrName)) { attribNames.add(attrName); } } } String[] attrNames = attribNames.toArray(new String[attribNames.size()]); if (objectName.indexOf("*") == -1) { LogUtils.debugf(this, "%s Collector - getAttributes: %s, # attributes: %d, # composite attribute members: %d", serviceName, objectName, attrNames.length, compAttribNames.size()); try { ObjectName oName = new ObjectName(objectName); if (mbeanServer.isRegistered(oName)) { AttributeList attrList = mbeanServer.getAttributes(oName, attrNames); Map<String, JMXDataSource> dsMap = nodeInfo.getDsMap(); for(Object attribute : attrList) { List<String> compositeMemberKeys = new ArrayList<String>(); Boolean isComposite = false; Attribute attrib=(Attribute)attribute; for (String compAttrName : compAttribNames ) { String[] attribKeys = compAttrName.split("\\|", -1); if (attrib.getName().equals(attribKeys[0])) { compositeMemberKeys.add(attribKeys[1]); isComposite = true; } } if (isComposite) { try { CompositeData cd = (CompositeData)attrib.getValue(); for (String key : compositeMemberKeys) { JMXDataSource ds = dsMap.get(objectName + "|" + attrib.getName() + "|" + key); JMXCollectionAttributeType attribType=new JMXCollectionAttributeType(ds, null, null, attribGroupType); collectionResource.setAttributeValue(attribType, cd.get(key).toString()); } } catch (final ClassCastException cce) { LogUtils.debugf(this, cce, "%s Collection - getAttributes (try CompositeData) - ERROR: Failed to cast attribute value to type CompositeData!", serviceName); } } else { JMXDataSource ds = dsMap.get(objectName + "|" + attrib.getName()); JMXCollectionAttributeType attribType=new JMXCollectionAttributeType(ds, null, null, attribGroupType); collectionResource.setAttributeValue(attribType, attrib.getValue().toString()); } } } } catch (final InstanceNotFoundException e) { LogUtils.errorf(this, e, "Unable to retrieve attributes from %s", objectName); } } else { Set<ObjectName> mbeanSet = getObjectNames(mbeanServer, objectName); for (Iterator<ObjectName> objectNameIter = mbeanSet.iterator(); objectNameIter.hasNext(); ) { ObjectName oName = objectNameIter.next(); LogUtils.debugf(this, "%s Collector - getAttributesWC: %s, # attributes: %d, alias: %s", serviceName, oName, attrNames.length, beanInfo.getKeyAlias()); try { if (excludeList == null) { if (mbeanServer.isRegistered(oName)) { AttributeList attrList = mbeanServer.getAttributes(oName, attrNames); Map<String, JMXDataSource> dsMap = nodeInfo.getDsMap(); for(Object attribute : attrList) { Attribute attrib=(Attribute)attribute; JMXDataSource ds = dsMap.get(objectName + "|" + attrib.getName()); JMXCollectionAttributeType attribType= new JMXCollectionAttributeType(ds, oName.getKeyProperty(beanInfo.getKeyField()), beanInfo.getKeyAlias(), attribGroupType); collectionResource.setAttributeValue(attribType, attrib.getValue().toString()); } } } else { String keyName = oName.getKeyProperty(beanInfo.getKeyField()); boolean found = false; StringTokenizer st = new StringTokenizer( excludeList, ","); while (st.hasMoreTokens()) { if (keyName.equals(st.nextToken())) { found = true; break; } } if (!found) { if (mbeanServer.isRegistered(oName)) { AttributeList attrList = mbeanServer.getAttributes(oName, attrNames); Map<String, JMXDataSource> dsMap = nodeInfo.getDsMap(); for(Object attribute : attrList) { Attribute attrib=(Attribute)attribute; JMXDataSource ds = dsMap.get(objectName + "|" + attrib.getName()); JMXCollectionAttributeType attribType = new JMXCollectionAttributeType(ds, oName.getKeyProperty(beanInfo.getKeyField()), beanInfo.getKeyAlias(), attribGroupType); collectionResource.setAttributeValue(attribType, attrib.getValue().toString()); } } } } } catch (final InstanceNotFoundException e) { LogUtils.errorf(this, e, "Error retrieving attributes for %s", oName); } } } } break; } catch (final Exception e) { LogUtils.debugf(this, e, "%s Collector.collect: IOException while collecting address: %s", serviceName, agent.getAddress()); } } } catch (final Exception e) { LogUtils.errorf(this, e, "Error getting MBeanServer"); } finally { if (connection != null) { connection.close(); } } collectionSet.setStatus(ServiceCollector.COLLECTION_SUCCEEDED); return collectionSet; }  String serviceName(); void setServiceName(String name); @Override void initialize(Map<String, String> parameters); @Override void release(); @Override void initialize(CollectionAgent agent, Map<String, Object> parameters); @Override void release(CollectionAgent agent); abstract ConnectionWrapper getMBeanServerConnection(Map<String, Object> map, InetAddress address); @Override CollectionSet collect(CollectionAgent agent, EventProxy eproxy, Map<String, Object> map); String getRRDValue_isthis_used_(JMXDataSource ds,
            JMXCollectorEntry collectorEntry); void setUseFriendlyName(boolean useFriendlyName); @Override RrdRepository getRrdRepository(String collectionName); }
JMXCollector implements ServiceCollector { @Override public CollectionSet collect(CollectionAgent agent, EventProxy eproxy, Map<String, Object> map) { InetAddress ipaddr = agent.getAddress(); JMXNodeInfo nodeInfo = agent.getAttribute(NODE_INFO_KEY); Map<String, BeanInfo> mbeans = nodeInfo.getMBeans(); String collDir = serviceName; boolean useMbeanForRrds = ParameterMap.getKeyedBoolean(map, "use-mbean-name-for-rrds", false); String port = ParameterMap.getKeyedString(map, "port", null); String friendlyName = ParameterMap.getKeyedString(map,"friendly-name", port); if (useFriendlyName) { collDir = friendlyName; } JMXCollectionSet collectionSet=new JMXCollectionSet(agent,collDir); collectionSet.setCollectionTimestamp(new Date()); JMXCollectionResource collectionResource=collectionSet.getResource(); ConnectionWrapper connection = null; LogUtils.debugf(this, "collecting %s on node ID %d", InetAddressUtils.str(ipaddr), nodeInfo.getNodeId()); try { connection = getMBeanServerConnection(map, ipaddr); if (connection == null) { return collectionSet; } MBeanServerConnection mbeanServer = connection.getMBeanServer(); int retry = ParameterMap.getKeyedInteger(map, "retry", 3); for (int attempts = 0; attempts <= retry; attempts++) { try { for (Iterator<BeanInfo> iter = mbeans.values().iterator(); iter.hasNext();) { BeanInfo beanInfo = iter.next(); String mbeanName = beanInfo.getMbeanName(); String objectName = beanInfo.getObjectName(); String excludeList = beanInfo.getExcludes(); String obj = useMbeanForRrds ? mbeanName : objectName; AttributeGroupType attribGroupType=new AttributeGroupType(fixGroupName(obj),"all"); List<String> attribNames = beanInfo.getAttributeNames(); List<String> compAttribNames = beanInfo.getCompositeAttributeNames(); for (String compAttribName : compAttribNames) { if (attribNames.contains(compAttribName) ) { attribNames.remove(compAttribName); String[] ac = compAttribName.split("\\|", -1); String attrName = ac[0]; if (!attribNames.contains(attrName)) { attribNames.add(attrName); } } } String[] attrNames = attribNames.toArray(new String[attribNames.size()]); if (objectName.indexOf("*") == -1) { LogUtils.debugf(this, "%s Collector - getAttributes: %s, # attributes: %d, # composite attribute members: %d", serviceName, objectName, attrNames.length, compAttribNames.size()); try { ObjectName oName = new ObjectName(objectName); if (mbeanServer.isRegistered(oName)) { AttributeList attrList = mbeanServer.getAttributes(oName, attrNames); Map<String, JMXDataSource> dsMap = nodeInfo.getDsMap(); for(Object attribute : attrList) { List<String> compositeMemberKeys = new ArrayList<String>(); Boolean isComposite = false; Attribute attrib=(Attribute)attribute; for (String compAttrName : compAttribNames ) { String[] attribKeys = compAttrName.split("\\|", -1); if (attrib.getName().equals(attribKeys[0])) { compositeMemberKeys.add(attribKeys[1]); isComposite = true; } } if (isComposite) { try { CompositeData cd = (CompositeData)attrib.getValue(); for (String key : compositeMemberKeys) { JMXDataSource ds = dsMap.get(objectName + "|" + attrib.getName() + "|" + key); JMXCollectionAttributeType attribType=new JMXCollectionAttributeType(ds, null, null, attribGroupType); collectionResource.setAttributeValue(attribType, cd.get(key).toString()); } } catch (final ClassCastException cce) { LogUtils.debugf(this, cce, "%s Collection - getAttributes (try CompositeData) - ERROR: Failed to cast attribute value to type CompositeData!", serviceName); } } else { JMXDataSource ds = dsMap.get(objectName + "|" + attrib.getName()); JMXCollectionAttributeType attribType=new JMXCollectionAttributeType(ds, null, null, attribGroupType); collectionResource.setAttributeValue(attribType, attrib.getValue().toString()); } } } } catch (final InstanceNotFoundException e) { LogUtils.errorf(this, e, "Unable to retrieve attributes from %s", objectName); } } else { Set<ObjectName> mbeanSet = getObjectNames(mbeanServer, objectName); for (Iterator<ObjectName> objectNameIter = mbeanSet.iterator(); objectNameIter.hasNext(); ) { ObjectName oName = objectNameIter.next(); LogUtils.debugf(this, "%s Collector - getAttributesWC: %s, # attributes: %d, alias: %s", serviceName, oName, attrNames.length, beanInfo.getKeyAlias()); try { if (excludeList == null) { if (mbeanServer.isRegistered(oName)) { AttributeList attrList = mbeanServer.getAttributes(oName, attrNames); Map<String, JMXDataSource> dsMap = nodeInfo.getDsMap(); for(Object attribute : attrList) { Attribute attrib=(Attribute)attribute; JMXDataSource ds = dsMap.get(objectName + "|" + attrib.getName()); JMXCollectionAttributeType attribType= new JMXCollectionAttributeType(ds, oName.getKeyProperty(beanInfo.getKeyField()), beanInfo.getKeyAlias(), attribGroupType); collectionResource.setAttributeValue(attribType, attrib.getValue().toString()); } } } else { String keyName = oName.getKeyProperty(beanInfo.getKeyField()); boolean found = false; StringTokenizer st = new StringTokenizer( excludeList, ","); while (st.hasMoreTokens()) { if (keyName.equals(st.nextToken())) { found = true; break; } } if (!found) { if (mbeanServer.isRegistered(oName)) { AttributeList attrList = mbeanServer.getAttributes(oName, attrNames); Map<String, JMXDataSource> dsMap = nodeInfo.getDsMap(); for(Object attribute : attrList) { Attribute attrib=(Attribute)attribute; JMXDataSource ds = dsMap.get(objectName + "|" + attrib.getName()); JMXCollectionAttributeType attribType = new JMXCollectionAttributeType(ds, oName.getKeyProperty(beanInfo.getKeyField()), beanInfo.getKeyAlias(), attribGroupType); collectionResource.setAttributeValue(attribType, attrib.getValue().toString()); } } } } } catch (final InstanceNotFoundException e) { LogUtils.errorf(this, e, "Error retrieving attributes for %s", oName); } } } } break; } catch (final Exception e) { LogUtils.debugf(this, e, "%s Collector.collect: IOException while collecting address: %s", serviceName, agent.getAddress()); } } } catch (final Exception e) { LogUtils.errorf(this, e, "Error getting MBeanServer"); } finally { if (connection != null) { connection.close(); } } collectionSet.setStatus(ServiceCollector.COLLECTION_SUCCEEDED); return collectionSet; }  String serviceName(); void setServiceName(String name); @Override void initialize(Map<String, String> parameters); @Override void release(); @Override void initialize(CollectionAgent agent, Map<String, Object> parameters); @Override void release(CollectionAgent agent); abstract ConnectionWrapper getMBeanServerConnection(Map<String, Object> map, InetAddress address); @Override CollectionSet collect(CollectionAgent agent, EventProxy eproxy, Map<String, Object> map); String getRRDValue_isthis_used_(JMXDataSource ds,
            JMXCollectorEntry collectorEntry); void setUseFriendlyName(boolean useFriendlyName); @Override RrdRepository getRrdRepository(String collectionName);  }