You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@zookeeper.apache.org by iv...@apache.org on 2013/10/29 10:08:54 UTC

svn commit: r1536616 - in /zookeeper/bookkeeper/trunk: ./ bookkeeper-stats/ bookkeeper-stats/src/ bookkeeper-stats/src/main/ bookkeeper-stats/src/main/java/ bookkeeper-stats/src/main/java/org/ bookkeeper-stats/src/main/java/org/apache/ bookkeeper-stats...

Author: ivank
Date: Tue Oct 29 09:08:54 2013
New Revision: 1536616

URL: http://svn.apache.org/r1536616
Log:
BOOKKEEPER-614: Generic stats interface, which multiple providers can be plugged into (sijie & ivank via ivank)

Added:
    zookeeper/bookkeeper/trunk/bookkeeper-stats/
    zookeeper/bookkeeper/trunk/bookkeeper-stats/pom.xml
    zookeeper/bookkeeper/trunk/bookkeeper-stats/src/
    zookeeper/bookkeeper/trunk/bookkeeper-stats/src/main/
    zookeeper/bookkeeper/trunk/bookkeeper-stats/src/main/java/
    zookeeper/bookkeeper/trunk/bookkeeper-stats/src/main/java/org/
    zookeeper/bookkeeper/trunk/bookkeeper-stats/src/main/java/org/apache/
    zookeeper/bookkeeper/trunk/bookkeeper-stats/src/main/java/org/apache/bookkeeper/
    zookeeper/bookkeeper/trunk/bookkeeper-stats/src/main/java/org/apache/bookkeeper/stats/
    zookeeper/bookkeeper/trunk/bookkeeper-stats/src/main/java/org/apache/bookkeeper/stats/Counter.java
    zookeeper/bookkeeper/trunk/bookkeeper-stats/src/main/java/org/apache/bookkeeper/stats/Gauge.java
    zookeeper/bookkeeper/trunk/bookkeeper-stats/src/main/java/org/apache/bookkeeper/stats/NullStatsLogger.java
    zookeeper/bookkeeper/trunk/bookkeeper-stats/src/main/java/org/apache/bookkeeper/stats/NullStatsProvider.java
    zookeeper/bookkeeper/trunk/bookkeeper-stats/src/main/java/org/apache/bookkeeper/stats/OpStatsData.java
    zookeeper/bookkeeper/trunk/bookkeeper-stats/src/main/java/org/apache/bookkeeper/stats/OpStatsLogger.java
    zookeeper/bookkeeper/trunk/bookkeeper-stats/src/main/java/org/apache/bookkeeper/stats/Stats.java
    zookeeper/bookkeeper/trunk/bookkeeper-stats/src/main/java/org/apache/bookkeeper/stats/StatsLogger.java
    zookeeper/bookkeeper/trunk/bookkeeper-stats/src/main/java/org/apache/bookkeeper/stats/StatsProvider.java
Modified:
    zookeeper/bookkeeper/trunk/CHANGES.txt

Modified: zookeeper/bookkeeper/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/zookeeper/bookkeeper/trunk/CHANGES.txt?rev=1536616&r1=1536615&r2=1536616&view=diff
==============================================================================
--- zookeeper/bookkeeper/trunk/CHANGES.txt (original)
+++ zookeeper/bookkeeper/trunk/CHANGES.txt Tue Oct 29 09:08:54 2013
@@ -50,6 +50,8 @@ Trunk (unreleased changes)
 
       BOOKKEEPER-605: Use static Logger objects everywhere for bookkeeper (sijie via ivank)
 
+      BOOKKEEPER-614: Generic stats interface, which multiple providers can be plugged into (sijie & ivank via ivank)
+
       bookkeeper-server:
 
         BOOKKEEPER-567: ReadOnlyBookieTest hangs on shutdown (sijie via ivank)

