Пример #1
0
  /** 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());
  }
Пример #2
0
 @Test
 public void testCollector() throws Exception {
   Map<String, Object> parameters = new HashMap<String, Object>();
   parameters.put("port", getServer().getLocalPort());
   NSClientCollector collector = getCollector(parameters);
   CollectionSet collectionSet = collector.collect(m_collectionAgent, m_eventProxy, parameters);
   Assert.assertEquals(ServiceCollector.COLLECTION_SUCCEEDED, collectionSet.getStatus());
   CountResourcesVisitor visitor = new CountResourcesVisitor();
   collectionSet.visit(visitor);
   Assert.assertEquals(42, visitor.getCount());
 }
Пример #3
0
  @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());
  }
Пример #4
0
  @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());
  }
  /**
   * Executes collector test.
   *
   * @param parameters the parameters
   * @param expectedFiles the expected amount of JRB files
   * @throws Exception the exception
   */
  public void executeCollectorTest(Map<String, Object> parameters, int expectedFiles)
      throws Exception {
    XmlCollector collector = new XmlCollector();
    collector.setXmlCollectionDao(m_xmlCollectionDao);
    collector.initialize(m_collectionAgent, parameters);
    CollectionSet collectionSet = collector.collect(m_collectionAgent, m_eventProxy, parameters);
    collector.release(m_collectionAgent);
    Assert.assertEquals(ServiceCollector.COLLECTION_SUCCEEDED, collectionSet.getStatus());

    ServiceParameters serviceParams = new ServiceParameters(new HashMap<String, Object>());
    BasePersister persister =
        new GroupPersister(
            serviceParams,
            createRrdRepository((String) parameters.get("collection"))); // storeByGroup=true;
    collectionSet.visit(persister);

    Assert.assertEquals(
        expectedFiles,
        FileUtils.listFiles(new File(TEST_SNMP_DIRECTORY), new String[] {"jrb"}, true).size());
  }
Пример #6
0
 /** 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());
 }