commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rmannibu...@apache.org
Subject svn commit: r1534136 [2/2] - in /commons/sandbox/monitoring/trunk: ./ collector/ collector/src/main/java/org/apache/commons/monitoring/collector/rest/ collector/src/main/java/org/apache/commons/monitoring/collector/server/ collector/src/main/java/org/a...
Date Mon, 21 Oct 2013 12:54:18 GMT
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=1534136&r1=1534135&r2=1534136&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
Mon Oct 21 12:54:16 2013
@@ -21,7 +21,8 @@ import org.apache.commons.monitoring.sto
 
 import java.util.concurrent.atomic.AtomicInteger;
 import java.util.concurrent.locks.Lock;
-import java.util.concurrent.locks.ReentrantLock;
+import java.util.concurrent.locks.ReadWriteLock;
+import java.util.concurrent.locks.ReentrantReadWriteLock;
 
 public class DefaultCounter implements Counter {
     private final AtomicInteger concurrency = new AtomicInteger(0);
@@ -29,7 +30,7 @@ public class DefaultCounter implements C
     private final CounterDataStore dataStore;
     private volatile int maxConcurrency = 0;
     protected SummaryStatistics statistics;
-    protected Lock lock = new ReentrantLock();
+    protected ReadWriteLock lock = new ReentrantReadWriteLock();
 
     public DefaultCounter(final Key key, final CounterDataStore store) {
         this.key = key;
@@ -81,55 +82,93 @@ public class DefaultCounter implements C
 
     @Override
     public double getMax() {
-        return statistics.getMax();
+        final Lock rl = lock.readLock();
+        rl.lock();
+        try {
+            return statistics.getMax();
+        } finally {
+            rl.unlock();
+        }
     }
 
     @Override
     public double getMin() {
-        return statistics.getMin();
+        final Lock rl = lock.readLock();
+        rl.lock();
+        try {
+            return statistics.getMin();
+        } finally {
+            rl.unlock();
+        }
     }
 
     @Override
     public double getSum() {
-        return statistics.getSum();
+        final Lock rl = lock.readLock();
+        rl.lock();
+        try {
+            return statistics.getSum();
+        } finally {
+            rl.unlock();
+        }
     }
 
     @Override
     public double getStandardDeviation() {
-        return statistics.getStandardDeviation();
+        final Lock rl = lock.readLock();
+        rl.lock();
+        try {
+            return statistics.getStandardDeviation();
+        } finally {
+            rl.unlock();
+        }
     }
 
     @Override
     public double getVariance() {
-        return statistics.getVariance();
+        final Lock rl = lock.readLock();
+        rl.lock();
+        try {
+            return statistics.getVariance();
+        } finally {
+            rl.unlock();
+        }
     }
 
     @Override
     public double getMean() {
-        return statistics.getMean();
-    }
-
-    @Override
-    public double getGeometricMean() {
-        return statistics.getGeometricMean();
-    }
-
-    @Override
-    public double getSumOfLogs() {
-        return statistics.getSumOfLogs();
+        final Lock rl = lock.readLock();
+        rl.lock();
+        try {
+            return statistics.getMean();
+        } finally {
+            rl.unlock();
+        }
     }
 
     @Override
-    public double getSumOfSquares() {
-        return statistics.getSumOfLogs();
+    public double getSecondMoment() {
+        final Lock rl = lock.readLock();
+        rl.lock();
+        try {
+            return statistics.getSecondMoment();
+        } finally {
+            rl.unlock();
+        }
     }
 
     @Override
     public long getHits() {
-        return statistics.getN();
+        final Lock rl = lock.readLock();
+        rl.lock();
+        try {
+            return statistics.getN();
+        } finally {
+            rl.unlock();
+        }
     }
 
-    public Lock getLock() {
+    public ReadWriteLock getLock() {
         return lock;
     }
 }

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=1534136&r1=1534135&r2=1534136&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
Mon Oct 21 12:54:16 2013
@@ -98,28 +98,6 @@ public enum MetricData {
             return true;
         }
     },
-    SumOfLogs {
-        @Override
-        public double value(final Counter counter) {
-            return counter.getSumOfLogs();
-        }
-
-        @Override
-        public boolean isTime() {
-            return false;
-        }
-    },
-    SumOfSquares {
-        @Override
-        public double value(final Counter counter) {
-            return counter.getSumOfSquares();
-        }
-
-        @Override
-        public boolean isTime() {
-            return false;
-        }
-    },
     Variance {
         @Override
         public double value(final Counter counter) {
@@ -131,17 +109,6 @@ public enum MetricData {
             return false;
         }
     },
-    GeometricMean {
-        @Override
-        public double value(final Counter counter) {
-            return counter.getGeometricMean();
-        }
-
-        @Override
-        public boolean isTime() {
-            return false;
-        }
-    },
     Value {
         @Override
         public double value(final Counter counter) {

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=1534136&r1=1534135&r2=1534136&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
Mon Oct 21 12:54:16 2013
@@ -73,7 +73,8 @@ public final class DefaultGaugeManager i
             final long time = System.currentTimeMillis();
             final double value = gauge.value();
 
-            store.addToGauge(gauge, time, value);
+            // role could be dynamic...even if not advised
+            store.addToGauge(gauge.role(), time, value);
         }
     }
 }

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=1534136&r1=1534135&r2=1534136&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
Mon Oct 21 12:54:16 2013
@@ -18,9 +18,9 @@ package org.apache.commons.monitoring.ga
 
 import org.apache.commons.monitoring.Role;
 import org.apache.commons.monitoring.repositories.Repository;
+import org.apache.commons.monitoring.spi.SPI;
 
 import java.util.LinkedList;
-import java.util.ServiceLoader;
 
 public interface Gauge {
     Role role();
@@ -35,10 +35,10 @@ public interface Gauge {
         public LoaderHelper(final boolean excludeParent, final String... includedPrefixes)
{
             final ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
 
-            for (final Gauge g : ServiceLoader.load(Gauge.class, classLoader)) {
+            for (final Gauge g : SPI.INSTANCE.find(Gauge.class, classLoader)) {
                 addGaugeIfNecessary(classLoader, g, excludeParent, includedPrefixes);
             }
-            for (final GaugeFactory gf : ServiceLoader.load(GaugeFactory.class, classLoader))
{
+            for (final GaugeFactory gf : SPI.INSTANCE.find(GaugeFactory.class, classLoader))
{
                 for (final Gauge g : gf.gauges()) {
                     addGaugeIfNecessary(classLoader, g, excludeParent, includedPrefixes);
                 }

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=1534136&r1=1534135&r2=1534136&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
Mon Oct 21 12:54:16 2013
@@ -54,10 +54,12 @@ public class DefaultRepository implement
 
         if (counter == null) {
             counter = Configuration.findOrCreateInstance(DataStoreFactory.class).getCounterDataStore();
+            Configuration.setSingletonInstance(CounterDataStore.class, counter);
         }
 
         if (gauge == null) {
             gauge = Configuration.findOrCreateInstance(DataStoreFactory.class).getGaugeDataStore();
+            Configuration.setSingletonInstance(GaugeDataStore.class, gauge);
         }
         this.counterDataStore = counter;
         this.gaugeDataStore = gauge;

Added: commons/sandbox/monitoring/trunk/core/src/main/java/org/apache/commons/monitoring/spi/DefaultSPI.java
URL: http://svn.apache.org/viewvc/commons/sandbox/monitoring/trunk/core/src/main/java/org/apache/commons/monitoring/spi/DefaultSPI.java?rev=1534136&view=auto
==============================================================================
--- commons/sandbox/monitoring/trunk/core/src/main/java/org/apache/commons/monitoring/spi/DefaultSPI.java
(added)
+++ commons/sandbox/monitoring/trunk/core/src/main/java/org/apache/commons/monitoring/spi/DefaultSPI.java
Mon Oct 21 12:54:16 2013
@@ -0,0 +1,26 @@
+/*
+ * 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.spi;
+
+import java.util.ServiceLoader;
+
+public class DefaultSPI implements SPI {
+    @Override
+    public <T> Iterable<T> find(final Class<T> api, final ClassLoader loader)
{
+        return ServiceLoader.load(api, loader);
+    }
+}

Added: commons/sandbox/monitoring/trunk/core/src/main/java/org/apache/commons/monitoring/spi/SPI.java
URL: http://svn.apache.org/viewvc/commons/sandbox/monitoring/trunk/core/src/main/java/org/apache/commons/monitoring/spi/SPI.java?rev=1534136&view=auto
==============================================================================
--- commons/sandbox/monitoring/trunk/core/src/main/java/org/apache/commons/monitoring/spi/SPI.java
(added)
+++ commons/sandbox/monitoring/trunk/core/src/main/java/org/apache/commons/monitoring/spi/SPI.java
Mon Oct 21 12:54:16 2013
@@ -0,0 +1,26 @@
+/*
+ * 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.spi;
+
+import org.apache.commons.monitoring.configuration.Configuration;
+
+// ServiceLoader is sometimes just wrong
+public interface SPI {
+    SPI INSTANCE = Configuration.findOrCreateInstance(SPI.class);
+
+    <T> Iterable<T> find(Class<T> api, ClassLoader loader);
+}

Modified: 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=1534136&r1=1534135&r2=1534136&view=diff
==============================================================================
--- commons/sandbox/monitoring/trunk/core/src/main/java/org/apache/commons/monitoring/store/GaugeDataStore.java
(original)
+++ commons/sandbox/monitoring/trunk/core/src/main/java/org/apache/commons/monitoring/store/GaugeDataStore.java
Mon Oct 21 12:54:16 2013
@@ -26,5 +26,5 @@ public interface GaugeDataStore {
 
     void createOrNoopGauge(Role role);
 
-    void addToGauge(Gauge gauge, long time, double value);
+    void addToGauge(Role role, long time, double value);
 }

Modified: 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=1534136&r1=1534135&r2=1534136&view=diff
==============================================================================
--- commons/sandbox/monitoring/trunk/core/src/main/java/org/apache/commons/monitoring/store/InMemoryCounterDataStore.java
(original)
+++ commons/sandbox/monitoring/trunk/core/src/main/java/org/apache/commons/monitoring/store/InMemoryCounterDataStore.java
Mon Oct 21 12:54:16 2013
@@ -25,7 +25,15 @@ import java.util.concurrent.ConcurrentMa
 import java.util.concurrent.locks.Lock;
 
 public class InMemoryCounterDataStore implements CounterDataStore {
-    protected final ConcurrentMap<Counter.Key, Counter> counters = new ConcurrentHashMap<Counter.Key,
Counter>(50);
+    protected final ConcurrentMap<Counter.Key, Counter> counters = newCounterMap();
+
+    protected ConcurrentMap<Counter.Key, Counter> newCounterMap() {
+        return new ConcurrentHashMap<Counter.Key, Counter>(50);
+    }
+
+    protected Counter newCounter(final Counter.Key key) {
+        return new DefaultCounter(key, this);
+    }
 
     @Override
     public Counter getOrCreateCounter(final Counter.Key key) {
@@ -50,10 +58,6 @@ public class InMemoryCounterDataStore im
         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)) {
@@ -61,7 +65,7 @@ public class InMemoryCounterDataStore im
         }
 
         final DefaultCounter defaultCounter = DefaultCounter.class.cast(counter);
-        final Lock lock = defaultCounter.getLock();
+        final Lock lock = defaultCounter.getLock().writeLock();
         lock.lock();
         try {
             defaultCounter.addInternal(delta);

Modified: 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=1534136&r1=1534135&r2=1534136&view=diff
==============================================================================
--- commons/sandbox/monitoring/trunk/core/src/main/java/org/apache/commons/monitoring/store/InMemoryGaugeDataStore.java
(original)
+++ commons/sandbox/monitoring/trunk/core/src/main/java/org/apache/commons/monitoring/store/InMemoryGaugeDataStore.java
Mon Oct 21 12:54:16 2013
@@ -18,7 +18,6 @@ package org.apache.commons.monitoring.st
 
 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;
@@ -53,15 +52,11 @@ public class InMemoryGaugeDataStore impl
         gauges.put(role, new FixedSizedMap());
     }
 
+    @Override
     public void addToGauge(final Role role, final long time, final double value) {
         gauges.get(role).put(time, value);
     }
 
-    @Override
-    public void addToGauge(final Gauge gauge, final long time, final double value) {
-        addToGauge(gauge.role(), 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);

Modified: commons/sandbox/monitoring/trunk/cube/pom.xml
URL: http://svn.apache.org/viewvc/commons/sandbox/monitoring/trunk/cube/pom.xml?rev=1534136&r1=1534135&r2=1534136&view=diff
==============================================================================
--- commons/sandbox/monitoring/trunk/cube/pom.xml (original)
+++ commons/sandbox/monitoring/trunk/cube/pom.xml Mon Oct 21 12:54:16 2013
@@ -43,8 +43,6 @@
     <dependency>
       <groupId>io.netty</groupId>
       <artifactId>netty-codec-http</artifactId>
-      <version>4.0.9.Final</version>
-      <scope>test</scope>
     </dependency>
   </dependencies>
 </project>

Modified: 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=1534136&r1=1534135&r2=1534136&view=diff
==============================================================================
--- commons/sandbox/monitoring/trunk/cube/src/main/java/org/apache/commons/monitoring/cube/CubeCounterDataStore.java
(original)
+++ commons/sandbox/monitoring/trunk/cube/src/main/java/org/apache/commons/monitoring/cube/CubeCounterDataStore.java
Mon Oct 21 12:54:16 2013
@@ -22,33 +22,22 @@ import org.apache.commons.monitoring.cou
 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);
-    }
+    private static final String NAME = "name";
+    private static final String ROLE = "role";
+    private static final String UNIT = "unit";
+    private static final String CONCURRENCY = "concurrency";
+    private static final String MEAN = "mean";
+    private static final String VARIANCE = "variance";
+    private static final String HITS = "hits";
+    private static final String MAX = "max";
+    private static final String MIN = "min";
+    private static final String SUM = "sum";
+    private static final String M_2 = "m2";
 
-    @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();
-        }
-    }
+    private final Cube cube = Configuration.findOrCreateInstance(CubeBuilder.class).build();
 
     @Override
     protected synchronized void pushCountersByBatch(final Repository instance) {
@@ -56,14 +45,18 @@ public class CubeCounterDataStore extend
         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())
-                    .add("unit", counter.getKey().getRole().getUnit())
-                            // 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))
+                    .add(NAME, counter.getKey().getName())
+                    .add(ROLE, counter.getKey().getRole().getName())
+                    .add(UNIT, counter.getKey().getRole().getUnit().getName())
+                    // minimum metrics to be able to aggregate counters later
+                    .add(CONCURRENCY, counter.currentConcurrency().intValue())
+                    .add(MEAN, counter.getMean())
+                    .add(VARIANCE, counter.getVariance())
+                    .add(HITS, counter.getHits())
+                    .add(MAX, counter.getMax())
+                    .add(MIN, counter.getMin())
+                    .add(SUM, counter.getSum())
+                    .add(M_2, counter.getSecondMoment())
                     .map());
         }
         cube.post(events);

Modified: 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=1534136&r1=1534135&r2=1534136&view=diff
==============================================================================
--- commons/sandbox/monitoring/trunk/cube/src/main/java/org/apache/commons/monitoring/cube/CubeDataStoreFactory.java
(original)
+++ commons/sandbox/monitoring/trunk/cube/src/main/java/org/apache/commons/monitoring/cube/CubeDataStoreFactory.java
Mon Oct 21 12:54:16 2013
@@ -16,13 +16,9 @@
  */
 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());
     }

Modified: 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=1534136&r1=1534135&r2=1534136&view=diff
==============================================================================
--- commons/sandbox/monitoring/trunk/cube/src/main/java/org/apache/commons/monitoring/cube/CubeGaugeDataStore.java
(original)
+++ commons/sandbox/monitoring/trunk/cube/src/main/java/org/apache/commons/monitoring/cube/CubeGaugeDataStore.java
Mon Oct 21 12:54:16 2013
@@ -18,7 +18,6 @@ package org.apache.commons.monitoring.cu
 
 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;
 
@@ -41,9 +40,7 @@ public class CubeGaugeDataStore implemen
     }
 
     @Override
-    public void addToGauge(final Gauge gauge, final long time, final double value) {
-        final Role role = gauge.role();
-
+    public void addToGauge(final Role role, final long time, final double value) {
         cube.post(
                 cube.buildEvent(new StringBuilder(), GAUGE_TYPE, time,
                         new MapBuilder()

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=1534136&r1=1534135&r2=1534136&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
Mon Oct 21 12:54:16 2013
@@ -39,7 +39,6 @@ public class CubeDataStoreTest {
     private CubeServer server;
     private Gauge.LoaderHelper gauges;
 
-
     @Before
     public void startCube() throws IOException {
         server = new CubeServer("localhost", 1234).start();

Modified: commons/sandbox/monitoring/trunk/cube/src/test/java/org/apache/commons/monitoring/cube/CubeServer.java
URL: http://svn.apache.org/viewvc/commons/sandbox/monitoring/trunk/cube/src/test/java/org/apache/commons/monitoring/cube/CubeServer.java?rev=1534136&r1=1534135&r2=1534136&view=diff
==============================================================================
--- commons/sandbox/monitoring/trunk/cube/src/test/java/org/apache/commons/monitoring/cube/CubeServer.java
(original)
+++ commons/sandbox/monitoring/trunk/cube/src/test/java/org/apache/commons/monitoring/cube/CubeServer.java
Mon Oct 21 12:54:16 2013
@@ -40,6 +40,7 @@ import io.netty.handler.stream.ChunkedWr
 
 import java.io.IOException;
 import java.net.ServerSocket;
+import java.nio.charset.Charset;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.LinkedList;
@@ -161,7 +162,7 @@ public class CubeServer {
             final ChannelFuture future;
             if (HttpMethod.POST.equals(fullHttpRequest.getMethod())) {
                 synchronized (messages) {
-                    messages.add(new String(fullHttpRequest.content().array()));
+                    messages.add(fullHttpRequest.content().toString(Charset.defaultCharset()));
                 }
                 final HttpResponse response = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1,
HttpResponseStatus.OK);
                 future = ctx.writeAndFlush(response);

Modified: 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=1534136&r1=1534135&r2=1534136&view=diff
==============================================================================
--- commons/sandbox/monitoring/trunk/graphite/src/main/java/org/apache/commons/monitoring/graphite/GraphiteGaugeDataStore.java
(original)
+++ commons/sandbox/monitoring/trunk/graphite/src/main/java/org/apache/commons/monitoring/graphite/GraphiteGaugeDataStore.java
Mon Oct 21 12:54:16 2013
@@ -18,7 +18,6 @@ package org.apache.commons.monitoring.gr
 
 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;
 
@@ -35,9 +34,9 @@ public class GraphiteGaugeDataStore impl
     private final Graphite graphite = Configuration.findOrCreateInstance(GraphiteBuilder.class).build();
 
     @Override
-    public void addToGauge(final Gauge gauge, final long time, final double value) {
+    public void addToGauge(final Role role, final long time, final double value) {
         try {
-            graphite.simplePush(GAUGE_PREFIX + gauge.role().getName(), value, time);
+            graphite.simplePush(GAUGE_PREFIX + role.getName(), value, time);
         } catch (final IOException e) {
             LOGGER.log(Level.SEVERE, e.getMessage(), e);
         }

Modified: commons/sandbox/monitoring/trunk/graphite/src/test/java/org/apache/commons/monitoring/graphite/GraphiteTest.java
URL: http://svn.apache.org/viewvc/commons/sandbox/monitoring/trunk/graphite/src/test/java/org/apache/commons/monitoring/graphite/GraphiteTest.java?rev=1534136&r1=1534135&r2=1534136&view=diff
==============================================================================
--- commons/sandbox/monitoring/trunk/graphite/src/test/java/org/apache/commons/monitoring/graphite/GraphiteTest.java
(original)
+++ commons/sandbox/monitoring/trunk/graphite/src/test/java/org/apache/commons/monitoring/graphite/GraphiteTest.java
Mon Oct 21 12:54:16 2013
@@ -54,7 +54,7 @@ public class GraphiteTest extends Graphi
         }
 
         { // counters
-            assertEquals(39, counters.size());
+            assertEquals(30, counters.size());
             assertTrue(counters.contains("counter-performances-test-Hits 2.00"));
             assertTrue(counters.contains("counter-performances-test-Max 1.60"));
             assertTrue(counters.contains("counter-performances-test-Mean 1.50"));

Modified: commons/sandbox/monitoring/trunk/pom.xml
URL: http://svn.apache.org/viewvc/commons/sandbox/monitoring/trunk/pom.xml?rev=1534136&r1=1534135&r2=1534136&view=diff
==============================================================================
--- commons/sandbox/monitoring/trunk/pom.xml (original)
+++ commons/sandbox/monitoring/trunk/pom.xml Mon Oct 21 12:54:16 2013
@@ -152,6 +152,11 @@
   <dependencyManagement>
     <dependencies>
       <dependency>
+        <groupId>org.apache.commons</groupId>
+        <artifactId>commons-math3</artifactId>
+        <version>3.2</version>
+      </dependency>
+      <dependency>
         <groupId>junit</groupId>
         <artifactId>junit</artifactId>
         <version>4.11</version>
@@ -183,6 +188,12 @@
         <artifactId>commons-monitoring-web</artifactId>
         <version>${project.version}</version>
       </dependency>
+      <dependency>
+        <groupId>io.netty</groupId>
+        <artifactId>netty-codec-http</artifactId>
+        <version>4.0.11.Final</version>
+        <scope>test</scope>
+      </dependency>
     </dependencies>
   </dependencyManagement>
 

Modified: commons/sandbox/monitoring/trunk/reporting/src/main/java/org/apache/commons/monitoring/reporting/web/plugin/PluginRepository.java
URL: http://svn.apache.org/viewvc/commons/sandbox/monitoring/trunk/reporting/src/main/java/org/apache/commons/monitoring/reporting/web/plugin/PluginRepository.java?rev=1534136&r1=1534135&r2=1534136&view=diff
==============================================================================
--- commons/sandbox/monitoring/trunk/reporting/src/main/java/org/apache/commons/monitoring/reporting/web/plugin/PluginRepository.java
(original)
+++ commons/sandbox/monitoring/trunk/reporting/src/main/java/org/apache/commons/monitoring/reporting/web/plugin/PluginRepository.java
Mon Oct 21 12:54:16 2013
@@ -19,6 +19,7 @@ package org.apache.commons.monitoring.re
 import org.apache.commons.monitoring.configuration.Configuration;
 import org.apache.commons.monitoring.reporting.web.handler.internal.EndpointInfo;
 import org.apache.commons.monitoring.reporting.web.handler.internal.Invoker;
+import org.apache.commons.monitoring.spi.SPI;
 
 import java.util.Collection;
 import java.util.Map;
@@ -35,7 +36,7 @@ public final class PluginRepository {
     public static final String ACTIVATED_FLAG = ".activated";
 
     static {
-        for (final Plugin plugin : ServiceLoader.load(Plugin.class, Plugin.class.getClassLoader()))
{
+        for (final Plugin plugin : SPI.INSTANCE.find(Plugin.class, Plugin.class.getClassLoader()))
{
             final String name = plugin.name();
             if (name == null) {
                 throw new IllegalArgumentException("plugin name can't be null");

Modified: commons/sandbox/monitoring/trunk/reporting/src/test/java/org/apache/commons/monitoring/reporting/FormatsTest.java
URL: http://svn.apache.org/viewvc/commons/sandbox/monitoring/trunk/reporting/src/test/java/org/apache/commons/monitoring/reporting/FormatsTest.java?rev=1534136&r1=1534135&r2=1534136&view=diff
==============================================================================
--- commons/sandbox/monitoring/trunk/reporting/src/test/java/org/apache/commons/monitoring/reporting/FormatsTest.java
(original)
+++ commons/sandbox/monitoring/trunk/reporting/src/test/java/org/apache/commons/monitoring/reporting/FormatsTest.java
Mon Oct 21 12:54:16 2013
@@ -59,8 +59,8 @@ public class FormatsTest {
         helper.renderPlain(template.getTemplate(), template.getUserParams());
 
         assertEquals("<?xml version=\"1.0\"?> <repository> " +
-            "<counter name=\"RendererTest\" role=\"failures\" unit=\"u\" Hits=\"1.0\"
Max=\"1.0\" Mean=\"1.0\" Min=\"1.0\" StandardDeviation=\"0.0\" Sum=\"1.0\" " +
-            "SumOfLogs=\"0.0\" SumOfSquares=\"0.0\" Variance=\"0.0\" GeometricMean=\"1.0\"
Value=\"1.0\" Concurrency=\"0.0\" MaxConcurrency=\"1.0\" />" +
+            "<counter name=\"RendererTest\" role=\"failures\" unit=\"u\" Hits=\"1.0\"
Max=\"1.0\" Mean=\"1.0\" Min=\"1.0\" " +
+            "StandardDeviation=\"0.0\" Sum=\"1.0\" Variance=\"0.0\" Value=\"1.0\" Concurrency=\"0.0\"
MaxConcurrency=\"1.0\" />" +
             " </repository>", inline(out));
     }
 
@@ -73,8 +73,8 @@ public class FormatsTest {
 
         assertEquals("{\"counters\":[" +
             " {\"name\":\"RendererTest\", \"role\":\"failures\",\"unit\":\"u\",\"Hits\":\"1.0\",\"Max\":\"1.0\",\"Mean\":\"1.0\",\"Min\":\"1.0\","
+
-            "\"StandardDeviation\":\"0.0\",\"Sum\":\"1.0\",\"SumOfLogs\":\"0.0\",\"SumOfSquares\":\"0.0\",\"Variance\":\"0.0\","
+
-            "\"GeometricMean\":\"1.0\",\"Value\":\"1.0\",\"Concurrency\":\"0.0\",\"MaxConcurrency\":\"1.0\"}
]}", inline(out));
+            "\"StandardDeviation\":\"0.0\",\"Sum\":\"1.0\",\"Variance\":\"0.0\"," +
+            "\"Value\":\"1.0\",\"Concurrency\":\"0.0\",\"MaxConcurrency\":\"1.0\"} ]}", inline(out));
     }
 
     @Test
@@ -85,7 +85,7 @@ public class FormatsTest {
         helper.renderPlain(template.getTemplate(), template.getUserParams());
 
         assertEquals(CSVFormat.HEADER +
-            "RendererTest;failures (u);1.0;1.0;1.0;1.0;0.0;1.0;0.0;0.0;0.0;1.0;1.0;0.0;1.0\n",
+            "RendererTest;failures (u);1.0;1.0;1.0;1.0;0.0;1.0;0.0;1.0;0.0;1.0\n",
             out.toString());
     }
 

Added: commons/sandbox/monitoring/trunk/src/site/markdown/collector.md
URL: http://svn.apache.org/viewvc/commons/sandbox/monitoring/trunk/src/site/markdown/collector.md?rev=1534136&view=auto
==============================================================================
--- commons/sandbox/monitoring/trunk/src/site/markdown/collector.md (added)
+++ commons/sandbox/monitoring/trunk/src/site/markdown/collector.md Mon Oct 21 12:54:16 2013
@@ -0,0 +1,64 @@
+<!---
+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.
+-->
+# Collector
+
+Collector modules aims to aggregate data from multiple instances.
+
+## Features
+
+Default implementation only store data in memory.
+
+## Configuration
+
+Just use the collector `DataStoreFactory`: `org.apache.commons.monitoring.collector.server.store.CollectorDataStoreFactory`.
+
+For instance your `commons-monitoring.properties` can look like:
+
+```
+org.apache.commons.monitoring.store.DataStore = org.apache.commons.monitoring.collector.server.store.CollectorDataStoreFactory
+```
+
+The `GaugeDataStore` can be configured through `org.apache.commons.monitoring.collector.gauge.store-class`
property.
+By default it uses the in memory implementation but you can set your own one if you want.
+
+Note: if your `GaugeDataStore` has a constructor with a `String`, the marker of the store
will be passed to the `GaugeDataStore`.
+
+The `CounterDataStore` needs to be an instance of `org.apache.commons.monitoring.collector.server.store.counter.CollectorCounterStore`.
+By default it is in memory too but it is easily extensible to be persisted if needed.
+
+## Installing the collector
+
+To setup the collector you just need to configure the `DataStoreFactory` (see configuration
part) and configure the
+servlet `org.apache.commons.monitoring.collector.server.Collector`.
+
+## Pushing data
+
+The input is an array of event. Events are either gauges or counters.
+
+Here is an array with a single gauge:
+
+```json
+[{"type": "gauge","time": "-","data": {"unit":"u","marker":"client1","value":0.0,"role":"mock"}}]
+```
+
+And here is an array with a single counter:
+
+```json
+[{"type": "counter","time": "2013-10-21T12:50:40Z","data": {"min":1.4,"unit":"ns","hits":4,"max":2.9,"marker":"client1","name":"test","concurrency":0,"m2":1.4099999999999997,"sum":8.2,"mean":2.05,"role":"performances","variance":0.4699999999999999}}]
+```

Modified: commons/sandbox/monitoring/trunk/src/site/markdown/index.md
URL: http://svn.apache.org/viewvc/commons/sandbox/monitoring/trunk/src/site/markdown/index.md?rev=1534136&r1=1534135&r2=1534136&view=diff
==============================================================================
--- commons/sandbox/monitoring/trunk/src/site/markdown/index.md (original)
+++ commons/sandbox/monitoring/trunk/src/site/markdown/index.md Mon Oct 21 12:54:16 2013
@@ -42,4 +42,6 @@ How to start?
 
 [See Cube](./cube.html)
 
+[See Collector](./collector.html)
+
 



Mime
View raw message