Search in sources :

Example 1 with ServiceParameters

use of org.opennms.netmgt.collection.api.ServiceParameters in project opennms by OpenNMS.

the class StressCommand method doExecute.

@Override
protected Void doExecute() {
    // Apply sane lower bounds to all of the configurable options
    intervalInSeconds = Math.max(1, intervalInSeconds);
    numberOfNodes = Math.max(1, numberOfNodes);
    numberOfInterfacesPerNode = Math.max(1, numberOfInterfacesPerNode);
    numberOfGroupsPerInterface = Math.max(1, numberOfGroupsPerInterface);
    numberOfNumericAttributesPerGroup = Math.max(0, numberOfNumericAttributesPerGroup);
    numberOfStringAttributesPerGroup = Math.max(0, numberOfStringAttributesPerGroup);
    reportIntervalInSeconds = Math.max(1, reportIntervalInSeconds);
    numberOfGeneratorThreads = Math.max(1, numberOfGeneratorThreads);
    stringVariationFactor = Math.max(0, stringVariationFactor);
    if (stringVariationFactor > 0) {
        stringAttributesVaried = metrics.meter("string-attributes-varied");
    }
    // Display the effective settings and rates
    double attributesPerSecond = (1 / (double) intervalInSeconds) * numberOfGroupsPerInterface * numberOfInterfacesPerNode * numberOfNodes;
    System.out.printf("Generating collection sets every %d seconds\n", intervalInSeconds);
    System.out.printf("\t for %d nodes\n", numberOfNodes);
    System.out.printf("\t with %d interfaces\n", numberOfInterfacesPerNode);
    System.out.printf("\t with %d attribute groups\n", numberOfGroupsPerInterface);
    System.out.printf("\t with %d numeric attributes\n", numberOfNumericAttributesPerGroup);
    System.out.printf("\t with %d string attributes\n", numberOfStringAttributesPerGroup);
    System.out.printf("Across %d threads\n", numberOfGeneratorThreads);
    if (stringVariationFactor > 0) {
        System.out.printf("With string variation factor %d\n", stringVariationFactor);
    }
    System.out.printf("Which will yield an effective\n");
    System.out.printf("\t %.2f numeric attributes per second\n", numberOfNumericAttributesPerGroup * attributesPerSecond);
    System.out.printf("\t %.2f string attributes per second\n", numberOfStringAttributesPerGroup * attributesPerSecond);
    ConsoleReporter reporter = ConsoleReporter.forRegistry(metrics).convertRatesTo(TimeUnit.SECONDS).convertDurationsTo(TimeUnit.MILLISECONDS).build();
    // Setup the executor
    ThreadFactory threadFactoy = new ThreadFactoryBuilder().setNameFormat("Metrics Stress Tool Generator #%d").build();
    ExecutorService executor = Executors.newFixedThreadPool(numberOfGeneratorThreads, threadFactoy);
    // Setup auxiliary objects needed by the persister
    ServiceParameters params = new ServiceParameters(Collections.emptyMap());
    RrdRepository repository = new RrdRepository();
    repository.setStep(Math.max(intervalInSeconds, 1));
    repository.setHeartBeat(repository.getStep() * 2);
    if (rras != null && rras.size() > 0) {
        repository.setRraList(rras);
    } else {
        repository.setRraList(Lists.newArrayList(// Use the default list of RRAs we provide in our stock configuration files
        "RRA:AVERAGE:0.5:1:2016", "RRA:AVERAGE:0.5:12:1488", "RRA:AVERAGE:0.5:288:366", "RRA:MAX:0.5:288:366", "RRA:MIN:0.5:288:366"));
    }
    repository.setRrdBaseDir(Paths.get(System.getProperty("opennms.home"), "share", "rrd", "snmp").toFile());
    // Calculate how we fast we should insert the collection sets
    int sleepTimeInMillisBetweenNodes = 0;
    int sleepTimeInSecondsBetweenIterations = 0;
    System.out.printf("Sleeping for\n");
    if (burst) {
        sleepTimeInSecondsBetweenIterations = intervalInSeconds;
        System.out.printf("\t %d seconds between batches\n", sleepTimeInSecondsBetweenIterations);
    } else {
        // We want to "stream" the collection sets
        sleepTimeInMillisBetweenNodes = Math.round((((float) intervalInSeconds * 1000) / numberOfNodes) * numberOfGeneratorThreads);
        System.out.printf("\t %d milliseconds between nodes\n", sleepTimeInMillisBetweenNodes);
    }
    // Start generating, and keep generating until we're interrupted
    try {
        reporter.start(reportIntervalInSeconds, TimeUnit.SECONDS);
        while (true) {
            final Context context = batchTimer.time();
            try {
                // Split the tasks up among the threads
                List<Future<Void>> futures = new ArrayList<>();
                for (int generatorThreadId = 0; generatorThreadId < numberOfGeneratorThreads; generatorThreadId++) {
                    futures.add(executor.submit(generateAndPersistCollectionSets(params, repository, generatorThreadId, sleepTimeInMillisBetweenNodes)));
                }
                // Wait for all the tasks to complete before starting others
                for (Future<Void> future : futures) {
                    future.get();
                }
            } catch (InterruptedException | ExecutionException e) {
                break;
            } finally {
                context.stop();
            }
            try {
                Thread.sleep(sleepTimeInSecondsBetweenIterations * 1000);
            } catch (InterruptedException e) {
                break;
            }
        }
    } finally {
        reporter.stop();
        abort.set(true);
        executor.shutdownNow();
    }
    return null;
}
Also used : Context(com.codahale.metrics.Timer.Context) ThreadFactory(java.util.concurrent.ThreadFactory) ConsoleReporter(com.codahale.metrics.ConsoleReporter) ArrayList(java.util.ArrayList) RrdRepository(org.opennms.netmgt.rrd.RrdRepository) ExecutorService(java.util.concurrent.ExecutorService) ThreadFactoryBuilder(com.google.common.util.concurrent.ThreadFactoryBuilder) Future(java.util.concurrent.Future) ServiceParameters(org.opennms.netmgt.collection.api.ServiceParameters) ExecutionException(java.util.concurrent.ExecutionException)

