You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by am...@apache.org on 2014/09/22 06:41:28 UTC

svn commit: r1626667 - in /sling/whiteboard/amitgupt: ./ monitoring/ monitoring/src/ monitoring/src/main/ monitoring/src/main/java/ monitoring/src/main/java/org/ monitoring/src/main/java/org/apache/ monitoring/src/main/java/org/apache/sling/ monitoring...

Author: amitgupt
Date: Mon Sep 22 04:41:28 2014
New Revision: 1626667

URL: http://svn.apache.org/r1626667
Log:
Sling Monitoring API (First Cut)

Added:
    sling/whiteboard/amitgupt/
    sling/whiteboard/amitgupt/monitoring/
    sling/whiteboard/amitgupt/monitoring/pom.xml
    sling/whiteboard/amitgupt/monitoring/src/
    sling/whiteboard/amitgupt/monitoring/src/main/
    sling/whiteboard/amitgupt/monitoring/src/main/java/
    sling/whiteboard/amitgupt/monitoring/src/main/java/org/
    sling/whiteboard/amitgupt/monitoring/src/main/java/org/apache/
    sling/whiteboard/amitgupt/monitoring/src/main/java/org/apache/sling/
    sling/whiteboard/amitgupt/monitoring/src/main/java/org/apache/sling/monitoring/
    sling/whiteboard/amitgupt/monitoring/src/main/java/org/apache/sling/monitoring/api/
    sling/whiteboard/amitgupt/monitoring/src/main/java/org/apache/sling/monitoring/api/Counter.java
    sling/whiteboard/amitgupt/monitoring/src/main/java/org/apache/sling/monitoring/api/Gauge.java
    sling/whiteboard/amitgupt/monitoring/src/main/java/org/apache/sling/monitoring/api/Meter.java
    sling/whiteboard/amitgupt/monitoring/src/main/java/org/apache/sling/monitoring/api/Metrics.java
    sling/whiteboard/amitgupt/monitoring/src/main/java/org/apache/sling/monitoring/api/Timer.java
    sling/whiteboard/amitgupt/monitoring/src/main/java/org/apache/sling/monitoring/api/package-info.java
    sling/whiteboard/amitgupt/monitoring/src/main/java/org/apache/sling/monitoring/impl/
    sling/whiteboard/amitgupt/monitoring/src/main/java/org/apache/sling/monitoring/impl/MetricsFactory.java
    sling/whiteboard/amitgupt/monitoring/src/main/java/org/apache/sling/monitoring/impl/MetricsInternal.java
    sling/whiteboard/amitgupt/monitoring/src/main/java/org/apache/sling/monitoring/impl/noop/
    sling/whiteboard/amitgupt/monitoring/src/main/java/org/apache/sling/monitoring/impl/noop/NoopMetricRegistry.java
    sling/whiteboard/amitgupt/monitoring/src/main/java/org/apache/sling/monitoring/spi/
    sling/whiteboard/amitgupt/monitoring/src/main/java/org/apache/sling/monitoring/spi/MetricRegistry.java
    sling/whiteboard/amitgupt/monitoring/src/main/java/org/apache/sling/monitoring/spi/MetricRegistryFactory.java
    sling/whiteboard/amitgupt/monitoring/src/main/java/org/apache/sling/monitoring/spi/package-info.java

