You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sirona.apache.org by rm...@apache.org on 2013/11/18 10:54:32 UTC

svn commit: r1542961 - in /incubator/sirona/trunk: agent/performance/jta/src/main/java/org/apache/sirona/jta/ agent/performance/jta/src/test/resources/ agent/performance/web/src/main/java/org/apache/sirona/web/servlet/ agent/performance/web/src/main/ja...

Author: rmannibucau
Date: Mon Nov 18 09:54:31 2013
New Revision: 1542961

URL: http://svn.apache.org/r1542961
Log:
getting rid of a thread by gauge trying to use snapshots

Added:
    incubator/sirona/trunk/core/src/main/java/org/apache/sirona/gauges/GaugeAware.java
    incubator/sirona/trunk/core/src/main/java/org/apache/sirona/store/gauge/BatchGaugeDataStoreAdapter.java
      - copied, changed from r1542909, incubator/sirona/trunk/core/src/main/java/org/apache/sirona/store/gauge/AggregatedGaugeDataStoreAdapter.java
    incubator/sirona/trunk/server/plugins/hazelcast/gui/src/test/resources/sirona.properties
Removed:
    incubator/sirona/trunk/agent/pull/src/main/java/org/apache/sirona/agent/webapp/pull/gauge/
    incubator/sirona/trunk/core/src/main/java/org/apache/sirona/gauges/DefaultGaugeManager.java
    incubator/sirona/trunk/core/src/main/java/org/apache/sirona/gauges/GaugeManager.java
    incubator/sirona/trunk/core/src/main/java/org/apache/sirona/gauges/NoopGaugeManager.java
Modified:
    incubator/sirona/trunk/agent/performance/jta/src/main/java/org/apache/sirona/jta/JTAGauges.java
    incubator/sirona/trunk/agent/performance/jta/src/test/resources/sirona.properties
    incubator/sirona/trunk/agent/performance/web/src/main/java/org/apache/sirona/web/servlet/StatusGauge.java
    incubator/sirona/trunk/agent/performance/web/src/main/java/org/apache/sirona/web/session/SessionGauge.java
    incubator/sirona/trunk/agent/performance/web/src/test/resources/sirona.properties
    incubator/sirona/trunk/agent/pull/src/main/java/org/apache/sirona/agent/webapp/pull/repository/PullRepository.java
    incubator/sirona/trunk/agent/pull/src/test/java/org/apache/sirona/agent/webapp/pull/PullAnswerTest.java
    incubator/sirona/trunk/agent/store/cube/src/main/java/org/apache/sirona/cube/Cube.java
    incubator/sirona/trunk/agent/store/cube/src/main/java/org/apache/sirona/cube/CubeDataStoreFactory.java
    incubator/sirona/trunk/agent/store/cube/src/main/java/org/apache/sirona/cube/CubeGaugeDataStore.java
    incubator/sirona/trunk/agent/store/cube/src/test/java/org/apache/sirona/cube/CubeDataStoreTest.java
    incubator/sirona/trunk/agent/store/cube/src/test/java/org/apache/sirona/cube/gauge/MockGauge.java
    incubator/sirona/trunk/agent/store/graphite/src/main/java/org/apache/sirona/graphite/GraphiteGaugeDataStore.java
    incubator/sirona/trunk/agent/store/graphite/src/test/java/org/apache/sirona/graphite/GraphiteTest.java
    incubator/sirona/trunk/agent/store/graphite/src/test/java/org/apache/sirona/graphite/gauge/MockGauge.java
    incubator/sirona/trunk/agent/store/graphite/src/test/resources/sirona.properties
    incubator/sirona/trunk/core/src/main/java/org/apache/sirona/gauges/Gauge.java
    incubator/sirona/trunk/core/src/main/java/org/apache/sirona/gauges/GaugeDataStoreAdapter.java
    incubator/sirona/trunk/core/src/main/java/org/apache/sirona/gauges/counter/CounterGauge.java
    incubator/sirona/trunk/core/src/main/java/org/apache/sirona/gauges/jmx/JMXAttributeGaugeBase.java
    incubator/sirona/trunk/core/src/main/java/org/apache/sirona/gauges/jvm/BaseMemoryGauge.java
    incubator/sirona/trunk/core/src/main/java/org/apache/sirona/gauges/jvm/CPUGauge.java
    incubator/sirona/trunk/core/src/main/java/org/apache/sirona/repositories/DefaultRepository.java
    incubator/sirona/trunk/core/src/main/java/org/apache/sirona/store/DefaultDataStoreFactory.java
    incubator/sirona/trunk/core/src/main/java/org/apache/sirona/store/counter/InMemoryCounterDataStore.java
    incubator/sirona/trunk/core/src/main/java/org/apache/sirona/store/gauge/AggregatedGaugeDataStoreAdapter.java
    incubator/sirona/trunk/core/src/main/java/org/apache/sirona/store/gauge/InMemoryGaugeDataStore.java
    incubator/sirona/trunk/server/plugins/hazelcast/agent/src/main/java/org/apache/sirona/plugin/hazelcast/agent/gauge/HazelcastGaugeBase.java
    incubator/sirona/trunk/server/plugins/hazelcast/agent/src/test/java/org/apache/sirona/plugin/hazelcast/BasicHazelcastTest.java
    incubator/sirona/trunk/server/plugins/hazelcast/agent/src/test/resources/sirona.properties
    incubator/sirona/trunk/server/plugins/hazelcast/gui/src/test/java/org/apache/sirona/hazelcast/plugin/gui/HazelcastGuiTest.java
    incubator/sirona/trunk/server/plugins/tomee/agent/src/main/java/org/apache/sirona/tomee/agent/gauge/PoolGauge.java
    incubator/sirona/trunk/server/plugins/tomee/agent/src/test/java/org/apache/sirona/tomee/agent/GaugesTest.java
    incubator/sirona/trunk/server/plugins/tomee/agent/src/test/resources/sirona.properties
    incubator/sirona/trunk/src/site/markdown/concepts.md
    incubator/sirona/trunk/src/site/markdown/configuration.md

Modified: incubator/sirona/trunk/agent/performance/jta/src/main/java/org/apache/sirona/jta/JTAGauges.java
URL: http://svn.apache.org/viewvc/incubator/sirona/trunk/agent/performance/jta/src/main/java/org/apache/sirona/jta/JTAGauges.java?rev=1542961&r1=1542960&r2=1542961&view=diff
==============================================================================
--- incubator/sirona/trunk/agent/performance/jta/src/main/java/org/apache/sirona/jta/JTAGauges.java (original)
+++ incubator/sirona/trunk/agent/performance/jta/src/main/java/org/apache/sirona/jta/JTAGauges.java Mon Nov 18 09:54:31 2013
@@ -63,11 +63,6 @@ public class JTAGauges implements GaugeF
         public double value() {
             return counter.getAndSet(0);
         }
-
-        @Override
-        public long period() {
-            return period;
-        }
     }
 
     protected static class JTAActiveGauge extends JTAGauge {

Modified: incubator/sirona/trunk/agent/performance/jta/src/test/resources/sirona.properties
URL: http://svn.apache.org/viewvc/incubator/sirona/trunk/agent/performance/jta/src/test/resources/sirona.properties?rev=1542961&r1=1542960&r2=1542961&view=diff
==============================================================================
--- incubator/sirona/trunk/agent/performance/jta/src/test/resources/sirona.properties (original)
+++ incubator/sirona/trunk/agent/performance/jta/src/test/resources/sirona.properties Mon Nov 18 09:54:31 2013
@@ -14,4 +14,4 @@
 # KIND, either express or implied.  See the License for the
 # specific language governing permissions and limitations
 # under the License.
-org.apache.sirona.gauge.jta.period = 100
+org.apache.sirona.inmemory.gauge.period = 100

Modified: incubator/sirona/trunk/agent/performance/web/src/main/java/org/apache/sirona/web/servlet/StatusGauge.java
URL: http://svn.apache.org/viewvc/incubator/sirona/trunk/agent/performance/web/src/main/java/org/apache/sirona/web/servlet/StatusGauge.java?rev=1542961&r1=1542960&r2=1542961&view=diff
==============================================================================
--- incubator/sirona/trunk/agent/performance/web/src/main/java/org/apache/sirona/web/servlet/StatusGauge.java (original)
+++ incubator/sirona/trunk/agent/performance/web/src/main/java/org/apache/sirona/web/servlet/StatusGauge.java Mon Nov 18 09:54:31 2013
@@ -17,14 +17,11 @@
 package org.apache.sirona.web.servlet;
 
 import org.apache.sirona.Role;
-import org.apache.sirona.configuration.Configuration;
 import org.apache.sirona.gauges.Gauge;
 
 import java.util.concurrent.atomic.AtomicLong;
 
 public class StatusGauge implements Gauge {
-    private static final int PERIOD = Configuration.getInteger(Configuration.CONFIG_PROPERTY_PREFIX + "web.gauge.status.period", 4000);
-
     private final Role role;
     private final AtomicLong count = new AtomicLong(0);
 
@@ -42,11 +39,6 @@ public class StatusGauge implements Gaug
         return count.getAndSet(0);
     }
 
-    @Override
-    public long period() {
-        return PERIOD;
-    }
-
     public void incr() {
         count.incrementAndGet();
     }

Modified: incubator/sirona/trunk/agent/performance/web/src/main/java/org/apache/sirona/web/session/SessionGauge.java
URL: http://svn.apache.org/viewvc/incubator/sirona/trunk/agent/performance/web/src/main/java/org/apache/sirona/web/session/SessionGauge.java?rev=1542961&r1=1542960&r2=1542961&view=diff
==============================================================================
--- incubator/sirona/trunk/agent/performance/web/src/main/java/org/apache/sirona/web/session/SessionGauge.java (original)
+++ incubator/sirona/trunk/agent/performance/web/src/main/java/org/apache/sirona/web/session/SessionGauge.java Mon Nov 18 09:54:31 2013
@@ -17,7 +17,6 @@
 package org.apache.sirona.web.session;
 
 import org.apache.sirona.Role;
-import org.apache.sirona.configuration.Configuration;
 import org.apache.sirona.counters.Unit;
 import org.apache.sirona.gauges.Gauge;
 
@@ -43,9 +42,4 @@ public class SessionGauge implements Gau
     public double value() {
         return counter.get();
     }
-
-    @Override
-    public long period() {
-        return Configuration.getInteger(Configuration.CONFIG_PROPERTY_PREFIX + "web.gauge.sessions.period", 4000);
-    }
 }

