use of com.codahale.metrics.ConsoleReporter in project hive by apache.
the class CodahaleMetrics method initReporting.
/**
* Should be only called once to initialize the reporters
*/
private void initReporting(Set<MetricsReporting> reportingSet) {
for (MetricsReporting reporting : reportingSet) {
switch(reporting) {
case CONSOLE:
final ConsoleReporter consoleReporter = ConsoleReporter.forRegistry(metricRegistry).convertRatesTo(TimeUnit.SECONDS).convertDurationsTo(TimeUnit.MILLISECONDS).build();
consoleReporter.start(1, TimeUnit.SECONDS);
reporters.add(consoleReporter);
break;
case JMX:
final JmxReporter jmxReporter = JmxReporter.forRegistry(metricRegistry).convertRatesTo(TimeUnit.SECONDS).convertDurationsTo(TimeUnit.MILLISECONDS).build();
jmxReporter.start();
reporters.add(jmxReporter);
break;
case JSON_FILE:
final JsonFileReporter jsonFileReporter = new JsonFileReporter();
jsonFileReporter.start();
reporters.add(jsonFileReporter);
break;
case HADOOP2:
String applicationName = conf.get(HiveConf.ConfVars.HIVE_METRICS_HADOOP2_COMPONENT_NAME.varname);
long reportingInterval = HiveConf.toTime(conf.get(HiveConf.ConfVars.HIVE_METRICS_HADOOP2_INTERVAL.varname), TimeUnit.SECONDS, TimeUnit.SECONDS);
final HadoopMetrics2Reporter metrics2Reporter = HadoopMetrics2Reporter.forRegistry(metricRegistry).convertRatesTo(TimeUnit.SECONDS).convertDurationsTo(TimeUnit.MILLISECONDS).build(// The application-level name
DefaultMetricsSystem.initialize(applicationName), // Component name
applicationName, // Component description
applicationName, // Name for each metric record
"General");
metrics2Reporter.start(reportingInterval, TimeUnit.SECONDS);
break;
}
}
}
use of com.codahale.metrics.ConsoleReporter in project opennms by OpenNMS.
the class HeartbeatSinkPerfIT method longRun.
@Ignore
public void longRun() throws Exception {
// Here we enable console logging of the metrics we gather
// To see these, you'll want to turn down the logging
// You can do this by setting the following system property
// on the JVM when running the tests:
// -Dorg.opennms.core.test.mockLogger.defaultLogLevel=WARN
ConsoleReporter reporter = ConsoleReporter.forRegistry(metrics).convertRatesTo(TimeUnit.SECONDS).convertDurationsTo(TimeUnit.MILLISECONDS).build();
try {
reporter.start(15, TimeUnit.SECONDS);
Thread.sleep(5 * 60 * 1000);
} finally {
reporter.stop();
}
}
use of com.codahale.metrics.ConsoleReporter in project opennms by OpenNMS.
the class StressCommand method doExecute.
@Override
protected Object doExecute() throws Exception {
// Create the client
final RpcClient<EchoRequest, EchoResponse> client = rpcClientFactory.getClient(EchoRpcModule.INSTANCE);
// Create metrics to capture the results
final MetricRegistry metrics = new MetricRegistry();
final Histogram responseTimes = metrics.histogram("response-times");
final Counter successes = metrics.counter("successes");
final Counter failures = metrics.counter("failures");
// Build and issue the requests
System.out.printf("Executing %d requests.\n", count);
final String message = Strings.repeat("*", messageSize);
final CountDownLatch doneSignal = new CountDownLatch(count);
long beforeExec = System.currentTimeMillis();
for (int i = 0; i < count; i++) {
client.execute(buildRequest(message)).whenComplete((r, e) -> {
if (e != null) {
failures.inc();
} else {
responseTimes.update(System.currentTimeMillis() - r.getId());
successes.inc();
}
doneSignal.countDown();
});
}
long afterExec = System.currentTimeMillis();
// Wait for the responses...
System.out.printf("Waiting for responses.\n");
while (true) {
try {
if (doneSignal.await(1, TimeUnit.SECONDS)) {
// Done!
System.out.printf("\nDone!\n");
break;
}
} catch (InterruptedException e) {
System.out.println("\nInterrupted!");
break;
}
System.out.print(".");
System.out.flush();
}
long afterResponse = System.currentTimeMillis();
System.out.println();
ConsoleReporter reporter = ConsoleReporter.forRegistry(metrics).convertRatesTo(TimeUnit.MILLISECONDS).convertDurationsTo(TimeUnit.MILLISECONDS).build();
reporter.report();
reporter.close();
System.out.printf("Total miliseconds elapsed: %d\n", afterResponse - beforeExec);
System.out.printf("Miliseconds spent generating requests: %d\n", afterExec - beforeExec);
System.out.printf("Miliseconds spent waiting for responses: %d\n", afterResponse - afterExec);
return null;
}
use of com.codahale.metrics.ConsoleReporter 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 com.codahale.metrics.ConsoleReporter in project opennms by OpenNMS.
the class StressCommand method doExecute.
@Override
protected Object doExecute() {
// Apply sane lower bounds to all of the configurable options
eventsPerSecondPerThread = Math.max(1, eventsPerSecondPerThread);
numberOfThreads = Math.max(1, numberOfThreads);
numSeconds = Math.max(1, numSeconds);
reportIntervalInSeconds = Math.max(1, reportIntervalInSeconds);
batchSize = Math.max(1, batchSize);
boolean useJexl = jexlExpressions != null && jexlExpressions.size() > 0;
// Display the effective settings and rates
double eventsPerSecond = eventsPerSecondPerThread * numberOfThreads;
System.out.printf("Generating %d events per second accross %d threads for %d seconds\n", eventsPerSecondPerThread, numberOfThreads, numSeconds);
System.out.printf("\t with UEI: %s\n", eventUei);
System.out.printf("\t with batch size: %d\n", batchSize);
System.out.printf("\t with synchronous calls: %s\n", isSynchronous);
System.out.printf("Which will yield an effective\n");
System.out.printf("\t %.2f events per second\n", eventsPerSecond);
System.out.printf("\t %.2f total events\n", eventsPerSecond * numSeconds);
if (useJexl) {
System.out.printf("Using JEXL expressions:\n");
for (String jexlExpression : jexlExpressions) {
System.out.printf("\t%s\n", jexlExpression);
}
}
// Setup the reporter
ConsoleReporter reporter = ConsoleReporter.forRegistry(metrics).convertRatesTo(TimeUnit.SECONDS).convertDurationsTo(TimeUnit.MILLISECONDS).build();
// Setup the executor
final ThreadFactory threadFactory = new ThreadFactoryBuilder().setNameFormat("Event Generator #%d").build();
final ExecutorService executor = Executors.newFixedThreadPool(numberOfThreads, threadFactory);
System.out.println("Starting.");
try {
reporter.start(reportIntervalInSeconds, TimeUnit.SECONDS);
for (int i = 0; i < numberOfThreads; i++) {
final EventGenerator eventGenerator = useJexl ? new JexlEventGenerator(jexlExpressions) : new EventGenerator();
executor.execute(eventGenerator);
}
System.out.println("Started.");
// Wait until we timeout or get interrupted
try {
Thread.sleep(SECONDS.toMillis(numSeconds));
} catch (InterruptedException e) {
}
// Stop!
try {
System.out.println("Stopping.");
executor.shutdownNow();
if (!executor.awaitTermination(2, TimeUnit.MINUTES)) {
System.err.println("The threads did not stop in time.");
} else {
System.out.println("Stopped.");
}
} catch (InterruptedException e) {
}
} finally {
// Make sure we always stop the reporter
reporter.stop();
}
// And display one last report...
reporter.report();
return null;
}
Aggregations