Added: sling/whiteboard/amitgupt/monitoring/pom.xml
URL: http://svn.apache.org/viewvc/sling/whiteboard/amitgupt/monitoring/pom.xml?rev=1626667&view=auto
==============================================================================
--- sling/whiteboard/amitgupt/monitoring/pom.xml (added)
+++ sling/whiteboard/amitgupt/monitoring/pom.xml Mon Sep 22 04:41:28 2014
@@ -0,0 +1,85 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+    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 xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+
+<modelVersion>4.0.0</modelVersion>
+
+  <parent>
+    <groupId>org.apache.sling</groupId>
+    <artifactId>sling</artifactId>
+    <version>20</version>
+  </parent>
+
+  <artifactId>org.apache.sling.monitoring</artifactId>
+  <packaging>bundle</packaging>
+  <version>1.0.0-SNAPSHOT</version>
+
+  <name>Apache Sling Monitoring</name>
+  <description>
+    Provides Monitoring Api for instrumenting sling application
+  </description>
+
+
+  <build>
+    <plugins>
+        <plugin>
+            <groupId>org.apache.felix</groupId>
+            <artifactId>maven-scr-plugin</artifactId>
+        </plugin>
+        <plugin>
+            <groupId>org.apache.felix</groupId>
+            <artifactId>maven-bundle-plugin</artifactId>
+            <extensions>true</extensions>
+        </plugin>
+    </plugins>
+  </build>
+
+  <dependencies>
+      <dependency>
+           <groupId>org.apache.sling</groupId>
+           <artifactId>org.apache.sling.commons.osgi</artifactId>
+           <version>2.2.0</version>
+      </dependency>
+      <dependency>
+          <groupId>org.slf4j</groupId>
+          <artifactId>slf4j-api</artifactId>
+          <scope>provided</scope>
+      </dependency>
+      <dependency>
+          <groupId>org.osgi</groupId>
+          <artifactId>org.osgi.core</artifactId>
+          <version>4.2.0</version>
+          <scope>provided</scope>
+      </dependency>
+      <dependency>
+          <groupId>org.osgi</groupId>
+          <artifactId>org.osgi.compendium</artifactId>
+          <version>4.2.0</version>
+          <scope>provided</scope>
+      </dependency>
+      <dependency>
+          <groupId>commons-lang</groupId>
+          <artifactId>commons-lang</artifactId>
+          <version>2.4</version>
+          <scope>provided</scope>
+      </dependency>
+  </dependencies>
+
+</project>
\ No newline at end of file

Added: sling/whiteboard/amitgupt/monitoring/src/main/java/org/apache/sling/monitoring/api/Counter.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/amitgupt/monitoring/src/main/java/org/apache/sling/monitoring/api/Counter.java?rev=1626667&view=auto
==============================================================================
--- sling/whiteboard/amitgupt/monitoring/src/main/java/org/apache/sling/monitoring/api/Counter.java (added)
+++ sling/whiteboard/amitgupt/monitoring/src/main/java/org/apache/sling/monitoring/api/Counter.java Mon Sep 22 04:41:28 2014
@@ -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.sling.monitoring.api;
+
+import aQute.bnd.annotation.ProviderType;
+
+/**
+ * An incrementing and decrementing counter.
+ */
+@ProviderType
+public interface Counter {
+    /**
+     * Returns the counter's current value.
+     *
+     * @return the counter's current value
+     */
+    long getCount();
+    /**
+     * Increment the counter by one.
+     */
+    void increment();
+    /**
+     * decrement the counter by one.
+     */
+    void decrement();
+}

Added: sling/whiteboard/amitgupt/monitoring/src/main/java/org/apache/sling/monitoring/api/Gauge.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/amitgupt/monitoring/src/main/java/org/apache/sling/monitoring/api/Gauge.java?rev=1626667&view=auto
==============================================================================
--- sling/whiteboard/amitgupt/monitoring/src/main/java/org/apache/sling/monitoring/api/Gauge.java (added)
+++ sling/whiteboard/amitgupt/monitoring/src/main/java/org/apache/sling/monitoring/api/Gauge.java Mon Sep 22 04:41:28 2014
@@ -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.sling.monitoring.api;
+
+import aQute.bnd.annotation.ConsumerType;
+
+/**
+ * A Gauge has an instantaneous value that can be queried by the monitoring
+ * subsystem on demand. If the value of the gauge cannot be provided in < 1ms,
+ * the gauge must specify a TTL > 0 which is the time the value is valid for.
+ * The more expensive the value is to create, the longer the TTL value should
+ * be. TTL is measured in seconds. Assume that 100s of request per second could
+ * be made to a Gauge implementation if the TTL is < 0.
+ * 
+ * @param <T>
+ */
+@ConsumerType
+public interface Gauge<T> {
+
+    /**
+     * @return the value of the gauge.
+     */
+    T getValue();
+
+    /**
+     * @return the number of seconds the value will be valid for. < 0 means no
+     *         caching of the value is allowed.
+     */
+    long getTTL();
+}