Modified: incubator/sirona/trunk/agent/performance/web/src/test/resources/sirona.properties
URL: http://svn.apache.org/viewvc/incubator/sirona/trunk/agent/performance/web/src/test/resources/sirona.properties?rev=1542961&r1=1542960&r2=1542961&view=diff
==============================================================================
--- incubator/sirona/trunk/agent/performance/web/src/test/resources/sirona.properties (original)
+++ incubator/sirona/trunk/agent/performance/web/src/test/resources/sirona.properties Mon Nov 18 09:54:31 2013
@@ -12,4 +12,4 @@
 # 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.
-org.apache.sirona.web.gauge.status.period = 150
+org.apache.sirona.inmemory.gauge.period = 150

Modified: incubator/sirona/trunk/agent/pull/src/main/java/org/apache/sirona/agent/webapp/pull/repository/PullRepository.java
URL: http://svn.apache.org/viewvc/incubator/sirona/trunk/agent/pull/src/main/java/org/apache/sirona/agent/webapp/pull/repository/PullRepository.java?rev=1542961&r1=1542960&r2=1542961&view=diff
==============================================================================
--- incubator/sirona/trunk/agent/pull/src/main/java/org/apache/sirona/agent/webapp/pull/repository/PullRepository.java (original)
+++ incubator/sirona/trunk/agent/pull/src/main/java/org/apache/sirona/agent/webapp/pull/repository/PullRepository.java Mon Nov 18 09:54:31 2013
@@ -16,14 +16,12 @@
  */
 package org.apache.sirona.agent.webapp.pull.repository;
 
-import org.apache.sirona.agent.webapp.pull.gauge.PullGaugeManager;
 import org.apache.sirona.configuration.ioc.IoCs;
 import org.apache.sirona.cube.Cube;
 import org.apache.sirona.cube.CubeBuilder;
 import org.apache.sirona.cube.MapBuilder;
 import org.apache.sirona.gauges.Gauge;
 import org.apache.sirona.gauges.GaugeDataStoreAdapter;
-import org.apache.sirona.gauges.GaugeManager;
 import org.apache.sirona.repositories.DefaultRepository;
 import org.apache.sirona.repositories.Repository;
 import org.apache.sirona.status.NodeStatus;
@@ -44,16 +42,11 @@ public class PullRepository extends Defa
         cube = IoCs.findOrCreateInstance(CubeBuilder.class).build();
     }
 
