Search in sources :

Example 1 with Persister

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

the class NewtsPersisterIT method canPersist.

@Test
public void canPersist() throws InterruptedException {
    ServiceParameters params = new ServiceParameters(Collections.emptyMap());
    RrdRepository repo = new RrdRepository();
    // Only the last element of the path matters here
    repo.setRrdBaseDir(Paths.get("a", "path", "that", "ends", "with", "snmp").toFile());
    Persister persister = m_persisterFactory.createPersister(params, repo);
    int nodeId = 1;
    CollectionAgent agent = mock(CollectionAgent.class);
    when(agent.getStorageResourcePath()).thenReturn(ResourcePath.get(Integer.toString(nodeId)));
    NodeLevelResource nodeLevelResource = new NodeLevelResource(nodeId);
    // Build a collection set with a single sample
    Timestamp now = Timestamp.now();
    CollectionSet collectionSet = new CollectionSetBuilder(agent).withNumericAttribute(nodeLevelResource, "metrics", "metric", 900, AttributeType.GAUGE).withTimestamp(now.asDate()).build();
    // Persist
    collectionSet.visit(persister);
    // Wait for the sample(s) to be flushed
    Thread.sleep(5 * 1000);
    // Fetch the (persisted) sample
    Resource resource = new Resource("snmp:1:metrics");
    Timestamp end = Timestamp.now();
    Results<Sample> samples = m_sampleRepository.select(Context.DEFAULT_CONTEXT, resource, Optional.of(now), Optional.of(end));
    assertEquals(1, samples.getRows().size());
    Row<Sample> row = samples.getRows().iterator().next();
    assertEquals(900, row.getElement("metric").getValue().doubleValue(), 0.00001);
}
Also used : CollectionSetBuilder(org.opennms.netmgt.collection.support.builder.CollectionSetBuilder) Sample(org.opennms.newts.api.Sample) Resource(org.opennms.newts.api.Resource) NodeLevelResource(org.opennms.netmgt.collection.support.builder.NodeLevelResource) RrdRepository(org.opennms.netmgt.rrd.RrdRepository) NodeLevelResource(org.opennms.netmgt.collection.support.builder.NodeLevelResource) Timestamp(org.opennms.newts.api.Timestamp) CollectionSet(org.opennms.netmgt.collection.api.CollectionSet) ServiceParameters(org.opennms.netmgt.collection.api.ServiceParameters) Persister(org.opennms.netmgt.collection.api.Persister) CollectionAgent(org.opennms.netmgt.collection.api.CollectionAgent) Test(org.junit.Test)

Example 2 with Persister

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

the class EvaluatePersisterFactoryIT method testPersisterFactory.

/**
 * Test persister factory.
 *
 * @throws Exception the exception
 */
@Test
public void testPersisterFactory() throws Exception {
    Persister persister = factory.createPersister(null, null);
    Assert.assertNotNull(persister);
}
Also used : Persister(org.opennms.netmgt.collection.api.Persister) Test(org.junit.Test)

Example 3 with Persister

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

the class CollectionResourceWrapperIT method addAttributeToCollectionResource.

private SnmpAttribute addAttributeToCollectionResource(SnmpCollectionResource resource, String attributeName, AttributeType attributeType, String attributeInstance, String value) {
    MibObject object = createMibObject(attributeType, attributeName, attributeInstance);
    SnmpAttributeType objectType = null;
    SnmpValue snmpValue = null;
    if (AttributeType.STRING.equals(attributeType)) {
        objectType = new SnmpAttributeType(resource.getResourceType(), "default", object, new AttributeGroupType("mibGroup", AttributeGroupType.IF_TYPE_IGNORE)) {

            @Override
            public AttributeType getType() {
                return AttributeType.STRING;
            }

            @Override
            public void storeAttribute(CollectionAttribute attribute, Persister persister) {
                persister.persistStringAttribute(attribute);
            }
        };
        snmpValue = SnmpUtils.getValueFactory().getOctetString(value.getBytes());
    } else {
        objectType = new NumericAttributeType(resource.getResourceType(), "default", object, new AttributeGroupType("mibGroup", AttributeGroupType.IF_TYPE_IGNORE));
        long v = Long.parseLong(value);
        snmpValue = AttributeType.COUNTER.equals(attributeType) ? SnmpUtils.getValueFactory().getCounter32(v) : SnmpUtils.getValueFactory().getGauge32(v);
    }
    resource.setAttributeValue(objectType, snmpValue);
    return new SnmpAttribute(resource, objectType, snmpValue);
}
Also used : CollectionAttribute(org.opennms.netmgt.collection.api.CollectionAttribute) NumericAttributeType(org.opennms.netmgt.collectd.NumericAttributeType) SnmpValue(org.opennms.netmgt.snmp.SnmpValue) SnmpAttribute(org.opennms.netmgt.collectd.SnmpAttribute) AttributeType(org.opennms.netmgt.collection.api.AttributeType) SnmpAttributeType(org.opennms.netmgt.collectd.SnmpAttributeType) NumericAttributeType(org.opennms.netmgt.collectd.NumericAttributeType) AttributeGroupType(org.opennms.netmgt.collection.api.AttributeGroupType) Persister(org.opennms.netmgt.collection.api.Persister) MibObject(org.opennms.netmgt.config.datacollection.MibObject) SnmpAttributeType(org.opennms.netmgt.collectd.SnmpAttributeType)