Added: sling/whiteboard/amitgupt/monitoring/src/main/java/org/apache/sling/monitoring/api/Meter.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/amitgupt/monitoring/src/main/java/org/apache/sling/monitoring/api/Meter.java?rev=1626667&view=auto
==============================================================================
--- sling/whiteboard/amitgupt/monitoring/src/main/java/org/apache/sling/monitoring/api/Meter.java (added)
+++ sling/whiteboard/amitgupt/monitoring/src/main/java/org/apache/sling/monitoring/api/Meter.java Mon Sep 22 04:41:28 2014
@@ -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.sling.monitoring.api;
+
+import aQute.bnd.annotation.ProviderType;
+
+/**
+ * A meter which measures mean throughput of events.
+ */
+@ProviderType
+public interface Meter {
+    /**
+     * Mark the occurrence of a an events.
+     */
+    void mark();
+    /**
+     * Mark the occurrence of a given number of events.
+     *
+     * @param n the number of events
+     */
+    void mark(long n);
+
+    /**
+     * Returns the number of events which have been marked.
+     *
+     * @return the number of events which have been marked
+     */
+    long getCount();
+    /**
+     * Returns the mean rate at which events have occurred since the meter was created.
+     *
+     * @return the mean rate at which events have occurred since the meter was created
+     */
+    double getMeanRate();
+}

Added: sling/whiteboard/amitgupt/monitoring/src/main/java/org/apache/sling/monitoring/api/Metrics.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/amitgupt/monitoring/src/main/java/org/apache/sling/monitoring/api/Metrics.java?rev=1626667&view=auto
==============================================================================
--- sling/whiteboard/amitgupt/monitoring/src/main/java/org/apache/sling/monitoring/api/Metrics.java (added)
+++ sling/whiteboard/amitgupt/monitoring/src/main/java/org/apache/sling/monitoring/api/Metrics.java Mon Sep 22 04:41:28 2014
@@ -0,0 +1,32 @@
+/*
+ * 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.sling.monitoring.api;
+
+import aQute.bnd.annotation.ProviderType;
+import org.apache.sling.monitoring.impl.MetricsInternal;
+
+/**
+ * A static Metrics class. Any objects returned from this class must not be
+ * referenced directly by the calling class on the heap. The lifetime of
+ * references on the stack should be limited.
+ *
+ * A Metrics instance is backed up by <code>MetricRegistry</code> that provides required functionality.
+ */
+@ProviderType
+public class Metrics extends MetricsInternal {
+}

Added: sling/whiteboard/amitgupt/monitoring/src/main/java/org/apache/sling/monitoring/api/Timer.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/amitgupt/monitoring/src/main/java/org/apache/sling/monitoring/api/Timer.java?rev=1626667&view=auto
==============================================================================
--- sling/whiteboard/amitgupt/monitoring/src/main/java/org/apache/sling/monitoring/api/Timer.java (added)
+++ sling/whiteboard/amitgupt/monitoring/src/main/java/org/apache/sling/monitoring/api/Timer.java Mon Sep 22 04:41:28 2014
@@ -0,0 +1,39 @@
+/*
+ * 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.sling.monitoring.api;
+
+import aQute.bnd.annotation.ProviderType;
+
+/**
+ * A timer allows time of an operation to be measured and recorded with metrics.
+ * It is create kept and stopped. Once stopped all references to the timer
+ * should be disposed of to ensure that no references to the timer remain in the
+ * heap longer than absolutely necessary.
+ */
+@ProviderType
+public interface Timer {
+
+    /**
+     * Stop the timer. Once this is done the timer should be set to null. 
+     * e.g.
+     * timer.stop();
+     * timer = null;
+     */
+    void stop();
+
+}