Added: zookeeper/bookkeeper/trunk/bookkeeper-stats/pom.xml
URL: http://svn.apache.org/viewvc/zookeeper/bookkeeper/trunk/bookkeeper-stats/pom.xml?rev=1536616&view=auto
==============================================================================
--- zookeeper/bookkeeper/trunk/bookkeeper-stats/pom.xml (added)
+++ zookeeper/bookkeeper/trunk/bookkeeper-stats/pom.xml Tue Oct 29 09:08:54 2013
@@ -0,0 +1,57 @@
+<?xml version="1.0"?>
+<!--
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to You under the Apache License, Version 2.0
+   (the "License"); you may not use this file except in compliance with
+   the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+-->
+<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
+    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+  <modelVersion>4.0.0</modelVersion>
+  <parent>
+    <artifactId>bookkeeper</artifactId>
+    <groupId>org.apache.bookkeeper</groupId>
+    <version>4.3.0-SNAPSHOT</version>
+  </parent>
+  <groupId>org.apache.bookkeeper.stats</groupId>
+  <artifactId>bookkeeper-stats-api</artifactId>
+  <name>Stats API for bookkeeper</name>
+  <url>http://maven.apache.org</url>
+  <properties>
+    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+    <project.libdir>${basedir}/lib</project.libdir>
+  </properties>
+  <dependencies>
+    <dependency>
+      <groupId>commons-configuration</groupId>
+      <artifactId>commons-configuration</artifactId>
+      <version>1.6</version>
+    </dependency>
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <version>4.8.1</version>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.slf4j</groupId>
+      <artifactId>slf4j-api</artifactId>
+      <version>1.6.4</version>
+    </dependency>
+    <dependency>
+      <groupId>org.slf4j</groupId>
+      <artifactId>slf4j-log4j12</artifactId>
+      <version>1.6.4</version>
+    </dependency>
+  </dependencies>
+</project>

Added: zookeeper/bookkeeper/trunk/bookkeeper-stats/src/main/java/org/apache/bookkeeper/stats/Counter.java
URL: http://svn.apache.org/viewvc/zookeeper/bookkeeper/trunk/bookkeeper-stats/src/main/java/org/apache/bookkeeper/stats/Counter.java?rev=1536616&view=auto
==============================================================================
--- zookeeper/bookkeeper/trunk/bookkeeper-stats/src/main/java/org/apache/bookkeeper/stats/Counter.java (added)
+++ zookeeper/bookkeeper/trunk/bookkeeper-stats/src/main/java/org/apache/bookkeeper/stats/Counter.java Tue Oct 29 09:08:54 2013
@@ -0,0 +1,50 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with this
+ * work for additional information regarding copyright ownership. The ASF
+ * licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package org.apache.bookkeeper.stats;
+
+/**
+ * Simple stats that require only increment and decrement
+ * functions on a Long. Metrics like the number of topics, persist queue size
+ * etc. should use this.
+ */
+public interface Counter {
+    /**
+     * Clear this stat.
+     */
+    public void clear();
+
+    /**
+     * Increment the value associated with this stat.
+     */
+    public void inc();
+
+    /**
+     * Decrement the value associated with this stat.
+     */
+    public void dec();
+
+    /**
+     * Add delta to the value associated with this stat.
+     * @param delta
+     */
+    public void add(long delta);
+
+    /**
+     * Get the value associated with this stat.
+     */
+    public Long get();
+}

Added: zookeeper/bookkeeper/trunk/bookkeeper-stats/src/main/java/org/apache/bookkeeper/stats/Gauge.java
URL: http://svn.apache.org/viewvc/zookeeper/bookkeeper/trunk/bookkeeper-stats/src/main/java/org/apache/bookkeeper/stats/Gauge.java?rev=1536616&view=auto
==============================================================================
--- zookeeper/bookkeeper/trunk/bookkeeper-stats/src/main/java/org/apache/bookkeeper/stats/Gauge.java (added)
+++ zookeeper/bookkeeper/trunk/bookkeeper-stats/src/main/java/org/apache/bookkeeper/stats/Gauge.java Tue Oct 29 09:08:54 2013
@@ -0,0 +1,28 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.bookkeeper.stats;
+
+/**
+ * A guage is a value that has only one value at a specific point in time.
+ * An example is the number of elements in a queue. The value of T must be
+ * some numeric type.
+ */
+public interface Gauge<T extends Number> {
+    public T getDefaultValue();
+    public T getSample();
+}

