You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sirona.apache.org by ol...@apache.org on 2013/11/22 11:05:26 UTC

svn commit: r1544459 - in /incubator/sirona/trunk: agent/store/graphite/src/test/java/org/apache/sirona/graphite/ plugins/ehcache/agent/src/main/java/org/apache/sirona/agent/ehcache/

Author: olamy
Date: Fri Nov 22 10:05:26 2013
New Revision: 1544459

URL: http://svn.apache.org/r1544459
Log:
create some gauge for ehcache on start

Modified:
    incubator/sirona/trunk/agent/store/graphite/src/test/java/org/apache/sirona/graphite/GraphiteTest.java
    incubator/sirona/trunk/plugins/ehcache/agent/src/main/java/org/apache/sirona/agent/ehcache/EhCacheCacheGauge.java
    incubator/sirona/trunk/plugins/ehcache/agent/src/main/java/org/apache/sirona/agent/ehcache/EhCacheCachesCountManagerGauge.java
    incubator/sirona/trunk/plugins/ehcache/agent/src/main/java/org/apache/sirona/agent/ehcache/EhCacheGaugeFactory.java

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=1544459&r1=1544458&r2=1544459&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 Fri Nov 22 10:05:26 2013
@@ -38,7 +38,7 @@ public class GraphiteTest extends Graphi
             Thread.sleep(140);
             counter.add(2.3);
             counter.add(2.9);