Example 2 with ServiceParameters

use of org.opennms.netmgt.collection.api.ServiceParameters in project opennms by OpenNMS.

the class CollectionResourceWrapperIT method testNumericFields.

@Test
public void testNumericFields() throws Exception {
    SnmpCollectionAgent agent = createCollectionAgent();
    MockDataCollectionConfig dataCollectionConfig = new MockDataCollectionConfig();
    OnmsSnmpCollection collection = new OnmsSnmpCollection(agent, new ServiceParameters(new HashMap<String, Object>()), dataCollectionConfig, m_locationAwareSnmpClient);
    ResourceType rt = new ResourceType();
    rt.setName("dskIndex");
    rt.setLabel("Disk Table Index (UCD-SNMP MIB)");
    StorageStrategy strategy = new StorageStrategy();
    strategy.setClazz("org.opennms.netmgt.dao.support.SiblingColumnStorageStrategy");
    strategy.addParameter(new Parameter("sibling-column-name", "ns-dskPath"));
    strategy.addParameter(new Parameter("replace-first", "s/^-$/_root_fs/"));
    strategy.addParameter(new Parameter("replace-all", "s/^-//"));
    strategy.addParameter(new Parameter("replace-all", "s/\\s//"));
    strategy.addParameter(new Parameter("replace-all", "s/:\\\\.*//"));
    rt.setStorageStrategy(strategy);
    PersistenceSelectorStrategy pstrategy = new PersistenceSelectorStrategy();
    pstrategy.setClazz("org.opennms.netmgt.collection.support.PersistAllSelectorStrategy");
    rt.setPersistenceSelectorStrategy(pstrategy);
    GenericIndexResourceType resourceType = new GenericIndexResourceType(agent, collection, rt);
    SnmpCollectionResource resource = new GenericIndexResource(resourceType, resourceType.getName(), new SnmpInstId(100));
    SnmpAttribute total = addAttributeToCollectionResource(resource, "ns-dskTotal", AttributeType.GAUGE, "dskIndex", "10000");
    SnmpAttribute used = addAttributeToCollectionResource(resource, "ns-dskUsed", AttributeType.GAUGE, "dskIndex", "5000");
    SnmpAttribute label = addAttributeToCollectionResource(resource, "ns-dskPath", AttributeType.STRING, "dskIndex", "/opt");
    Map<String, CollectionAttribute> attributes = new HashMap<String, CollectionAttribute>();
    attributes.put(used.getName(), used);
    attributes.put(total.getName(), total);
    attributes.put(label.getName(), label);
    CollectionResourceWrapper wrapper = createWrapper(resource, attributes);
    Assert.assertEquals("opt", wrapper.getInstanceLabel());
    Assert.assertEquals(new Double("10000.0"), wrapper.getAttributeValue(total.getName()));
    Assert.assertEquals("10000.0", wrapper.getFieldValue(total.getName()));
}
Also used : StorageStrategy(org.opennms.netmgt.config.datacollection.StorageStrategy) SnmpCollectionAgent(org.opennms.netmgt.collectd.SnmpCollectionAgent) HashMap(java.util.HashMap) ResourceType(org.opennms.netmgt.config.datacollection.ResourceType) GenericIndexResourceType(org.opennms.netmgt.collectd.GenericIndexResourceType) NodeResourceType(org.opennms.netmgt.collectd.NodeResourceType) IfResourceType(org.opennms.netmgt.collectd.IfResourceType) MockDataCollectionConfig(org.opennms.netmgt.mock.MockDataCollectionConfig) GenericIndexResource(org.opennms.netmgt.collectd.GenericIndexResource) GenericIndexResourceType(org.opennms.netmgt.collectd.GenericIndexResourceType) CollectionAttribute(org.opennms.netmgt.collection.api.CollectionAttribute) SnmpAttribute(org.opennms.netmgt.collectd.SnmpAttribute) SnmpInstId(org.opennms.netmgt.snmp.SnmpInstId) Parameter(org.opennms.netmgt.config.datacollection.Parameter) ServiceParameters(org.opennms.netmgt.collection.api.ServiceParameters) SnmpCollectionResource(org.opennms.netmgt.collectd.SnmpCollectionResource) OnmsSnmpCollection(org.opennms.netmgt.collectd.OnmsSnmpCollection) PersistenceSelectorStrategy(org.opennms.netmgt.config.datacollection.PersistenceSelectorStrategy) Test(org.junit.Test)

