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);
}
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);
}
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);
}
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);
}
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;
}
};
}
Aggregations