-    @Override
-    protected GaugeManager findGaugeManager() {
-        return new PullGaugeManager();
-    }
-
     public Collection<Gauge> getGauges() {
-        if (gaugeManager == null) {
+        if (!GaugeDataStoreAdapter.class.isInstance(gaugeDataStore)) {
             return Collections.emptyList();
         }
-        return PullGaugeManager.class.cast(gaugeManager).getGauges();
+        return GaugeDataStoreAdapter.class.cast(gaugeDataStore).getGauges();
     }
 
     public String snapshot() {
@@ -67,7 +60,7 @@ public class PullRepository extends Defa
         // gauges
         for (final Gauge g : getGauges()) {
             try {
-                answer.append(cube.gaugeSnapshot(time, g.role(), g.value()));
+                cube.gaugeSnapshot(answer, time, g.role(), g.value());
             } catch (final Exception e) {
                 // no-op: ignore
             }

Modified: incubator/sirona/trunk/agent/pull/src/test/java/org/apache/sirona/agent/webapp/pull/PullAnswerTest.java
URL: http://svn.apache.org/viewvc/incubator/sirona/trunk/agent/pull/src/test/java/org/apache/sirona/agent/webapp/pull/PullAnswerTest.java?rev=1542961&r1=1542960&r2=1542961&view=diff
==============================================================================
--- incubator/sirona/trunk/agent/pull/src/test/java/org/apache/sirona/agent/webapp/pull/PullAnswerTest.java (original)
+++ incubator/sirona/trunk/agent/pull/src/test/java/org/apache/sirona/agent/webapp/pull/PullAnswerTest.java Mon Nov 18 09:54:31 2013
@@ -88,11 +88,6 @@ public class PullAnswerTest {
             public double value() {
                 return value++;
             }
-
-            @Override
-            public long period() {
-                return -1;
-            }
         });
         return repo;
     }

Modified: incubator/sirona/trunk/agent/store/cube/src/main/java/org/apache/sirona/cube/Cube.java
URL: http://svn.apache.org/viewvc/incubator/sirona/trunk/agent/store/cube/src/main/java/org/apache/sirona/cube/Cube.java?rev=1542961&r1=1542960&r2=1542961&view=diff
==============================================================================
--- incubator/sirona/trunk/agent/store/cube/src/main/java/org/apache/sirona/cube/Cube.java (original)
+++ incubator/sirona/trunk/agent/store/cube/src/main/java/org/apache/sirona/cube/Cube.java Mon Nov 18 09:54:31 2013
@@ -230,8 +230,8 @@ public class Cube {
         return events;
     }
 
-    public StringBuilder gaugeSnapshot(final long time, final Role role, final double value) {
-        return buildEvent(new StringBuilder(), GAUGE_TYPE, time,
+    public StringBuilder gaugeSnapshot(final StringBuilder base, final long time, final Role role, final double value) {
+        return buildEvent(base, GAUGE_TYPE, time,
             new MapBuilder()
                 .add("value", value)
                 .add("role", role.getName())

Modified: incubator/sirona/trunk/agent/store/cube/src/main/java/org/apache/sirona/cube/CubeDataStoreFactory.java
URL: http://svn.apache.org/viewvc/incubator/sirona/trunk/agent/store/cube/src/main/java/org/apache/sirona/cube/CubeDataStoreFactory.java?rev=1542961&r1=1542960&r2=1542961&view=diff
==============================================================================
--- incubator/sirona/trunk/agent/store/cube/src/main/java/org/apache/sirona/cube/CubeDataStoreFactory.java (original)
+++ incubator/sirona/trunk/agent/store/cube/src/main/java/org/apache/sirona/cube/CubeDataStoreFactory.java Mon Nov 18 09:54:31 2013
@@ -23,7 +23,7 @@ public class CubeDataStoreFactory extend
     public CubeDataStoreFactory() {
         super(
             IoCs.processInstance(new CubeCounterDataStore()),
-            new CubeGaugeDataStore(),
+            IoCs.processInstance(new CubeGaugeDataStore()),
             IoCs.processInstance(new CubeNodeStatusDataStore()));
     }
 }

Modified: incubator/sirona/trunk/agent/store/cube/src/main/java/org/apache/sirona/cube/CubeGaugeDataStore.java
URL: http://svn.apache.org/viewvc/incubator/sirona/trunk/agent/store/cube/src/main/java/org/apache/sirona/cube/CubeGaugeDataStore.java?rev=1542961&r1=1542960&r2=1542961&view=diff
==============================================================================
--- incubator/sirona/trunk/agent/store/cube/src/main/java/org/apache/sirona/cube/CubeGaugeDataStore.java (original)
+++ incubator/sirona/trunk/agent/store/cube/src/main/java/org/apache/sirona/cube/CubeGaugeDataStore.java Mon Nov 18 09:54:31 2013
@@ -18,22 +18,28 @@ package org.apache.sirona.cube;
 
 import org.apache.sirona.Role;
 import org.apache.sirona.configuration.ioc.IoCs;
-import org.apache.sirona.gauges.GaugeDataStoreAdapter;
+import org.apache.sirona.store.gauge.BatchGaugeDataStoreAdapter;
 
+import java.util.Map;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 
-public class CubeGaugeDataStore extends GaugeDataStoreAdapter {
+public class CubeGaugeDataStore extends BatchGaugeDataStoreAdapter {
     private static final Logger LOGGER = Logger.getLogger(CubeGaugeDataStore.class.getName());
 
     private final Cube cube = IoCs.findOrCreateInstance(CubeBuilder.class).build();
 
     @Override
-    public void addToGauge(final Role role, final long time, final double value) {
-        try {
-            cube.post(cube.gaugeSnapshot(time, role, value));
-        } catch (final Exception e) {
-            LOGGER.log(Level.SEVERE, e.getMessage(), e);
+    protected void pushGauges(final Map<Role, Measure> gauges) {
+        final StringBuilder events = cube.newEventStream();
+        for (final Map.Entry<Role, Measure> entry : gauges.entrySet()) {
+            try {
+                final Measure value = entry.getValue();
+                cube.gaugeSnapshot(events, value.getTime(), entry.getKey(), value.getValue());
+            } catch (final Exception e) {
+                LOGGER.log(Level.SEVERE, e.getMessage(), e);
+            }
         }
+        cube.post(events);
     }
 }

Modified: incubator/sirona/trunk/agent/store/cube/src/test/java/org/apache/sirona/cube/CubeDataStoreTest.java
URL: http://svn.apache.org/viewvc/incubator/sirona/trunk/agent/store/cube/src/test/java/org/apache/sirona/cube/CubeDataStoreTest.java?rev=1542961&r1=1542960&r2=1542961&view=diff
==============================================================================
--- incubator/sirona/trunk/agent/store/cube/src/test/java/org/apache/sirona/cube/CubeDataStoreTest.java (original)
+++ incubator/sirona/trunk/agent/store/cube/src/test/java/org/apache/sirona/cube/CubeDataStoreTest.java Mon Nov 18 09:54:31 2013
@@ -94,7 +94,7 @@ public class CubeDataStoreTest {
 
                 final String valueStr = "value\":";
                 final int start = m.indexOf(valueStr) + valueStr.length();
-                gauges.add(Double.parseDouble(m.substring(start, Math.min(m.indexOf(',', start + 1), m.indexOf('}', start + 1)))));
+                gauges.add(Double.parseDouble(m.substring(start, indexOf(m, start))));
             } else if (m.contains("\"type\": \"counter\"")) {
                 counters++;
                 aCounterMessage = m;
@@ -114,4 +114,12 @@ public class CubeDataStoreTest {
         assertThat(aCounterMessage, containsString("concurrency"));
         assertThat(aCounterMessage, containsString("marker"));
     }
+
+    private static int indexOf(String m, int start) {
+        final int i = m.indexOf(',', start + 1);
+        if (i == -1) {
+            return m.indexOf('}', start + 1);
+        }
+        return i;
+    }
 }

Modified: incubator/sirona/trunk/agent/store/cube/src/test/java/org/apache/sirona/cube/gauge/MockGauge.java
URL: http://svn.apache.org/viewvc/incubator/sirona/trunk/agent/store/cube/src/test/java/org/apache/sirona/cube/gauge/MockGauge.java?rev=1542961&r1=1542960&r2=1542961&view=diff
==============================================================================
--- incubator/sirona/trunk/agent/store/cube/src/test/java/org/apache/sirona/cube/gauge/MockGauge.java (original)
+++ incubator/sirona/trunk/agent/store/cube/src/test/java/org/apache/sirona/cube/gauge/MockGauge.java Mon Nov 18 09:54:31 2013
@@ -34,9 +34,4 @@ public class MockGauge implements Gauge 
     public double value() {
         return count++;
     }
-
-    @Override
-    public long period() {
-        return 100;
-    }
 }

Modified: incubator/sirona/trunk/agent/store/graphite/src/main/java/org/apache/sirona/graphite/GraphiteGaugeDataStore.java
URL: http://svn.apache.org/viewvc/incubator/sirona/trunk/agent/store/graphite/src/main/java/org/apache/sirona/graphite/GraphiteGaugeDataStore.java?rev=1542961&r1=1542960&r2=1542961&view=diff
==============================================================================
--- incubator/sirona/trunk/agent/store/graphite/src/main/java/org/apache/sirona/graphite/GraphiteGaugeDataStore.java (original)
+++ incubator/sirona/trunk/agent/store/graphite/src/main/java/org/apache/sirona/graphite/GraphiteGaugeDataStore.java Mon Nov 18 09:54:31 2013
@@ -34,7 +34,7 @@ public class GraphiteGaugeDataStore exte
     private final Graphite graphite = IoCs.findOrCreateInstance(GraphiteBuilder.class).build();
 
     @Override
-    protected void pushGauges(final Map<Role, Value> gauges) {
+    protected void pushAggregatedGauges(final Map<Role, Value> gauges) {
         try {
             graphite.open();
 

Modified: incubator/sirona/trunk/agent/store/graphite/src/test/java/org/apache/sirona/graphite/GraphiteTest.java
URL: http://svn.apache.org/viewvc/incubator/sirona/trunk/agent/store/graphite/src/test/java/org/apache/sirona/graphite/GraphiteTest.java?rev=1542961&r1=1542960&r2=1542961&view=diff
==============================================================================
--- incubator/sirona/trunk/agent/store/graphite/src/test/java/org/apache/sirona/graphite/GraphiteTest.java (original)
+++ incubator/sirona/trunk/agent/store/graphite/src/test/java/org/apache/sirona/graphite/GraphiteTest.java Mon Nov 18 09:54:31 2013
@@ -41,19 +41,9 @@ public class GraphiteTest extends Graphi
             Thread.sleep(30);
         }
 
-        final Collection<String> messages = messages();
-        final Collection<String> counters = new ArrayList<String>(messages.size());
-        final Collection<String> gauges = new ArrayList<String>(messages.size());
-        for (final String msg : messages) {
-            final String substring = msg.substring(0, msg.lastIndexOf(" "));
-            if (msg.startsWith("counter")) {
-                counters.add(substring);
-            } else {
-                gauges.add(substring);
-            }
-        }
-
         { // counters
+            final Collection<String> counters = extract("counter");
+
             assertEquals(30, counters.size());
             assertTrue(counters.contains("counter-performances-test-Hits 2.00"));
             assertTrue(counters.contains("counter-performances-test-Max 1.60"));
@@ -63,14 +53,31 @@ public class GraphiteTest extends Graphi
             assertTrue(counters.contains("counter-performances-test-Sum 3.00"));
             assertTrue(counters.contains("counter-performances-test-Value 3.00"));
         }
+
         { // gauges
+            Thread.sleep(280);
+
+            final Collection<String> gauges = extract("gauge");
+
             assertEquals(3, gauges.size());
 
             final String message = gauges.toString();
             // graphite store uses an aggregated gauge store
-            assertTrue("0.5 " + message, gauges.contains("gauge-mock 0.50"));
-            assertTrue("2.0 " + message, gauges.contains("gauge-mock 2.00"));
-            assertTrue("3.0 " + message, gauges.contains("gauge-mock 3.00"));
+            assertTrue("0.0 " + message, gauges.contains("gauge-mock 0.00"));
+            assertTrue("1.5 " + message, gauges.contains("gauge-mock 1.50"));
+            assertTrue("3.5 " + message, gauges.contains("gauge-mock 3.50"));
+        }
+    }
+
+    private Collection<String> extract(final String prefix) {
+        final Collection<String> messages = messages();
+        final Collection<String> list = new ArrayList<String>(messages.size());
+        for (final String msg : messages) {
+            final String substring = msg.substring(0, msg.lastIndexOf(" "));
+            if (msg.startsWith(prefix)) {
+                list.add(substring);
+            }
         }
+        return list;
     }
 }

Modified: incubator/sirona/trunk/agent/store/graphite/src/test/java/org/apache/sirona/graphite/gauge/MockGauge.java
URL: http://svn.apache.org/viewvc/incubator/sirona/trunk/agent/store/graphite/src/test/java/org/apache/sirona/graphite/gauge/MockGauge.java?rev=1542961&r1=1542960&r2=1542961&view=diff
==============================================================================
--- incubator/sirona/trunk/agent/store/graphite/src/test/java/org/apache/sirona/graphite/gauge/MockGauge.java (original)
+++ incubator/sirona/trunk/agent/store/graphite/src/test/java/org/apache/sirona/graphite/gauge/MockGauge.java Mon Nov 18 09:54:31 2013
@@ -34,9 +34,4 @@ public class MockGauge implements Gauge 
     public double value() {
         return count++;
     }
-
-    @Override
-    public long period() {
-        return 100;
-    }
 }

Modified: incubator/sirona/trunk/agent/store/graphite/src/test/resources/sirona.properties
URL: http://svn.apache.org/viewvc/incubator/sirona/trunk/agent/store/graphite/src/test/resources/sirona.properties?rev=1542961&r1=1542960&r2=1542961&view=diff
==============================================================================
--- incubator/sirona/trunk/agent/store/graphite/src/test/resources/sirona.properties (original)
+++ incubator/sirona/trunk/agent/store/graphite/src/test/resources/sirona.properties Mon Nov 18 09:54:31 2013
@@ -16,6 +16,7 @@
 # under the License.
 org.apache.sirona.store.DataStoreFactory = org.apache.sirona.graphite.GraphiteDataStoreFactory
 
+org.apache.sirona.graphite.aggregated.gauge.period = 220
 org.apache.sirona.graphite.period = 125
 
 org.apache.sirona.graphite.GraphiteBuilder.address = localhost

Modified: incubator/sirona/trunk/core/src/main/java/org/apache/sirona/gauges/Gauge.java
URL: http://svn.apache.org/viewvc/incubator/sirona/trunk/core/src/main/java/org/apache/sirona/gauges/Gauge.java?rev=1542961&r1=1542960&r2=1542961&view=diff
==============================================================================
--- incubator/sirona/trunk/core/src/main/java/org/apache/sirona/gauges/Gauge.java (original)
+++ incubator/sirona/trunk/core/src/main/java/org/apache/sirona/gauges/Gauge.java Mon Nov 18 09:54:31 2013
@@ -29,8 +29,6 @@ public interface Gauge {
 
     double value();
 
-    long period();
-
     public static class LoaderHelper {
         private LinkedList<Gauge> gauges = new LinkedList<Gauge>();
 

Added: incubator/sirona/trunk/core/src/main/java/org/apache/sirona/gauges/GaugeAware.java
URL: http://svn.apache.org/viewvc/incubator/sirona/trunk/core/src/main/java/org/apache/sirona/gauges/GaugeAware.java?rev=1542961&view=auto
==============================================================================
--- incubator/sirona/trunk/core/src/main/java/org/apache/sirona/gauges/GaugeAware.java (added)
+++ incubator/sirona/trunk/core/src/main/java/org/apache/sirona/gauges/GaugeAware.java Mon Nov 18 09:54:31 2013
@@ -0,0 +1,22 @@
+/*
+ * 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.sirona.gauges;
+
+// allows a gauge datastore to hold gauges
+public interface GaugeAware {
+    void addGauge(Gauge gauge);
+}

Modified: incubator/sirona/trunk/core/src/main/java/org/apache/sirona/gauges/GaugeDataStoreAdapter.java
URL: http://svn.apache.org/viewvc/incubator/sirona/trunk/core/src/main/java/org/apache/sirona/gauges/GaugeDataStoreAdapter.java?rev=1542961&r1=1542960&r2=1542961&view=diff
==============================================================================
--- incubator/sirona/trunk/core/src/main/java/org/apache/sirona/gauges/GaugeDataStoreAdapter.java (original)
+++ incubator/sirona/trunk/core/src/main/java/org/apache/sirona/gauges/GaugeDataStoreAdapter.java Mon Nov 18 09:54:31 2013
@@ -22,10 +22,14 @@ import org.apache.sirona.store.gauge.Gau
 
 import java.util.Collection;
 import java.util.Collections;
+import java.util.Map;
 import java.util.SortedMap;
 import java.util.TreeMap;
+import java.util.concurrent.ConcurrentHashMap;
+
+public class GaugeDataStoreAdapter implements GaugeDataStore, GaugeAware {
+    protected final Map<Role, Gauge> gauges = new ConcurrentHashMap<Role, Gauge>();
 
-public class GaugeDataStoreAdapter implements GaugeDataStore {
     @Override
     public SortedMap<Long, Double> getGaugeValues(final GaugeValuesRequest gaugeValuesRequest) {
         return new TreeMap<Long, Double>();
@@ -53,6 +57,15 @@ public class GaugeDataStoreAdapter imple
 
     @Override
     public void gaugeStopped(final Role gauge) {
-        // no-op
+        gauges.remove(gauge);
+    }
+
+    @Override
+    public void addGauge(final Gauge gauge) {
+        gauges.put(gauge.role(), gauge);
+    }
+
+    public Collection<Gauge> getGauges() {
+        return gauges.values();
     }
 }

Modified: incubator/sirona/trunk/core/src/main/java/org/apache/sirona/gauges/counter/CounterGauge.java
URL: http://svn.apache.org/viewvc/incubator/sirona/trunk/core/src/main/java/org/apache/sirona/gauges/counter/CounterGauge.java?rev=1542961&r1=1542960&r2=1542961&view=diff
==============================================================================
--- incubator/sirona/trunk/core/src/main/java/org/apache/sirona/gauges/counter/CounterGauge.java (original)
+++ incubator/sirona/trunk/core/src/main/java/org/apache/sirona/gauges/counter/CounterGauge.java Mon Nov 18 09:54:31 2013
@@ -17,7 +17,6 @@
 package org.apache.sirona.gauges.counter;
 
 import org.apache.sirona.Role;
-import org.apache.sirona.configuration.Configuration;
 import org.apache.sirona.counters.Counter;
 import org.apache.sirona.counters.MetricData;
 import org.apache.sirona.counters.Unit;
@@ -47,9 +46,4 @@ public class CounterGauge implements Gau
     public double value() {
         return metric.value(counter);
     }
-
-    @Override
-    public long period() {
-        return Configuration.getInteger(Configuration.CONFIG_PROPERTY_PREFIX + "gauge.counter.period", 4000);
-    }
 }

Modified: incubator/sirona/trunk/core/src/main/java/org/apache/sirona/gauges/jmx/JMXAttributeGaugeBase.java
URL: http://svn.apache.org/viewvc/incubator/sirona/trunk/core/src/main/java/org/apache/sirona/gauges/jmx/JMXAttributeGaugeBase.java?rev=1542961&r1=1542960&r2=1542961&view=diff
==============================================================================
--- incubator/sirona/trunk/core/src/main/java/org/apache/sirona/gauges/jmx/JMXAttributeGaugeBase.java (original)
+++ incubator/sirona/trunk/core/src/main/java/org/apache/sirona/gauges/jmx/JMXAttributeGaugeBase.java Mon Nov 18 09:54:31 2013
@@ -18,7 +18,6 @@ package org.apache.sirona.gauges.jmx;
 
 import org.apache.sirona.Role;
 import org.apache.sirona.SironaException;
-import org.apache.sirona.configuration.Configuration;
 import org.apache.sirona.counters.Unit;
 import org.apache.sirona.gauges.Gauge;
 
@@ -56,9 +55,4 @@ public abstract class JMXAttributeGaugeB
             throw new SironaException(e);
         }
     }
-
-    @Override
-    public long period() {
-        return Configuration.getInteger(Configuration.CONFIG_PROPERTY_PREFIX + "gauge.jmx.period", 4000);
-    }
 }

Modified: incubator/sirona/trunk/core/src/main/java/org/apache/sirona/gauges/jvm/BaseMemoryGauge.java
URL: http://svn.apache.org/viewvc/incubator/sirona/trunk/core/src/main/java/org/apache/sirona/gauges/jvm/BaseMemoryGauge.java?rev=1542961&r1=1542960&r2=1542961&view=diff
==============================================================================
--- incubator/sirona/trunk/core/src/main/java/org/apache/sirona/gauges/jvm/BaseMemoryGauge.java (original)
+++ incubator/sirona/trunk/core/src/main/java/org/apache/sirona/gauges/jvm/BaseMemoryGauge.java Mon Nov 18 09:54:31 2013
@@ -16,7 +16,6 @@
  */
 package org.apache.sirona.gauges.jvm;
 
-import org.apache.sirona.configuration.Configuration;
 import org.apache.sirona.gauges.Gauge;
 
 import java.lang.management.ManagementFactory;
@@ -24,9 +23,4 @@ import java.lang.management.MemoryMXBean
 
 public abstract class BaseMemoryGauge implements Gauge {
     protected static final MemoryMXBean MEMORY_MX_BEAN = ManagementFactory.getMemoryMXBean();
-
-    @Override
-    public long period() {
-        return Configuration.getInteger(Configuration.CONFIG_PROPERTY_PREFIX + "gauge.memory.period", 4000);
-    }
 }

Modified: incubator/sirona/trunk/core/src/main/java/org/apache/sirona/gauges/jvm/CPUGauge.java
URL: http://svn.apache.org/viewvc/incubator/sirona/trunk/core/src/main/java/org/apache/sirona/gauges/jvm/CPUGauge.java?rev=1542961&r1=1542960&r2=1542961&view=diff
==============================================================================
--- incubator/sirona/trunk/core/src/main/java/org/apache/sirona/gauges/jvm/CPUGauge.java (original)
+++ incubator/sirona/trunk/core/src/main/java/org/apache/sirona/gauges/jvm/CPUGauge.java Mon Nov 18 09:54:31 2013
@@ -17,7 +17,6 @@
 package org.apache.sirona.gauges.jvm;
 
 import org.apache.sirona.Role;
-import org.apache.sirona.configuration.Configuration;
 import org.apache.sirona.counters.Unit;
 import org.apache.sirona.gauges.Gauge;
 
@@ -38,9 +37,4 @@ public class CPUGauge implements Gauge {
     public double value() {
         return SYSTEM_MX_BEAN.getSystemLoadAverage();
     }
-
-    @Override
-    public long period() {
-        return Configuration.getInteger(Configuration.CONFIG_PROPERTY_PREFIX + "gauge.cpu.period", 4000);
-    }
 }

Modified: incubator/sirona/trunk/core/src/main/java/org/apache/sirona/repositories/DefaultRepository.java
URL: http://svn.apache.org/viewvc/incubator/sirona/trunk/core/src/main/java/org/apache/sirona/repositories/DefaultRepository.java?rev=1542961&r1=1542960&r2=1542961&view=diff
==============================================================================
--- incubator/sirona/trunk/core/src/main/java/org/apache/sirona/repositories/DefaultRepository.java (original)
+++ incubator/sirona/trunk/core/src/main/java/org/apache/sirona/repositories/DefaultRepository.java Mon Nov 18 09:54:31 2013
@@ -19,12 +19,10 @@ package org.apache.sirona.repositories;
 import org.apache.sirona.Role;
 import org.apache.sirona.SironaException;
 import org.apache.sirona.configuration.Configuration;
-import org.apache.sirona.configuration.ioc.Destroying;
 import org.apache.sirona.configuration.ioc.IoCs;
 import org.apache.sirona.counters.Counter;
-import org.apache.sirona.gauges.DefaultGaugeManager;
 import org.apache.sirona.gauges.Gauge;
-import org.apache.sirona.gauges.GaugeManager;
+import org.apache.sirona.gauges.GaugeAware;
 import org.apache.sirona.gauges.jvm.CPUGauge;
 import org.apache.sirona.gauges.jvm.UsedMemoryGauge;
 import org.apache.sirona.gauges.jvm.UsedNonHeapMemoryGauge;
@@ -49,7 +47,6 @@ public class DefaultRepository implement
     protected final CounterDataStore counterDataStore;
     protected final NodeStatusDataStore nodeStatusDataStore;
     protected final CommonGaugeDataStore gaugeDataStore;
-    protected final GaugeManager gaugeManager;
 
     public DefaultRepository() {
         this(findCounterDataStore(), findGaugeDataStore(), findStatusDataStore());
@@ -76,8 +73,6 @@ public class DefaultRepository implement
             IoCs.setSingletonInstance(NodeStatusDataStore.class, status);
         }
 
-        this.gaugeManager = findGaugeManager();
-
         if (Configuration.is(Configuration.CONFIG_PROPERTY_PREFIX + "core.gauge.activated", true)) {
             addGauge(new CPUGauge());
             addGauge(new UsedMemoryGauge());
@@ -85,22 +80,6 @@ public class DefaultRepository implement
         }
     }
 
-    protected GaugeManager findGaugeManager() {
-        final GaugeManager manager;
-        if (GaugeDataStore.class.isInstance(gaugeDataStore)) {
-            GaugeManager mgr;
-            try {
-                mgr = IoCs.findOrCreateInstance(GaugeManager.class);
-            } catch (final SironaException e) {
-                mgr = new DefaultGaugeManager();
-            }
-            manager = mgr;
-        } else {
-            manager = null;
-        }
-        return manager;
-    }
-
     private static NodeStatusDataStore findStatusDataStore() {
         NodeStatusDataStore status = null;
         try {
@@ -154,13 +133,6 @@ public class DefaultRepository implement
         return counter;
     }
 
-    @Destroying
-    public void stopGaugeManager() {
-        if (gaugeManager != null) {
-            gaugeManager.stop();
-        }
-    }
-
     @Override
     public Counter getCounter(final Counter.Key key) {
         return counterDataStore.getOrCreateCounter(key);
@@ -179,10 +151,10 @@ public class DefaultRepository implement
     @Override
     public void reset() {
         clearCounters();
-        if (gaugeManager != null) {
-            gaugeManager.stop();
-        }
         nodeStatusDataStore.reset();
+        for (final Role g : gauges()) {
+            gaugeDataStore.gaugeStopped(g);
+        }
     }
 
     @Override
@@ -210,16 +182,13 @@ public class DefaultRepository implement
         if (GaugeDataStore.class.isInstance(gaugeDataStore)) {
             GaugeDataStore.class.cast(gaugeDataStore).createOrNoopGauge(gauge.role());
         }
-        if (gaugeManager != null) {
-            gaugeManager.addGauge(gauge);
+        if (GaugeAware.class.isInstance(gaugeDataStore)) {
+            GaugeAware.class.cast(gaugeDataStore).addGauge(gauge);
         }
     }
 
     @Override
     public void stopGauge(final Gauge gauge) {
-        if (gaugeManager != null) {
-            gaugeManager.stopGauge(gauge);
-        }
         if (GaugeDataStore.class.isInstance(gaugeDataStore)) {
             GaugeDataStore.class.cast(gaugeDataStore).gaugeStopped(gauge.role());
         }

Modified: incubator/sirona/trunk/core/src/main/java/org/apache/sirona/store/DefaultDataStoreFactory.java
URL: http://svn.apache.org/viewvc/incubator/sirona/trunk/core/src/main/java/org/apache/sirona/store/DefaultDataStoreFactory.java?rev=1542961&r1=1542960&r2=1542961&view=diff
==============================================================================
--- incubator/sirona/trunk/core/src/main/java/org/apache/sirona/store/DefaultDataStoreFactory.java (original)
+++ incubator/sirona/trunk/core/src/main/java/org/apache/sirona/store/DefaultDataStoreFactory.java Mon Nov 18 09:54:31 2013
@@ -23,7 +23,8 @@ import org.apache.sirona.store.status.Pe
 
 public class DefaultDataStoreFactory extends DelegateDataStoreFactory {
     public DefaultDataStoreFactory() {
-        super(new InMemoryCounterDataStore(), new InMemoryGaugeDataStore(),
+        super(new InMemoryCounterDataStore(),
+            IoCs.processInstance(new InMemoryGaugeDataStore()),
             IoCs.processInstance(new PeriodicNodeStatusDataStore())); // this one has hooks
     }
 }

Modified: incubator/sirona/trunk/core/src/main/java/org/apache/sirona/store/counter/InMemoryCounterDataStore.java
URL: http://svn.apache.org/viewvc/incubator/sirona/trunk/core/src/main/java/org/apache/sirona/store/counter/InMemoryCounterDataStore.java?rev=1542961&r1=1542960&r2=1542961&view=diff
==============================================================================
--- incubator/sirona/trunk/core/src/main/java/org/apache/sirona/store/counter/InMemoryCounterDataStore.java (original)
+++ incubator/sirona/trunk/core/src/main/java/org/apache/sirona/store/counter/InMemoryCounterDataStore.java Mon Nov 18 09:54:31 2013
@@ -28,7 +28,6 @@ import java.util.Collection;
 import java.util.LinkedList;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.ConcurrentMap;
-import java.util.concurrent.atomic.AtomicInteger;
 import java.util.concurrent.locks.Lock;
 
 public class InMemoryCounterDataStore implements CounterDataStore {

Modified: incubator/sirona/trunk/core/src/main/java/org/apache/sirona/store/gauge/AggregatedGaugeDataStoreAdapter.java
URL: http://svn.apache.org/viewvc/incubator/sirona/trunk/core/src/main/java/org/apache/sirona/store/gauge/AggregatedGaugeDataStoreAdapter.java?rev=1542961&r1=1542960&r2=1542961&view=diff
==============================================================================
--- incubator/sirona/trunk/core/src/main/java/org/apache/sirona/store/gauge/AggregatedGaugeDataStoreAdapter.java (original)
+++ incubator/sirona/trunk/core/src/main/java/org/apache/sirona/store/gauge/AggregatedGaugeDataStoreAdapter.java Mon Nov 18 09:54:31 2013
@@ -18,9 +18,8 @@ package org.apache.sirona.store.gauge;
 
 import org.apache.commons.math3.stat.descriptive.SummaryStatistics;
 import org.apache.sirona.Role;
-import org.apache.sirona.configuration.Configuration;
+import org.apache.sirona.configuration.ioc.Created;
 import org.apache.sirona.configuration.ioc.Destroying;
-import org.apache.sirona.gauges.GaugeDataStoreAdapter;
 import org.apache.sirona.store.BatchFuture;
 import org.apache.sirona.util.DaemonThreadFactory;
 
@@ -35,33 +34,39 @@ import java.util.concurrent.TimeUnit;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 
-public abstract class AggregatedGaugeDataStoreAdapter extends GaugeDataStoreAdapter {
+public abstract class AggregatedGaugeDataStoreAdapter extends BatchGaugeDataStoreAdapter {
     private static final Logger LOGGER = Logger.getLogger(AggregatedGaugeDataStoreAdapter.class.getName());
 
     private final ConcurrentMap<Role, SummaryStatistics> gauges = new ConcurrentHashMap<Role, SummaryStatistics>();
+    private BatchFuture scheduledAggregatedTask;
 
-    protected final BatchFuture scheduledTask;
+    protected abstract void pushAggregatedGauges(final Map<Role, Value> gauges);
 
-    public AggregatedGaugeDataStoreAdapter() {
-        final String name = getClass().getSimpleName().toLowerCase(Locale.ENGLISH).replace("gaugedatastore", "");
+    @Created // call it only when main impl not in delegated mode so use IoC lifecycle management
+    public void initAggregated() {
+        final String name = getClass().getSimpleName().toLowerCase(Locale.ENGLISH).replace("gaugedatastore", "") + ".aggregated";
         final long period = getPeriod(name);
 
-        final ScheduledExecutorService ses = Executors.newSingleThreadScheduledExecutor(new DaemonThreadFactory(name + "-gauge-schedule-"));
+        final ScheduledExecutorService ses = Executors.newSingleThreadScheduledExecutor(new DaemonThreadFactory(name + "-aggregated-gauge-schedule-"));
         final ScheduledFuture<?> future = ses.scheduleAtFixedRate(new PushGaugesTask(), period, period, TimeUnit.MILLISECONDS);
-        scheduledTask = new BatchFuture(ses, future);
-    }
-
-    protected int getPeriod(final String name) {
-        return Configuration.getInteger(Configuration.CONFIG_PROPERTY_PREFIX + name + ".gauge.period",
-            Configuration.getInteger(Configuration.CONFIG_PROPERTY_PREFIX + name + ".period", 60000));
+        scheduledAggregatedTask = new BatchFuture(ses, future);
     }
 
     @Destroying
     public void shutdown() {
-        scheduledTask.done();
+        scheduledAggregatedTask.done();
+    }
+
+    @Override
+    protected void pushGauges(Map<Role, Measure> gauges) {
+
     }
 
-    protected abstract void pushGauges(final Map<Role, Value> gauges);
+    @Override
+    public void gaugeStopped(final Role gauge) {
+        gauges.remove(gauge);
+        super.gaugeStopped(gauge);
+    }
 
     @Override
     public void addToGauge(final Role role, final long time, final double value) {
@@ -92,7 +97,7 @@ public abstract class AggregatedGaugeDat
         @Override
         public void run() {
             try {
-                pushGauges(copyAndClearGauges());
+                pushAggregatedGauges(copyAndClearGauges());
             } catch (final Exception e) {
                 LOGGER.log(Level.SEVERE, e.getMessage(), e);
             }

Copied: incubator/sirona/trunk/core/src/main/java/org/apache/sirona/store/gauge/BatchGaugeDataStoreAdapter.java (from r1542909, incubator/sirona/trunk/core/src/main/java/org/apache/sirona/store/gauge/AggregatedGaugeDataStoreAdapter.java)
URL: http://svn.apache.org/viewvc/incubator/sirona/trunk/core/src/main/java/org/apache/sirona/store/gauge/BatchGaugeDataStoreAdapter.java?p2=incubator/sirona/trunk/core/src/main/java/org/apache/sirona/store/gauge/BatchGaugeDataStoreAdapter.java&p1=incubator/sirona/trunk/core/src/main/java/org/apache/sirona/store/gauge/AggregatedGaugeDataStoreAdapter.java&r1=1542909&r2=1542961&rev=1542961&view=diff
==============================================================================
--- incubator/sirona/trunk/core/src/main/java/org/apache/sirona/store/gauge/AggregatedGaugeDataStoreAdapter.java (original)
+++ incubator/sirona/trunk/core/src/main/java/org/apache/sirona/store/gauge/BatchGaugeDataStoreAdapter.java Mon Nov 18 09:54:31 2013
@@ -16,18 +16,19 @@
  */
 package org.apache.sirona.store.gauge;
 
-import org.apache.commons.math3.stat.descriptive.SummaryStatistics;
 import org.apache.sirona.Role;
 import org.apache.sirona.configuration.Configuration;
+import org.apache.sirona.configuration.ioc.Created;
 import org.apache.sirona.configuration.ioc.Destroying;
+import org.apache.sirona.gauges.Gauge;
+import org.apache.sirona.gauges.GaugeAware;
 import org.apache.sirona.gauges.GaugeDataStoreAdapter;
 import org.apache.sirona.store.BatchFuture;
 import org.apache.sirona.util.DaemonThreadFactory;
 
+import java.util.HashMap;
 import java.util.Locale;
 import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.ConcurrentMap;
 import java.util.concurrent.Executors;
 import java.util.concurrent.ScheduledExecutorService;
 import java.util.concurrent.ScheduledFuture;
@@ -35,14 +36,13 @@ import java.util.concurrent.TimeUnit;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 
-public abstract class AggregatedGaugeDataStoreAdapter extends GaugeDataStoreAdapter {
-    private static final Logger LOGGER = Logger.getLogger(AggregatedGaugeDataStoreAdapter.class.getName());
+public abstract class BatchGaugeDataStoreAdapter extends GaugeDataStoreAdapter implements GaugeAware {
+    private static final Logger LOGGER = Logger.getLogger(BatchGaugeDataStoreAdapter.class.getName());
 
-    private final ConcurrentMap<Role, SummaryStatistics> gauges = new ConcurrentHashMap<Role, SummaryStatistics>();
+    protected BatchFuture scheduledTask;
 
-    protected final BatchFuture scheduledTask;
-
-    public AggregatedGaugeDataStoreAdapter() {
+    @Created // call it only when main impl not in delegated mode so use IoC lifecycle management
+    public void initBatch() {
         final String name = getClass().getSimpleName().toLowerCase(Locale.ENGLISH).replace("gaugedatastore", "");
         final long period = getPeriod(name);
 
@@ -61,79 +61,55 @@ public abstract class AggregatedGaugeDat
         scheduledTask.done();
     }
 
-    protected abstract void pushGauges(final Map<Role, Value> gauges);
-
-    @Override
-    public void addToGauge(final Role role, final long time, final double value) {
-        SummaryStatistics stat = gauges.get(role);
-        if (stat == null) {
-            stat = new SummaryStatistics();
-            final SummaryStatistics existing = gauges.putIfAbsent(role, stat);
-            if (existing != null) {
-                stat = existing;
-            }
-        }
-        stat.addValue(value);
-    }
+    protected abstract void pushGauges(final Map<Role, Measure> gauges);
 
-    private ConcurrentMap<Role, Value> copyAndClearGauges() {
-        final ConcurrentMap<Role, SummaryStatistics> copy = new ConcurrentHashMap<Role, SummaryStatistics>();
-        copy.putAll(gauges);
-        gauges.clear();
+    protected Map<Role, Measure> snapshot() {
+        final long ts = System.currentTimeMillis();
+        final Map<Role, Measure> snapshot = new HashMap<Role, Measure>();
+        for (final Gauge gauge : gauges.values()) {
+            final Role role = gauge.role();
+            final double value = gauge.value();
 
-        final ConcurrentMap<Role, Value> toPush = new ConcurrentHashMap<Role, Value>();
-        for (final Map.Entry<Role, SummaryStatistics> entry : copy.entrySet()) {
-            toPush.put(entry.getKey(), new ValueImpl(entry.getValue()));
+            addToGauge(role, ts, value);
+            snapshot.put(role, new Measure(ts, value));
         }
-        return toPush;
+        return snapshot;
     }
 
     private class PushGaugesTask implements Runnable {
         @Override
         public void run() {
             try {
-                pushGauges(copyAndClearGauges());
+                pushGauges(snapshot());
             } catch (final Exception e) {
                 LOGGER.log(Level.SEVERE, e.getMessage(), e);
             }
         }
     }
 
-    private static class ValueImpl implements Value {
-        private final SummaryStatistics delegate;
-
-        public ValueImpl(final SummaryStatistics value) {
-            delegate = value;
-        }
-
-        @Override
-        public double getMean() {
-            return delegate.getMean();
-        }
-
-        @Override
-        public double getMax() {
-            return delegate.getMax();
-        }
+    public static class Measure {
+        private long time;
+        private double value;
 
-        @Override
-        public double getMin() {
-            return delegate.getMin();
+        private Measure(final long time, final double value) {
+            this.time = time;
+            this.value = value;
         }
 
-        @Override
-        public long getN() {
-            return delegate.getN();
+        public long getTime() {
+            return time;
         }
 
-        @Override
-        public double getSum() {
-            return delegate.getSum();
+        public double getValue() {
+            return value;
         }
 
         @Override
         public String toString() {
-            return "ValueImpl{delegate=" + delegate + '}';
+            return "Measure{" +
+                "time=" + time +
+                ", value=" + value +
+                '}';
         }
     }
 }

Modified: incubator/sirona/trunk/core/src/main/java/org/apache/sirona/store/gauge/InMemoryGaugeDataStore.java
URL: http://svn.apache.org/viewvc/incubator/sirona/trunk/core/src/main/java/org/apache/sirona/store/gauge/InMemoryGaugeDataStore.java?rev=1542961&r1=1542960&r2=1542961&view=diff
==============================================================================
--- incubator/sirona/trunk/core/src/main/java/org/apache/sirona/store/gauge/InMemoryGaugeDataStore.java (original)
+++ incubator/sirona/trunk/core/src/main/java/org/apache/sirona/store/gauge/InMemoryGaugeDataStore.java Mon Nov 18 09:54:31 2013
@@ -28,7 +28,7 @@ import java.util.concurrent.ConcurrentHa
 import java.util.concurrent.ConcurrentMap;
 import java.util.concurrent.ConcurrentSkipListMap;
 
-public class InMemoryGaugeDataStore implements GaugeDataStore {
+public class InMemoryGaugeDataStore extends BatchGaugeDataStoreAdapter {
     protected final ConcurrentMap<Role, SortedMap<Long, Double>> gauges = new ConcurrentHashMap<Role, SortedMap<Long, Double>>();
     protected final Map<String, Role> roleMapping = new ConcurrentHashMap<String, Role>();
 
@@ -53,9 +53,9 @@ public class InMemoryGaugeDataStore impl
     }
 
     @Override
-    public void createOrNoopGauge(final Role role) {
-        gauges.putIfAbsent(role, new FixedSizedMap());
-        roleMapping.put(role.getName(), role);
+    public void createOrNoopGauge(final Role gauge) {
+        gauges.putIfAbsent(gauge, new FixedSizedMap());
+        roleMapping.put(gauge.getName(), gauge);
     }
 
     @Override
@@ -74,7 +74,16 @@ public class InMemoryGaugeDataStore impl
     }
 
     @Override
+    protected void pushGauges(final Map<Role, Measure> gauges) {
+        for (final Map.Entry<Role, Measure> entry : gauges.entrySet()) {
+            final Measure value = entry.getValue();
+            addToGauge(entry.getKey(), value.getTime(), value.getValue());
+        }
+    }
+
+    @Override
     public void gaugeStopped(final Role gauge) {
+        super.gaugeStopped(gauge);
         roleMapping.remove(gauge.getName());
     }
 

Modified: incubator/sirona/trunk/server/plugins/hazelcast/agent/src/main/java/org/apache/sirona/plugin/hazelcast/agent/gauge/HazelcastGaugeBase.java
URL: http://svn.apache.org/viewvc/incubator/sirona/trunk/server/plugins/hazelcast/agent/src/main/java/org/apache/sirona/plugin/hazelcast/agent/gauge/HazelcastGaugeBase.java?rev=1542961&r1=1542960&r2=1542961&view=diff
==============================================================================
--- incubator/sirona/trunk/server/plugins/hazelcast/agent/src/main/java/org/apache/sirona/plugin/hazelcast/agent/gauge/HazelcastGaugeBase.java (original)
+++ incubator/sirona/trunk/server/plugins/hazelcast/agent/src/main/java/org/apache/sirona/plugin/hazelcast/agent/gauge/HazelcastGaugeBase.java Mon Nov 18 09:54:31 2013
@@ -18,13 +18,10 @@ package org.apache.sirona.plugin.hazelca
 
 import com.hazelcast.core.HazelcastInstance;
 import org.apache.sirona.Role;
-import org.apache.sirona.configuration.Configuration;
 import org.apache.sirona.counters.Unit;
 import org.apache.sirona.gauges.Gauge;
 
 public abstract class HazelcastGaugeBase implements Gauge {
-    private static final int PERIOD = Configuration.getInteger(Configuration.CONFIG_PROPERTY_PREFIX + "hazelcast.gauge.members.period", 4000);
-
     private final Role role;
     protected final HazelcastInstance instance;
 
@@ -37,9 +34,4 @@ public abstract class HazelcastGaugeBase
     public Role role() {
         return role;
     }
-
-    @Override
-    public long period() {
-        return PERIOD;
-    }
 }

Modified: incubator/sirona/trunk/server/plugins/hazelcast/agent/src/test/java/org/apache/sirona/plugin/hazelcast/BasicHazelcastTest.java
URL: http://svn.apache.org/viewvc/incubator/sirona/trunk/server/plugins/hazelcast/agent/src/test/java/org/apache/sirona/plugin/hazelcast/BasicHazelcastTest.java?rev=1542961&r1=1542960&r2=1542961&view=diff
==============================================================================
--- incubator/sirona/trunk/server/plugins/hazelcast/agent/src/test/java/org/apache/sirona/plugin/hazelcast/BasicHazelcastTest.java (original)
+++ incubator/sirona/trunk/server/plugins/hazelcast/agent/src/test/java/org/apache/sirona/plugin/hazelcast/BasicHazelcastTest.java Mon Nov 18 09:54:31 2013
@@ -29,6 +29,7 @@ import org.junit.After;
 import org.junit.Test;
 
 import java.util.Map;
+import java.util.SortedMap;
 import java.util.TreeMap;
 import java.util.concurrent.CountDownLatch;
 
@@ -43,12 +44,12 @@ public class BasicHazelcastTest {
     }
 
     @Test
-    public void gauges() throws InterruptedException {
+    public void gauges() throws Throwable {
         final HazelcastInstance instance1 = Hazelcast.newHazelcastInstance();
         final HazelcastInstance instance2 = Hazelcast.newHazelcastInstance();
         HazelcastInstance instance3 = null;
 
-        Map<Long, Double> members1 = null, members2 = null, partitions = null;
+        Map<Long, Double> members1 = null, partitions;
 
         final Gauge.LoaderHelper loader = new Gauge.LoaderHelper(false);
         try {
@@ -59,6 +60,10 @@ public class BasicHazelcastTest {
             members1 = gaugeValues("hazelcast-members-cluster");
             partitions = gaugeValues("hazelcast-partitions-cluster");
 
+            Thread.sleep(300);
+            assertNotNull(partitions);
+            assertEquals(instance2.getPartitionService().getPartitions().size(), partitions.values().iterator().next(), 0.);
+
             final CountDownLatch instance1Stopped = new CountDownLatch(1);
             instance1.getLifecycleService().addLifecycleListener(new LifecycleListener() {
                 @Override
@@ -72,10 +77,25 @@ public class BasicHazelcastTest {
             instance1Stopped.await();
             Thread.sleep(300);
 
-            assertNotNull(partitions);
-            assertEquals(instance2.getPartitionService().getPartitions().size(), partitions.values().iterator().next(), 0.);
+            assertNotNull(members1);
 
-            members2 = gaugeValues("hazelcast-members-cluster");
+            assertEquals(2., members1.values().iterator().next(), 0.);
+            assertEquals(2., gaugeValues("hazelcast-members-cluster").values().iterator().next(), 0.);
+            assertEquals(3., new TreeMap<Long, Double>(members1).lastEntry().getValue(), 0.);
+            int tryCount = 0;
+            while (true) { // we shouldn't need it but MVN+machine related things can make it fragile if not
+                try {
+                    assertEquals(2., new TreeMap<Long, Double>(gaugeValues("hazelcast-members-cluster")).lastEntry().getValue(), 0.);
+                    break;
+                } catch (final Throwable th) {
+                    if (tryCount < 10) {
+                        tryCount++;
+                        Thread.sleep(100);
+                    } else {
+                        throw th;
+                    }
+                }
+            }
         } finally {
             loader.destroy();
             instance2.getLifecycleService().shutdown();
@@ -86,17 +106,9 @@ public class BasicHazelcastTest {
                 instance1.getLifecycleService().shutdown();
             }
         }
-
-        assertNotNull(members1);
-        assertNotNull(members2);
-
-        assertEquals(2., members1.values().iterator().next(), 0.);
-        assertEquals(2., members2.values().iterator().next(), 0.);
-        assertEquals(3., new TreeMap<Long, Double>(members1).lastEntry().getValue(), 0.);
-        assertEquals(2., new TreeMap<Long, Double>(members2).lastEntry().getValue(), 0.);
     }
 
-    private static Map<Long, Double> gaugeValues(final String role) {
+    private static SortedMap<Long, Double> gaugeValues(final String role) {
         return Repository.INSTANCE.getGaugeValues(0, System.currentTimeMillis(), new Role(role, Unit.UNARY));
     }
 }

Modified: incubator/sirona/trunk/server/plugins/hazelcast/agent/src/test/resources/sirona.properties
URL: http://svn.apache.org/viewvc/incubator/sirona/trunk/server/plugins/hazelcast/agent/src/test/resources/sirona.properties?rev=1542961&r1=1542960&r2=1542961&view=diff
==============================================================================
--- incubator/sirona/trunk/server/plugins/hazelcast/agent/src/test/resources/sirona.properties (original)
+++ incubator/sirona/trunk/server/plugins/hazelcast/agent/src/test/resources/sirona.properties Mon Nov 18 09:54:31 2013
@@ -17,4 +17,4 @@
 org.apache.sirona.hazelcast.clusters = cluster
 org.apache.sirona.hazelcast.cluster.client = true
 org.apache.sirona.hazelcast.cluster.addresses = localhost:5702
-org.apache.sirona.hazelcast.gauge.members.period = 100
+org.apache.sirona.inmemory.gauge.period = 100

Modified: incubator/sirona/trunk/server/plugins/hazelcast/gui/src/test/java/org/apache/sirona/hazelcast/plugin/gui/HazelcastGuiTest.java
URL: http://svn.apache.org/viewvc/incubator/sirona/trunk/server/plugins/hazelcast/gui/src/test/java/org/apache/sirona/hazelcast/plugin/gui/HazelcastGuiTest.java?rev=1542961&r1=1542960&r2=1542961&view=diff
==============================================================================
--- incubator/sirona/trunk/server/plugins/hazelcast/gui/src/test/java/org/apache/sirona/hazelcast/plugin/gui/HazelcastGuiTest.java (original)
+++ incubator/sirona/trunk/server/plugins/hazelcast/gui/src/test/java/org/apache/sirona/hazelcast/plugin/gui/HazelcastGuiTest.java Mon Nov 18 09:54:31 2013
@@ -98,11 +98,6 @@ public class HazelcastGuiTest {
                     latch1.countDown();
                 }
             }
-
-            @Override
-            public long period() {
-                return 100;
-            }
         };
 
         final Role role2 = new Role("hazelcast-partitions-cluster", Unit.UNARY);
@@ -121,11 +116,6 @@ public class HazelcastGuiTest {
                     latch2.countDown();
                 }
             }
-
-            @Override
-            public long period() {
-                return 100;
-            }
         };
         Repository.INSTANCE.reset();
         Repository.INSTANCE.addGauge(gauge1);

Added: incubator/sirona/trunk/server/plugins/hazelcast/gui/src/test/resources/sirona.properties
URL: http://svn.apache.org/viewvc/incubator/sirona/trunk/server/plugins/hazelcast/gui/src/test/resources/sirona.properties?rev=1542961&view=auto
==============================================================================
--- incubator/sirona/trunk/server/plugins/hazelcast/gui/src/test/resources/sirona.properties (added)
+++ incubator/sirona/trunk/server/plugins/hazelcast/gui/src/test/resources/sirona.properties Mon Nov 18 09:54:31 2013
@@ -0,0 +1,17 @@
+# 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.
+org.apache.sirona.inmemory.gauge.period = 100

Modified: incubator/sirona/trunk/server/plugins/tomee/agent/src/main/java/org/apache/sirona/tomee/agent/gauge/PoolGauge.java
URL: http://svn.apache.org/viewvc/incubator/sirona/trunk/server/plugins/tomee/agent/src/main/java/org/apache/sirona/tomee/agent/gauge/PoolGauge.java?rev=1542961&r1=1542960&r2=1542961&view=diff
==============================================================================
--- incubator/sirona/trunk/server/plugins/tomee/agent/src/main/java/org/apache/sirona/tomee/agent/gauge/PoolGauge.java (original)
+++ incubator/sirona/trunk/server/plugins/tomee/agent/src/main/java/org/apache/sirona/tomee/agent/gauge/PoolGauge.java Mon Nov 18 09:54:31 2013
@@ -18,7 +18,6 @@ package org.apache.sirona.tomee.agent.ga
 
 import org.apache.openejb.util.reflection.Reflections;
 import org.apache.sirona.Role;
-import org.apache.sirona.configuration.Configuration;
 import org.apache.sirona.counters.Unit;
 import org.apache.sirona.gauges.Gauge;
 import org.apache.sirona.tomee.agent.Reflection;
@@ -26,8 +25,6 @@ import org.apache.sirona.tomee.agent.Ref
 import java.beans.Introspector;
 
 public class PoolGauge implements Gauge, Reflection {
-    private static final int PERIOD = Configuration.getInteger(Configuration.CONFIG_PROPERTY_PREFIX + "gauge.tomee.period", 4000);
-
     private final Object stats;
     private final Role role;
     private final String aggregate;
@@ -47,9 +44,4 @@ public class PoolGauge implements Gauge,
     public double value() {
         return Number.class.cast(Reflections.invokeByReflection(stats, aggregate, NO_PARAM_TYPES, NO_PARAM)).doubleValue();
     }
-
-    @Override
-    public long period() {
-        return PERIOD;
-    }
 }

Modified: incubator/sirona/trunk/server/plugins/tomee/agent/src/test/java/org/apache/sirona/tomee/agent/GaugesTest.java
URL: http://svn.apache.org/viewvc/incubator/sirona/trunk/server/plugins/tomee/agent/src/test/java/org/apache/sirona/tomee/agent/GaugesTest.java?rev=1542961&r1=1542960&r2=1542961&view=diff
==============================================================================
--- incubator/sirona/trunk/server/plugins/tomee/agent/src/test/java/org/apache/sirona/tomee/agent/GaugesTest.java (original)
+++ incubator/sirona/trunk/server/plugins/tomee/agent/src/test/java/org/apache/sirona/tomee/agent/GaugesTest.java Mon Nov 18 09:54:31 2013
@@ -36,6 +36,7 @@ import javax.ejb.Stateless;
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.fail;
 
 @RunWith(ApplicationComposer.class)
 public class GaugesTest {
@@ -68,14 +69,21 @@ public class GaugesTest {
     public void checkGauges() throws InterruptedException {
         final Role gaugeRole = Repository.INSTANCE.findGaugeRole("tomee-pool-stateless-instancesPooled-AStatelessBean");
         final Role gaugeActiveRole = Repository.INSTANCE.findGaugeRole("tomee-pool-stateless-instancesActive-AStatelessBean");
-        assertNotNull(gaugeRole);
-        assertNotNull(gaugeActiveRole);
+        assertNotNull("gauge role should be found", gaugeRole);
+        assertNotNull("gauge active role should be found", gaugeActiveRole);
         assertEquals(0, sum(gaugeRole));
         assertEquals(0, sum(gaugeActiveRole));
         bean.work();
-        Thread.sleep(125);
-        assertEquals(1, sum(gaugeRole));
-        // hard to get active > 0 in this test
+        Thread.sleep(135);
+
+        int failCount = 0;
+        while (sum(gaugeRole) < 1 && failCount < 10) {
+            Thread.sleep(20);
+            failCount++;
+        }
+        if (failCount >= 10) {
+            fail("Can't get statless pool count");
+        }
     }
 
     @Stateless

Modified: incubator/sirona/trunk/server/plugins/tomee/agent/src/test/resources/sirona.properties
URL: http://svn.apache.org/viewvc/incubator/sirona/trunk/server/plugins/tomee/agent/src/test/resources/sirona.properties?rev=1542961&r1=1542960&r2=1542961&view=diff
==============================================================================
--- incubator/sirona/trunk/server/plugins/tomee/agent/src/test/resources/sirona.properties (original)
+++ incubator/sirona/trunk/server/plugins/tomee/agent/src/test/resources/sirona.properties Mon Nov 18 09:54:31 2013
@@ -14,5 +14,5 @@
 # KIND, either express or implied.  See the License for the
 # specific language governing permissions and limitations
 # under the License.
-org.apache.sirona.gauge.tomee.period = 100
+org.apache.sirona.inmemory.gauge.period = 100
 org.apache.sirona.periodic.status.period = 100

Modified: incubator/sirona/trunk/src/site/markdown/concepts.md
URL: http://svn.apache.org/viewvc/incubator/sirona/trunk/src/site/markdown/concepts.md?rev=1542961&r1=1542960&r2=1542961&view=diff
==============================================================================
--- incubator/sirona/trunk/src/site/markdown/concepts.md (original)
+++ incubator/sirona/trunk/src/site/markdown/concepts.md Mon Nov 18 09:54:31 2013
@@ -65,7 +65,6 @@ A gauge is a way to get a measure. It is
 public interface Gauge {
     Role role();
     double value();
-    long period();
 }
 ]]></pre>
 

Modified: incubator/sirona/trunk/src/site/markdown/configuration.md
URL: http://svn.apache.org/viewvc/incubator/sirona/trunk/src/site/markdown/configuration.md?rev=1542961&r1=1542960&r2=1542961&view=diff
==============================================================================
--- incubator/sirona/trunk/src/site/markdown/configuration.md (original)
+++ incubator/sirona/trunk/src/site/markdown/configuration.md Mon Nov 18 09:54:31 2013
@@ -55,7 +55,9 @@ You can also use `org.apache.sirona.conf
 * org.apache.sirona.core.gauge.activated: a boolean to deactivate cpu/memory gauges
 * org.apache.sirona.\<name>.period: the period to use to flush counters for a batch data store (like graphite one)
 * org.apache.sirona.periodic.status.period: the period to use for status reporting. Note: when using another reporter (cube typically) you'll need to replace `periodic` by the specific name of the reporter (`cube`). Note too that `period` is optional to allow to share the same period between all stores.
-* org.apache.sirona.gauges.GaugeManager: the gauge manager to use, by default for agents it uses timers to store/push metrics but you can set `org.apache.sirona.gauges.NoopGaugeManager` to prevent it.
+* org.apache.sirona.\<name>.gauge.period: the default period defining when gauge snapshots are taken (default name = `inmemory`)
+* org.apache.sirona.\<name>.aggregated.gauge.period: the default period defining when gauge snapshots are persisted/pushed (ex: graphite)
+
 
 #### Reporting