commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jlmonte...@apache.org
Subject svn commit: r1533455 - in /commons/sandbox/monitoring/trunk: core/src/main/java/org/apache/commons/monitoring/ core/src/main/java/org/apache/commons/monitoring/configuration/ core/src/main/java/org/apache/commons/monitoring/counters/ core/src/main/java...
Date Fri, 18 Oct 2013 13:56:09 GMT
Author: jlmonteiro
Date: Fri Oct 18 13:56:08 2013
New Revision: 1533455

URL: http://svn.apache.org/r1533455
Log:
Make it possible to have a different datastore for counter and gauge

Added:
    commons/sandbox/monitoring/trunk/core/src/main/java/org/apache/commons/monitoring/store/CounterDataStore.java   (with props)
    commons/sandbox/monitoring/trunk/core/src/main/java/org/apache/commons/monitoring/store/DataStoreFactory.java   (with props)
    commons/sandbox/monitoring/trunk/core/src/main/java/org/apache/commons/monitoring/store/DefaultDataStoreFactory.java   (with props)
    commons/sandbox/monitoring/trunk/core/src/main/java/org/apache/commons/monitoring/store/DelegateDataStoreFactory.java   (with props)
    commons/sandbox/monitoring/trunk/core/src/main/java/org/apache/commons/monitoring/store/GaugeDataStore.java   (with props)
    commons/sandbox/monitoring/trunk/core/src/main/java/org/apache/commons/monitoring/store/InMemoryCounterDataStore.java   (with props)
    commons/sandbox/monitoring/trunk/core/src/main/java/org/apache/commons/monitoring/store/InMemoryGaugeDataStore.java   (with props)
    commons/sandbox/monitoring/trunk/cube/src/main/java/org/apache/commons/monitoring/cube/CubeCounterDataStore.java   (with props)
    commons/sandbox/monitoring/trunk/cube/src/main/java/org/apache/commons/monitoring/cube/CubeDataStoreFactory.java   (with props)
    commons/sandbox/monitoring/trunk/cube/src/main/java/org/apache/commons/monitoring/cube/CubeGaugeDataStore.java   (with props)
    commons/sandbox/monitoring/trunk/cube/src/main/java/org/apache/commons/monitoring/cube/MapBuilder.java   (with props)
    commons/sandbox/monitoring/trunk/graphite/src/main/java/org/apache/commons/monitoring/graphite/GraphiteCounterDataStore.java   (with props)
    commons/sandbox/monitoring/trunk/graphite/src/main/java/org/apache/commons/monitoring/graphite/GraphiteDataStoreFactory.java   (with props)
    commons/sandbox/monitoring/trunk/graphite/src/main/java/org/apache/commons/monitoring/graphite/GraphiteGaugeDataStore.java   (with props)
Removed:
    commons/sandbox/monitoring/trunk/core/src/main/java/org/apache/commons/monitoring/store/DataStore.java
    commons/sandbox/monitoring/trunk/core/src/main/java/org/apache/commons/monitoring/store/DefaultDataStore.java
    commons/sandbox/monitoring/trunk/core/src/main/java/org/apache/commons/monitoring/store/InMemoryCounterBaseStore.java
    commons/sandbox/monitoring/trunk/cube/src/main/java/org/apache/commons/monitoring/cube/CubeDataStore.java
    commons/sandbox/monitoring/trunk/graphite/src/main/java/org/apache/commons/monitoring/graphite/GraphiteDataStore.java
Modified:
    commons/sandbox/monitoring/trunk/core/src/main/java/org/apache/commons/monitoring/Role.java
    commons/sandbox/monitoring/trunk/core/src/main/java/org/apache/commons/monitoring/configuration/Configuration.java
    commons/sandbox/monitoring/trunk/core/src/main/java/org/apache/commons/monitoring/counters/DefaultCounter.java
    commons/sandbox/monitoring/trunk/core/src/main/java/org/apache/commons/monitoring/counters/MetricData.java
    commons/sandbox/monitoring/trunk/core/src/main/java/org/apache/commons/monitoring/counters/Unit.java
    commons/sandbox/monitoring/trunk/core/src/main/java/org/apache/commons/monitoring/gauges/DefaultGaugeManager.java
    commons/sandbox/monitoring/trunk/core/src/main/java/org/apache/commons/monitoring/gauges/Gauge.java
    commons/sandbox/monitoring/trunk/core/src/main/java/org/apache/commons/monitoring/gauges/GaugeManager.java
    commons/sandbox/monitoring/trunk/core/src/main/java/org/apache/commons/monitoring/repositories/DefaultRepository.java
    commons/sandbox/monitoring/trunk/core/src/main/java/org/apache/commons/monitoring/repositories/Repository.java
    commons/sandbox/monitoring/trunk/core/src/main/java/org/apache/commons/monitoring/store/BatchCounterDataStore.java
    commons/sandbox/monitoring/trunk/core/src/main/java/org/apache/commons/monitoring/store/GaugeValuesRequest.java
    commons/sandbox/monitoring/trunk/core/src/test/java/org/apache/commons/monitoring/counters/CounterBench.java
    commons/sandbox/monitoring/trunk/cube/src/main/java/org/apache/commons/monitoring/cube/CubeCounter.java
    commons/sandbox/monitoring/trunk/cube/src/test/java/org/apache/commons/monitoring/cube/CubeDataStoreTest.java
    commons/sandbox/monitoring/trunk/cube/src/test/resources/commons-monitoring.properties
    commons/sandbox/monitoring/trunk/graphite/src/main/java/org/apache/commons/monitoring/graphite/Graphite.java
    commons/sandbox/monitoring/trunk/graphite/src/test/resources/commons-monitoring.properties

Modified: commons/sandbox/monitoring/trunk/core/src/main/java/org/apache/commons/monitoring/Role.java
URL: http://svn.apache.org/viewvc/commons/sandbox/monitoring/trunk/core/src/main/java/org/apache/commons/monitoring/Role.java?rev=1533455&r1=1533454&r2=1533455&view=diff
==============================================================================
--- commons/sandbox/monitoring/trunk/core/src/main/java/org/apache/commons/monitoring/Role.java (original)
+++ commons/sandbox/monitoring/trunk/core/src/main/java/org/apache/commons/monitoring/Role.java Fri Oct 18 13:56:08 2013
@@ -71,21 +71,17 @@ public class Role implements Comparable<
     }
 
     @Override
