use of org.opennms.netmgt.collection.api.CollectionSet in project opennms by OpenNMS.
the class CollectableServiceTest method canWrapResourcesWithTimekeeper.
/**
* Validates that we can successfully wrap collection sets with a custom time-keeper,
* allowing us to override the timestamp of the attributes within the collection set.
*/
@Test
public void canWrapResourcesWithTimekeeper() throws CollectionInitializationException, CollectionException, IOException, RrdException {
System.setProperty(CollectableService.USE_COLLECTION_START_TIME_SYS_PROP, Boolean.TRUE.toString());
createCollectableService();
long collectionDelayInSecs = 2;
when(spec.collect(any())).then(new Answer<CollectionSet>() {
@Override
public CollectionSet answer(InvocationOnMock invocation) throws InterruptedException {
Thread.sleep(collectionDelayInSecs * 1000);
CollectionAgent agent = (CollectionAgent) invocation.getArguments()[0];
NodeLevelResource nodeResource = new NodeLevelResource(agent.getNodeId());
return new CollectionSetBuilder(agent).withNumericAttribute(nodeResource, "mibGroup", "myCounter", 1000, AttributeType.COUNTER).build();
}
});
File nodeDir = fileAnticipator.expecting(getSnmpRrdDirectory(), "1");
File jrbFile = fileAnticipator.expecting(nodeDir, "myCounter" + rrdStrategy.getDefaultFileExtension());
fileAnticipator.expecting(nodeDir, "myCounter" + ".meta");
long beforeInMs = System.currentTimeMillis();
service.run();
long afterInMs = System.currentTimeMillis();
// Quick sanity check
assertTrue(String.format("Delay was not succesfully applied (delay was %d).", beforeInMs - afterInMs), afterInMs - beforeInMs >= collectionDelayInSecs * 1000);
// Verify the last update time match the start of the collection time
RrdDb rrdDb = new RrdDb(jrbFile);
long lastUpdateTimeInSecs = rrdDb.getLastUpdateTime();
long beforeInSecs = Math.floorDiv(beforeInMs, 1000);
long afterInSecs = Math.floorDiv(afterInMs, 1000) + 1;
assertTrue("Last update was before the collector was invoked!", lastUpdateTimeInSecs >= beforeInSecs);
assertTrue("Last update was too long after the collector was invoked!", lastUpdateTimeInSecs < (afterInSecs - (collectionDelayInSecs / 2d)));
}
use of org.opennms.netmgt.collection.api.CollectionSet in project opennms by OpenNMS.
the class HttpCollectorIT method testCollect.
/**
* Test method for {@link org.opennms.netmgt.collectd.HttpCollector#collect(
* org.opennms.netmgt.collection.api.CollectionAgent, org.opennms.netmgt.model.events.EventProxy, Map)}.
*/
@Test
@JUnitHttpServer(port = 10342, vhosts = { "127.0.0.1" })
@JUnitCollector(datacollectionConfig = "/org/opennms/netmgt/config/http-datacollection-config.xml", datacollectionType = "http", anticipateRrds = { "1/documentCount", "1/greatAnswer", "1/someNumber" }, anticipateFiles = { "1/strings.properties" })
public final void testCollect() throws Exception {
CollectionSet collectionSet = m_collectionSpecification.collect(m_collectionAgent);
assertEquals("collection status", CollectionStatus.SUCCEEDED, collectionSet.getStatus());
CollectorTestUtils.persistCollectionSet(m_rrdStrategy, m_resourceStorageDao, m_collectionSpecification, collectionSet);
}
use of org.opennms.netmgt.collection.api.CollectionSet in project opennms by OpenNMS.
the class SnmpCollectorIT method testBrocadeCollect.
@Test
@Transactional
@JUnitCollector(datacollectionConfig = "/org/opennms/netmgt/config/datacollection-brocade-config.xml", datacollectionType = "snmp", anticipateRrds = { "1/brocadeFCPortIndex/1/swFCPortTxWords", "1/brocadeFCPortIndex/1/swFCPortRxWords", "1/brocadeFCPortIndex/2/swFCPortTxWords", "1/brocadeFCPortIndex/2/swFCPortRxWords", "1/brocadeFCPortIndex/3/swFCPortTxWords", "1/brocadeFCPortIndex/3/swFCPortRxWords", "1/brocadeFCPortIndex/4/swFCPortTxWords", "1/brocadeFCPortIndex/4/swFCPortRxWords", "1/brocadeFCPortIndex/5/swFCPortTxWords", "1/brocadeFCPortIndex/5/swFCPortRxWords", "1/brocadeFCPortIndex/6/swFCPortTxWords", "1/brocadeFCPortIndex/6/swFCPortRxWords", "1/brocadeFCPortIndex/7/swFCPortTxWords", "1/brocadeFCPortIndex/7/swFCPortRxWords", "1/brocadeFCPortIndex/8/swFCPortTxWords", "1/brocadeFCPortIndex/8/swFCPortRxWords" }, anticipateFiles = { "1", "1/brocadeFCPortIndex", "1/brocadeFCPortIndex/1/strings.properties", "1/brocadeFCPortIndex/1", "1/brocadeFCPortIndex/2/strings.properties", "1/brocadeFCPortIndex/2", "1/brocadeFCPortIndex/3/strings.properties", "1/brocadeFCPortIndex/3", "1/brocadeFCPortIndex/4/strings.properties", "1/brocadeFCPortIndex/4", "1/brocadeFCPortIndex/5/strings.properties", "1/brocadeFCPortIndex/5", "1/brocadeFCPortIndex/6/strings.properties", "1/brocadeFCPortIndex/6", "1/brocadeFCPortIndex/7/strings.properties", "1/brocadeFCPortIndex/7", "1/brocadeFCPortIndex/8/strings.properties", "1/brocadeFCPortIndex/8" })
@JUnitSnmpAgent(resource = "/org/opennms/netmgt/snmp/brocadeTestData1.properties")
public void testBrocadeCollect() throws Exception {
// now do the actual collection
CollectionSet collectionSet = m_collectionSpecification.collect(m_collectionAgent);
assertEquals("collection status", CollectionStatus.SUCCEEDED, collectionSet.getStatus());
CollectorTestUtils.persistCollectionSet(m_rrdStrategy, m_resourceStorageDao, m_collectionSpecification, collectionSet);
System.err.println("FIRST COLLECTION FINISHED");
// need a one second time elapse to update the RRD
Thread.sleep(1000);
// try collecting again
assertEquals("collection status", CollectionStatus.SUCCEEDED, m_collectionSpecification.collect(m_collectionAgent).getStatus());
System.err.println("SECOND COLLECTION FINISHED");
}
use of org.opennms.netmgt.collection.api.CollectionSet in project opennms by OpenNMS.
the class SnmpCollectorIT method testCollect.
@Test
@JUnitCollector(datacollectionConfig = "/org/opennms/netmgt/config/datacollection-config.xml", datacollectionType = "snmp", anticipateFiles = { "1", "1/fw0" }, anticipateRrds = { "1/tcpActiveOpens", "1/tcpAttemptFails", "1/tcpPassiveOpens", "1/tcpRetransSegs", "1/tcpCurrEstab", "1/tcpEstabResets", "1/tcpInErrors", "1/tcpInSegs", "1/tcpOutRsts", "1/tcpOutSegs", "1/fw0/ifInDiscards", "1/fw0/ifInErrors", "1/fw0/ifInNUcastpkts", "1/fw0/ifInOctets", "1/fw0/ifInUcastpkts", "1/fw0/ifOutErrors", "1/fw0/ifOutNUcastPkts", "1/fw0/ifOutOctets", "1/fw0/ifOutUcastPkts" })
@JUnitSnmpAgent(resource = "/org/opennms/netmgt/snmp/snmpTestData1.properties")
public void testCollect() throws Exception {
System.setProperty("org.opennms.netmgt.collectd.SnmpCollector.limitCollectionToInstances", "true");
// now do the actual collection
CollectionSet collectionSet = m_collectionSpecification.collect(m_collectionAgent);
assertEquals("collection status", CollectionStatus.SUCCEEDED, collectionSet.getStatus());
CollectorTestUtils.persistCollectionSet(m_rrdStrategy, m_resourceStorageDao, m_collectionSpecification, collectionSet);
System.err.println("FIRST COLLECTION FINISHED");
// need a one second time elapse to update the RRD
Thread.sleep(1000);
// try collecting again
assertEquals("collection status", CollectionStatus.SUCCEEDED, m_collectionSpecification.collect(m_collectionAgent).getStatus());
System.err.println("SECOND COLLECTION FINISHED");
}
use of org.opennms.netmgt.collection.api.CollectionSet in project opennms by OpenNMS.
the class SnmpCollectorIT method testBug2447_GenericIndexedOnlyCollect.
@Test
@Transactional
@JUnitCollector(datacollectionConfig = "/org/opennms/netmgt/config/datacollection-brocade-no-ifaces-config.xml", datacollectionType = "snmp", anticipateRrds = { "1/brocadeFCPortIndex/1/swFCPortTxWords", "1/brocadeFCPortIndex/1/swFCPortRxWords", "1/brocadeFCPortIndex/2/swFCPortTxWords", "1/brocadeFCPortIndex/2/swFCPortRxWords", "1/brocadeFCPortIndex/3/swFCPortTxWords", "1/brocadeFCPortIndex/3/swFCPortRxWords", "1/brocadeFCPortIndex/4/swFCPortTxWords", "1/brocadeFCPortIndex/4/swFCPortRxWords", "1/brocadeFCPortIndex/5/swFCPortTxWords", "1/brocadeFCPortIndex/5/swFCPortRxWords", "1/brocadeFCPortIndex/6/swFCPortTxWords", "1/brocadeFCPortIndex/6/swFCPortRxWords", "1/brocadeFCPortIndex/7/swFCPortTxWords", "1/brocadeFCPortIndex/7/swFCPortRxWords", "1/brocadeFCPortIndex/8/swFCPortTxWords", "1/brocadeFCPortIndex/8/swFCPortRxWords" }, anticipateFiles = { "1", "1/brocadeFCPortIndex", "1/brocadeFCPortIndex/1/strings.properties", "1/brocadeFCPortIndex/1", "1/brocadeFCPortIndex/2/strings.properties", "1/brocadeFCPortIndex/2", "1/brocadeFCPortIndex/3/strings.properties", "1/brocadeFCPortIndex/3", "1/brocadeFCPortIndex/4/strings.properties", "1/brocadeFCPortIndex/4", "1/brocadeFCPortIndex/5/strings.properties", "1/brocadeFCPortIndex/5", "1/brocadeFCPortIndex/6/strings.properties", "1/brocadeFCPortIndex/6", "1/brocadeFCPortIndex/7/strings.properties", "1/brocadeFCPortIndex/7", "1/brocadeFCPortIndex/8/strings.properties", "1/brocadeFCPortIndex/8" })
@JUnitSnmpAgent(resource = "/org/opennms/netmgt/snmp/brocadeTestData1.properties")
public void testBug2447_GenericIndexedOnlyCollect() throws Exception {
// now do the actual collection
CollectionSet collectionSet = m_collectionSpecification.collect(m_collectionAgent);
assertEquals("collection status", CollectionStatus.SUCCEEDED, collectionSet.getStatus());
CollectorTestUtils.persistCollectionSet(m_rrdStrategy, m_resourceStorageDao, m_collectionSpecification, collectionSet);
System.err.println("FIRST COLLECTION FINISHED");
// need a one second time elapse to update the RRD
Thread.sleep(1000);
// try collecting again
assertEquals("collection status", CollectionStatus.SUCCEEDED, m_collectionSpecification.collect(m_collectionAgent).getStatus());
System.err.println("SECOND COLLECTION FINISHED");
}
Aggregations