Added: sling/whiteboard/amitgupt/monitoring/src/main/java/org/apache/sling/monitoring/api/package-info.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/amitgupt/monitoring/src/main/java/org/apache/sling/monitoring/api/package-info.java?rev=1626667&view=auto
==============================================================================
--- sling/whiteboard/amitgupt/monitoring/src/main/java/org/apache/sling/monitoring/api/package-info.java (added)
+++ sling/whiteboard/amitgupt/monitoring/src/main/java/org/apache/sling/monitoring/api/package-info.java Mon Sep 22 04:41:28 2014
@@ -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.
+ */
+
+/**
+ * Apache Sling - Instrumentation utilities.
+ *
+ * @version 0.0.1
+ */
+@Version("0.0.1")
+@Export(optional = "provide:=true")
+package org.apache.sling.monitoring.api;
+
+import aQute.bnd.annotation.Export;
+import aQute.bnd.annotation.Version;
\ No newline at end of file

Added: sling/whiteboard/amitgupt/monitoring/src/main/java/org/apache/sling/monitoring/impl/MetricsFactory.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/amitgupt/monitoring/src/main/java/org/apache/sling/monitoring/impl/MetricsFactory.java?rev=1626667&view=auto
==============================================================================
--- sling/whiteboard/amitgupt/monitoring/src/main/java/org/apache/sling/monitoring/impl/MetricsFactory.java (added)
+++ sling/whiteboard/amitgupt/monitoring/src/main/java/org/apache/sling/monitoring/impl/MetricsFactory.java Mon Sep 22 04:41:28 2014
@@ -0,0 +1,67 @@
+/*
+ * 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.sling.monitoring.impl;
+
+import org.apache.felix.scr.annotations.Activate;
+import org.apache.felix.scr.annotations.Component;
+import org.apache.felix.scr.annotations.Deactivate;
+import org.apache.felix.scr.annotations.Reference;
+import org.apache.felix.scr.annotations.ReferenceCardinality;
+import org.apache.felix.scr.annotations.ReferencePolicy;
+import org.apache.felix.scr.annotations.Service;
+import org.apache.sling.monitoring.impl.noop.NoopMetricRegistry;
+import org.apache.sling.monitoring.spi.MetricRegistry;
+import org.apache.sling.monitoring.spi.MetricRegistryFactory;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.Map;
+
+@Component(immediate=true)
+@Service(value=MetricsFactory.class)
+public class MetricsFactory {
+    private static final Logger log = LoggerFactory.getLogger(MetricsFactory.class);
+
+    @Reference(policy = ReferencePolicy.DYNAMIC, cardinality = ReferenceCardinality.OPTIONAL_UNARY)
+    MetricRegistryFactory registryFactory;
+
+    void bindMetricRegistryFactory(final MetricRegistryFactory factory) {
+        registryFactory = factory;
+        MetricsInternal.setMetricsRegistry(factory.getMetricRegistry());
+        log.debug("binding metric registry factory");
+    }
+
+    void unbindMetricRegistryFactory(final MetricRegistryFactory factory) {
+        registryFactory = null;
+        MetricsInternal.setMetricsRegistry(new NoopMetricRegistry());
+        log.debug("un-binding metric registry factory");
+    }
+
+    @Activate
+    public void activate(Map<String, Object> props) {
+        if (registryFactory != null) {
+            MetricsInternal.setMetricsRegistry(registryFactory.getMetricRegistry());
+        }
+    }
+
+    @Deactivate
+    public void deactivate(Map<String, Object> props) {
+        registryFactory = null;
+        MetricsInternal.setMetricsRegistry(null);
+    }
+
+}

Added: sling/whiteboard/amitgupt/monitoring/src/main/java/org/apache/sling/monitoring/impl/MetricsInternal.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/amitgupt/monitoring/src/main/java/org/apache/sling/monitoring/impl/MetricsInternal.java?rev=1626667&view=auto
==============================================================================
--- sling/whiteboard/amitgupt/monitoring/src/main/java/org/apache/sling/monitoring/impl/MetricsInternal.java (added)
+++ sling/whiteboard/amitgupt/monitoring/src/main/java/org/apache/sling/monitoring/impl/MetricsInternal.java Mon Sep 22 04:41:28 2014
@@ -0,0 +1,194 @@
+/*
+ * 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.sling.monitoring.impl;
+
+import org.apache.commons.lang.StringUtils;
+import org.apache.sling.monitoring.api.Gauge;
+import org.apache.sling.monitoring.api.Timer;
+import org.apache.sling.monitoring.impl.noop.NoopMetricRegistry;
+import org.apache.sling.monitoring.spi.MetricRegistry;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * A static Metrics class. Any objects returned from this class must not be
+ * referenced directly by the calling class on the heap. The lifetime of
+ * references on the stack should be limited.
+ *
+ * A Metrics instance is backed up by <code>MetricRegistry</code> that provides required functionality.
+ */
+public class MetricsInternal {
+    protected static final Logger LOGGER = LoggerFactory.getLogger(MetricsInternal.class);
+
+    protected static MetricRegistry metricRegistry;
+
+    static void setMetricsRegistry(MetricRegistry registry) {
+        metricRegistry = registry;
+    }
+
+    protected static String name(String name, String metricName) {
+        final StringBuilder builder = new StringBuilder(name);
+        if (metricName != null && !StringUtils.isEmpty(metricName)) {
+            builder.append('.').append(metricName);
+        }
+        return builder.toString();
+    }
+
+
+    /**
+     * Start a timer for a class with a name.
+     * @param clazz the class where the timer is.
+     * @param timerName the name of the timner.
+     * @return the Timer.
+     */
+    public static Timer startTimer(Class<?> clazz, String timerName) {
+        return startTimer(name(clazz.getName(), timerName));
+    }
+
+    /**
+     * Start a time with a global name.
+     * @param timerName the name of the timer.
+     * @return the timer.
+     */
+    public static Timer startTimer(String timerName) {
+        if (metricRegistry != null ) {
+            try {
+                return metricRegistry.startTimer(timerName + "_t");
+            } catch (Throwable e) {
+                LOGGER.error("Unable to create metric: " + timerName, e);
+            }
+        }
+        return new NoopMetricRegistry.NoopTimer();
+    }
+
+    /**
+     * Increment a counter identified by class and name.
+     * @param clazz the class.
+     * @param counterName the name.
+     */
+    public static void incrementCounter(Class<?> clazz, String counterName) {
+        incrementCounter(name(clazz.getName(), counterName));
+    }
+
+    /**
+     * Increment a counter identified by global name.
+     * @param counterName the counter name.
+     */
+    public static void incrementCounter(String counterName) {
+        if (metricRegistry != null ) {
+            try {
+                metricRegistry.getCounter(counterName + "_c").increment();
+            } catch (Throwable e) {
+                LOGGER.error("Unable to increment counter: " + counterName, e);
+            }
+        }
+    }
+
+    /**
+     * Decrement a counter identified by class and name.
+     * @param clazz the class.
+     * @param counterName the name.
+     */
+    public static void decrementCounter(Class<?> clazz, String counterName) {
+        decrementCounter(name(clazz.getName(), counterName));
+    }
+
+    /**
+     * Decrement a counter identified by global name.
+     * @param counterName the counter name.
+     */
+    public static void decrementCounter(String counterName) {
+        if (metricRegistry != null ) {
+            try {
+                metricRegistry.getCounter(counterName+"_c").decrement();
+            } catch (Throwable e) {
+                LOGGER.error("Unable to increment counter: " + counterName, e);
+            }
+        }
+    }
+
+    /**
+     * Measure throughput with a meter by marking operations. The meter is identified by class and name.
+     * @param clazz the class associated with the meter.
+     * @param meterName the name of the meter.
+     */
+    public static void markMeter(Class<?> clazz, String meterName) {
+        markMeter(name(clazz.getName(), meterName));
+    }
+
+    /**
+     * Measure throughput with a meter by marking operations. The meter is identified by name.
+     * @param meterName the name of the meter.
+     */
+    public static void markMeter(String meterName) {
+        if (metricRegistry != null ) {
+            try {
+                metricRegistry.getMeter(meterName + "_m").mark();
+            } catch (Throwable e) {
+                LOGGER.error("Unable to mark meter: " + meterName, e);
+            }
+        }
+    }
+
+    /**
+     * Mark the meter with a set number of operations.
+     * @param clazz the class associated with the meter.
+     * @param meterName the name of the meter scoped to the class.
+     * @param n the number of operations.
+     */
+    public static void markMeter(Class<?> clazz, String meterName, long n) {
+        markMeter(name(clazz.getName(), meterName), n);
+    }
+
+    /**
+     * Mark a meter identified by name with a number of operations.
+     * @param meterName the meter name, scoped globally.
+     * @param n the number of operations.
+     */
+    public static void markMeter(String meterName, long n) {
+        if (metricRegistry != null ) {
+            try {
+                metricRegistry.getMeter(meterName+"_m").mark(n);
+            } catch (Throwable e) {
+                LOGGER.error("Unable to mark meter: " + meterName, e);
+            }
+        }
+    }
+
+    /**
+     * Register a gauge associated with a class.
+     * @param clazz the class.
+     * @param gaugeName the name of the gauge.
+     * @param gauge the gauge.
+     */
+    public static <T> void registerGauge(Class<?> clazz, String gaugeName, final Gauge<T> gauge) {
+        registerGauge(name(clazz.getName(), gaugeName), gauge);
+    }
+
+    /**
+     * Register a gauge associated with a global name.
+     * @param gaugeName the name of the gauge.
+     * @param gauge the gauge.
+     */
+    public static <T> void registerGauge(String gaugeName, final Gauge<T> gauge) {
+        if (metricRegistry != null ) {
+            metricRegistry.registerGauge(gaugeName + "_g", gauge);
+        }
+    }
+
+}

