Hi Team,

Reviving the old thread [1] around introducing an API to collect
Metric data using Metric library [2].

Recently as part of OAK-3814 in Jackrabbit Oak we added support for
collecting important runtime performance data using the Metric library
and it looks useful. Based on that experience I think it would be good
to have a similar API in Sling also. I have done initial
implementation at [3] which provides a simple wrapper API over Metrics
library

Design Points
==========

1. Expose the sub set of Metric API which is useful for majority code
which just need to collect data - Metric API has both data collection
and data reporting api. Former is the one which would be used by
majority of code while later is used only for tooling. So the api
proposed in [3] is subset of Metric API

2. Provide a NOOP implementation so as to make Metric integration
optional - As the new Metrics support would be getting used in core
areas of Sling which so far do not have any dependency. It should be
possible to have a simple NOOP implementation which can be inlined
into using bundle (if required). It would also allow us to turn of
Metric integration easily so as to access impact of monitoring (if
any/or if it gives problem)

3. WebConsole Integration - Metric bundle exposes a WebConsole plugin
[4] and printer to dump all metric data in a single place

4. Support for Adapting to underlying Metric instance - One can access
the Metric instance if required

TODO
======

1. Have TimeSeries support - Would be good to have something similar
to Jackrabbit TimeSeries [6] in Sling. It would allow us to view the
data as it updated in time. This can be easily plugged in later with
current design

Usage
=====

API is very much similar to [5]

---------------------------------------------------------------------------

import org.apache.sling.metrics.Counter;
import org.apache.sling.metrics.MetricsService;

@Reference
private MetricsService metricsService;

private Counter counter;

@Activate
private void activate(){
    counter = metricsService.counter("sessionCounter");
}

public void onSessionCreation(){
    counter.inc();
}
---------------------------------------------------------------------------

1. Get a reference to MetricsService
2. Initialize the require Meter e.g. Counter in above case
3. Make use of Meter to capture require stats

Kindly provide your feedback here or in SLING-4080!

Also should we move the code now to commons from whiteboard?

Chetan Mehrotra
[1] http://markmail.org/thread/cyjc2v34l3lxrtxb
[2] http://metrics.dropwizard.io/
[3] 
https://svn.apache.org/repos/asf/sling/whiteboard/chetanm/metrics/src/main/java/org/apache/sling/metrics/
[4] 
https://issues.apache.org/jira/secure/attachment/12780565/metric-web-console.png
[5] http://metrics.dropwizard.io/3.1.0/getting-started/#counters
[6] 
https://github.com/apache/jackrabbit/blob/trunk/jackrabbit-api/src/main/java/org/apache/jackrabbit/api/stats/TimeSeries.java

Reply via email to