-            Thread.sleep(30);
+            Thread.sleep(130);
         }
 
         { // counters

Modified: incubator/sirona/trunk/plugins/ehcache/agent/src/main/java/org/apache/sirona/agent/ehcache/EhCacheCacheGauge.java
URL: http://svn.apache.org/viewvc/incubator/sirona/trunk/plugins/ehcache/agent/src/main/java/org/apache/sirona/agent/ehcache/EhCacheCacheGauge.java?rev=1544459&r1=1544458&r2=1544459&view=diff
==============================================================================
--- incubator/sirona/trunk/plugins/ehcache/agent/src/main/java/org/apache/sirona/agent/ehcache/EhCacheCacheGauge.java (original)
+++ incubator/sirona/trunk/plugins/ehcache/agent/src/main/java/org/apache/sirona/agent/ehcache/EhCacheCacheGauge.java Fri Nov 22 10:05:26 2013
@@ -16,17 +16,19 @@
  */
 package org.apache.sirona.agent.ehcache;
 
+import net.sf.ehcache.Cache;
 import net.sf.ehcache.CacheManager;
 import org.apache.sirona.SironaException;
 
 import java.lang.reflect.Method;
 
 public class EhCacheCacheGauge extends EhCacheManagerGaugeBase {
-    private final String cache;
+    private final Cache cache;
     private final Method method;
 
-    public EhCacheCacheGauge(final Method method, final CacheManager cacheManager, final String cache) {
-        super(method.getName(), cacheManager);
+    public EhCacheCacheGauge(final Method method, final Cache cache) {
+        super(method.getName(), cache.getCacheManager());
+
         this.cache = cache;
         this.method = method;
     }
@@ -34,7 +36,7 @@ public class EhCacheCacheGauge extends E
     @Override
     public double value() {
         try {
-            return Number.class.cast(method.invoke(manager.getCache(cache).getStatistics())).doubleValue();
+            return Number.class.cast(method.invoke(cache.getStatistics())).doubleValue();
         } catch (final Exception e) {
             throw new SironaException(e);
         }

Modified: incubator/sirona/trunk/plugins/ehcache/agent/src/main/java/org/apache/sirona/agent/ehcache/EhCacheCachesCountManagerGauge.java
URL: http://svn.apache.org/viewvc/incubator/sirona/trunk/plugins/ehcache/agent/src/main/java/org/apache/sirona/agent/ehcache/EhCacheCachesCountManagerGauge.java?rev=1544459&r1=1544458&r2=1544459&view=diff
==============================================================================
--- incubator/sirona/trunk/plugins/ehcache/agent/src/main/java/org/apache/sirona/agent/ehcache/EhCacheCachesCountManagerGauge.java (original)
+++ incubator/sirona/trunk/plugins/ehcache/agent/src/main/java/org/apache/sirona/agent/ehcache/EhCacheCachesCountManagerGauge.java Fri Nov 22 10:05:26 2013
@@ -90,7 +90,7 @@ public class EhCacheCachesCountManagerGa
                 if (m.getParameterTypes().length == 0 &&
                     (returnType.equals(Long.TYPE) || returnType.equals(Double.TYPE))
                     && !name.startsWith("get") && !name.startsWith("local") && !name.startsWith("xa")) {
-                    gauges.add(new EhCacheCacheGauge(m, manager, cacheName));
+                    gauges.add(new EhCacheCacheGauge(m, manager.getCache( cacheName)));
                 }
             }
             children.put(cacheName, gauges);

Modified: incubator/sirona/trunk/plugins/ehcache/agent/src/main/java/org/apache/sirona/agent/ehcache/EhCacheGaugeFactory.java
URL: http://svn.apache.org/viewvc/incubator/sirona/trunk/plugins/ehcache/agent/src/main/java/org/apache/sirona/agent/ehcache/EhCacheGaugeFactory.java?rev=1544459&r1=1544458&r2=1544459&view=diff
==============================================================================
--- incubator/sirona/trunk/plugins/ehcache/agent/src/main/java/org/apache/sirona/agent/ehcache/EhCacheGaugeFactory.java (original)
+++ incubator/sirona/trunk/plugins/ehcache/agent/src/main/java/org/apache/sirona/agent/ehcache/EhCacheGaugeFactory.java Fri Nov 22 10:05:26 2013
@@ -16,16 +16,22 @@
  */
 package org.apache.sirona.agent.ehcache;
 
+import net.sf.ehcache.Cache;
 import net.sf.ehcache.CacheManager;
+import net.sf.ehcache.statistics.FlatStatistics;
 import org.apache.sirona.configuration.Configuration;
 import org.apache.sirona.gauges.Gauge;
 import org.apache.sirona.gauges.GaugeFactory;
 
 import java.lang.reflect.Field;
+import java.lang.reflect.Method;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collection;
+import java.util.Collections;
 import java.util.List;
+import java.util.logging.Level;
+import java.util.logging.Logger;
 
 public class EhCacheGaugeFactory implements GaugeFactory {
     @Override
@@ -42,6 +48,12 @@ public class EhCacheGaugeFactory impleme
             final Collection<Gauge> gauges = new ArrayList<Gauge>(managers.size() * 3);
             for (final CacheManager manager : managers) {
                 gauges.addAll(register(manager));
+                for (String name:manager.getCacheNames()){
+                    Cache cache = manager.getCache( name );
+                    if (cache!=null){
+                        gauges.addAll(register( cache ));
+                    }
+                }
             }
             return gauges.toArray(new Gauge[gauges.size()]);
         } catch (final Exception e) {
@@ -49,6 +61,44 @@ public class EhCacheGaugeFactory impleme
         }
     }
 
+    /**
+     * record gauge to run runtime statistics on Cache
+     * @param cache
+     * @return
+     */
+    public static Collection<Gauge> register(Cache cache){
+
+        try {
+            Collection<Gauge> gauges = new ArrayList<Gauge>( 6 );
+
+            Method method = FlatStatistics.class.getMethod( "cacheHitCount", null );
+            gauges.add( new EhCacheCacheGauge(method, cache) );
+
+            method = FlatStatistics.class.getMethod( "cacheMissCount", null );
+            gauges.add( new EhCacheCacheGauge(method, cache) );
+
+            method = FlatStatistics.class.getMethod( "cacheHitRatio", null );
+            gauges.add( new EhCacheCacheGauge(method, cache) );
+
+            method = FlatStatistics.class.getMethod( "getSize", null );
+            gauges.add( new EhCacheCacheGauge(method, cache) );
+
+            method = FlatStatistics.class.getMethod( "getLocalHeapSizeInBytes", null );
+            gauges.add( new EhCacheCacheGauge(method, cache) );
+
+            method = FlatStatistics.class.getMethod( "getLocalDiskSizeInBytes", null );
+            gauges.add( new EhCacheCacheGauge(method, cache) );
+
+            return gauges;
+        } catch ( NoSuchMethodException e ) {
+
+            Logger.getLogger( EhCacheGaugeFactory.class.getName() )
+                .log( Level.WARNING, "fail to record ehcache gauge: " + e.getMessage(), e );
+            return Collections.emptyList();
+        }
+
+    }
+
     // utility method user can reuse for custom managers
     public static Collection<Gauge> register(final CacheManager manager) {
         final EhCacheTransactionCommittedCountManagerGauge commits = new EhCacheTransactionCommittedCountManagerGauge(manager);