Search in sources :

Example 6 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)

Example 7 with Persister

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;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) CollectionResource(org.opennms.netmgt.collection.api.CollectionResource) AbstractCollectionResource(org.opennms.netmgt.collection.support.AbstractCollectionResource) AbstractCollectionAttribute(org.opennms.netmgt.collection.support.AbstractCollectionAttribute) CollectionResource(org.opennms.netmgt.collection.api.CollectionResource) AbstractCollectionResource(org.opennms.netmgt.collection.support.AbstractCollectionResource) Resource(org.opennms.netmgt.collection.support.builder.Resource) AbstractCollectionAttribute(org.opennms.netmgt.collection.support.AbstractCollectionAttribute) CollectionAttribute(org.opennms.netmgt.collection.api.CollectionAttribute) AttributeGroupType(org.opennms.netmgt.collection.api.AttributeGroupType) Persister(org.opennms.netmgt.collection.api.Persister) ServiceParameters(org.opennms.netmgt.collection.api.ServiceParameters) AbstractCollectionResource(org.opennms.netmgt.collection.support.AbstractCollectionResource) AbstractCollectionAttributeType(org.opennms.netmgt.collection.support.AbstractCollectionAttributeType)

Example 8 with Persister

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);
    }
}
Also used : CollectionAttribute(org.opennms.netmgt.collection.api.CollectionAttribute) CollectionResource(org.opennms.netmgt.collection.api.CollectionResource) CollectionSetVisitor(org.opennms.netmgt.collection.api.CollectionSetVisitor) Persister(org.opennms.netmgt.collection.api.Persister) ServiceParameters(org.opennms.netmgt.collection.api.ServiceParameters)

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