use of org.opennms.netmgt.collection.api.ServiceParameters in project opennms by OpenNMS.
the class TcaCollectorIT method testCollector.
/**
* Test collector.
*
* @throws Exception the exception
*/
@Test
public void testCollector() throws Exception {
Map<String, Object> parameters = new HashMap<String, Object>();
parameters.put("collection", "default");
// Create Collection Set
TcaCollector collector = new TcaCollector();
collector.setConfigDao(m_configDao);
collector.setResourceStorageDao(m_resourceStorageDao);
collector.setResourceTypesDao(m_resourceTypesDao);
collector.setLocationAwareSnmpClient(m_client);
CollectionSetVisitor persister = m_persisterFactory.createOneToOnePersister(new ServiceParameters(parameters), collector.getRrdRepository("default"), false, false);
// Setup SNMP Value Handling
SnmpValueFactory valFac = SnmpUtils.getValueFactory();
SnmpObjId peer1 = SnmpObjId.get(".1.3.6.1.4.1.27091.3.1.6.1.2.171.19.37.60");
SnmpObjId peer2 = SnmpObjId.get(".1.3.6.1.4.1.27091.3.1.6.1.2.171.19.38.70");
// Collect and Persist Data - Step 1
CollectionSet collectionSet = collector.collect(m_collectionAgent, parameters);
validateCollectionSet(collectionSet);
collectionSet.visit(persister);
// Generate new SNMP Data
final StringBuilder sb = new StringBuilder("|25|");
long ts = 1327451787l;
for (int i = 0; i < 25; i++) {
sb.append(ts++);
sb.append(",12,-1,12,-2,1|");
}
// Get Current Values
SnmpValue v1a = SnmpUtils.get(m_collectionAgent.getAgentConfig(), peer1);
SnmpValue v2a = SnmpUtils.get(m_collectionAgent.getAgentConfig(), peer2);
// Set New Values
SnmpUtils.set(m_collectionAgent.getAgentConfig(), peer1, valFac.getOctetString(sb.toString().getBytes()));
SnmpUtils.set(m_collectionAgent.getAgentConfig(), peer2, valFac.getOctetString(sb.toString().getBytes()));
// Validate New Values
SnmpValue v1b = SnmpUtils.get(m_collectionAgent.getAgentConfig(), peer1);
SnmpValue v2b = SnmpUtils.get(m_collectionAgent.getAgentConfig(), peer2);
Assert.assertFalse(v1a.toDisplayString().equals(v1b.toDisplayString()));
Assert.assertFalse(v2a.toDisplayString().equals(v2b.toDisplayString()));
// Collect and Persist Data - Step 2
collectionSet = collector.collect(m_collectionAgent, parameters);
validateCollectionSet(collectionSet);
collectionSet.visit(persister);
// Validate Persisted Data
Path pathToJrbFile = getSnmpRoot().toPath().resolve(Paths.get("1", TcaCollectionHandler.RESOURCE_TYPE_NAME, "171.19.37.60", TcaCollectionHandler.INBOUND_DELAY + m_rrdStrategy.getDefaultFileExtension()));
RrdDb jrb = new RrdDb(pathToJrbFile.toString());
// According with the Fixed Step
Assert.assertEquals(1, jrb.getArchive(0).getArcStep());
// According with the Sample Data
Assert.assertEquals(ts - 1, jrb.getArchive(0).getEndTime());
Robin inboundDelay = jrb.getArchive(0).getRobin(0);
for (int i = inboundDelay.getSize() - 49; i < inboundDelay.getSize() - 25; i++) {
Assert.assertEquals(new Double(11), Double.valueOf(inboundDelay.getValue(i)));
}
for (int i = inboundDelay.getSize() - 24; i < inboundDelay.getSize(); i++) {
Assert.assertEquals(new Double(12), Double.valueOf(inboundDelay.getValue(i)));
}
}
use of org.opennms.netmgt.collection.api.ServiceParameters in project opennms by OpenNMS.
the class StressCommand method execute.
@Override
public Void execute() throws Exception {
// Apply sane lower bounds to all of the configurable options
intervalInSeconds = Math.max(1, intervalInSeconds);
numberOfNodes = Math.max(1, numberOfNodes);
numberOfInterfacesPerNode = Math.max(1, numberOfInterfacesPerNode);
numberOfGroupsPerInterface = Math.max(1, numberOfGroupsPerInterface);
numberOfNumericAttributesPerGroup = Math.max(0, numberOfNumericAttributesPerGroup);
numberOfStringAttributesPerGroup = Math.max(0, numberOfStringAttributesPerGroup);
reportIntervalInSeconds = Math.max(1, reportIntervalInSeconds);
numberOfGeneratorThreads = Math.max(1, numberOfGeneratorThreads);
stringVariationFactor = Math.max(0, stringVariationFactor);
if (stringVariationFactor > 0) {
stringAttributesVaried = metrics.meter("string-attributes-varied");
}
// Display the effective settings and rates
double attributesPerSecond = (1 / (double) intervalInSeconds) * numberOfGroupsPerInterface * numberOfInterfacesPerNode * numberOfNodes;
System.out.printf("Generating collection sets every %d seconds\n", intervalInSeconds);
System.out.printf("\t for %d nodes\n", numberOfNodes);
System.out.printf("\t with %d interfaces\n", numberOfInterfacesPerNode);
System.out.printf("\t with %d attribute groups\n", numberOfGroupsPerInterface);
System.out.printf("\t with %d numeric attributes\n", numberOfNumericAttributesPerGroup);
System.out.printf("\t with %d string attributes\n", numberOfStringAttributesPerGroup);
System.out.printf("Across %d threads\n", numberOfGeneratorThreads);
if (stringVariationFactor > 0) {
System.out.printf("With string variation factor %d\n", stringVariationFactor);
}
System.out.printf("Which will yield an effective\n");
System.out.printf("\t %.2f numeric attributes per second\n", numberOfNumericAttributesPerGroup * attributesPerSecond);
System.out.printf("\t %.2f string attributes per second\n", numberOfStringAttributesPerGroup * attributesPerSecond);
ConsoleReporter reporter = ConsoleReporter.forRegistry(metrics).convertRatesTo(TimeUnit.SECONDS).convertDurationsTo(TimeUnit.MILLISECONDS).build();
// Setup the executor
ThreadFactory threadFactoy = new ThreadFactoryBuilder().setNameFormat("Metrics Stress Tool Generator #%d").build();
ExecutorService executor = Executors.newFixedThreadPool(numberOfGeneratorThreads, threadFactoy);
// Setup auxiliary objects needed by the persister
ServiceParameters params = new ServiceParameters(Collections.emptyMap());
RrdRepository repository = new RrdRepository();
repository.setStep(Math.max(intervalInSeconds, 1));
repository.setHeartBeat(repository.getStep() * 2);
if (rras != null && rras.size() > 0) {
repository.setRraList(rras);
} else {
repository.setRraList(Lists.newArrayList(// Use the default list of RRAs we provide in our stock configuration files
"RRA:AVERAGE:0.5:1:2016", "RRA:AVERAGE:0.5:12:1488", "RRA:AVERAGE:0.5:288:366", "RRA:MAX:0.5:288:366", "RRA:MIN:0.5:288:366"));
}
repository.setRrdBaseDir(Paths.get(System.getProperty("opennms.home"), "share", "rrd", "snmp").toFile());
// Calculate how we fast we should insert the collection sets
int sleepTimeInMillisBetweenNodes = 0;
int sleepTimeInSecondsBetweenIterations = 0;
System.out.printf("Sleeping for\n");
if (burst) {
sleepTimeInSecondsBetweenIterations = intervalInSeconds;
System.out.printf("\t %d seconds between batches\n", sleepTimeInSecondsBetweenIterations);
} else {
// We want to "stream" the collection sets
sleepTimeInMillisBetweenNodes = Math.round((((float) intervalInSeconds * 1000) / numberOfNodes) * numberOfGeneratorThreads);
System.out.printf("\t %d milliseconds between nodes\n", sleepTimeInMillisBetweenNodes);
}
// Start generating, and keep generating until we're interrupted
try {
reporter.start(reportIntervalInSeconds, TimeUnit.SECONDS);
while (true) {
final Context context = batchTimer.time();
try {
// Split the tasks up among the threads
List<Future<Void>> futures = new ArrayList<>();
for (int generatorThreadId = 0; generatorThreadId < numberOfGeneratorThreads; generatorThreadId++) {
futures.add(executor.submit(generateAndPersistCollectionSets(params, repository, generatorThreadId, sleepTimeInMillisBetweenNodes)));
}
// Wait for all the tasks to complete before starting others
for (Future<Void> future : futures) {
future.get();
}
} catch (InterruptedException | ExecutionException e) {
break;
} finally {
context.stop();
}
try {
Thread.sleep(sleepTimeInSecondsBetweenIterations * 1000L);
} catch (InterruptedException e) {
break;
}
}
} finally {
reporter.stop();
abort.set(true);
executor.shutdownNow();
}
return null;
}
use of org.opennms.netmgt.collection.api.ServiceParameters in project opennms by OpenNMS.
the class CollectableServiceTest method createCollectableService.
private void createCollectableService() throws CollectionInitializationException, IOException {
// Mock it all!
OnmsIpInterface iface = mock(OnmsIpInterface.class, RETURNS_DEEP_STUBS);
IpInterfaceDao ifaceDao = mock(IpInterfaceDao.class);
spec = mock(CollectionSpecification.class);
scheduler = mock(Scheduler.class);
SchedulingCompletedFlag schedulingCompletedFlag = mock(SchedulingCompletedFlag.class);
PlatformTransactionManager transMgr = mock(PlatformTransactionManager.class);
RrdPersisterFactory persisterFactory = new RrdPersisterFactory();
persisterFactory.setRrdStrategy(rrdStrategy);
ResourceStorageDao resourceStorageDao = mock(ResourceStorageDao.class);
// Disable thresholding
Map<String, Object> paramsMap = new HashMap<>();
paramsMap.put("thresholding-enabled", Boolean.FALSE.toString());
ServiceParameters params = new ServiceParameters(paramsMap);
when(iface.getNode().getId()).thenReturn(1);
when(spec.getServiceParameters()).thenReturn(params);
when(spec.getRrdRepository(any())).thenReturn(createRrdRepository());
when(ifaceDao.load(any())).thenReturn(iface);
when(iface.getIpAddress()).thenReturn(InetAddrUtils.getLocalHostAddress());
service = new CollectableService(iface, ifaceDao, spec, scheduler, schedulingCompletedFlag, transMgr, persisterFactory, resourceStorageDao);
}
use of org.opennms.netmgt.collection.api.ServiceParameters in project opennms by OpenNMS.
the class SnmpAttributeTest method testPersisting.
@Ignore
private void testPersisting(String matchValue, SnmpValue snmpValue) throws Exception {
OnmsNode node = new OnmsNode();
node.setId(3);
OnmsIpInterface ipInterface = new OnmsIpInterface();
ipInterface.setId(1);
ipInterface.setNode(node);
ipInterface.setIpAddress(InetAddressUtils.addr("192.168.1.1"));
// It used to be 3, but I think it is more correct to use getStoreDir from DefaultCollectionAgentService on DefaultCollectionAgent (NMS-7516)
expect(m_ipInterfaceDao.load(1)).andReturn(ipInterface).times(5);
expect(m_rrdStrategy.getDefaultFileExtension()).andReturn(".myLittleEasyMockedStrategyAndMe").anyTimes();
expect(m_rrdStrategy.createDefinition(isA(String.class), isA(String.class), isA(String.class), anyInt(), isAList(RrdDataSource.class), isAList(String.class))).andReturn(new Object());
m_rrdStrategy.createFile(isA(Object.class));
expect(m_rrdStrategy.openFile(isA(String.class))).andReturn(new Object());
m_rrdStrategy.updateFile(isA(Object.class), isA(String.class), matches(".*:" + matchValue));
m_rrdStrategy.closeFile(isA(Object.class));
m_mocks.replayAll();
SnmpCollectionAgent agent = DefaultSnmpCollectionAgent.create(ipInterface.getId(), m_ipInterfaceDao, new MockPlatformTransactionManager());
OnmsSnmpCollection snmpCollection = new OnmsSnmpCollection(agent, new ServiceParameters(new HashMap<String, Object>()), new MockDataCollectionConfig(), m_locationAwareSnmpClient);
NodeResourceType resourceType = new NodeResourceType(agent, snmpCollection);
NodeInfo nodeInfo = resourceType.getNodeInfo();
MibObject mibObject = new MibObject();
mibObject.setOid(".1.3.6.1.4.1.12238.55.9997.4.1.2.9.116.101.109.112.95.117.108.107.111");
mibObject.setInstance("1");
mibObject.setAlias("temp_ulko");
mibObject.setType("gauge");
NumericAttributeType attributeType = new NumericAttributeType(resourceType, snmpCollection.getName(), mibObject, new AttributeGroupType("foo", AttributeGroupType.IF_TYPE_IGNORE));
attributeType.storeResult(new SnmpCollectionSet(agent, snmpCollection, m_locationAwareSnmpClient), null, new SnmpResult(mibObject.getSnmpObjId(), new SnmpInstId(mibObject.getInstance()), snmpValue));
RrdRepository repository = createRrdRepository();
repository.setRraList(Collections.singletonList("RRA:AVERAGE:0.5:1:2016"));
RrdPersisterFactory persisterFactory = new RrdPersisterFactory();
persisterFactory.setRrdStrategy(m_rrdStrategy);
persisterFactory.setResourceStorageDao(m_resourceStorageDao);
CollectionSetVisitor persister = persisterFactory.createPersister(new ServiceParameters(Collections.emptyMap()), repository);
final AtomicInteger count = new AtomicInteger(0);
nodeInfo.visit(new CollectionSetVisitorWrapper(persister) {
@Override
public void visitAttribute(CollectionAttribute attribute) {
super.visitAttribute(attribute);
count.incrementAndGet();
}
});
assertEquals(1, count.get());
}
use of org.opennms.netmgt.collection.api.ServiceParameters in project opennms by OpenNMS.
the class LatencyStoringServiceMonitorAdaptor method persistLatencySamples.
private void persistLatencySamples(MonitoredService service, Map<String, Number> entries, File rrdRepositoryRoot, String rrdBaseName) {
RrdRepository repository = new RrdRepository();
repository.setStep(m_pollerConfig.getStep(m_pkg));
repository.setRraList(m_pollerConfig.getRRAList(m_pkg));
repository.setHeartBeat(repository.getStep() * HEARTBEAT_STEP_MULTIPLIER);
repository.setRrdBaseDir(rrdRepositoryRoot);
// When making calls directly to RrdUtils#createRrd() and RrdUtils#updateRrd(),
// the behavior was as follows:
// 1) All samples get written to response/${ipAddr}/${rrdBaseName}.rrd
// This happens whether or not storeByGroup is enabled.
// 2) If multiple entries are present, the DSs are created in the same order that they
// appear in the map
LatencyCollectionResource latencyResource = new LatencyCollectionResource(service.getSvcName(), service.getIpAddr(), service.getNodeLocation());
for (final Entry<String, Number> entry : entries.entrySet()) {
final String ds = entry.getKey();
final Number value = entry.getValue() != null ? entry.getValue() : Double.NaN;
LatencyCollectionAttributeType latencyType = new LatencyCollectionAttributeType(rrdBaseName, ds);
latencyResource.addAttribute(new LatencyCollectionAttribute(latencyResource, latencyType, ds, value.doubleValue()));
}
ServiceParameters params = new ServiceParameters(Collections.emptyMap());
CollectionSetVisitor persister = m_persisterFactory.createPersister(params, repository, false, true, true);
SingleResourceCollectionSet collectionSet = new SingleResourceCollectionSet(latencyResource, new Date());
collectionSet.setStatus(CollectionStatus.SUCCEEDED);
collectionSet.visit(persister);
}
Aggregations