Added: sling/whiteboard/amitgupt/monitoring/src/main/java/org/apache/sling/monitoring/impl/noop/NoopMetricRegistry.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/amitgupt/monitoring/src/main/java/org/apache/sling/monitoring/impl/noop/NoopMetricRegistry.java?rev=1626667&view=auto
==============================================================================
--- sling/whiteboard/amitgupt/monitoring/src/main/java/org/apache/sling/monitoring/impl/noop/NoopMetricRegistry.java (added)
+++ sling/whiteboard/amitgupt/monitoring/src/main/java/org/apache/sling/monitoring/impl/noop/NoopMetricRegistry.java Mon Sep 22 04:41:28 2014
@@ -0,0 +1,71 @@
+package org.apache.sling.monitoring.impl.noop;
+/*
+ * 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.
+ */
+import org.apache.sling.monitoring.api.Counter;
+import org.apache.sling.monitoring.api.Gauge;
+import org.apache.sling.monitoring.api.Meter;
+import org.apache.sling.monitoring.api.Timer;
+import org.apache.sling.monitoring.spi.MetricRegistry;
+
+/**
+ * A No-Op(eration) implementation of MetricRegistry
+ */
+public class NoopMetricRegistry implements MetricRegistry {
+
+    public Timer startTimer(String timerName) {
+        return new NoopTimer();
+    }
+
+    public Counter getCounter(String counterName) {
+        return new NoopCounter();
+    }
+
+    public Meter getMeter(String meterName) {
+        return new NoopMeter();
+    }
+
+    public <T> void registerGauge(String gaugeName, Gauge<T> gauge) {
+
+    }
+
+    public static class NoopTimer implements Timer {
+        public void stop() {}
+    }
+
+    private class NoopCounter implements Counter {
+        public long getCount() {
+            return 0;
+        }
+
+        public void increment() {}
+
+        public void decrement() { }
+    }
+
+    private class NoopMeter implements Meter {
+        public void mark() {
+        }
+        public void mark(long n) {
+        }
+        public long getCount() {
+            return 0;
+        }
+        public double getMeanRate() {
+            return 0;
+        }
+    }
+}

