use of org.opennms.netmgt.collection.api.ServiceParameters in project opennms by OpenNMS.
the class StressCommand method doExecute.
@Override
protected Void doExecute() {
// 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 * 1000);
} 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 CollectorTestUtils method persistCollectionSet.
public static void persistCollectionSet(RrdStrategy<?, ?> rrdStrategy, ResourceStorageDao resourceStorageDao, CollectionSpecification spec, CollectionSet collectionSet) {
RrdRepository repository = spec.getRrdRepository("default");
System.err.println("repository = " + repository);
ServiceParameters params = spec.getServiceParameters();
System.err.println("service parameters = " + params);
RrdPersisterFactory persisterFactory = new RrdPersisterFactory();
persisterFactory.setRrdStrategy(rrdStrategy);
persisterFactory.setResourceStorageDao(resourceStorageDao);
CollectionSetVisitor persister = persisterFactory.createPersister(params, repository);
System.err.println("persister = " + persister);
collectionSet.visit(persister);
}
use of org.opennms.netmgt.collection.api.ServiceParameters in project opennms by OpenNMS.
the class DefaultPollerBackEnd method saveResponseTimeData.
/**
* <p>saveResponseTimeData</p>
*
* @param locationMonitorId a {@link java.lang.String} object.
* @param monSvc a {@link org.opennms.netmgt.model.OnmsMonitoredService} object.
* @param responseTime a double.
* @param pkg a {@link org.opennms.netmgt.config.poller.Package} object.
*/
@Override
public void saveResponseTimeData(final String locationMonitorId, final OnmsMonitoredService monSvc, final double responseTime, final Package pkg) {
final String svcName = monSvc.getServiceName();
final Service svc = m_pollerConfig.getServiceInPackage(svcName, pkg);
String dsName = getServiceParameter(svc, "ds-name");
if (dsName == null) {
dsName = PollStatus.PROPERTY_RESPONSE_TIME;
}
String rrdBaseName = getServiceParameter(svc, "rrd-base-name");
if (rrdBaseName == null) {
rrdBaseName = dsName;
}
final String rrdRepository = getServiceParameter(svc, "rrd-repository");
if (rrdRepository == null) {
return;
}
RrdRepository repository = new RrdRepository();
repository.setStep(m_pollerConfig.getStep(pkg));
repository.setHeartBeat(repository.getStep() * HEARTBEAT_STEP_MULTIPLIER);
repository.setRraList(m_pollerConfig.getRRAList(pkg));
repository.setRrdBaseDir(new File(rrdRepository));
DistributedLatencyCollectionResource distributedLatencyResource = new DistributedLatencyCollectionResource(locationMonitorId, InetAddressUtils.toIpAddrString(monSvc.getIpAddress()));
DistributedLatencyCollectionAttributeType distributedLatencyType = new DistributedLatencyCollectionAttributeType(rrdBaseName, dsName);
distributedLatencyResource.addAttribute(new DistributedLatencyCollectionAttribute(distributedLatencyResource, distributedLatencyType, responseTime));
ServiceParameters params = new ServiceParameters(Collections.emptyMap());
CollectionSetVisitor persister = m_persisterFactory.createPersister(params, repository, false, true, true);
SingleResourceCollectionSet collectionSet = new SingleResourceCollectionSet(distributedLatencyResource, new Date());
collectionSet.setStatus(CollectionStatus.SUCCEEDED);
collectionSet.visit(persister);
}
use of org.opennms.netmgt.collection.api.ServiceParameters in project opennms by OpenNMS.
the class AbstractVTDXmlCollectorTest method executeCollectorTest.
/**
* Executes collector test.
*
* @param parameters the parameters
* @param expectedFiles the expected amount of JRB files
* @throws Exception the exception
*/
public void executeCollectorTest(Map<String, Object> parameters, int expectedFiles) throws Exception {
XmlCollector collector = new XmlCollector();
collector.setXmlCollectionDao(m_xmlCollectionDao);
CollectionSet collectionSet = XmlCollectorTestUtils.doCollect(collector, m_collectionAgent, parameters);
Assert.assertEquals(CollectionStatus.SUCCEEDED, collectionSet.getStatus());
ServiceParameters serviceParams = new ServiceParameters(new HashMap<String, Object>());
CollectionSetVisitor persister = m_persisterFactory.createGroupPersister(serviceParams, createRrdRepository((String) parameters.get("collection")), false, false);
collectionSet.visit(persister);
Assert.assertEquals(expectedFiles, FileUtils.listFiles(getSnmpRoot(), new String[] { "jrb" }, true).size());
}
use of org.opennms.netmgt.collection.api.ServiceParameters in project opennms by OpenNMS.
the class CollectdTest method testOverrides.
/**
* Test override of read community string and max repetitions in Collectd configuration parameters
*/
@Test
public void testOverrides() {
Map<String, Object> map = new HashMap<String, Object>();
map.put("max-repetitions", "11");
map.put("read-community", "notPublic");
ServiceParameters params = new ServiceParameters(map);
int reps = params.getSnmpMaxRepetitions(6);
assertEquals("Overriding max repetitions failed.", 11, reps);
params = new ServiceParameters(map);
map.remove("max-repetitions");
map.put("maxRepetitions", "11");
assertEquals("Overriding max repetitions failed.", 11, reps);
String s = params.getSnmpReadCommunity("public");
assertEquals("Overriding read community failed.", "notPublic", s);
map.remove("read-community");
map.put("readCommunity", "notPublic");
params = new ServiceParameters(map);
s = params.getSnmpReadCommunity("public");
assertEquals("Overriding read community failed.", "notPublic", s);
}
Aggregations