Example 3 with ServiceParameters

use of org.opennms.netmgt.collection.api.ServiceParameters in project opennms by OpenNMS.

the class AbstractVTDXmlCollectorTest method executeCollectorTest.

/**
     * 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);
    CollectionSet collectionSet = XmlCollectorTestUtils.doCollect(collector, m_collectionAgent, parameters);
    Assert.assertEquals(CollectionStatus.SUCCEEDED, collectionSet.getStatus());
    ServiceParameters serviceParams = new ServiceParameters(new HashMap<String, Object>());
    CollectionSetVisitor persister = m_persisterFactory.createGroupPersister(serviceParams, createRrdRepository((String) parameters.get("collection")), false, false);
    collectionSet.visit(persister);
    Assert.assertEquals(expectedFiles, FileUtils.listFiles(getSnmpRoot(), new String[] { "jrb" }, true).size());
}
Also used : XmlCollector(org.opennms.protocols.xml.collector.XmlCollector) CollectionSetVisitor(org.opennms.netmgt.collection.api.CollectionSetVisitor) ServiceParameters(org.opennms.netmgt.collection.api.ServiceParameters) CollectionSet(org.opennms.netmgt.collection.api.CollectionSet)

Example 4 with ServiceParameters

use of org.opennms.netmgt.collection.api.ServiceParameters in project opennms by OpenNMS.

the class NMS7963IT method testHttpCollection.

/**
     * Test HTTP Data Collection with XPath
     *
     * @throws Exception the exception
     */
@Test
@JUnitHttpServer(port = 10342, https = false, webapps = { @Webapp(context = "/junit", path = "src/test/resources/test-webapp") })
public void testHttpCollection() throws Exception {
    File configFile = new File("src/test/resources/http-datacollection-config.xml");
    XmlDataCollectionConfig config = JaxbUtils.unmarshal(XmlDataCollectionConfig.class, configFile);
    XmlDataCollection collection = config.getDataCollectionByName("NMS-7963");
    RrdRepository repository = createRrdRepository(collection.getXmlRrd());
    Map<String, Object> parameters = new HashMap<String, Object>();
    parameters.put("collection", "NMS-7963");
    DefaultXmlCollectionHandler collector = new DefaultXmlCollectionHandler();
    collector.setRrdRepository(repository);
    collector.setServiceName("HTTP");
    CollectionSet collectionSet = XmlCollectorTestUtils.doCollect(m_nodeDao, collector, m_collectionAgent, collection, parameters);
    Assert.assertEquals(CollectionStatus.SUCCEEDED, collectionSet.getStatus());
    ServiceParameters serviceParams = new ServiceParameters(new HashMap<String, Object>());
    CollectionSetVisitor persister = m_persisterFactory.createGroupPersister(serviceParams, repository, false, false);
    collectionSet.visit(persister);
    RrdDb jrb = new RrdDb(new File(getSnmpRoot(), "1/xml-retrv-wipo-data.jrb"));
    Assert.assertNotNull(jrb);
    Assert.assertEquals(1, jrb.getDsCount());
    Datasource ds = jrb.getDatasource("xml-wipo-paco");
    Assert.assertNotNull(ds);
    Assert.assertEquals(new Double(903), Double.valueOf(ds.getLastValue()));
}
Also used : Datasource(org.jrobin.core.Datasource) XmlDataCollectionConfig(org.opennms.protocols.xml.config.XmlDataCollectionConfig) HashMap(java.util.HashMap) CollectionSetVisitor(org.opennms.netmgt.collection.api.CollectionSetVisitor) RrdRepository(org.opennms.netmgt.rrd.RrdRepository) CollectionSet(org.opennms.netmgt.collection.api.CollectionSet) XmlDataCollection(org.opennms.protocols.xml.config.XmlDataCollection) RrdDb(org.jrobin.core.RrdDb) ServiceParameters(org.opennms.netmgt.collection.api.ServiceParameters) File(java.io.File) Test(org.junit.Test) JUnitHttpServer(org.opennms.core.test.http.annotations.JUnitHttpServer)