Added: zookeeper/bookkeeper/trunk/bookkeeper-stats/src/main/java/org/apache/bookkeeper/stats/NullStatsLogger.java
URL: http://svn.apache.org/viewvc/zookeeper/bookkeeper/trunk/bookkeeper-stats/src/main/java/org/apache/bookkeeper/stats/NullStatsLogger.java?rev=1536616&view=auto
==============================================================================
--- zookeeper/bookkeeper/trunk/bookkeeper-stats/src/main/java/org/apache/bookkeeper/stats/NullStatsLogger.java (added)
+++ zookeeper/bookkeeper/trunk/bookkeeper-stats/src/main/java/org/apache/bookkeeper/stats/NullStatsLogger.java Tue Oct 29 09:08:54 2013
@@ -0,0 +1,96 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with this
+ * work for additional information regarding copyright ownership. The ASF
+ * licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package org.apache.bookkeeper.stats;
+
+public class NullStatsLogger implements StatsLogger {
+
+    public static final NullStatsLogger INSTANCE = new NullStatsLogger();
+
+    static class NullOpStatsLogger implements OpStatsLogger {
+        final OpStatsData nullOpStats = new OpStatsData(0, 0, 0, new long[6]);
+
+        @Override
+        public void registerFailedEvent(long eventLatencyMillis) {
+            // nop
+        }
+
+        @Override
+        public void registerSuccessfulEvent(long eventLatencyMillis) {
+            // nop
+        }
+
+        @Override
+        public OpStatsData toOpStatsData() {
+            return nullOpStats;
+        }
+
+        @Override
+        public void clear() {
+            // nop
+        }
+    }
+    static NullOpStatsLogger nullOpStatsLogger = new NullOpStatsLogger();
+
+    static class NullCounter implements Counter {
+        @Override
+        public void clear() {
+            // nop
+        }
+
+        @Override
+        public void inc() {
+            // nop
+        }
+
+        @Override
+        public void dec() {
+            // nop
+        }
+
+        @Override
+        public void add(long delta) {
+            // nop
+        }
+
+        @Override
+        public Long get() {
+            return 0L;
+        }
+    }
+    static NullCounter nullCounter = new NullCounter();
+
+    @Override
+    public OpStatsLogger getOpStatsLogger(String name) {
+        return nullOpStatsLogger;
+    }
+
+    @Override
+    public Counter getCounter(String name) {
+        return nullCounter;
+    }
+
+    @Override
+    public <T extends Number> void registerGauge(String name, Gauge<T> gauge) {
+        // nop
+    }
+
+    @Override
+    public StatsLogger scope(String name) {
+        return this;
+    }
+
+}

Added: zookeeper/bookkeeper/trunk/bookkeeper-stats/src/main/java/org/apache/bookkeeper/stats/NullStatsProvider.java
URL: http://svn.apache.org/viewvc/zookeeper/bookkeeper/trunk/bookkeeper-stats/src/main/java/org/apache/bookkeeper/stats/NullStatsProvider.java?rev=1536616&view=auto
==============================================================================
--- zookeeper/bookkeeper/trunk/bookkeeper-stats/src/main/java/org/apache/bookkeeper/stats/NullStatsProvider.java (added)
+++ zookeeper/bookkeeper/trunk/bookkeeper-stats/src/main/java/org/apache/bookkeeper/stats/NullStatsProvider.java Tue Oct 29 09:08:54 2013
@@ -0,0 +1,40 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with this
+ * work for additional information regarding copyright ownership. The ASF
+ * licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package org.apache.bookkeeper.stats;
+
+import org.apache.commons.configuration.Configuration;
+
+public class NullStatsProvider implements StatsProvider {
+
+    final StatsLogger nullStatsLogger = new NullStatsLogger();
+
+    @Override
+    public void start(Configuration conf) {
+        // nop
+    }
+
+    @Override
+    public void stop() {
+        // nop
+    }
+
+    @Override
+    public StatsLogger getStatsLogger(String scope) {
+        return nullStatsLogger;
+    }
+
+}