Example 4 with Persister

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

the class TcpOutputStrategyTest method persist.

public void persist(CollectionSet collectionSet, boolean forceStoreByGroup) {
    ServiceParameters params = new ServiceParameters(Collections.emptyMap());
    RrdRepository repo = new RrdRepository();
    repo.setRrdBaseDir(tempFolder.getRoot());
    Persister persister = persisterFactory.createPersister(params, repo, false, forceStoreByGroup, false);
    collectionSet.visit(persister);
}
Also used : ServiceParameters(org.opennms.netmgt.collection.api.ServiceParameters) Persister(org.opennms.netmgt.collection.api.Persister) RrdRepository(org.opennms.netmgt.rrd.RrdRepository)

Example 5 with Persister

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

the class StressCommand method generateAndPersistCollectionSets.

private Callable<Void> generateAndPersistCollectionSets(ServiceParameters params, RrdRepository repository, int generatorThreadId, int sleepTimeInMillisBetweenNodes) {
    return new Callable<Void>() {

        @Override
        public Void call() throws Exception {
            for (int nodeId = 0; nodeId < numberOfNodes; nodeId++) {
                if (nodeId % numberOfGeneratorThreads != generatorThreadId) {
                    // A different generator will handle this node
                    continue;
                }
                // Build the node resource
                CollectionAgent agent = new MockCollectionAgent(nodeId);
                NodeLevelResource nodeResource = new NodeLevelResource(nodeId);
                // Don't reuse the persister instance across nodes to help simulate collectd's actual behavior
                Persister persister = persisterFactory.createPersister(params, repository);
                for (int interfaceId = 0; interfaceId < numberOfInterfacesPerNode; interfaceId++) {
                    // Return immediately if the abort flag is set
                    if (abort.get()) {
                        return null;
                    }
                    // Build the interface resource
                    InterfaceLevelResource interfaceResource = new InterfaceLevelResource(nodeResource, "tap" + interfaceId);
                    // Generate the collection set
                    CollectionSet collectionSet = generateCollectionSet(agent, nodeId, interfaceId, interfaceResource);
                    // Persist
                    collectionSet.visit(persister);
                }
                Thread.sleep(sleepTimeInMillisBetweenNodes);
            }
            return null;
        }
    };
}
Also used : InterfaceLevelResource(org.opennms.netmgt.collection.support.builder.InterfaceLevelResource) Persister(org.opennms.netmgt.collection.api.Persister) CollectionAgent(org.opennms.netmgt.collection.api.CollectionAgent) NodeLevelResource(org.opennms.netmgt.collection.support.builder.NodeLevelResource) Callable(java.util.concurrent.Callable) CollectionSet(org.opennms.netmgt.collection.api.CollectionSet)

Aggregations

Persister (org.opennms.netmgt.collection.api.Persister)8 ServiceParameters (org.opennms.netmgt.collection.api.ServiceParameters)4 CollectionAttribute (org.opennms.netmgt.collection.api.CollectionAttribute)3 CollectionSet (org.opennms.netmgt.collection.api.CollectionSet)3 RrdRepository (org.opennms.netmgt.rrd.RrdRepository)3 Test (org.junit.Test)2 AttributeGroupType (org.opennms.netmgt.collection.api.AttributeGroupType)2 CollectionAgent (org.opennms.netmgt.collection.api.CollectionAgent)2 CollectionResource (org.opennms.netmgt.collection.api.CollectionResource)2 NodeLevelResource (org.opennms.netmgt.collection.support.builder.NodeLevelResource)2 File (java.io.File)1 LinkedHashSet (java.util.LinkedHashSet)1 Callable (java.util.concurrent.Callable)1 ExecutionException (java.util.concurrent.ExecutionException)1 NumericAttributeType (org.opennms.netmgt.collectd.NumericAttributeType)1 SnmpAttribute (org.opennms.netmgt.collectd.SnmpAttribute)1 SnmpAttributeType (org.opennms.netmgt.collectd.SnmpAttributeType)1 AttributeType (org.opennms.netmgt.collection.api.AttributeType)1 CollectionSetVisitor (org.opennms.netmgt.collection.api.CollectionSetVisitor)1 AbstractCollectionAttribute (org.opennms.netmgt.collection.support.AbstractCollectionAttribute)1