Added: sling/whiteboard/amitgupt/monitoring/src/main/java/org/apache/sling/monitoring/spi/MetricRegistry.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/amitgupt/monitoring/src/main/java/org/apache/sling/monitoring/spi/MetricRegistry.java?rev=1626667&view=auto
==============================================================================
--- sling/whiteboard/amitgupt/monitoring/src/main/java/org/apache/sling/monitoring/spi/MetricRegistry.java (added)
+++ sling/whiteboard/amitgupt/monitoring/src/main/java/org/apache/sling/monitoring/spi/MetricRegistry.java Mon Sep 22 04:41:28 2014
@@ -0,0 +1,59 @@
+/*
+ * 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.sling.monitoring.spi;
+
+import aQute.bnd.annotation.ConsumerType;
+import org.apache.sling.monitoring.api.Counter;
+import org.apache.sling.monitoring.api.Gauge;
+import org.apache.sling.monitoring.api.Meter;
+import org.apache.sling.monitoring.api.Timer;
+
+/**
+ * <code>MetricRegistry</code> provides different type of metrics i.e.
+ * <li>
+ *     <code>Counter</code>
+ *     <code>Meter</code>
+ *     <code>Timer</code>
+ *     <code>Gauge</code>
+ * </li>
+ */
+@ConsumerType
+public interface MetricRegistry {
+    /**
+     * Start a time with a global name.
+     * @param timerName the name of the timer.
+     * @return the timer.
+     */
+    Timer startTimer(String timerName);
+    /**
+     * returns a counter identified by global name.
+     * @param counterName the counter name.
+     */
+    Counter getCounter(String counterName);
+
+    /**
+     * returns the identified by name.
+     * @param meterName the name of the meter.
+     */
+    Meter getMeter(String meterName);
+    /**
+     * Register a gauge associated with a global name.
+     * @param gaugeName the name of the gauge.
+     * @param gauge the gauge.
+     */
+    <T> void registerGauge(String gaugeName, final Gauge<T> gauge);
+}