Added: zookeeper/bookkeeper/trunk/bookkeeper-stats/src/main/java/org/apache/bookkeeper/stats/OpStatsData.java
URL: http://svn.apache.org/viewvc/zookeeper/bookkeeper/trunk/bookkeeper-stats/src/main/java/org/apache/bookkeeper/stats/OpStatsData.java?rev=1536616&view=auto
==============================================================================
--- zookeeper/bookkeeper/trunk/bookkeeper-stats/src/main/java/org/apache/bookkeeper/stats/OpStatsData.java (added)
+++ zookeeper/bookkeeper/trunk/bookkeeper-stats/src/main/java/org/apache/bookkeeper/stats/OpStatsData.java Tue Oct 29 09:08:54 2013
@@ -0,0 +1,76 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with this
+ * work for additional information regarding copyright ownership. The ASF
+ * licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package org.apache.bookkeeper.stats;
+
+import java.util.Arrays;
+
+/**
+ * This class provides a read view of operation specific stats.
+ * We expose this to JMX.
+ * We use primitives because the class has to conform to CompositeViewData.
+ */
+public class OpStatsData {
+    private final long numSuccessfulEvents, numFailedEvents;
+    // All latency values are in Milliseconds.
+    private final double avgLatencyMillis;
+    // 10.0 50.0, 90.0, 99.0, 99.9, 99.99 in that order.
+    // TODO(Aniruddha): Figure out if we can use a Map
+    private final long[] percentileLatenciesMillis;
+    public OpStatsData (long numSuccessfulEvents, long numFailedEvents,
+                        double avgLatencyMillis, long[] percentileLatenciesMillis) {
+        this.numSuccessfulEvents = numSuccessfulEvents;
+        this.numFailedEvents = numFailedEvents;
+        this.avgLatencyMillis = avgLatencyMillis;
+        this.percentileLatenciesMillis =
+            Arrays.copyOf(percentileLatenciesMillis, percentileLatenciesMillis.length);
+    }
+
+    public long getP10Latency() {
+        return this.percentileLatenciesMillis[0];
+    }
+    public long getP50Latency() {
+        return this.percentileLatenciesMillis[1];
+    }
+
+    public long getP90Latency() {
+        return this.percentileLatenciesMillis[2];
+    }
+
+    public long getP99Latency() {
+        return this.percentileLatenciesMillis[3];
+    }
+
+    public long getP999Latency() {
+        return this.percentileLatenciesMillis[4];
+    }
+
+    public long getP9999Latency() {
+        return this.percentileLatenciesMillis[5];
+    }
+
+    public long getNumSuccessfulEvents() {
+        return this.numSuccessfulEvents;
+    }
+
+    public long getNumFailedEvents() {
+        return this.numFailedEvents;
+    }
+
+    public double getAvgLatencyMillis() {
+        return this.avgLatencyMillis;
+    }
+}

Added: zookeeper/bookkeeper/trunk/bookkeeper-stats/src/main/java/org/apache/bookkeeper/stats/OpStatsLogger.java
URL: http://svn.apache.org/viewvc/zookeeper/bookkeeper/trunk/bookkeeper-stats/src/main/java/org/apache/bookkeeper/stats/OpStatsLogger.java?rev=1536616&view=auto
==============================================================================
--- zookeeper/bookkeeper/trunk/bookkeeper-stats/src/main/java/org/apache/bookkeeper/stats/OpStatsLogger.java (added)
+++ zookeeper/bookkeeper/trunk/bookkeeper-stats/src/main/java/org/apache/bookkeeper/stats/OpStatsLogger.java Tue Oct 29 09:08:54 2013
@@ -0,0 +1,49 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with this
+ * work for additional information regarding copyright ownership. The ASF
+ * licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package org.apache.bookkeeper.stats;
+
+/**
+ * This interface handles logging of statistics related to each operation (PUBLISH,
+ * CONSUME etc.)
+ */
+public interface OpStatsLogger {
+
+    /**
+     * Increment the failed op counter with the given eventLatencyMillis.
+     * @param eventLatencyMillis The event latency in milliseconds.
+     */
+    public void registerFailedEvent(long eventLatencyMillis);
+
+    /**
+     * An operation succeeded with the given eventLatencyMillis. Update
+     * stats to reflect the same
+     * @param eventLatencyMillis The event latency in milliseconds.
+     */
+    public void registerSuccessfulEvent(long eventLatencyMillis);
+
+    /**
+     * @return Returns an OpStatsData object with necessary values. We need this function
+     * to support JMX exports. This should be deprecated sometime in the near future.
+     * populated.
+     */
+    public OpStatsData toOpStatsData();
+
+    /**
+     * Clear stats for this operation.
+     */
+    public void clear();
+}

Added: zookeeper/bookkeeper/trunk/bookkeeper-stats/src/main/java/org/apache/bookkeeper/stats/Stats.java
URL: http://svn.apache.org/viewvc/zookeeper/bookkeeper/trunk/bookkeeper-stats/src/main/java/org/apache/bookkeeper/stats/Stats.java?rev=1536616&view=auto
==============================================================================
--- zookeeper/bookkeeper/trunk/bookkeeper-stats/src/main/java/org/apache/bookkeeper/stats/Stats.java (added)
+++ zookeeper/bookkeeper/trunk/bookkeeper-stats/src/main/java/org/apache/bookkeeper/stats/Stats.java Tue Oct 29 09:08:54 2013
@@ -0,0 +1,63 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.apache.bookkeeper.stats;
+
+import org.apache.commons.configuration.Configuration;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
+
+public class Stats {
+    static final Logger LOG = LoggerFactory.getLogger(Stats.class);
+    public final static String STATS_PROVIDER_CLASS = "statsProviderClass";
+
+    static StatsProvider prov = new NullStatsProvider();
+
+    public static void loadStatsProvider(Configuration conf) {
+        String className = conf.getString(STATS_PROVIDER_CLASS);
+        if (className != null) {
+            try {
+                Class cls = Class.forName(className);
+                @SuppressWarnings("unchecked")
+                Constructor<? extends StatsProvider> cons =
+                    (Constructor<? extends StatsProvider>)cls.getDeclaredConstructor();
+                prov = cons.newInstance();
+            } catch (ClassNotFoundException cnfe) {
+                LOG.error("Couldn't find configured class(" + className +")", cnfe);
+            } catch (NoSuchMethodException nsme) {
+                LOG.error("Couldn't find default constructor for class (" + className + ")", nsme);
+            } catch (InstantiationException ie) {
+                LOG.error("Couldn't construct class (" + className + ")", ie);
+            } catch (IllegalAccessException iae) {
+                LOG.error("Couldn't construct class (" + className + "),"
+                          + " Is the constructor private?", iae);
+            } catch (InvocationTargetException ite) {
+                LOG.error("Constructor threw an exception. It should not have.", ite);
+            }
+        }
+    }
+
+    public static StatsProvider get() {
+        return prov;
+    }
+}