-    public boolean equals( Object o )
-    {
-        if ( this == o )
-        {
+    public boolean equals(Object o) {
+        if (this == o) {
             return true;
         }
-        if ( o == null || getClass() != o.getClass() )
-        {
+        if (o == null || getClass() != o.getClass()) {
             return false;
         }
 
         Role role = (Role) o;
 
-        if ( !name.equals( role.name ) )
-        {
+        if (!name.equals(role.name)) {
             return false;
         }
 
@@ -100,12 +96,11 @@ public class Role implements Comparable<
     }
 
     @Override
-    public String toString()
-    {
-        final StringBuilder sb = new StringBuilder( "Role{" );
-        sb.append( "name='" ).append( name ).append( '\'' );
-        sb.append( ", unit=" ).append( unit );
-        sb.append( '}' );
+    public String toString() {
+        final StringBuilder sb = new StringBuilder("Role{");
+        sb.append("name='").append(name).append('\'');
+        sb.append(", unit=").append(unit);
+        sb.append('}');
         return sb.toString();
     }
 }

Modified: commons/sandbox/monitoring/trunk/core/src/main/java/org/apache/commons/monitoring/configuration/Configuration.java
URL: http://svn.apache.org/viewvc/commons/sandbox/monitoring/trunk/core/src/main/java/org/apache/commons/monitoring/configuration/Configuration.java?rev=1533455&r1=1533454&r2=1533455&view=diff
==============================================================================
--- commons/sandbox/monitoring/trunk/core/src/main/java/org/apache/commons/monitoring/configuration/Configuration.java (original)
+++ commons/sandbox/monitoring/trunk/core/src/main/java/org/apache/commons/monitoring/configuration/Configuration.java Fri Oct 18 13:56:08 2013
@@ -53,6 +53,7 @@ public final class Configuration {
     private static Thread shutdownHook = null;
 
     private static final Properties PROPERTIES = new Properties(System.getProperties());
+
     static {
         try {
             final InputStream is = findConfiguration();
@@ -63,6 +64,7 @@ public final class Configuration {
             LOGGER.log(Level.SEVERE, e.getMessage(), e);
         }
     }
+
     private static InputStream findConfiguration() throws FileNotFoundException {
         final String filename = System.getProperty(COMMONS_MONITORING_PREFIX + "configuration", DEFAULT_CONFIGURATION_FILE);
         if (new File(filename).exists()) {

Modified: commons/sandbox/monitoring/trunk/core/src/main/java/org/apache/commons/monitoring/counters/DefaultCounter.java
URL: http://svn.apache.org/viewvc/commons/sandbox/monitoring/trunk/core/src/main/java/org/apache/commons/monitoring/counters/DefaultCounter.java?rev=1533455&r1=1533454&r2=1533455&view=diff
==============================================================================
--- commons/sandbox/monitoring/trunk/core/src/main/java/org/apache/commons/monitoring/counters/DefaultCounter.java (original)
+++ commons/sandbox/monitoring/trunk/core/src/main/java/org/apache/commons/monitoring/counters/DefaultCounter.java Fri Oct 18 13:56:08 2013
@@ -17,7 +17,7 @@
 package org.apache.commons.monitoring.counters;
 
 import org.apache.commons.math3.stat.descriptive.SummaryStatistics;
-import org.apache.commons.monitoring.store.DataStore;
+import org.apache.commons.monitoring.store.CounterDataStore;
 
 import java.util.concurrent.atomic.AtomicInteger;
 import java.util.concurrent.locks.Lock;
@@ -26,12 +26,12 @@ import java.util.concurrent.locks.Reentr
 public class DefaultCounter implements Counter {
     private final AtomicInteger concurrency = new AtomicInteger(0);
     private final Key key;
-    private final DataStore dataStore;
+    private final CounterDataStore dataStore;
     private volatile int maxConcurrency = 0;
     private SummaryStatistics statistics;
     private Lock lock = new ReentrantLock();
 
-    public DefaultCounter(final Key key, final DataStore store) {
+    public DefaultCounter(final Key key, final CounterDataStore store) {
         this.key = key;
         this.statistics = new SummaryStatistics();
         this.dataStore = store;

Modified: commons/sandbox/monitoring/trunk/core/src/main/java/org/apache/commons/monitoring/counters/MetricData.java
URL: http://svn.apache.org/viewvc/commons/sandbox/monitoring/trunk/core/src/main/java/org/apache/commons/monitoring/counters/MetricData.java?rev=1533455&r1=1533454&r2=1533455&view=diff
==============================================================================
--- commons/sandbox/monitoring/trunk/core/src/main/java/org/apache/commons/monitoring/counters/MetricData.java (original)
+++ commons/sandbox/monitoring/trunk/core/src/main/java/org/apache/commons/monitoring/counters/MetricData.java Fri Oct 18 13:56:08 2013
@@ -177,5 +177,6 @@ public enum MetricData {
     };
 
     public abstract double value(Counter counter);
+
     public abstract boolean isTime();
 }
\ No newline at end of file

Modified: commons/sandbox/monitoring/trunk/core/src/main/java/org/apache/commons/monitoring/counters/Unit.java
URL: http://svn.apache.org/viewvc/commons/sandbox/monitoring/trunk/core/src/main/java/org/apache/commons/monitoring/counters/Unit.java?rev=1533455&r1=1533454&r2=1533455&view=diff
==============================================================================
--- commons/sandbox/monitoring/trunk/core/src/main/java/org/apache/commons/monitoring/counters/Unit.java (original)
+++ commons/sandbox/monitoring/trunk/core/src/main/java/org/apache/commons/monitoring/counters/Unit.java Fri Oct 18 13:56:08 2013
@@ -67,7 +67,7 @@ public class Unit implements Comparable<
      * Binary data units
      */
     public static class Binary
-        extends Unit {
+            extends Unit {
 
         public static final Unit BYTE = new Unit("b");
 

Modified: commons/sandbox/monitoring/trunk/core/src/main/java/org/apache/commons/monitoring/gauges/DefaultGaugeManager.java
URL: http://svn.apache.org/viewvc/commons/sandbox/monitoring/trunk/core/src/main/java/org/apache/commons/monitoring/gauges/DefaultGaugeManager.java?rev=1533455&r1=1533454&r2=1533455&view=diff
==============================================================================
--- commons/sandbox/monitoring/trunk/core/src/main/java/org/apache/commons/monitoring/gauges/DefaultGaugeManager.java (original)
+++ commons/sandbox/monitoring/trunk/core/src/main/java/org/apache/commons/monitoring/gauges/DefaultGaugeManager.java Fri Oct 18 13:56:08 2013
@@ -17,7 +17,7 @@
 package org.apache.commons.monitoring.gauges;
 
 import org.apache.commons.monitoring.Role;
-import org.apache.commons.monitoring.store.DataStore;
+import org.apache.commons.monitoring.store.GaugeDataStore;
 
 import java.util.Map;
 import java.util.Timer;
@@ -26,9 +26,9 @@ import java.util.concurrent.ConcurrentHa
 
 public final class DefaultGaugeManager implements GaugeManager {
     private final Map<Role, Timer> timers = new ConcurrentHashMap<Role, Timer>();
-    private final DataStore store;
+    private final GaugeDataStore store;
 
-    public DefaultGaugeManager(final DataStore dataStore) {
+    public DefaultGaugeManager(final GaugeDataStore dataStore) {
         store = dataStore;
     }
 
@@ -61,9 +61,9 @@ public final class DefaultGaugeManager i
 
     private static class GaugeTask extends TimerTask {
         private final Gauge gauge;
-        private final DataStore store;
+        private final GaugeDataStore store;
 
-        public GaugeTask(final DataStore store, final Gauge gauge) {
+        public GaugeTask(final GaugeDataStore store, final Gauge gauge) {
             this.store = store;
             this.gauge = gauge;
         }

Modified: commons/sandbox/monitoring/trunk/core/src/main/java/org/apache/commons/monitoring/gauges/Gauge.java
URL: http://svn.apache.org/viewvc/commons/sandbox/monitoring/trunk/core/src/main/java/org/apache/commons/monitoring/gauges/Gauge.java?rev=1533455&r1=1533454&r2=1533455&view=diff
==============================================================================
--- commons/sandbox/monitoring/trunk/core/src/main/java/org/apache/commons/monitoring/gauges/Gauge.java (original)
+++ commons/sandbox/monitoring/trunk/core/src/main/java/org/apache/commons/monitoring/gauges/Gauge.java Fri Oct 18 13:56:08 2013
@@ -24,7 +24,9 @@ import java.util.ServiceLoader;
 
 public interface Gauge {
     Role role();
+
     double value();
+
     long period();
 
     public static class LoaderHelper {

Modified: commons/sandbox/monitoring/trunk/core/src/main/java/org/apache/commons/monitoring/gauges/GaugeManager.java
URL: http://svn.apache.org/viewvc/commons/sandbox/monitoring/trunk/core/src/main/java/org/apache/commons/monitoring/gauges/GaugeManager.java?rev=1533455&r1=1533454&r2=1533455&view=diff
==============================================================================
--- commons/sandbox/monitoring/trunk/core/src/main/java/org/apache/commons/monitoring/gauges/GaugeManager.java (original)
+++ commons/sandbox/monitoring/trunk/core/src/main/java/org/apache/commons/monitoring/gauges/GaugeManager.java Fri Oct 18 13:56:08 2013
@@ -20,6 +20,8 @@ import org.apache.commons.monitoring.Rol
 
 public interface GaugeManager {
     void stop();
+
     void addGauge(Gauge gauge);
+
     void stopGauge(Role role);
 }

Modified: commons/sandbox/monitoring/trunk/core/src/main/java/org/apache/commons/monitoring/repositories/DefaultRepository.java
URL: http://svn.apache.org/viewvc/commons/sandbox/monitoring/trunk/core/src/main/java/org/apache/commons/monitoring/repositories/DefaultRepository.java?rev=1533455&r1=1533454&r2=1533455&view=diff
==============================================================================
--- commons/sandbox/monitoring/trunk/core/src/main/java/org/apache/commons/monitoring/repositories/DefaultRepository.java (original)
+++ commons/sandbox/monitoring/trunk/core/src/main/java/org/apache/commons/monitoring/repositories/DefaultRepository.java Fri Oct 18 13:56:08 2013
@@ -16,6 +16,7 @@
  */
 package org.apache.commons.monitoring.repositories;
 
+import org.apache.commons.monitoring.MonitoringException;
 import org.apache.commons.monitoring.Role;
 import org.apache.commons.monitoring.configuration.Configuration;
 import org.apache.commons.monitoring.counters.Counter;
@@ -23,19 +24,42 @@ import org.apache.commons.monitoring.gau
 import org.apache.commons.monitoring.gauges.Gauge;
 import org.apache.commons.monitoring.stopwatches.CounterStopWatch;
 import org.apache.commons.monitoring.stopwatches.StopWatch;
-import org.apache.commons.monitoring.store.DataStore;
+import org.apache.commons.monitoring.store.CounterDataStore;
+import org.apache.commons.monitoring.store.DataStoreFactory;
+import org.apache.commons.monitoring.store.GaugeDataStore;
 import org.apache.commons.monitoring.store.GaugeValuesRequest;
 
 import java.util.Iterator;
 import java.util.Map;
 
 public class DefaultRepository implements Repository {
-    private final DataStore dataStore;
+    private final CounterDataStore counterDataStore;
+    private final GaugeDataStore gaugeDataStore;
     private final DefaultGaugeManager gaugeManager;
 
     public DefaultRepository() {
-        this.dataStore = Configuration.findOrCreateInstance(DataStore.class);
-        this.gaugeManager = new DefaultGaugeManager(dataStore);
+        CounterDataStore counter = null;
+        try {
+            counter = Configuration.findOrCreateInstance(CounterDataStore.class);
+        } catch (MonitoringException e) {
+        }
+
+        GaugeDataStore gauge = null;
+        try {
+            gauge = Configuration.findOrCreateInstance(GaugeDataStore.class);
+        } catch (MonitoringException e) {
+        }
+
+        if (counter == null) {
+            counter = Configuration.findOrCreateInstance(DataStoreFactory.class).getCounterDataStore();
+        }
+
+        if (gauge == null) {
+            gauge = Configuration.findOrCreateInstance(DataStoreFactory.class).getGaugeDataStore();
+        }
+        this.counterDataStore = counter;
+        this.gaugeDataStore = gauge;
+        this.gaugeManager = new DefaultGaugeManager(this.gaugeDataStore);
     }
 
     @Configuration.Destroying
@@ -45,12 +69,12 @@ public class DefaultRepository implement
 
     @Override
     public Counter getCounter(final Counter.Key key) {
-        return dataStore.getOrCreateCounter(key);
+        return counterDataStore.getOrCreateCounter(key);
     }
 
     @Override
     public void clear() {
-        dataStore.clearCounters();
+        counterDataStore.clearCounters();
     }
 
     @Override
@@ -60,12 +84,12 @@ public class DefaultRepository implement
 
     @Override
     public Iterator<Counter> iterator() {
-        return dataStore.getCounters().iterator();
+        return counterDataStore.getCounters().iterator();
     }
 
     @Override
     public Map<Long, Double> getGaugeValues(final long start, final long end, final Role role) {
-        return dataStore.getGaugeValues(new GaugeValuesRequest(start, end, role));
+        return gaugeDataStore.getGaugeValues(new GaugeValuesRequest(start, end, role));
     }
 
     @Override

Modified: commons/sandbox/monitoring/trunk/core/src/main/java/org/apache/commons/monitoring/repositories/Repository.java
URL: http://svn.apache.org/viewvc/commons/sandbox/monitoring/trunk/core/src/main/java/org/apache/commons/monitoring/repositories/Repository.java?rev=1533455&r1=1533454&r2=1533455&view=diff
==============================================================================
--- commons/sandbox/monitoring/trunk/core/src/main/java/org/apache/commons/monitoring/repositories/Repository.java (original)
+++ commons/sandbox/monitoring/trunk/core/src/main/java/org/apache/commons/monitoring/repositories/Repository.java Fri Oct 18 13:56:08 2013
@@ -29,10 +29,14 @@ public interface Repository extends Iter
     Repository INSTANCE = Configuration.findOrCreateInstance(Repository.class);
 
     Counter getCounter(Counter.Key key);
+
     void clear();
+
     StopWatch start(Counter counter);
 
     void addGauge(final Gauge gauge);
+
     void stopGauge(Role role);
+
     Map<Long, Double> getGaugeValues(long start, long end, Role role);
 }

Modified: commons/sandbox/monitoring/trunk/core/src/main/java/org/apache/commons/monitoring/store/BatchCounterDataStore.java
URL: http://svn.apache.org/viewvc/commons/sandbox/monitoring/trunk/core/src/main/java/org/apache/commons/monitoring/store/BatchCounterDataStore.java?rev=1533455&r1=1533454&r2=1533455&view=diff
==============================================================================
--- commons/sandbox/monitoring/trunk/core/src/main/java/org/apache/commons/monitoring/store/BatchCounterDataStore.java (original)
+++ commons/sandbox/monitoring/trunk/core/src/main/java/org/apache/commons/monitoring/store/BatchCounterDataStore.java Fri Oct 18 13:56:08 2013
@@ -16,26 +16,21 @@
  */
 package org.apache.commons.monitoring.store;
 
-import org.apache.commons.monitoring.Role;
 import org.apache.commons.monitoring.configuration.Configuration;
-import org.apache.commons.monitoring.counters.Counter;
-import org.apache.commons.monitoring.counters.DefaultCounter;
 import org.apache.commons.monitoring.repositories.Repository;
 import org.apache.commons.monitoring.util.DaemonThreadFactory;
 
-import java.util.Collections;
 import java.util.Locale;
-import java.util.Map;
 import java.util.concurrent.Executors;
 import java.util.concurrent.ScheduledExecutorService;
 import java.util.concurrent.ScheduledFuture;
 import java.util.concurrent.TimeUnit;
 
-public abstract class BatchCounterDataStore extends InMemoryCounterBaseStore {
+public abstract class BatchCounterDataStore extends InMemoryCounterDataStore {
     protected final BatchFuture scheduledTask;
 
     protected BatchCounterDataStore() {
-        final String name = getClass().getSimpleName().toLowerCase(Locale.ENGLISH).replace("datastore", "");
+        final String name = getClass().getSimpleName().toLowerCase(Locale.ENGLISH).replace("counterdatastore", "");
         final long period = Configuration.getInteger(Configuration.COMMONS_MONITORING_PREFIX + name + ".period", 60000);
 
         final ScheduledExecutorService ses = Executors.newSingleThreadScheduledExecutor(new DaemonThreadFactory(name + "-schedule-"));
@@ -48,33 +43,6 @@ public abstract class BatchCounterDataSt
         scheduledTask.done();
     }
 
-    @Override
-    public Counter getOrCreateCounter(final Counter.Key key) {
-        Counter counter = counters.get(key);
-        if (counter == null) {
-            counter = newCounter(key);
-            final Counter previous = counters.putIfAbsent(key, counter);
-            if (previous != null) {
-                counter = previous;
-            }
-        }
-        return counter;
-    }
-
-    protected Counter newCounter(final Counter.Key key) {
-        return new DefaultCounter(key, this);
-    }
-
-    @Override
-    public void createOrNoopGauge(final Role role) {
-        // no-op
-    }
-
-    @Override
-    public Map<Long, Double> getGaugeValues(final GaugeValuesRequest gaugeValuesRequest) {
-        return Collections.emptyMap(); // often we use another aggregator/visualisator in this case
-    }
-
     protected abstract void pushCountersByBatch(final Repository instance);
 
     private class BatchPushCountersTask implements Runnable {

Added: commons/sandbox/monitoring/trunk/core/src/main/java/org/apache/commons/monitoring/store/CounterDataStore.java
URL: http://svn.apache.org/viewvc/commons/sandbox/monitoring/trunk/core/src/main/java/org/apache/commons/monitoring/store/CounterDataStore.java?rev=1533455&view=auto
==============================================================================
--- commons/sandbox/monitoring/trunk/core/src/main/java/org/apache/commons/monitoring/store/CounterDataStore.java (added)
+++ commons/sandbox/monitoring/trunk/core/src/main/java/org/apache/commons/monitoring/store/CounterDataStore.java Fri Oct 18 13:56:08 2013
@@ -0,0 +1,31 @@
+/*
+ * 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.commons.monitoring.store;
+
+import org.apache.commons.monitoring.counters.Counter;
+
+import java.util.Collection;
+
+public interface CounterDataStore {
+    Counter getOrCreateCounter(Counter.Key key);
+
+    void clearCounters();
+
+    Collection<Counter> getCounters();
+
+    void addToCounter(Counter defaultCounter, double delta);  // sensitive method which need to be thread safe
+}

Propchange: commons/sandbox/monitoring/trunk/core/src/main/java/org/apache/commons/monitoring/store/CounterDataStore.java
------------------------------------------------------------------------------
    svn:executable = *

Added: commons/sandbox/monitoring/trunk/core/src/main/java/org/apache/commons/monitoring/store/DataStoreFactory.java
URL: http://svn.apache.org/viewvc/commons/sandbox/monitoring/trunk/core/src/main/java/org/apache/commons/monitoring/store/DataStoreFactory.java?rev=1533455&view=auto
==============================================================================
--- commons/sandbox/monitoring/trunk/core/src/main/java/org/apache/commons/monitoring/store/DataStoreFactory.java (added)
+++ commons/sandbox/monitoring/trunk/core/src/main/java/org/apache/commons/monitoring/store/DataStoreFactory.java Fri Oct 18 13:56:08 2013
@@ -0,0 +1,25 @@
+/*
+ * 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.commons.monitoring.store;
+
+public interface DataStoreFactory {
+
+    CounterDataStore getCounterDataStore();
+
+    GaugeDataStore getGaugeDataStore();
+
+}

Propchange: commons/sandbox/monitoring/trunk/core/src/main/java/org/apache/commons/monitoring/store/DataStoreFactory.java
------------------------------------------------------------------------------
    svn:executable = *

Added: commons/sandbox/monitoring/trunk/core/src/main/java/org/apache/commons/monitoring/store/DefaultDataStoreFactory.java
URL: http://svn.apache.org/viewvc/commons/sandbox/monitoring/trunk/core/src/main/java/org/apache/commons/monitoring/store/DefaultDataStoreFactory.java?rev=1533455&view=auto
==============================================================================
--- commons/sandbox/monitoring/trunk/core/src/main/java/org/apache/commons/monitoring/store/DefaultDataStoreFactory.java (added)
+++ commons/sandbox/monitoring/trunk/core/src/main/java/org/apache/commons/monitoring/store/DefaultDataStoreFactory.java Fri Oct 18 13:56:08 2013
@@ -0,0 +1,25 @@
+/*
+ * 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.commons.monitoring.store;
+
+public class DefaultDataStoreFactory extends DelegateDataStoreFactory {
+
+    public DefaultDataStoreFactory() {
+        super(new InMemoryCounterDataStore(), new InMemoryGaugeDataStore());
+    }
+
+}

Propchange: commons/sandbox/monitoring/trunk/core/src/main/java/org/apache/commons/monitoring/store/DefaultDataStoreFactory.java
------------------------------------------------------------------------------
    svn:executable = *

Added: commons/sandbox/monitoring/trunk/core/src/main/java/org/apache/commons/monitoring/store/DelegateDataStoreFactory.java
URL: http://svn.apache.org/viewvc/commons/sandbox/monitoring/trunk/core/src/main/java/org/apache/commons/monitoring/store/DelegateDataStoreFactory.java?rev=1533455&view=auto
==============================================================================
--- commons/sandbox/monitoring/trunk/core/src/main/java/org/apache/commons/monitoring/store/DelegateDataStoreFactory.java (added)
+++ commons/sandbox/monitoring/trunk/core/src/main/java/org/apache/commons/monitoring/store/DelegateDataStoreFactory.java Fri Oct 18 13:56:08 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.commons.monitoring.store;
+
+public class DelegateDataStoreFactory implements DataStoreFactory {
+
+    private final CounterDataStore counterDataStore;
+    private final GaugeDataStore gaugeDataStore;
+
+    public DelegateDataStoreFactory(CounterDataStore counterDataStore, GaugeDataStore gaugeDataStore) {
+        this.counterDataStore = counterDataStore;
+        this.gaugeDataStore = gaugeDataStore;
+    }
+
+    @Override
+    public CounterDataStore getCounterDataStore() {
+        return counterDataStore;
+    }
+
+    @Override
+    public GaugeDataStore getGaugeDataStore() {
+        return gaugeDataStore;
+    }
+
+
+}

Propchange: commons/sandbox/monitoring/trunk/core/src/main/java/org/apache/commons/monitoring/store/DelegateDataStoreFactory.java
------------------------------------------------------------------------------
    svn:executable = *

Added: commons/sandbox/monitoring/trunk/core/src/main/java/org/apache/commons/monitoring/store/GaugeDataStore.java
URL: http://svn.apache.org/viewvc/commons/sandbox/monitoring/trunk/core/src/main/java/org/apache/commons/monitoring/store/GaugeDataStore.java?rev=1533455&view=auto
==============================================================================
--- commons/sandbox/monitoring/trunk/core/src/main/java/org/apache/commons/monitoring/store/GaugeDataStore.java (added)
+++ commons/sandbox/monitoring/trunk/core/src/main/java/org/apache/commons/monitoring/store/GaugeDataStore.java Fri Oct 18 13:56:08 2013
@@ -0,0 +1,30 @@
+/*
+ * 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.commons.monitoring.store;
+
+import org.apache.commons.monitoring.Role;
+import org.apache.commons.monitoring.gauges.Gauge;
+
+import java.util.Map;
+
+public interface GaugeDataStore {
+    Map<Long, Double> getGaugeValues(GaugeValuesRequest gaugeValuesRequest);
+
+    void createOrNoopGauge(Role role);
+
+    void addToGauge(Gauge gauge, long time, double value);
+}

Propchange: commons/sandbox/monitoring/trunk/core/src/main/java/org/apache/commons/monitoring/store/GaugeDataStore.java
------------------------------------------------------------------------------
    svn:executable = *

Modified: commons/sandbox/monitoring/trunk/core/src/main/java/org/apache/commons/monitoring/store/GaugeValuesRequest.java
URL: http://svn.apache.org/viewvc/commons/sandbox/monitoring/trunk/core/src/main/java/org/apache/commons/monitoring/store/GaugeValuesRequest.java?rev=1533455&r1=1533454&r2=1533455&view=diff
==============================================================================
--- commons/sandbox/monitoring/trunk/core/src/main/java/org/apache/commons/monitoring/store/GaugeValuesRequest.java (original)
+++ commons/sandbox/monitoring/trunk/core/src/main/java/org/apache/commons/monitoring/store/GaugeValuesRequest.java Fri Oct 18 13:56:08 2013
@@ -21,8 +21,7 @@ import org.apache.commons.monitoring.Rol
 /**
  * @author Olivier Lamy
  */
-public class GaugeValuesRequest
-{
+public class GaugeValuesRequest {
 
     private long start;
 
@@ -30,45 +29,37 @@ public class GaugeValuesRequest
 
     private Role role;
 
-    public GaugeValuesRequest()
-    {
+    public GaugeValuesRequest() {
         // no op
     }
 
-    public GaugeValuesRequest( long start, long end, Role role )
-    {
+    public GaugeValuesRequest(long start, long end, Role role) {
         this.start = start;
         this.end = end;
         this.role = role;
     }
 
-    public long getStart()
-    {
+    public long getStart() {
         return start;
     }
 
-    public void setStart( long start )
-    {
+    public void setStart(long start) {
         this.start = start;
     }
 
-    public long getEnd()
-    {
+    public long getEnd() {
         return end;
     }
 
-    public void setEnd( long end )
-    {
+    public void setEnd(long end) {
         this.end = end;
     }
 
-    public Role getRole()
-    {
+    public Role getRole() {
         return role;
     }
 
-    public void setRole( Role role )
-    {
+    public void setRole(Role role) {
         this.role = role;
     }
 }

Added: commons/sandbox/monitoring/trunk/core/src/main/java/org/apache/commons/monitoring/store/InMemoryCounterDataStore.java
URL: http://svn.apache.org/viewvc/commons/sandbox/monitoring/trunk/core/src/main/java/org/apache/commons/monitoring/store/InMemoryCounterDataStore.java?rev=1533455&view=auto
==============================================================================
--- commons/sandbox/monitoring/trunk/core/src/main/java/org/apache/commons/monitoring/store/InMemoryCounterDataStore.java (added)
+++ commons/sandbox/monitoring/trunk/core/src/main/java/org/apache/commons/monitoring/store/InMemoryCounterDataStore.java Fri Oct 18 13:56:08 2013
@@ -0,0 +1,72 @@
+/*
+ * 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.commons.monitoring.store;
+
+import org.apache.commons.monitoring.counters.Counter;
+import org.apache.commons.monitoring.counters.DefaultCounter;
+
+import java.util.Collection;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
+import java.util.concurrent.locks.Lock;
+
+public class InMemoryCounterDataStore implements CounterDataStore {
+    protected final ConcurrentMap<Counter.Key, Counter> counters = new ConcurrentHashMap<Counter.Key, Counter>(50);
+
+    @Override
+    public Counter getOrCreateCounter(final Counter.Key key) {
+        Counter counter = counters.get(key);
+        if (counter == null) {
+            counter = newCounter(key);
+            final Counter previous = counters.putIfAbsent(key, counter);
+            if (previous != null) {
+                counter = previous;
+            }
+        }
+        return counter;
+    }
+
+    @Override
+    public void clearCounters() {
+        counters.clear();
+    }
+
+    @Override
+    public Collection<Counter> getCounters() {
+        return counters.values();
+    }
+
+    protected Counter newCounter(final Counter.Key key) {
+        return new DefaultCounter(key, this);
+    }
+
+    @Override
+    public void addToCounter(final Counter counter, final double delta) {
+        if (!DefaultCounter.class.isInstance(counter)) {
+            throw new IllegalArgumentException(getClass().getName() + " only supports " + DefaultCounter.class.getName());
+        }
+
+        final DefaultCounter defaultCounter = DefaultCounter.class.cast(counter);
+        final Lock lock = defaultCounter.getLock();
+        lock.lock();
+        try {
+            defaultCounter.addInternal(delta);
+        } finally {
+            lock.unlock();
+        }
+    }
+}

Propchange: commons/sandbox/monitoring/trunk/core/src/main/java/org/apache/commons/monitoring/store/InMemoryCounterDataStore.java
------------------------------------------------------------------------------
    svn:executable = *

Added: commons/sandbox/monitoring/trunk/core/src/main/java/org/apache/commons/monitoring/store/InMemoryGaugeDataStore.java
URL: http://svn.apache.org/viewvc/commons/sandbox/monitoring/trunk/core/src/main/java/org/apache/commons/monitoring/store/InMemoryGaugeDataStore.java?rev=1533455&view=auto
==============================================================================
--- commons/sandbox/monitoring/trunk/core/src/main/java/org/apache/commons/monitoring/store/InMemoryGaugeDataStore.java (added)
+++ commons/sandbox/monitoring/trunk/core/src/main/java/org/apache/commons/monitoring/store/InMemoryGaugeDataStore.java Fri Oct 18 13:56:08 2013
@@ -0,0 +1,81 @@
+/*
+ * 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.commons.monitoring.store;
+
+import org.apache.commons.monitoring.Role;
+import org.apache.commons.monitoring.configuration.Configuration;
+import org.apache.commons.monitoring.gauges.Gauge;
+
+import java.util.Collections;
+import java.util.Map;
+import java.util.TreeMap;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentSkipListMap;
+
+public class InMemoryGaugeDataStore implements GaugeDataStore {
+    private final Map<Role, Map<Long, Double>> gauges = new ConcurrentHashMap<Role, Map<Long, Double>>();
+
+    @Override
+    public Map<Long, Double> getGaugeValues(GaugeValuesRequest gaugeValuesRequest) {
+        final Map<Long, Double> map = gauges.get(gaugeValuesRequest.getRole());
+        if (map == null) {
+            return Collections.emptyMap();
+        }
+
+        final Map<Long, Double> copy = new TreeMap<Long, Double>(map);
+
+        final Map<Long, Double> out = new TreeMap<Long, Double>();
+        for (final Map.Entry<Long, Double> entry : copy.entrySet()) {
+            final long time = entry.getKey();
+            if (time >= gaugeValuesRequest.getStart() && time <= gaugeValuesRequest.getEnd()) {
+                out.put(time, entry.getValue());
+            }
+        }
+        return out;
+    }
+
+    @Override
+    public void createOrNoopGauge(final Role role) {
+        gauges.put(role, new FixedSizedMap());
+    }
+
+    @Override
+    public void addToGauge(final Gauge gauge, final long time, final double value) {
+        gauges.get(gauge.role()).put(time, value);
+    }
+
+    // no perf issues here normally since add is called not that often
+    protected static class FixedSizedMap extends ConcurrentSkipListMap<Long, Double> {
+        private static final int MAX_SIZE = Configuration.getInteger(Configuration.COMMONS_MONITORING_PREFIX + "gauge.max-size", 100);
+
+        protected FixedSizedMap() {
+            // no-op
+        }
+
+        protected FixedSizedMap(final Map<Long, Double> value) {
+            super(value);
+        }
+
+        @Override
+        public Double put(final Long key, final Double value) {
+            if (size() >= MAX_SIZE) {
+                remove(keySet().iterator().next());
+            }
+            return super.put(key, value);
+        }
+    }
+}

Propchange: commons/sandbox/monitoring/trunk/core/src/main/java/org/apache/commons/monitoring/store/InMemoryGaugeDataStore.java
------------------------------------------------------------------------------
    svn:executable = *

Modified: commons/sandbox/monitoring/trunk/core/src/test/java/org/apache/commons/monitoring/counters/CounterBench.java
URL: http://svn.apache.org/viewvc/commons/sandbox/monitoring/trunk/core/src/test/java/org/apache/commons/monitoring/counters/CounterBench.java?rev=1533455&r1=1533454&r2=1533455&view=diff
==============================================================================
--- commons/sandbox/monitoring/trunk/core/src/test/java/org/apache/commons/monitoring/counters/CounterBench.java (original)
+++ commons/sandbox/monitoring/trunk/core/src/test/java/org/apache/commons/monitoring/counters/CounterBench.java Fri Oct 18 13:56:08 2013
@@ -17,7 +17,7 @@
 package org.apache.commons.monitoring.counters;
 
 import org.apache.commons.monitoring.Role;
-import org.apache.commons.monitoring.store.DefaultDataStore;
+import org.apache.commons.monitoring.store.InMemoryCounterDataStore;
 import org.junit.Test;
 
 import java.util.concurrent.ExecutorService;
@@ -36,7 +36,7 @@ public class CounterBench implements Run
     @Test
     public void defaultCounter() throws Exception {
         mode = "RentrantLockCounter";
-        counter = new DefaultCounter(new Counter.Key(Role.FAILURES, mode), new DefaultDataStore());
+        counter = new DefaultCounter(new Counter.Key(Role.FAILURES, mode), new InMemoryCounterDataStore());
         runConcurrent();
     }
 

Modified: commons/sandbox/monitoring/trunk/cube/src/main/java/org/apache/commons/monitoring/cube/CubeCounter.java
URL: http://svn.apache.org/viewvc/commons/sandbox/monitoring/trunk/cube/src/main/java/org/apache/commons/monitoring/cube/CubeCounter.java?rev=1533455&r1=1533454&r2=1533455&view=diff
==============================================================================
--- commons/sandbox/monitoring/trunk/cube/src/main/java/org/apache/commons/monitoring/cube/CubeCounter.java (original)
+++ commons/sandbox/monitoring/trunk/cube/src/main/java/org/apache/commons/monitoring/cube/CubeCounter.java Fri Oct 18 13:56:08 2013
@@ -18,7 +18,7 @@ package org.apache.commons.monitoring.cu
 
 import org.apache.commons.monitoring.counters.Counter;
 import org.apache.commons.monitoring.counters.Unit;
-import org.apache.commons.monitoring.store.DataStore;
+import org.apache.commons.monitoring.store.CounterDataStore;
 
 import java.util.concurrent.atomic.AtomicInteger;
 import java.util.concurrent.locks.Lock;
@@ -31,9 +31,9 @@ public class CubeCounter implements Coun
     private final AtomicInteger concurrency = new AtomicInteger(0);
     private volatile int maxConcurrency = 0;
     private Lock lock = new ReentrantLock();
-    private final DataStore dataStore;
+    private final CounterDataStore dataStore;
 
-    public CubeCounter(final Key key, final DataStore store) {
+    public CubeCounter(final Key key, final CounterDataStore store) {
         this.key = key;
         this.dataStore = store;
     }

Added: commons/sandbox/monitoring/trunk/cube/src/main/java/org/apache/commons/monitoring/cube/CubeCounterDataStore.java
URL: http://svn.apache.org/viewvc/commons/sandbox/monitoring/trunk/cube/src/main/java/org/apache/commons/monitoring/cube/CubeCounterDataStore.java?rev=1533455&view=auto
==============================================================================
--- commons/sandbox/monitoring/trunk/cube/src/main/java/org/apache/commons/monitoring/cube/CubeCounterDataStore.java (added)
+++ commons/sandbox/monitoring/trunk/cube/src/main/java/org/apache/commons/monitoring/cube/CubeCounterDataStore.java Fri Oct 18 13:56:08 2013
@@ -0,0 +1,70 @@
+/*
+ * 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.commons.monitoring.cube;
+
+import org.apache.commons.monitoring.configuration.Configuration;
+import org.apache.commons.monitoring.counters.Counter;
+import org.apache.commons.monitoring.counters.MetricData;
+import org.apache.commons.monitoring.repositories.Repository;
+import org.apache.commons.monitoring.store.BatchCounterDataStore;
+
+import java.util.concurrent.locks.Lock;
+
+public class CubeCounterDataStore extends BatchCounterDataStore {
+    private static final String COUNTER_TYPE = "counter";
+
+    private final Cube cube = Configuration.findOrCreateInstance(CubeBuilder.class).build();
+
+    @Override
+    protected Counter newCounter(final Counter.Key key) {
+        return new CubeCounter(key, this);
+    }
+
+    @Override
+    public void addToCounter(final Counter counter, final double delta) {
+        if (!CubeCounter.class.isInstance(counter)) {
+            throw new IllegalArgumentException(getClass().getName() + " only supports " + CubeCounter.class.getName());
+        }
+
+        final CubeCounter cubeCounter = CubeCounter.class.cast(counter);
+        final Lock lock = cubeCounter.getLock();
+        lock.lock();
+        try {
+            cubeCounter.addInternal(delta);
+        } finally {
+            lock.unlock();
+        }
+    }
+
+    @Override
+    protected synchronized void pushCountersByBatch(final Repository instance) {
+        final long ts = System.currentTimeMillis();
+        final StringBuilder events = cube.newEventStream();
+        for (final Counter counter : instance) {
+            cube.buildEvent(events, COUNTER_TYPE, ts, new MapBuilder()
+                    .add("name", counter.getKey().getName())
+                    .add("role", counter.getKey().getRole().getName())
+                            // other metrics are not handled by CubeCounter and useless since cube re-aggregate
+                            // so to reduce overhead we just store it locally
+                    .add("concurrency", MetricData.Concurrency.value(counter))
+                    .add("sum", MetricData.Sum.value(counter))
+                    .add("hits", MetricData.Hits.value(counter))
+                    .map());
+        }
+        cube.post(events);
+    }
+}

Propchange: commons/sandbox/monitoring/trunk/cube/src/main/java/org/apache/commons/monitoring/cube/CubeCounterDataStore.java
------------------------------------------------------------------------------
    svn:executable = *

Added: commons/sandbox/monitoring/trunk/cube/src/main/java/org/apache/commons/monitoring/cube/CubeDataStoreFactory.java
URL: http://svn.apache.org/viewvc/commons/sandbox/monitoring/trunk/cube/src/main/java/org/apache/commons/monitoring/cube/CubeDataStoreFactory.java?rev=1533455&view=auto
==============================================================================
--- commons/sandbox/monitoring/trunk/cube/src/main/java/org/apache/commons/monitoring/cube/CubeDataStoreFactory.java (added)
+++ commons/sandbox/monitoring/trunk/cube/src/main/java/org/apache/commons/monitoring/cube/CubeDataStoreFactory.java Fri Oct 18 13:56:08 2013
@@ -0,0 +1,29 @@
+/*
+ * 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.commons.monitoring.cube;
+
+import org.apache.commons.monitoring.store.CounterDataStore;
+import org.apache.commons.monitoring.store.DataStoreFactory;
+import org.apache.commons.monitoring.store.DelegateDataStoreFactory;
+import org.apache.commons.monitoring.store.GaugeDataStore;
+
+public class CubeDataStoreFactory extends DelegateDataStoreFactory {
+
+    public CubeDataStoreFactory() {
+        super(new CubeCounterDataStore(), new CubeGaugeDataStore());
+    }
+}

Propchange: commons/sandbox/monitoring/trunk/cube/src/main/java/org/apache/commons/monitoring/cube/CubeDataStoreFactory.java
------------------------------------------------------------------------------
    svn:executable = *

Added: commons/sandbox/monitoring/trunk/cube/src/main/java/org/apache/commons/monitoring/cube/CubeGaugeDataStore.java
URL: http://svn.apache.org/viewvc/commons/sandbox/monitoring/trunk/cube/src/main/java/org/apache/commons/monitoring/cube/CubeGaugeDataStore.java?rev=1533455&view=auto
==============================================================================
--- commons/sandbox/monitoring/trunk/cube/src/main/java/org/apache/commons/monitoring/cube/CubeGaugeDataStore.java (added)
+++ commons/sandbox/monitoring/trunk/cube/src/main/java/org/apache/commons/monitoring/cube/CubeGaugeDataStore.java Fri Oct 18 13:56:08 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.commons.monitoring.cube;
+
+import org.apache.commons.monitoring.Role;
+import org.apache.commons.monitoring.configuration.Configuration;
+import org.apache.commons.monitoring.gauges.Gauge;
+import org.apache.commons.monitoring.store.GaugeDataStore;
+import org.apache.commons.monitoring.store.GaugeValuesRequest;
+
+import java.util.Collections;
+import java.util.Map;
+
+public class CubeGaugeDataStore implements GaugeDataStore {
+    private static final String GAUGE_TYPE = "gauge";
+
+    private final Cube cube = Configuration.findOrCreateInstance(CubeBuilder.class).build();
+
+    @Override
+    public Map<Long, Double> getGaugeValues(GaugeValuesRequest gaugeValuesRequest) {
+        return Collections.emptyMap();
+    }
+
+    @Override
+    public void createOrNoopGauge(Role role) {
+        // no-op
+    }
+
+    @Override
+    public void addToGauge(final Gauge gauge, final long time, final double value) {
+        final Role role = gauge.role();
+
+        cube.post(
+                cube.buildEvent(new StringBuilder(), GAUGE_TYPE, time,
+                        new MapBuilder()
+                                .add("value", value)
+                                .add("role", role.getName())
+                                .add("unit", role.getUnit().getName())
+                                .map()));
+    }
+}

Propchange: commons/sandbox/monitoring/trunk/cube/src/main/java/org/apache/commons/monitoring/cube/CubeGaugeDataStore.java
------------------------------------------------------------------------------
    svn:executable = *

Added: commons/sandbox/monitoring/trunk/cube/src/main/java/org/apache/commons/monitoring/cube/MapBuilder.java
URL: http://svn.apache.org/viewvc/commons/sandbox/monitoring/trunk/cube/src/main/java/org/apache/commons/monitoring/cube/MapBuilder.java?rev=1533455&view=auto
==============================================================================
--- commons/sandbox/monitoring/trunk/cube/src/main/java/org/apache/commons/monitoring/cube/MapBuilder.java (added)
+++ commons/sandbox/monitoring/trunk/cube/src/main/java/org/apache/commons/monitoring/cube/MapBuilder.java Fri Oct 18 13:56:08 2013
@@ -0,0 +1,33 @@
+/*
+ * 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.commons.monitoring.cube;
+
+import java.util.HashMap;
+import java.util.Map;
+
+public class MapBuilder {
+    private final Map<String, Object> map = new HashMap<String, Object>();
+
+    public MapBuilder add(final String key, final Object value) {
+        map.put(key, value);
+        return this;
+    }
+
+    public Map<String, Object> map() {
+        return map;
+    }
+}
\ No newline at end of file

Propchange: commons/sandbox/monitoring/trunk/cube/src/main/java/org/apache/commons/monitoring/cube/MapBuilder.java
------------------------------------------------------------------------------
    svn:executable = *

Modified: commons/sandbox/monitoring/trunk/cube/src/test/java/org/apache/commons/monitoring/cube/CubeDataStoreTest.java
URL: http://svn.apache.org/viewvc/commons/sandbox/monitoring/trunk/cube/src/test/java/org/apache/commons/monitoring/cube/CubeDataStoreTest.java?rev=1533455&r1=1533454&r2=1533455&view=diff
==============================================================================
--- commons/sandbox/monitoring/trunk/cube/src/test/java/org/apache/commons/monitoring/cube/CubeDataStoreTest.java (original)
+++ commons/sandbox/monitoring/trunk/cube/src/test/java/org/apache/commons/monitoring/cube/CubeDataStoreTest.java Fri Oct 18 13:56:08 2013
@@ -39,6 +39,7 @@ public class CubeDataStoreTest {
     private CubeServer server;
     private Gauge.LoaderHelper gauges;
 
+
     @Before
     public void startCube() throws IOException {
         server = new CubeServer("localhost", 1234).start();
@@ -53,6 +54,7 @@ public class CubeDataStoreTest {
         server.stop();
     }
 
+
     @Test
     public void store() throws InterruptedException, UnknownHostException {
         { // force some counter data
@@ -62,7 +64,7 @@ public class CubeDataStoreTest {
             Thread.sleep(150);
             counter.add(2.3);
             counter.add(2.9);
-            Thread.sleep(150);
+            Thread.sleep(1500);
         }
 
         final Collection<String> messages = server.getMessages();

Modified: commons/sandbox/monitoring/trunk/cube/src/test/resources/commons-monitoring.properties
URL: http://svn.apache.org/viewvc/commons/sandbox/monitoring/trunk/cube/src/test/resources/commons-monitoring.properties?rev=1533455&r1=1533454&r2=1533455&view=diff
==============================================================================
--- commons/sandbox/monitoring/trunk/cube/src/test/resources/commons-monitoring.properties (original)
+++ commons/sandbox/monitoring/trunk/cube/src/test/resources/commons-monitoring.properties Fri Oct 18 13:56:08 2013
@@ -14,6 +14,7 @@
 # KIND, either express or implied.  See the License for the
 # specific language governing permissions and limitations
 # under the License.
-org.apache.commons.monitoring.store.DataStore = org.apache.commons.monitoring.cube.CubeDataStore
+org.apache.commons.monitoring.store.DataStoreFactory = org.apache.commons.monitoring.cube.CubeDataStoreFactory
 org.apache.commons.monitoring.cube.period = 100
 org.apache.commons.monitoring.cube.CubeBuilder.collector = http://localhost:1234/1.0/event/put
+

Modified: commons/sandbox/monitoring/trunk/graphite/src/main/java/org/apache/commons/monitoring/graphite/Graphite.java
URL: http://svn.apache.org/viewvc/commons/sandbox/monitoring/trunk/graphite/src/main/java/org/apache/commons/monitoring/graphite/Graphite.java?rev=1533455&r1=1533454&r2=1533455&view=diff
==============================================================================
--- commons/sandbox/monitoring/trunk/graphite/src/main/java/org/apache/commons/monitoring/graphite/Graphite.java (original)
+++ commons/sandbox/monitoring/trunk/graphite/src/main/java/org/apache/commons/monitoring/graphite/Graphite.java Fri Oct 18 13:56:08 2013
@@ -29,7 +29,7 @@ import java.util.regex.Pattern;
 
 public class Graphite implements Closeable {
     private static final char LN = '\n';
-    private static final char SPACE = ' ';
+    private static final String SPACE = " ";
     private static final Charset UTF_8 = Charset.forName("UTF-8");
     private static final Pattern WHITESPACE = Pattern.compile("[\\s]+");
     private static final String SPACE_REPLACEMENT = "_";
@@ -80,10 +80,10 @@ public class Graphite implements Closeab
      */
     public void push(final String metricPath, final double metricValue, final long metricTimeStamp) throws IOException {
         writer.write(
-            WHITESPACE.matcher(metricPath).replaceAll(SPACE_REPLACEMENT) + SPACE
-            + String.format(Locale.US, VALUE_FORMAT, metricValue) + SPACE
-            + metricTimeStamp
-            + LN);
+                WHITESPACE.matcher(noSpace(metricPath)).replaceAll(SPACE_REPLACEMENT) + SPACE
+                        + String.format(Locale.US, VALUE_FORMAT, metricValue) + SPACE
+                        + metricTimeStamp
+                        + LN);
     }
 
     /**
@@ -120,4 +120,9 @@ public class Graphite implements Closeab
         writer = null;
         socket = null;
     }
+
+    private static String noSpace(final String s) {
+        return s.replace(SPACE, SPACE_REPLACEMENT);
+    }
+
 }

Added: commons/sandbox/monitoring/trunk/graphite/src/main/java/org/apache/commons/monitoring/graphite/GraphiteCounterDataStore.java
URL: http://svn.apache.org/viewvc/commons/sandbox/monitoring/trunk/graphite/src/main/java/org/apache/commons/monitoring/graphite/GraphiteCounterDataStore.java?rev=1533455&view=auto
==============================================================================
--- commons/sandbox/monitoring/trunk/graphite/src/main/java/org/apache/commons/monitoring/graphite/GraphiteCounterDataStore.java (added)
+++ commons/sandbox/monitoring/trunk/graphite/src/main/java/org/apache/commons/monitoring/graphite/GraphiteCounterDataStore.java Fri Oct 18 13:56:08 2013
@@ -0,0 +1,62 @@
+/*
+ * 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.commons.monitoring.graphite;
+
+import org.apache.commons.monitoring.configuration.Configuration;
+import org.apache.commons.monitoring.counters.Counter;
+import org.apache.commons.monitoring.counters.MetricData;
+import org.apache.commons.monitoring.repositories.Repository;
+import org.apache.commons.monitoring.store.BatchCounterDataStore;
+
+import java.io.IOException;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+public class GraphiteCounterDataStore extends BatchCounterDataStore {
+    private static final Logger LOGGER = Logger.getLogger(GraphiteCounterDataStore.class.getName());
+
+    private static final String COUNTER_PREFIX = "counter-";
+    private static final char SEP = '-';
+
+    private final Graphite graphite = Configuration.findOrCreateInstance(GraphiteBuilder.class).build();
+
+    @Override
+    protected synchronized void pushCountersByBatch(final Repository instance) {
+        try {
+            graphite.open();
+
+            final long ts = System.currentTimeMillis();
+
+            for (final Counter counter : instance) {
+                final Counter.Key key = counter.getKey();
+                final String prefix = COUNTER_PREFIX + key.getRole().getName() + SEP + key.getName() + SEP;
+
+                for (final MetricData data : MetricData.values()) {
+                    graphite.push(
+                            prefix + data.name(),
+                            data.value(counter),
+                            ts);
+                }
+            }
+        } catch (final IOException e) {
+            LOGGER.log(Level.SEVERE, e.getMessage(), e);
+        } finally {
+            graphite.close();
+        }
+    }
+
+}

Propchange: commons/sandbox/monitoring/trunk/graphite/src/main/java/org/apache/commons/monitoring/graphite/GraphiteCounterDataStore.java
------------------------------------------------------------------------------
    svn:executable = *

Added: commons/sandbox/monitoring/trunk/graphite/src/main/java/org/apache/commons/monitoring/graphite/GraphiteDataStoreFactory.java
URL: http://svn.apache.org/viewvc/commons/sandbox/monitoring/trunk/graphite/src/main/java/org/apache/commons/monitoring/graphite/GraphiteDataStoreFactory.java?rev=1533455&view=auto
==============================================================================
--- commons/sandbox/monitoring/trunk/graphite/src/main/java/org/apache/commons/monitoring/graphite/GraphiteDataStoreFactory.java (added)
+++ commons/sandbox/monitoring/trunk/graphite/src/main/java/org/apache/commons/monitoring/graphite/GraphiteDataStoreFactory.java Fri Oct 18 13:56:08 2013
@@ -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.
+ */
+package org.apache.commons.monitoring.graphite;
+
+import org.apache.commons.monitoring.store.CounterDataStore;
+import org.apache.commons.monitoring.store.DelegateDataStoreFactory;
+import org.apache.commons.monitoring.store.GaugeDataStore;
+
+public class GraphiteDataStoreFactory extends DelegateDataStoreFactory {
+    public GraphiteDataStoreFactory() {
+        super(new GraphiteCounterDataStore(), new GraphiteGaugeDataStore());
+    }
+}

Propchange: commons/sandbox/monitoring/trunk/graphite/src/main/java/org/apache/commons/monitoring/graphite/GraphiteDataStoreFactory.java
------------------------------------------------------------------------------
    svn:executable = *

Added: commons/sandbox/monitoring/trunk/graphite/src/main/java/org/apache/commons/monitoring/graphite/GraphiteGaugeDataStore.java
URL: http://svn.apache.org/viewvc/commons/sandbox/monitoring/trunk/graphite/src/main/java/org/apache/commons/monitoring/graphite/GraphiteGaugeDataStore.java?rev=1533455&view=auto
==============================================================================
--- commons/sandbox/monitoring/trunk/graphite/src/main/java/org/apache/commons/monitoring/graphite/GraphiteGaugeDataStore.java (added)
+++ commons/sandbox/monitoring/trunk/graphite/src/main/java/org/apache/commons/monitoring/graphite/GraphiteGaugeDataStore.java Fri Oct 18 13:56:08 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.commons.monitoring.graphite;
+
+import org.apache.commons.monitoring.Role;
+import org.apache.commons.monitoring.configuration.Configuration;
+import org.apache.commons.monitoring.gauges.Gauge;
+import org.apache.commons.monitoring.store.GaugeDataStore;
+import org.apache.commons.monitoring.store.GaugeValuesRequest;
+
+import java.io.IOException;
+import java.util.Collections;
+import java.util.Map;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+public class GraphiteGaugeDataStore implements GaugeDataStore {
+    private static final Logger LOGGER = Logger.getLogger(GraphiteGaugeDataStore.class.getName());
+
+    private static final String GAUGE_PREFIX = "gauge-";
+    private final Graphite graphite = Configuration.findOrCreateInstance(GraphiteBuilder.class).build();
+
+    @Override
+    public void addToGauge(final Gauge gauge, final long time, final double value) {
+        try {
+            graphite.simplePush(GAUGE_PREFIX + gauge.role().getName(), value, time);
+        } catch (final IOException e) {
+            LOGGER.log(Level.SEVERE, e.getMessage(), e);
+        }
+    }
+
+    @Override
+    public Map<Long, Double> getGaugeValues(final GaugeValuesRequest gaugeValuesRequest) {
+        return Collections.emptyMap(); // when using graphite we expect the user to use Graphite to render metrics
+    }
+
+    @Override
+    public void createOrNoopGauge(Role role) {
+        // no-op
+    }
+}

Propchange: commons/sandbox/monitoring/trunk/graphite/src/main/java/org/apache/commons/monitoring/graphite/GraphiteGaugeDataStore.java
------------------------------------------------------------------------------
    svn:executable = *

Modified: commons/sandbox/monitoring/trunk/graphite/src/test/resources/commons-monitoring.properties
URL: http://svn.apache.org/viewvc/commons/sandbox/monitoring/trunk/graphite/src/test/resources/commons-monitoring.properties?rev=1533455&r1=1533454&r2=1533455&view=diff
==============================================================================
--- commons/sandbox/monitoring/trunk/graphite/src/test/resources/commons-monitoring.properties (original)
+++ commons/sandbox/monitoring/trunk/graphite/src/test/resources/commons-monitoring.properties Fri Oct 18 13:56:08 2013
@@ -14,7 +14,7 @@
 # KIND, either express or implied.  See the License for the
 # specific language governing permissions and limitations
 # under the License.
-org.apache.commons.monitoring.store.DataStore = org.apache.commons.monitoring.graphite.GraphiteDataStore
+org.apache.commons.monitoring.store.DataStoreFactory = org.apache.commons.monitoring.graphite.GraphiteDataStoreFactory
 
 org.apache.commons.monitoring.graphite.period = 100
 



Mime
View raw message