/** * @see org.jboss.msc.value.Value#getValue() */ @Override public RepositoryMonitor getValue() throws IllegalStateException, IllegalArgumentException { try { return this.repoInjector.getValue().getRepositoryStatistics(); } catch (Exception e) { // nothing to do } return RepositoryMonitor.EMPTY_MONITOR; }
protected final RepositoryStatistics statistics() { return session.repository().getRepositoryStatistics(); }
protected final RepositoryStatistics statistics() { return session.repository().getRepositoryStatistics(); }
@Override public void run() { System.out.println("Starting ..."); sw.start(); int counter = 0; while (!stop.get()) { try { Thread.sleep(MILLISECONDS.convert(10, SECONDS)); if (!stop.get()) { ++counter; sw.lap(); System.out.println(" continuing after " + sw.getTotalDuration().toSimpleString()); } if (counter % 24 == 0) { History history = repository.getRepositoryStatistics().getHistory(ValueMetric.SESSION_COUNT, Window.PREVIOUS_60_SECONDS); System.out.println(history); } } catch (Throwable t) { t.printStackTrace(); stop.set(true); break; } } } });
@Test public void shouldProvideStatisticsImmediatelyAfterStartup() throws Exception { History history = repository.getRepositoryStatistics() .getHistory(ValueMetric.WORKSPACE_COUNT, Window.PREVIOUS_60_SECONDS); Statistics[] stats = history.getStats(); assertThat(stats.length, is(not(0))); assertThat(history.getTotalDuration(TimeUnit.SECONDS), is(60L)); System.out.println(history); }
Thread.sleep(1000L); History history = repository.getRepositoryStatistics().getHistory(ValueMetric.SESSION_COUNT, Window.PREVIOUS_60_SECONDS); Statistics[] stats = history.getStats(); assertThat(stats.length, is(12)); System.out.println(history); DurationActivity[] lifetimes = repository.getRepositoryStatistics().getLongestRunning(DurationMetric.SESSION_LIFETIME); System.out.println("Session lifetimes: "); for (DurationActivity activity : lifetimes) {
/** * Skipping this test because it purposefully runs over 6 seconds, mostly just waiting for the statistics thread to wake up * once every 5 seconds. * * @throws Exception */ @Ignore @Test public void shouldProvideStatistics() throws Exception { for (int i = 0; i != 3; ++i) { JcrSession session1 = repository.login(); assertThat(session1.getRootNode(), is(notNullValue())); } // wait for 6 seconds, so that the statistics have a value ... Thread.sleep(6000L); History history = repository.getRepositoryStatistics().getHistory(ValueMetric.SESSION_COUNT, Window.PREVIOUS_60_SECONDS); Statistics[] stats = history.getStats(); assertThat(stats.length, is(12)); assertThat(stats[0], is(nullValue())); assertThat(stats[11], is(notNullValue())); assertThat(stats[11].getMaximum(), is(3L)); assertThat(stats[11].getMinimum(), is(3L)); assertThat(history.getTotalDuration(TimeUnit.SECONDS), is(60L)); System.out.println(history); }
Thread.sleep(MILLISECONDS.convert(5, SECONDS)); History history = repository.getRepositoryStatistics().getHistory(ValueMetric.SESSION_COUNT, Window.PREVIOUS_60_MINUTES); Statistics[] stats = history.getStats(); System.out.println(history); assertThat(history.getTotalDuration(TimeUnit.MINUTES), is(60L)); history = repository.getRepositoryStatistics().getHistory(ValueMetric.SESSION_COUNT, Window.PREVIOUS_60_SECONDS); stats = history.getStats(); System.out.println(history); assertThat(history.getTotalDuration(TimeUnit.SECONDS), is(60L)); history = repository.getRepositoryStatistics().getHistory(ValueMetric.SESSION_COUNT, Window.PREVIOUS_24_HOURS); stats = history.getStats(); System.out.println(history);