Added: zookeeper/bookkeeper/trunk/bookkeeper-stats/src/main/java/org/apache/bookkeeper/stats/StatsLogger.java
URL: http://svn.apache.org/viewvc/zookeeper/bookkeeper/trunk/bookkeeper-stats/src/main/java/org/apache/bookkeeper/stats/StatsLogger.java?rev=1536616&view=auto
==============================================================================
--- zookeeper/bookkeeper/trunk/bookkeeper-stats/src/main/java/org/apache/bookkeeper/stats/StatsLogger.java (added)
+++ zookeeper/bookkeeper/trunk/bookkeeper-stats/src/main/java/org/apache/bookkeeper/stats/StatsLogger.java Tue Oct 29 09:08:54 2013
@@ -0,0 +1,55 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with this
+ * work for additional information regarding copyright ownership. The ASF
+ * licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package org.apache.bookkeeper.stats;
+
+/**
+ * A simple interface that exposes just 2 useful methods. One to get the logger for an Op stat
+ * and another to get the logger for a simple stat
+ */
+public interface StatsLogger {
+    /**
+     * @param name
+     *          Stats Name
+     * @return Get the logger for an OpStat described by the <i>name</i>.
+     */
+    public OpStatsLogger getOpStatsLogger(String name);
+
+    /**
+     * @param name
+     *          Stats Name
+     * @return Get the logger for a simple stat described by the <i>name</i>
+     */
+    public Counter getCounter(String name);
+
+    /**
+     * Register given <i>guage</i> as name <i>name</i>.
+     *
+     * @param name
+     *          gauge name
+     */
+    public <T extends Number> void registerGauge(String name, Gauge<T> gauge);
+
+    /**
+     * Provide the stats logger under scope <i>name</i>.
+     *
+     * @param name
+     *          scope name.
+     * @return stats logger under scope <i>name</i>.
+     */
+    public StatsLogger scope(String name);
+
+}

Added: zookeeper/bookkeeper/trunk/bookkeeper-stats/src/main/java/org/apache/bookkeeper/stats/StatsProvider.java
URL: http://svn.apache.org/viewvc/zookeeper/bookkeeper/trunk/bookkeeper-stats/src/main/java/org/apache/bookkeeper/stats/StatsProvider.java?rev=1536616&view=auto
==============================================================================
--- zookeeper/bookkeeper/trunk/bookkeeper-stats/src/main/java/org/apache/bookkeeper/stats/StatsProvider.java (added)
+++ zookeeper/bookkeeper/trunk/bookkeeper-stats/src/main/java/org/apache/bookkeeper/stats/StatsProvider.java Tue Oct 29 09:08:54 2013
@@ -0,0 +1,45 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with this
+ * work for additional information regarding copyright ownership. The ASF
+ * licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package org.apache.bookkeeper.stats;
+
+import org.apache.commons.configuration.Configuration;
+
+/**
+ * Provider to provide stats logger for different scopes.
+ */
+public interface StatsProvider {
+    /**
+     * Intialize the stats provider by loading the given configuration <i>conf</i>.
+     *
+     * @param conf
+     *          Configuration to configure the stats provider.
+     */
+    public void start(Configuration conf);
+
+    /**
+     * Close the stats provider
+     */
+    public void stop();
+
+    /**
+     * Return the stats logger to a given <i>scope</i>
+     * @param scope
+     *          Scope for the given stats
+     * @return stats logger for the given <i>scope</i>
+     */
+    public StatsLogger getStatsLogger(String scope);
+}