use of org.opennms.netmgt.collection.support.builder.InterfaceLevelResource in project opennms by OpenNMS.
the class CollectionSetDTOTest method data.
@Parameters
public static Collection<Object[]> data() throws ParseException {
CollectionAgent collectionAgent = mock(CollectionAgent.class);
NodeLevelResource nodeLevelResource = new NodeLevelResource(1);
InterfaceLevelResource interfaceLevelResource = new InterfaceLevelResource(nodeLevelResource, "eth0");
ResourceType rt = mock(ResourceType.class, RETURNS_DEEP_STUBS);
when(rt.getName()).thenReturn("Charles");
when(rt.getStorageStrategy().getClazz()).thenReturn(MockStorageStrategy.class.getCanonicalName());
when(rt.getPersistenceSelectorStrategy().getClazz()).thenReturn(MockPersistenceSelectorStrategy.class.getCanonicalName());
DeferredGenericTypeResource deferredGenericTypeResource = new DeferredGenericTypeResource(nodeLevelResource, "Charles", "id");
GenericTypeResource genericTypeResource = new GenericTypeResource(nodeLevelResource, rt, "idx");
genericTypeResource.setTimestamp(new Date(0));
ResourceTypeMapper.getInstance().setResourceTypeMapper((name) -> rt);
// For complete coverage make sure that there is at least one attribute
// for every different resource type, and that every different type
// of attribute is represented at least once
CollectionSet collectionSet = new CollectionSetBuilder(collectionAgent).withTimestamp(new Date(0)).withNumericAttribute(nodeLevelResource, "ucd-sysstat", "CpuRawIdle", 99, AttributeType.GAUGE).withNumericAttribute(interfaceLevelResource, "mib2-X-interfaces", "ifHCInOctets", 1001, AttributeType.COUNTER).withStringAttribute(interfaceLevelResource, "mib2-X-interfaces", "ifDescr", "LAN").withIdentifiedNumericAttribute(deferredGenericTypeResource, "net-snmp-disk", "ns-dsk1", 1024, AttributeType.GAUGE, "some-oid").withIdentifiedNumericAttribute(genericTypeResource, "net-snmp-disk", "ns-dskTotal", 1024, AttributeType.GAUGE, "some-oid").build();
return Arrays.asList(new Object[][] { { collectionSet, "<collection-set status=\"SUCCEEDED\" timestamp=\"" + StringUtils.iso8601OffsetString(new Date(0), ZoneId.systemDefault(), ChronoUnit.SECONDS) + "\">\n" + " <agent type=\"0\" store-by-fs=\"false\" node-id=\"0\" sys-up-time=\"0\"/>\n" + " <collection-resource>\n" + " <node-level-resource node-id=\"1\"/>\n" + " <numeric-attribute group=\"ucd-sysstat\" name=\"CpuRawIdle\" type=\"gauge\" value=\"99\"/>\n" + " </collection-resource>\n" + " <collection-resource>\n" + " <interface-level-resource if-name=\"eth0\">\n" + " <node-level-resource node-id=\"1\"/>\n" + " </interface-level-resource>\n" + " <numeric-attribute group=\"mib2-X-interfaces\" name=\"ifHCInOctets\" type=\"counter\" value=\"1001\"/>\n" + " <string-attribute group=\"mib2-X-interfaces\" name=\"ifDescr\" type=\"string\" value=\"LAN\"/>\n" + " </collection-resource>\n" + " <collection-resource>\n" + " <generic-type-resource name=\"Charles\" instance=\"id\">\n" + " <node-level-resource node-id=\"1\"/>\n" + " </generic-type-resource>\n" + " <numeric-attribute group=\"net-snmp-disk\" name=\"ns-dsk1\" type=\"gauge\" identifier=\"some-oid\" value=\"1024\"/>\n" + " </collection-resource>\n" + " <collection-resource>\n" + " <generic-type-resource name=\"Charles\" instance=\"idx\" timestamp=\"" + StringUtils.iso8601OffsetString(new Date(0), ZoneId.systemDefault(), ChronoUnit.SECONDS) + "\">\n" + " <node-level-resource node-id=\"1\"/>\n" + " </generic-type-resource>\n" + " <numeric-attribute group=\"net-snmp-disk\" name=\"ns-dskTotal\" type=\"gauge\" identifier=\"some-oid\" value=\"1024\"/>\n" + " </collection-resource>\n" + "</collection-set>" } });
}
use of org.opennms.netmgt.collection.support.builder.InterfaceLevelResource in project opennms by OpenNMS.
the class InterfaceLevelResourceDTO method toResource.
public InterfaceLevelResource toResource() {
final InterfaceLevelResource resource = new InterfaceLevelResource(parent.toResource(), ifName);
resource.setTimestamp(timestamp);
return resource;
}
use of org.opennms.netmgt.collection.support.builder.InterfaceLevelResource in project opennms by OpenNMS.
the class TcpOutputStrategyTest method peristAndReceiveProtobufMessages.
@Test
public void peristAndReceiveProtobufMessages() {
// Build a collection set with both numeric and string attributes
String owner = "192.168.1.1";
MockCollectionAgent agent = new MockCollectionAgent(1, "n1", InetAddressUtils.addr(owner));
CollectionSetBuilder builder = new CollectionSetBuilder(agent);
NodeLevelResource node = new NodeLevelResource(agent.getNodeId());
InterfaceLevelResource eth0 = new InterfaceLevelResource(node, "eth0");
builder.withNumericAttribute(eth0, "mib2-interfaces", "ifInErrors", 0.0, AttributeType.COUNTER);
builder.withStringAttribute(eth0, "mib2-interfaces", "ifSpeed", "10000000");
builder.withStringAttribute(eth0, "mib2-interfaces", "ifHighSpeed", "10");
CollectionSet collectionSet = builder.build();
// Persist without storeByGroup
persist(collectionSet, false);
// Wait for the server to receive the readings
await().until(() -> allReadings.size() == 1);
PerformanceDataReadings readings = allReadings.get(0);
// The reading should contain three messages
assertEquals(3, readings.getMessageCount());
PerformanceDataReading reading = readings.getMessage(0);
assertEquals(PerformanceDataReading.newBuilder().setPath(Paths.get(tempFolder.getRoot().getAbsolutePath(), "1", "eth0", "ifInErrors").toString()).setOwner(owner).setTimestamp(reading.getTimestamp()).addAllDblValue(Arrays.asList(Double.valueOf(0.0))).addAllStrValue(Collections.emptyList()).build(), reading);
reading = readings.getMessage(1);
assertEquals(PerformanceDataReading.newBuilder().setPath(Paths.get(tempFolder.getRoot().getAbsolutePath(), "1", "eth0", "ifSpeed").toString()).setOwner(owner).setTimestamp(reading.getTimestamp()).addAllDblValue(Collections.emptyList()).addAllStrValue(Arrays.asList("10000000")).build(), reading);
reading = readings.getMessage(2);
assertEquals(PerformanceDataReading.newBuilder().setPath(Paths.get(tempFolder.getRoot().getAbsolutePath(), "1", "eth0", "ifHighSpeed").toString()).setOwner(owner).setTimestamp(reading.getTimestamp()).addAllDblValue(Collections.emptyList()).addAllStrValue(Arrays.asList("10")).build(), reading);
// Persist with storeByGroup
persist(collectionSet, true);
// Wait for the server to receive the readings
await().until(() -> allReadings.size() == 2);
readings = allReadings.get(1);
// The reading should contain 1 message
assertEquals(1, readings.getMessageCount());
reading = readings.getMessage(0);
assertEquals(PerformanceDataReading.newBuilder().setPath(Paths.get(tempFolder.getRoot().getAbsolutePath(), "1", "eth0", "mib2-interfaces").toString()).setOwner(owner).setTimestamp(reading.getTimestamp()).addAllDblValue(Arrays.asList(Double.valueOf(0.0))).addAllStrValue(Arrays.asList("10", "10000000")).build(), reading);
}
use of org.opennms.netmgt.collection.support.builder.InterfaceLevelResource 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.support.builder.InterfaceLevelResource in project opennms by OpenNMS.
the class EvaluateStatsIT method testPersister.
/**
* Test persister.
*
* @throws Exception the exception
*/
@Test
public void testPersister() throws Exception {
RrdRepository repo = new RrdRepository();
repo.setRrdBaseDir(new File("/tmp"));
EvaluateGroupPersister persister = new EvaluateGroupPersister(stats, new ServiceParameters(new HashMap<String, Object>()), repo);
MockCollectionAgent agent = new MockCollectionAgent(1, "node.local", "Test", "001", InetAddressUtils.addr("127.0.0.1"));
CollectionSetBuilder builder = new CollectionSetBuilder(agent);
NodeLevelResource node = new NodeLevelResource(agent.getNodeId());
InterfaceLevelResource eth0 = new InterfaceLevelResource(node, "eth0");
builder.withNumericAttribute(eth0, "mib2-interfaces", "ifInErrors", 0.0, AttributeType.COUNTER);
builder.withNumericAttribute(eth0, "mib2-interfaces", "ifOutErrors", 0.0, AttributeType.COUNTER);
builder.withNumericAttribute(eth0, "mib2-X-interfaces", "ifHCInOctets", 100.0, AttributeType.COUNTER);
builder.withNumericAttribute(eth0, "mib2-X-interfaces", "ifHCOutOctets", 100.0, AttributeType.COUNTER);
builder.withStringAttribute(eth0, "mib2-X-interfaces", "ifHighSpeed", "1000");
InterfaceLevelResource eth1 = new InterfaceLevelResource(node, "eth1");
builder.withNumericAttribute(eth1, "mib2-interfaces", "ifInErrors", 0.0, AttributeType.COUNTER);
builder.withNumericAttribute(eth1, "mib2-interfaces", "ifOutErrors", 0.0, AttributeType.COUNTER);
builder.withNumericAttribute(eth1, "mib2-X-interfaces", "ifHCInOctets", 100.0, AttributeType.COUNTER);
builder.withNumericAttribute(eth1, "mib2-X-interfaces", "ifHCOutOctets", 100.0, AttributeType.COUNTER);
builder.withStringAttribute(eth1, "mib2-X-interfaces", "ifHighSpeed", "1000");
builder.build().visit(persister);
stats.dumpCache();
Assert.assertEquals(1, registry.getGauges().get("evaluate.nodes").getValue());
Assert.assertEquals(2, registry.getGauges().get("evaluate.resources").getValue());
Assert.assertEquals(4, registry.getGauges().get("evaluate.groups").getValue());
Assert.assertEquals(8, registry.getGauges().get("evaluate.numeric-attributes").getValue());
Assert.assertEquals(2, registry.getGauges().get("evaluate.string-attributes").getValue());
Assert.assertEquals(8, registry.getMeters().get("evaluate.samples").getCount());
}
Aggregations