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;
}
};
}
use of org.opennms.netmgt.collection.api.Persister in project opennms by OpenNMS.
the class CollectionSetDTO method buildCollectionResources.
private Set<CollectionResource> buildCollectionResources() {
final Set<CollectionResource> collectionResources = new LinkedHashSet<>();
for (CollectionResourceDTO entry : this.collectionResources) {
final Resource resource = entry.getResource();
final AbstractCollectionResource collectionResource = CollectionSetBuilder.toCollectionResource(resource, agent);
for (Attribute<?> attribute : entry.getAttributes()) {
final AttributeGroupType groupType = new AttributeGroupType(attribute.getGroup(), AttributeGroupType.IF_TYPE_ALL);
final AbstractCollectionAttributeType attributeType = new AbstractCollectionAttributeType(groupType) {
@Override
public AttributeType getType() {
return attribute.getType();
}
@Override
public String getName() {
return attribute.getName();
}
@Override
public void storeAttribute(CollectionAttribute collectionAttribute, Persister persister) {
if (AttributeType.STRING.equals(attribute.getType())) {
persister.persistStringAttribute(collectionAttribute);
} else {
persister.persistNumericAttribute(collectionAttribute);
}
}
@Override
public String toString() {
return attribute.toString();
}
};
collectionResource.addAttribute(new AbstractCollectionAttribute(attributeType, collectionResource) {
@Override
public String getMetricIdentifier() {
return attribute.getName();
}
@Override
public Number getNumericValue() {
return attribute.getNumericValue();
}
@Override
public String getStringValue() {
return attribute.getStringValue();
}
@Override
public boolean shouldPersist(ServiceParameters params) {
return !(Boolean.FALSE.equals(disableCounterPersistence) && AttributeType.COUNTER.equals(attribute.getType()));
}
@Override
public String toString() {
return String.format("Attribute[%s:%s]", getMetricIdentifier(), attribute.getValue());
}
});
}
collectionResources.add(collectionResource);
}
return collectionResources;
}
use of org.opennms.netmgt.collection.api.Persister in project opennms by OpenNMS.
the class MockCollectionResource method visit.
@Override
public void visit(CollectionSetVisitor visitor) {
for (Entry<String, String> entry : attributes.entrySet()) {
final CollectionResource resource = this;
final String attrName = entry.getKey();
final String attrValue = entry.getValue();
CollectionAttribute attribute = new CollectionAttribute() {
@Override
public CollectionResource getResource() {
return resource;
}
@Override
public String getStringValue() {
return attrValue;
}
@Override
public Double getNumericValue() {
try {
return Double.parseDouble(attrValue);
} catch (NumberFormatException | NullPointerException e) {
return null;
}
}
@Override
public String getName() {
return attrName;
}
@Override
public void storeAttribute(Persister persister) {
}
@Override
public boolean shouldPersist(ServiceParameters params) {
return true;
}
@Override
public CollectionAttributeType getAttributeType() {
return null;
}
@Override
public void visit(CollectionSetVisitor visitor) {
}
@Override
public AttributeType getType() {
return AttributeType.STRING;
}
@Override
public String getMetricIdentifier() {
return "MOCK_" + getName();
}
};
visitor.visitAttribute(attribute);
}
}
Aggregations