Search in sources :

Example 1 with RepositoryStatistics

use of org.apache.jackrabbit.api.stats.RepositoryStatistics in project jackrabbit by apache.

the class StatisticsServlet method doGet.

@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    String klass = RepositoryContext.class.getName();
    String name = getServletConfig().getInitParameter(klass);
    if (name == null) {
        name = klass;
    }
    RepositoryContext context = (RepositoryContext) getServletContext().getAttribute(name);
    if (context != null) {
        RepositoryStatistics statistics = context.getRepositoryStatistics();
        response.setContentType("application/json");
        Writer writer = response.getWriter();
        writer.write('{');
        write(writer, "read", statistics.getTimeSeries(RepositoryStatistics.Type.SESSION_READ_COUNTER));
        writer.write(',');
        write(writer, "write", statistics.getTimeSeries(RepositoryStatistics.Type.SESSION_WRITE_COUNTER));
        writer.write(',');
        write(writer, "login", statistics.getTimeSeries(RepositoryStatistics.Type.SESSION_LOGIN_COUNTER));
        writer.write('}');
    } else {
        response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Jackrabbit repository internals are not available");
    }
}
Also used : RepositoryContext(org.apache.jackrabbit.core.RepositoryContext) RepositoryStatistics(org.apache.jackrabbit.api.stats.RepositoryStatistics) Writer(java.io.Writer)

Example 2 with RepositoryStatistics

use of org.apache.jackrabbit.api.stats.RepositoryStatistics in project jackrabbit-oak by apache.

the class SimpleStatsTest method noopRepoStatsTest.

@Test
public void noopRepoStatsTest() throws Exception {
    RepositoryStatistics stats = StatisticsProvider.NOOP.getStats();
    assertNotNull(stats);
    assertNotNull(stats.getTimeSeries("foo", false));
    assertNotNull(stats.getTimeSeries(RepositoryStatistics.Type.QUERY_COUNT));
    TimeSeries ts = stats.getTimeSeries("foo", false);
    assertNotNull(ts.getValuePerHour());
    assertNotNull(ts.getValuePerMinute());
    assertNotNull(ts.getValuePerSecond());
    assertNotNull(ts.getValuePerWeek());
    assertEquals(0, ts.getMissingValue());
}
Also used : TimeSeries(org.apache.jackrabbit.api.stats.TimeSeries) RepositoryStatistics(org.apache.jackrabbit.api.stats.RepositoryStatistics) Test(org.junit.Test)

Aggregations

RepositoryStatistics (org.apache.jackrabbit.api.stats.RepositoryStatistics)2 Writer (java.io.Writer)1 TimeSeries (org.apache.jackrabbit.api.stats.TimeSeries)1 RepositoryContext (org.apache.jackrabbit.core.RepositoryContext)1 Test (org.junit.Test)1