use of com.codahale.metrics.ConsoleReporter in project opennms by OpenNMS.
the class StressCommand method execute.
@Override
public Object execute() 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 execute.
@Override
public Object execute() {
// 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 = (double) eventsPerSecondPerThread * (double) 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;
}
use of com.codahale.metrics.ConsoleReporter in project libresonic by Libresonic.
the class MediaScannerServiceTestCase method testScanLibrary.
/**
* Tests the MediaScannerService by scanning the test media library into an empty database.
*/
@Test
public void testScanLibrary() {
MusicFolderTestData.getTestMusicFolders().forEach(musicFolderDao::createMusicFolder);
settingsService.clearMusicFolderCache();
Timer globalTimer = metrics.timer(MetricRegistry.name(MediaScannerServiceTestCase.class, "Timer.global"));
Timer.Context globalTimerContext = globalTimer.time();
TestCaseUtils.execScan(mediaScannerService);
globalTimerContext.stop();
System.out.println("--- Report of records count per table ---");
Map<String, Integer> records = TestCaseUtils.recordsInAllTables(daoHelper);
records.keySet().forEach(tableName -> System.out.println(tableName + " : " + records.get(tableName).toString()));
System.out.println("--- *********************** ---");
// Music Folder Music must have 3 children
List<MediaFile> listeMusicChildren = mediaFileDao.getChildrenOf(MusicFolderTestData.resolveMusicFolderPath());
Assert.assertEquals(3, listeMusicChildren.size());
// Music Folder Music2 must have 1 children
List<MediaFile> listeMusic2Children = mediaFileDao.getChildrenOf(MusicFolderTestData.resolveMusic2FolderPath());
Assert.assertEquals(1, listeMusic2Children.size());
System.out.println("--- List of all artists ---");
System.out.println("artistName#albumCount");
List<Artist> allArtists = artistDao.getAlphabetialArtists(0, 0, musicFolderDao.getAllMusicFolders());
allArtists.forEach(artist -> System.out.println(artist.getName() + "#" + artist.getAlbumCount()));
System.out.println("--- *********************** ---");
System.out.println("--- List of all albums ---");
System.out.println("name#artist");
List<Album> allAlbums = albumDao.getAlphabetialAlbums(0, 0, true, musicFolderDao.getAllMusicFolders());
allAlbums.forEach(album -> System.out.println(album.getName() + "#" + album.getArtist()));
Assert.assertEquals(5, allAlbums.size());
System.out.println("--- *********************** ---");
List<MediaFile> listeSongs = mediaFileDao.getSongsByGenre("Baroque Instrumental", 0, 0, musicFolderDao.getAllMusicFolders());
Assert.assertEquals(2, listeSongs.size());
// display out metrics report
ConsoleReporter reporter = ConsoleReporter.forRegistry(metrics).convertRatesTo(TimeUnit.SECONDS.SECONDS).convertDurationsTo(TimeUnit.MILLISECONDS).build();
reporter.report();
System.out.print("End");
}
use of com.codahale.metrics.ConsoleReporter in project selenium_java by sergueik.
the class WholeSuiteListener method testRunFinished.
@Override
public void testRunFinished(Result result) throws Exception {
super.testRunFinished(result);
final ConsoleReporter reporter = ConsoleReporter.forRegistry(codahaleMetricsMonitor.getMetrics()).convertRatesTo(TimeUnit.MILLISECONDS).convertDurationsTo(TimeUnit.MILLISECONDS).outputTo(System.out).build();
reporter.report();
}
use of com.codahale.metrics.ConsoleReporter in project copper-cms by PogeyanOSS.
the class AkkaServletContextListener method contextInitialized.
@Override
public void contextInitialized(ServletContextEvent sce) {
ActorSystem system = ActorSystem.create("GatewaySystem");
sce.getServletContext().setAttribute("ActorSystem", system);
String configFilename = sce.getServletContext().getInitParameter(CONFIG_INIT_PARAM);
if (configFilename == null) {
configFilename = CONFIG_FILENAME;
}
DatabaseServiceFactory.add(MongoClientFactory.createDatabaseService());
LOG.info("Registering actors to main actor system");
system.actorOf(Props.create(GatewayActor.class), "gateway");
system.actorOf(Props.create(LoginActor.class), "login");
system.actorOf(Props.create(RepositoryActor.class), "repository");
system.actorOf(Props.create(ObjectActor.class), "object");
system.actorOf(Props.create(NavigationActor.class), "navigation");
system.actorOf(Props.create(RelationshipActor.class), "relationships");
system.actorOf(Props.create(PolicyActor.class), "policy");
system.actorOf(Props.create(VersioningActor.class), "versioning");
system.actorOf(Props.create(AclActor.class), "acl");
system.actorOf(Props.create(DiscoveryActor.class), "discovery");
LOG.info("Initializing service factory instances");
try {
boolean factory = createServiceFactory(sce, configFilename);
if (!factory) {
throw new IllegalArgumentException("Repository manager class not initilaized");
}
} catch (Exception e) {
LOG.error("Service factory couldn't be created: {}", e.toString(), e);
}
if (externalActorClassMap != null && !externalActorClassMap.isEmpty()) {
externalActorClassMap.forEach((key, value) -> system.actorOf(Props.create(key), value));
}
if (Helpers.isPerfMode()) {
ConsoleReporter reporter = ConsoleReporter.forRegistry(MetricsInputs.get().getMetrics()).convertRatesTo(TimeUnit.SECONDS).convertDurationsTo(TimeUnit.MILLISECONDS).build();
reporter.start(10, TimeUnit.SECONDS);
if (Helpers.isPrometheusMode()) {
MetricsInputs.collectorRegistry().register(new DropwizardExports(MetricsInputs.get().getMetrics()));
}
}
}
Aggregations