Example 5 with ServiceParameters

use of org.opennms.netmgt.collection.api.ServiceParameters in project opennms by OpenNMS.

the class NodeLevelDataOnMultipleNodesTest method executeCollectorTest.

/**
     * Executes collector test.
     *
     * @param nodeId the node id
     * @param ipAddress the IP address
     * @param xmlSampleFileName the XML sample file name
     * @param parameters the parameters
     * @param expectedFiles the expected amount of JRB files
     * @throws Exception the exception
     */
public void executeCollectorTest(int nodeId, String ipAddress, String xmlSampleFileName, Map<String, Object> parameters, int expectedFiles) throws Exception {
    MockDocumentBuilder.setXmlFileName(xmlSampleFileName);
    CollectionAgent collectionAgent = new MockCollectionAgent(nodeId, "mynode", InetAddrUtils.addr(ipAddress));
    CollectionSet collectionSet = XmlCollectorTestUtils.doCollect(m_collector, collectionAgent, parameters);
    Assert.assertEquals(CollectionStatus.SUCCEEDED, collectionSet.getStatus());
    ServiceParameters serviceParams = new ServiceParameters(new HashMap<String, Object>());
    CollectionSetVisitor persister = m_persisterFactory.createGroupPersister(serviceParams, createRrdRepository((String) parameters.get("collection")), false, false);
    collectionSet.visit(persister);
    Assert.assertEquals(expectedFiles, FileUtils.listFiles(new File(getSnmpRoot(), Integer.toString(nodeId)), new String[] { getRrdExtension() }, true).size());
}
Also used : CollectionSetVisitor(org.opennms.netmgt.collection.api.CollectionSetVisitor) MockCollectionAgent(org.opennms.core.collection.test.MockCollectionAgent) ServiceParameters(org.opennms.netmgt.collection.api.ServiceParameters) CollectionAgent(org.opennms.netmgt.collection.api.CollectionAgent) MockCollectionAgent(org.opennms.core.collection.test.MockCollectionAgent) File(java.io.File) CollectionSet(org.opennms.netmgt.collection.api.CollectionSet)

Aggregations

ServiceParameters (org.opennms.netmgt.collection.api.ServiceParameters)42 HashMap (java.util.HashMap)27 Test (org.junit.Test)18 RrdRepository (org.opennms.netmgt.rrd.RrdRepository)17 CollectionSetVisitor (org.opennms.netmgt.collection.api.CollectionSetVisitor)14 MockDataCollectionConfig (org.opennms.netmgt.mock.MockDataCollectionConfig)14 File (java.io.File)10 CollectionSet (org.opennms.netmgt.collection.api.CollectionSet)10 OnmsSnmpCollection (org.opennms.netmgt.collectd.OnmsSnmpCollection)9 MibObject (org.opennms.netmgt.config.datacollection.MibObject)9 AttributeGroupType (org.opennms.netmgt.collection.api.AttributeGroupType)7 SnmpInstId (org.opennms.netmgt.snmp.SnmpInstId)7 RrdDb (org.jrobin.core.RrdDb)6 NodeResourceType (org.opennms.netmgt.collectd.NodeResourceType)6 CollectionResource (org.opennms.netmgt.collection.api.CollectionResource)6 Datasource (org.jrobin.core.Datasource)5 SnmpCollectionAgent (org.opennms.netmgt.collectd.SnmpCollectionAgent)5 SnmpCollectionResource (org.opennms.netmgt.collectd.SnmpCollectionResource)5 CollectionAttribute (org.opennms.netmgt.collection.api.CollectionAttribute)5 JUnitHttpServer (org.opennms.core.test.http.annotations.JUnitHttpServer)4