Added: sling/whiteboard/amitgupt/monitoring/src/main/java/org/apache/sling/monitoring/spi/MetricRegistryFactory.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/amitgupt/monitoring/src/main/java/org/apache/sling/monitoring/spi/MetricRegistryFactory.java?rev=1626667&view=auto
==============================================================================
--- sling/whiteboard/amitgupt/monitoring/src/main/java/org/apache/sling/monitoring/spi/MetricRegistryFactory.java (added)
+++ sling/whiteboard/amitgupt/monitoring/src/main/java/org/apache/sling/monitoring/spi/MetricRegistryFactory.java Mon Sep 22 04:41:28 2014
@@ -0,0 +1,32 @@
+/*
+ * 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.sling.monitoring.spi;
+
+import aQute.bnd.annotation.ConsumerType;
+
+/**
+ * Provides a factory for <code>MetricRegistry</code>
+ */
+@ConsumerType
+public interface MetricRegistryFactory {
+
+    /**
+     * Returns <code>MetricRegistry</code> instance
+     * @return
+     */
+    MetricRegistry getMetricRegistry();
+}

Added: sling/whiteboard/amitgupt/monitoring/src/main/java/org/apache/sling/monitoring/spi/package-info.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/amitgupt/monitoring/src/main/java/org/apache/sling/monitoring/spi/package-info.java?rev=1626667&view=auto
==============================================================================
--- sling/whiteboard/amitgupt/monitoring/src/main/java/org/apache/sling/monitoring/spi/package-info.java (added)
+++ sling/whiteboard/amitgupt/monitoring/src/main/java/org/apache/sling/monitoring/spi/package-info.java Mon Sep 22 04:41:28 2014
@@ -0,0 +1,27 @@
+/*
+ * 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.
+ */
+
+/**
+ * Apache Sling - Instrumentation utilities.
+ *
+ * @version 0.0.1
+ */
+@Version("0.0.1")
+package org.apache.sling.monitoring.spi;
+
+import aQute.bnd.annotation.Export;
+import aQute.bnd.annotation.Version;
\ No newline at end of file