/** Check if CompositeAttributes will be collected */ @Test public void collectJvmDefaultComposites() { String mBeansObjectName = "java.lang:type=GarbageCollector,name=PS MarkSweep"; Map<String, BeanInfo> mBeans = new HashMap<String, BeanInfo>(); BeanInfo beanInfo = new BeanInfo(); beanInfo.setObjectName(mBeansObjectName); List<String> attributes = new ArrayList<String>(); attributes.add("CollectionCount"); attributes.add("LastGcInfo"); beanInfo.setAttributes(attributes); List<String> compositeAttributes = new ArrayList<String>(); compositeAttributes.add("LastGcInfo"); beanInfo.setCompositeAttributes(compositeAttributes); mBeans.put("first", beanInfo); jmxNodeInfo.setMBeans(mBeans); Map<String, JMXDataSource> dataSourceMap = new HashMap<String, JMXDataSource>(); dataSourceMap.put(mBeansObjectName + "|CollectionCount", new JMXDataSource()); // ToDo Tak set the JmxDataSource type to composite? dataSourceMap.put(mBeansObjectName + "|LastGcInfo", new JMXDataSource()); jmxNodeInfo.setDsMap(dataSourceMap); CollectionSet collectionSet = jmxCollector.collect(collectionAgent, null, null); assertEquals( "Collection of one Jvm default value run successfully", 1, collectionSet.getStatus()); }
/** * {@inheritDoc} * * <p>Responsible for performing all necessary initialization for the specified interface in * preparation for data collection. */ @Override public void initialize(CollectionAgent agent, Map<String, Object> parameters) { InetAddress ipAddr = agent.getAddress(); int nodeID = agent.getNodeId(); // Retrieve the name of the JMX data collector String collectionName = ParameterMap.getKeyedString(parameters, "collection", serviceName); final String hostAddress = InetAddressUtils.str(ipAddr); LogUtils.debugf( this, "initialize: InetAddress=%s, collectionName=%s", hostAddress, collectionName); JMXNodeInfo nodeInfo = new JMXNodeInfo(nodeID); LogUtils.debugf(this, "nodeInfo: %s %d %s", hostAddress, nodeID, agent); /* * Retrieve list of MBean objects to be collected from the * remote agent which are to be stored in the node-level RRD file. * These objects pertain to the node itself not any individual * interfaces. */ Map<String, List<Attrib>> attrMap = JMXDataCollectionConfigFactory.getInstance() .getAttributeMap(collectionName, serviceName, hostAddress); nodeInfo.setAttributeMap(attrMap); Map<String, JMXDataSource> dsList = buildDataSourceList(collectionName, attrMap); nodeInfo.setDsMap(dsList); nodeInfo.setMBeans(JMXDataCollectionConfigFactory.getInstance().getMBeanInfo(collectionName)); // Add the JMXNodeInfo object as an attribute of the interface agent.setAttribute(NODE_INFO_KEY, nodeInfo); agent.setAttribute("collectionName", collectionName); }
@Test public void collectSingleMbeanWithOneCompAttribWithOneIgnoredCompMembers() { String collectionName = "collectSingleMbeanWithOneCompAttribWithOneIgnoredCompMembers"; jmxNodeInfo.setMBeans(jmxConfigFactory.getMBeanInfo(collectionName)); jmxNodeInfo.setDsMap( generateDataSourceMap(jmxConfigFactory.getAttributeMap(collectionName, "", ""))); // start collection 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(3, group.getAttributes().size()); printDebugAttributeGroup(group); assertEquals( "Collection: " + collectionName + " run successfully", 1, collectionSet.getStatus()); }
@Test public void collectSingleMbeanWithSingleAttribute() { String collectionName = "collectSingleMbeanWithSingleAttribute"; jmxNodeInfo.setMBeans(jmxConfigFactory.getMBeanInfo(collectionName)); jmxNodeInfo.setDsMap( generateDataSourceMap(jmxConfigFactory.getAttributeMap(collectionName, "", ""))); // start collection CollectionSet collectionSet = jmxCollector.collect(collectionAgent, null, null); JMXCollectionSet jmxCollectionSet = (JMXCollectionSet) collectionSet; JMXCollectionResource jmxCollectionResource = jmxCollectionSet.getResource(); AttributeGroup group = jmxCollectionResource.getGroup(new AttributeGroupType("java_lang_type_Compilation", "all")); assertEquals(1, group.getAttributes().size()); printDebugAttributeGroup(group); // ToDo Tak how to check if all metrics where collected? assertEquals( "Collection: " + collectionName + " run successfully", 1, collectionSet.getStatus()); }
/** This test is just a prove of concept. */ @Test public void collectTwoBasicValues() { String mBeansObjectName = "org.opennms.netmgt.collectd.jmxhelper:type=JmxTest"; Map<String, BeanInfo> mBeans = new HashMap<String, BeanInfo>(); BeanInfo beanInfo = new BeanInfo(); beanInfo.setObjectName(mBeansObjectName); List<String> attributes = new ArrayList<String>(); attributes.add("X"); attributes.add("Name"); // TODO Tak: Test attributes that will return null is the next step // attributes.add("NullString"); beanInfo.setAttributes(attributes); mBeans.put("first", beanInfo); jmxNodeInfo.setMBeans(mBeans); Map<String, JMXDataSource> dataSourceMap = new HashMap<String, JMXDataSource>(); dataSourceMap.put(mBeansObjectName + "|X", new JMXDataSource()); dataSourceMap.put(mBeansObjectName + "|Name", new JMXDataSource()); // dataSourceMap.put("org.opennms.netmgt.collectd.jmxhelper:type=JmxTest|NullString", new // JMXDataSource()); jmxNodeInfo.setDsMap(dataSourceMap); CollectionSet collectionSet = jmxCollector.collect(collectionAgent, null, null); assertEquals("Collection of two dummy values run successfully", 1, collectionSet.getStatus()); }