commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rmannibu...@apache.org
Subject svn commit: r1534205 - in /commons/sandbox/monitoring/trunk: collector/src/main/java/org/apache/commons/monitoring/collector/server/store/counter/ core/src/main/java/org/apache/commons/monitoring/counters/ reporting/ reporting/src/main/java/org/apache/...
Date Mon, 21 Oct 2013 15:07:44 GMT
Author: rmannibucau
Date: Mon Oct 21 15:07:43 2013
New Revision: 1534205

URL: http://svn.apache.org/r1534205
Log:
adding counter detail page

Added:
    commons/sandbox/monitoring/trunk/core/src/main/java/org/apache/commons/monitoring/counters/AggregatedCounter.java
    commons/sandbox/monitoring/trunk/reporting/src/main/resources/templates/report/counter.vm
      - copied, changed from r1534028, commons/sandbox/monitoring/trunk/reporting/src/main/resources/templates/report/report.vm
    commons/sandbox/monitoring/trunk/reporting/src/test/java/org/apache/commons/monitoring/reporting/template/
    commons/sandbox/monitoring/trunk/reporting/src/test/java/org/apache/commons/monitoring/reporting/template/CounterDetailTemplateTest.java
    commons/sandbox/monitoring/trunk/reporting/src/test/resources/
    commons/sandbox/monitoring/trunk/reporting/src/test/resources/arquillian.xml
Modified:
    commons/sandbox/monitoring/trunk/collector/src/main/java/org/apache/commons/monitoring/collector/server/store/counter/AggregatedCollectorCounter.java
    commons/sandbox/monitoring/trunk/core/src/main/java/org/apache/commons/monitoring/counters/Counter.java
    commons/sandbox/monitoring/trunk/reporting/pom.xml
    commons/sandbox/monitoring/trunk/reporting/src/main/java/org/apache/commons/monitoring/reporting/web/plugin/report/ReportEndpoints.java
    commons/sandbox/monitoring/trunk/reporting/src/main/java/org/apache/commons/monitoring/reporting/web/plugin/report/format/HTMLFormat.java
    commons/sandbox/monitoring/trunk/reporting/src/main/java/org/apache/commons/monitoring/reporting/web/plugin/report/format/MapFormat.java
    commons/sandbox/monitoring/trunk/reporting/src/main/resources/templates/report/report.vm
    commons/sandbox/monitoring/trunk/reporting/src/test/java/org/apache/commons/monitoring/reporting/FormatsTest.java

Modified: commons/sandbox/monitoring/trunk/collector/src/main/java/org/apache/commons/monitoring/collector/server/store/counter/AggregatedCollectorCounter.java
URL: http://svn.apache.org/viewvc/commons/sandbox/monitoring/trunk/collector/src/main/java/org/apache/commons/monitoring/collector/server/store/counter/AggregatedCollectorCounter.java?rev=1534205&r1=1534204&r2=1534205&view=diff
==============================================================================
--- commons/sandbox/monitoring/trunk/collector/src/main/java/org/apache/commons/monitoring/collector/server/store/counter/AggregatedCollectorCounter.java
(original)
+++ commons/sandbox/monitoring/trunk/collector/src/main/java/org/apache/commons/monitoring/collector/server/store/counter/AggregatedCollectorCounter.java
Mon Oct 21 15:07:43 2013
@@ -17,13 +17,16 @@
 package org.apache.commons.monitoring.collector.server.store.counter;
 
 import org.apache.commons.monitoring.collector.server.math.Aggregators;
+import org.apache.commons.monitoring.counters.AggregatedCounter;
+import org.apache.commons.monitoring.counters.Counter;
 
 import java.util.Collection;
+import java.util.Map;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.ConcurrentMap;
 import java.util.concurrent.locks.Lock;
 
-public class AggregatedCollectorCounter extends CollectorCounter {
+public class AggregatedCollectorCounter extends CollectorCounter implements AggregatedCounter
{
     private final ConcurrentMap<String, LeafCollectorCounter> aggregation = new ConcurrentHashMap<String,
LeafCollectorCounter>(50);
 
     public AggregatedCollectorCounter(Key key) {
@@ -54,4 +57,9 @@ public class AggregatedCollectorCounter 
         }
         return i;
     }
+
+    @Override
+    public Map<String, ? extends Counter> aggregated() {
+        return aggregation;
+    }
 }

Added: commons/sandbox/monitoring/trunk/core/src/main/java/org/apache/commons/monitoring/counters/AggregatedCounter.java
URL: http://svn.apache.org/viewvc/commons/sandbox/monitoring/trunk/core/src/main/java/org/apache/commons/monitoring/counters/AggregatedCounter.java?rev=1534205&view=auto
==============================================================================
--- commons/sandbox/monitoring/trunk/core/src/main/java/org/apache/commons/monitoring/counters/AggregatedCounter.java
(added)
+++ commons/sandbox/monitoring/trunk/core/src/main/java/org/apache/commons/monitoring/counters/AggregatedCounter.java
Mon Oct 21 15:07:43 2013
@@ -0,0 +1,24 @@
+/*
+ * 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.counters;
+
+import java.util.Map;
+
+// we need to be able to unpack an aggregation to print details
+public interface AggregatedCounter {
+    Map<String, ? extends Counter> aggregated();
+}

Modified: commons/sandbox/monitoring/trunk/core/src/main/java/org/apache/commons/monitoring/counters/Counter.java
URL: http://svn.apache.org/viewvc/commons/sandbox/monitoring/trunk/core/src/main/java/org/apache/commons/monitoring/counters/Counter.java?rev=1534205&r1=1534204&r2=1534205&view=diff
==============================================================================
--- commons/sandbox/monitoring/trunk/core/src/main/java/org/apache/commons/monitoring/counters/Counter.java
(original)
+++ commons/sandbox/monitoring/trunk/core/src/main/java/org/apache/commons/monitoring/counters/Counter.java
Mon Oct 21 15:07:43 2013
@@ -14,11 +14,12 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-
 package org.apache.commons.monitoring.counters;
 
 import org.apache.commons.monitoring.Role;
 
+import java.util.Collection;
+import java.util.Map;
 import java.util.concurrent.atomic.AtomicInteger;
 
 /**

Modified: commons/sandbox/monitoring/trunk/reporting/pom.xml
URL: http://svn.apache.org/viewvc/commons/sandbox/monitoring/trunk/reporting/pom.xml?rev=1534205&r1=1534204&r2=1534205&view=diff
==============================================================================
--- commons/sandbox/monitoring/trunk/reporting/pom.xml (original)
+++ commons/sandbox/monitoring/trunk/reporting/pom.xml Mon Oct 21 15:07:43 2013
@@ -32,6 +32,9 @@
   <properties>
     <tomcatRunPort>8080</tomcatRunPort>
     <tomcatRunPath>/monitoring</tomcatRunPath>
+
+    <tomcat.version>7.0.42</tomcat.version>
+    <arquillian.version>1.0.3.Final</arquillian.version>
   </properties>
 
   <dependencies>
@@ -69,6 +72,67 @@
       <groupId>junit</groupId>
       <artifactId>junit</artifactId>
     </dependency>
+    <dependency>
+      <groupId>org.jboss.shrinkwrap.descriptors</groupId>
+      <artifactId>shrinkwrap-descriptors-impl-javaee</artifactId>
+      <version>2.0.0-alpha-5</version>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.jboss.shrinkwrap.resolver</groupId>
+      <artifactId>shrinkwrap-resolver-impl-maven</artifactId>
+      <version>2.0.0</version>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.jboss.arquillian.junit</groupId>
+      <artifactId>arquillian-junit-container</artifactId>
+      <version>${arquillian.version}</version>
+      <!-- sadly tomcat7 embedded is not compatible with later impl in v1.0.0.CR5 -->
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.jboss.arquillian.protocol</groupId>
+      <artifactId>arquillian-protocol-servlet</artifactId>
+      <version>${arquillian.version}</version>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.jboss.arquillian.container</groupId>
+      <artifactId>arquillian-tomcat-embedded-7</artifactId>
+      <version>1.0.0.CR5</version>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.tomcat.embed</groupId>
+      <artifactId>tomcat-embed-core</artifactId>
+      <version>${tomcat.version}</version>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.tomcat.embed</groupId>
+      <artifactId>tomcat-embed-jasper</artifactId>
+      <version>${tomcat.version}</version>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.tomcat.embed</groupId>
+      <artifactId>tomcat-embed-logging-juli</artifactId>
+      <version>${tomcat.version}</version>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.eclipse.jdt.core.compiler</groupId>
+      <artifactId>ecj</artifactId>
+      <version>4.2.1</version>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>net.sourceforge.htmlunit</groupId>
+      <artifactId>htmlunit</artifactId>
+      <version>2.12</version>
+      <scope>test</scope>
+    </dependency>
   </dependencies>
 
   <build>

Modified: commons/sandbox/monitoring/trunk/reporting/src/main/java/org/apache/commons/monitoring/reporting/web/plugin/report/ReportEndpoints.java
URL: http://svn.apache.org/viewvc/commons/sandbox/monitoring/trunk/reporting/src/main/java/org/apache/commons/monitoring/reporting/web/plugin/report/ReportEndpoints.java?rev=1534205&r1=1534204&r2=1534205&view=diff
==============================================================================
--- commons/sandbox/monitoring/trunk/reporting/src/main/java/org/apache/commons/monitoring/reporting/web/plugin/report/ReportEndpoints.java
(original)
+++ commons/sandbox/monitoring/trunk/reporting/src/main/java/org/apache/commons/monitoring/reporting/web/plugin/report/ReportEndpoints.java
Mon Oct 21 15:07:43 2013
@@ -17,14 +17,30 @@
 package org.apache.commons.monitoring.reporting.web.plugin.report;
 
 import org.apache.commons.monitoring.MonitoringException;
+import org.apache.commons.monitoring.Role;
+import org.apache.commons.monitoring.counters.AggregatedCounter;
+import org.apache.commons.monitoring.counters.Counter;
+import org.apache.commons.monitoring.counters.Unit;
 import org.apache.commons.monitoring.reporting.web.handler.api.Regex;
 import org.apache.commons.monitoring.reporting.web.handler.api.Template;
 import org.apache.commons.monitoring.reporting.web.plugin.report.format.Format;
+import org.apache.commons.monitoring.reporting.web.plugin.report.format.HTMLFormat;
+import org.apache.commons.monitoring.reporting.web.plugin.report.format.MapFormat;
+import org.apache.commons.monitoring.reporting.web.template.MapBuilder;
 import org.apache.commons.monitoring.repositories.Repository;
 
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 import java.io.IOException;
+import java.io.UnsupportedEncodingException;
+import java.net.URLDecoder;
+import java.util.Collection;
+import java.util.Map;
+import java.util.TreeMap;
+
+import static org.apache.commons.monitoring.reporting.web.plugin.report.format.MapFormat.format;
+import static org.apache.commons.monitoring.reporting.web.plugin.report.format.MapFormat.generateLine;
+import static org.apache.commons.monitoring.reporting.web.plugin.report.format.MapFormat.timeUnit;
 
 public class ReportEndpoints {
     @Regex
@@ -32,6 +48,31 @@ public class ReportEndpoints {
         return renderFormat(request, response, Format.Defaults.HTML);
     }
 
+    @Regex("/counter/([^/]*)/([^/]*)/([^/]*)")
+    public Template counterDetail(final String role, final String unit, final String name,
final HttpServletRequest request) {
+        final Counter counter = Repository.INSTANCE.getCounter(new Counter.Key(new Role(decode(role),
Unit.get(unit)), decode(name)));
+
+        final Map<String, String[]> params = request.getParameterMap();
+        final Unit timeUnit = timeUnit(params);
+        final String format = format(params, HTMLFormat.NUMBER_FORMAT);
+
+        final Map<String, Collection<String>> counters = new TreeMap<String,
Collection<String>>();
+        if (AggregatedCounter.class.isInstance(counter)) {
+            for (final Map.Entry<String, ? extends Counter> marker : AggregatedCounter.class.cast(counter).aggregated().entrySet())
{
+                counters.put(marker.getKey(), generateLine(marker.getValue(), timeUnit, format));
+            }
+        } else {
+            counters.put("", generateLine(counter, timeUnit, format));
+        }
+
+        return new Template("report/counter.vm",
+            new MapBuilder<String, Object>()
+                .set("headers", HTMLFormat.ATTRIBUTES_ORDERED_LIST)
+                .set("counter", counter)
+                .set("counters", counters)
+                .build());
+    }
+
     @Regex(".csv")
     public Template csv(final HttpServletRequest request, final HttpServletResponse response)
{
         return renderFormat(request, response, Format.Defaults.CSV);
@@ -61,4 +102,12 @@ public class ReportEndpoints {
         response.setContentType(format.type());
         return format.render(request.getParameterMap());
     }
+
+    private static String decode(final String role) {
+        try {
+            return URLDecoder.decode(role, MapFormat.ENCODING);
+        } catch (final UnsupportedEncodingException e) {
+            throw new IllegalStateException(e);
+        }
+    }
 }

Modified: commons/sandbox/monitoring/trunk/reporting/src/main/java/org/apache/commons/monitoring/reporting/web/plugin/report/format/HTMLFormat.java
URL: http://svn.apache.org/viewvc/commons/sandbox/monitoring/trunk/reporting/src/main/java/org/apache/commons/monitoring/reporting/web/plugin/report/format/HTMLFormat.java?rev=1534205&r1=1534204&r2=1534205&view=diff
==============================================================================
--- commons/sandbox/monitoring/trunk/reporting/src/main/java/org/apache/commons/monitoring/reporting/web/plugin/report/format/HTMLFormat.java
(original)
+++ commons/sandbox/monitoring/trunk/reporting/src/main/java/org/apache/commons/monitoring/reporting/web/plugin/report/format/HTMLFormat.java
Mon Oct 21 15:07:43 2013
@@ -23,7 +23,7 @@ import org.apache.commons.monitoring.rep
 import java.util.Map;
 
 public class HTMLFormat extends MapFormat implements Format {
-    private static final String NUMBER_FORMAT = "###,###,###,##0.00"; // DecimalFormat is
not thread safe so don't init it statically
+    public static final String NUMBER_FORMAT = "###,###,###,##0.00"; // DecimalFormat is
not thread safe so don't init it statically
 
     @Override
     public Template render(final Map<String, ?> params) {
@@ -32,7 +32,7 @@ public class HTMLFormat extends MapForma
             new MapBuilder<String, Object>()
                 .set(Map.class.cast(params))
                 .set("headers", ATTRIBUTES_ORDERED_LIST)
-                .set("data", snapshot(timeUnit, format(params, NUMBER_FORMAT)))
+                .set("data", snapshotByPath(timeUnit, format(params, NUMBER_FORMAT)))
                 .build());
     }
 

Modified: commons/sandbox/monitoring/trunk/reporting/src/main/java/org/apache/commons/monitoring/reporting/web/plugin/report/format/MapFormat.java
URL: http://svn.apache.org/viewvc/commons/sandbox/monitoring/trunk/reporting/src/main/java/org/apache/commons/monitoring/reporting/web/plugin/report/format/MapFormat.java?rev=1534205&r1=1534204&r2=1534205&view=diff
==============================================================================
--- commons/sandbox/monitoring/trunk/reporting/src/main/java/org/apache/commons/monitoring/reporting/web/plugin/report/format/MapFormat.java
(original)
+++ commons/sandbox/monitoring/trunk/reporting/src/main/java/org/apache/commons/monitoring/reporting/web/plugin/report/format/MapFormat.java
Mon Oct 21 15:07:43 2013
@@ -16,6 +16,7 @@
  */
 package org.apache.commons.monitoring.reporting.web.plugin.report.format;
 
+import org.apache.commons.monitoring.Role;
 import org.apache.commons.monitoring.counters.Counter;
 import org.apache.commons.monitoring.counters.MetricData;
 import org.apache.commons.monitoring.counters.Unit;
@@ -23,14 +24,18 @@ import org.apache.commons.monitoring.rep
 
 import java.io.UnsupportedEncodingException;
 import java.net.URLDecoder;
+import java.net.URLEncoder;
 import java.text.DecimalFormat;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Map;
+import java.util.TreeMap;
 import java.util.concurrent.CopyOnWriteArrayList;
 
 public abstract class MapFormat {
-    protected static final Collection<String> ATTRIBUTES_ORDERED_LIST = buildMetricDataHeader();
+    public static final String ENCODING = "UTF-8";
+
+    public static final Collection<String> ATTRIBUTES_ORDERED_LIST = buildMetricDataHeader();
 
     protected static Collection<String> buildMetricDataHeader() {
         final Collection<String> list = new CopyOnWriteArrayList<String>();
@@ -42,7 +47,11 @@ public abstract class MapFormat {
         return list;
     }
 
-    protected static String format(final Map<String, ?> params, final String defaultValue)
{
+    public static String format(final Map<String, ?> params, final String defaultValue)
{
+        if (params == null) {
+            return defaultValue;
+        }
+
         final Object format = params.get("format");
         if (format != null) {
             if (String.class.isInstance(format)) {
@@ -65,7 +74,11 @@ public abstract class MapFormat {
         }
     }
 
-    protected static Unit timeUnit(final Map<String, ?> params) {
+    public static Unit timeUnit(final Map<String, ?> params) {
+        if (params == null) {
+            return Unit.Time.MILLISECOND;
+        }
+
         final Object u = params.get("unit");
         if (u != null) {
             if (String.class.isInstance(u)) {
@@ -87,42 +100,69 @@ public abstract class MapFormat {
         return Unit.Time.MILLISECOND;
     }
 
+    protected static Map<String, Collection<String>> snapshotByPath(final Unit
timeUnit, final String format) {
+        final Map<String, Collection<String>> data = new TreeMap<String, Collection<String>>();
+        for (final Counter counter : Repository.INSTANCE) {
+            final Counter.Key key = counter.getKey();
+            data.put(generateCounterKeyString(key), generateLine(counter, timeUnit, format));
+        }
+        return data;
+    }
+
+    public static String generateCounterKeyString(final Counter.Key key) {
+        final Role role = key.getRole();
+        try {
+            return encode(role.getName()) + '/' + role.getUnit().getName() + '/' + encode(key.getName());
+        } catch (final UnsupportedEncodingException e) {
+            throw new IllegalStateException(e);
+        }
+    }
+
     protected static Collection<Collection<String>> snapshot(final Unit timeUnit,
final String format) {
         final Collection<Collection<String>> data = new ArrayList<Collection<String>>();
         for (final Counter counter : Repository.INSTANCE) {
-            final Unit counterUnit = counter.getKey().getRole().getUnit();
-            final boolean compatible = timeUnit.isCompatible(counterUnit);
+            data.add(generateLine(counter, timeUnit, format));
+        }
+        return data;
+    }
 
-            final Collection<String> line = new ArrayList<String>();
-            data.add(line);
+    public static Collection<String> generateLine(final Counter counter, final Unit
timeUnit, final String format) {
+        final Unit counterUnit = counter.getKey().getRole().getUnit();
+        final boolean compatible = timeUnit.isCompatible(counterUnit);
+
+        final Collection<String> line = new ArrayList<String>();
+
+        line.add(counter.getKey().getName());
+
+        if (compatible) {
+            line.add(counter.getKey().getRole().getName() + " (" + timeUnit.getName() + ")");
+        } else {
+            line.add(counter.getKey().getRole().getName() + " (" + counterUnit.getName()
+ ")");
+        }
 
-            line.add(counter.getKey().getName());
+        final DecimalFormat formatter;
+        if (format != null) {
+            formatter = new DecimalFormat(format);
+        } else {
+            formatter = null;
+        }
 
-            if (compatible) {
-                line.add(counter.getKey().getRole().getName() + " (" + timeUnit.getName()
+ ")");
-            } else {
-                line.add(counter.getKey().getRole().getName() + " (" + counterUnit.getName()
+ ")");
+        for (final MetricData md : MetricData.values()) {
+            double value = md.value(counter);
+            if (md.isTime() && compatible && timeUnit != counterUnit) {
+                value = timeUnit.convert(value, counterUnit);
             }
-
-            final DecimalFormat formatter;
-            if (format != null) {
-                formatter = new DecimalFormat(format);
+            if (formatter != null && !Double.isNaN(value) && !Double.isInfinite(value))
{
+                line.add(formatter.format(value));
             } else {
-                formatter = null;
-            }
-
-            for (final MetricData md : MetricData.values()) {
-                double value = md.value(counter);
-                if (md.isTime() && compatible && timeUnit != counterUnit)
{
-                    value = timeUnit.convert(value, counterUnit);
-                }
-                if (formatter != null && !Double.isNaN(value) && !Double.isInfinite(value))
{
-                    line.add(formatter.format(value));
-                } else {
-                    line.add(Double.toString(value));
-                }
+                line.add(Double.toString(value));
             }
         }
-        return data;
+
+        return line;
+    }
+
+    private static String encode(final String value) throws UnsupportedEncodingException
{
+        return URLEncoder.encode(value, ENCODING);
     }
 }

Copied: commons/sandbox/monitoring/trunk/reporting/src/main/resources/templates/report/counter.vm
(from r1534028, commons/sandbox/monitoring/trunk/reporting/src/main/resources/templates/report/report.vm)
URL: http://svn.apache.org/viewvc/commons/sandbox/monitoring/trunk/reporting/src/main/resources/templates/report/counter.vm?p2=commons/sandbox/monitoring/trunk/reporting/src/main/resources/templates/report/counter.vm&p1=commons/sandbox/monitoring/trunk/reporting/src/main/resources/templates/report/report.vm&r1=1534028&r2=1534205&rev=1534205&view=diff
==============================================================================
--- commons/sandbox/monitoring/trunk/reporting/src/main/resources/templates/report/report.vm
(original)
+++ commons/sandbox/monitoring/trunk/reporting/src/main/resources/templates/report/counter.vm
Mon Oct 21 15:07:43 2013
@@ -14,87 +14,31 @@
   See the License for the specific language governing permissions and
   limitations under the License.
 *#
-<h1>Report</h1>
+#macro ( counter $marker $data )
+    #if( !$marker.isEmpty() )
+        <h2>$marker</h2>
+    #end
 
-<ul class="nav nav-pills">
-    <li class="dropdown">
-        <a class="dropdown-toggle" data-toggle="dropdown" href="#">
-            Actions <b class="caret"></b>
-        </a>
-        <ul class="dropdown-menu">
-            <li><a href="$mapping/report/clear">Clear</a></li>
-        </ul>
-    </li>
-    <li class="dropdown">
-        <a class="dropdown-toggle" data-toggle="dropdown" href="#">
-            Formats <b class="caret"></b>
-        </a>
-        <ul class="dropdown-menu">
-            <li><a href="$mapping/report.xml">xml</a></li>
-            <li><a href="$mapping/report.csv">csv</a></li>
-            <li><a href="$mapping/report.json">json</a></li>
-        </ul>
-    </li>
-    <li class="dropdown">
-        <a class="dropdown-toggle" data-toggle="dropdown" href="#">
-            Time Unit <b class="caret"></b>
-        </a>
-        <ul class="dropdown-menu">
-            <li><a href="$mapping/report?unit=s">s</a></li>
-            <li><a href="$mapping/report?unit=ms">ms</a></li>
-            <li><a href="$mapping/report?unit=ns">ns</a></li>
-        </ul>
-    </li>
-</ul>
-
-<table id="report-table" class="table table-bordered table-striped table-hover">
-    <thead>
-        <tr>
-            #foreach( $header in $headers )
-                <th>$header</th>
-            #end
-        </tr>
-    </thead>
-    <tbody>
-        #foreach( $line in $data )
+    <table id="counter$marker" class="table table-bordered table-striped table-hover">
+        <thead>
             <tr>
-                #foreach( $item in $line )
-                    <td>$item</td>
+                #foreach( $header in $headers )
+                    <th>$header</th>
                 #end
             </tr>
-        #end
-    </tbody>
-</table>
+        </thead>
+        <tbody>
+            <tr>
+            #foreach( $item in $data )
+                <td>$item</td>
+            #end
+            </tr>
+        </tbody>
+    </table>
+#end
 
-<script type="text/javascript" src="$mapping/resources/js/bootstrap-dropdown.js"></script>
-<script type="text/javascript" src="$mapping/resources/js/jquery.tablesorter.js"></script>
-<script type="text/javascript" src="$mapping/resources/js/jquery.tablesorter.widgets.js"></script>
-<script type="text/javascript">
-    $(function() {
-        $("table#report-table").tablesorter({
-            widthFixed : false,
-            widgets: [ "filter" ],
-            widgetOptions : {
-                filter_childRows : false,
-                filter_columnFilters : true,
-                filter_cssFilter : 'tablesorter-filter',
-                filter_filteredRow   : 'filtered',
-                filter_formatter : null,
-                filter_functions : null,
-                filter_hideFilters : false,
-                filter_ignoreCase : true,
-                filter_liveSearch : true,
-                filter_reset : 'button.reset',
-                filter_searchDelay : 300,
-                filter_serversideFiltering: false,
-                filter_startsWith : false,
-                filter_useParsedData : false,
-                cssAsc: 'headerSortUp',
-                cssDesc: 'headerSortDown',
-                sortList: [[4, 1]] // sort by mean in descending order
-            }
-        });
+<h1>Counter $counter.key.name</h1>
 
-        $("table#report-table tr th div").addClass("blue");
-    });
-</script>
+#foreach( $entry in $counters.entrySet() )
+    #counter( $entry.key, $entry.value )
+#end

Modified: commons/sandbox/monitoring/trunk/reporting/src/main/resources/templates/report/report.vm
URL: http://svn.apache.org/viewvc/commons/sandbox/monitoring/trunk/reporting/src/main/resources/templates/report/report.vm?rev=1534205&r1=1534204&r2=1534205&view=diff
==============================================================================
--- commons/sandbox/monitoring/trunk/reporting/src/main/resources/templates/report/report.vm
(original)
+++ commons/sandbox/monitoring/trunk/reporting/src/main/resources/templates/report/report.vm
Mon Oct 21 15:07:43 2013
@@ -56,10 +56,16 @@
         </tr>
     </thead>
     <tbody>
-        #foreach( $line in $data )
+        #foreach( $line in $data.entrySet() )
             <tr>
-                #foreach( $item in $line )
-                    <td>$item</td>
+                #foreach( $item in $line.getValue() )
+                    <td>
+                        #if ($foreach.isFirst())
+                            <a href="$mapping/report/counter/$line.getKey()">$item</a>
+                        #else
+                            $item
+                        #end
+                    </td>
                 #end
             </tr>
         #end

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=1534205&r1=1534204&r2=1534205&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 15:07:43 2013
@@ -14,7 +14,6 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-
 package org.apache.commons.monitoring.reporting;
 
 import org.apache.commons.monitoring.Role;

Added: commons/sandbox/monitoring/trunk/reporting/src/test/java/org/apache/commons/monitoring/reporting/template/CounterDetailTemplateTest.java
URL: http://svn.apache.org/viewvc/commons/sandbox/monitoring/trunk/reporting/src/test/java/org/apache/commons/monitoring/reporting/template/CounterDetailTemplateTest.java?rev=1534205&view=auto
==============================================================================
--- commons/sandbox/monitoring/trunk/reporting/src/test/java/org/apache/commons/monitoring/reporting/template/CounterDetailTemplateTest.java
(added)
+++ commons/sandbox/monitoring/trunk/reporting/src/test/java/org/apache/commons/monitoring/reporting/template/CounterDetailTemplateTest.java
Mon Oct 21 15:07:43 2013
@@ -0,0 +1,116 @@
+/*
+ * 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.reporting.template;
+
+import com.gargoylesoftware.htmlunit.WebAssert;
+import com.gargoylesoftware.htmlunit.WebClient;
+import com.gargoylesoftware.htmlunit.html.HtmlPage;
+import org.apache.catalina.startup.Constants;
+import org.apache.commons.monitoring.Role;
+import org.apache.commons.monitoring.counters.Counter;
+import org.apache.commons.monitoring.counters.Unit;
+import org.apache.commons.monitoring.reporting.web.plugin.Plugin;
+import org.apache.commons.monitoring.reporting.web.plugin.report.ReportPlugin;
+import org.apache.commons.monitoring.reporting.web.plugin.report.format.MapFormat;
+import org.apache.commons.monitoring.reporting.web.registration.MonitoringReportingInitializer;
+import org.apache.commons.monitoring.repositories.Repository;
+import org.jboss.arquillian.container.test.api.Deployment;
+import org.jboss.arquillian.junit.Arquillian;
+import org.jboss.arquillian.test.api.ArquillianResource;
+import org.jboss.shrinkwrap.api.Archive;
+import org.jboss.shrinkwrap.api.ShrinkWrap;
+import org.jboss.shrinkwrap.api.asset.ClassLoaderAsset;
+import org.jboss.shrinkwrap.api.spec.JavaArchive;
+import org.jboss.shrinkwrap.api.spec.WebArchive;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import javax.servlet.ServletContainerInitializer;
+import java.io.IOException;
+import java.net.URL;
+
+import static org.junit.Assert.assertEquals;
+
+@RunWith(Arquillian.class)
+public class CounterDetailTemplateTest {
+    @Deployment(testable = false)
+    public static Archive<?> war() { // note: we depend on tomcat embedded adapter
since we don't add dependencies + we use the fact Repository.INSTANCE is in the same JVM
+        // we use this hack to init jars to skip since this method is triggered before any
deployment
+        // so ContextConfig is not yet loaded
+        System.setProperty(Constants.DEFAULT_JARS_TO_SKIP, "a*,c*,d*,e*,g*,h*,i*,j*,l*,m*,n*,p*,r*,sa*,se*,sh*,su*,t*,v*,w*,x*,z*");
+
+        // real impl of this method starts here
+        return ShrinkWrap.create(WebArchive.class, "sirona-test.war")
+            .addPackages(true, "org.apache.commons.monitoring.reporting.web")
+            .addAsServiceProvider(Plugin.class, ReportPlugin.class)
+            .addAsWebInfResource(new ClassLoaderAsset("templates/report/report.vm"), "classes/templates/report/report.vm")
+            .addAsWebInfResource(new ClassLoaderAsset("templates/report/counter.vm"), "classes/templates/report/counter.vm")
+            .addAsWebInfResource(new ClassLoaderAsset("templates/macro.vm"), "classes/templates/macro.vm")
+            .addAsLibraries(
+                ShrinkWrap.create(JavaArchive.class, "sci.jar") // bug in tomcat?
+                    .addAsServiceProvider(ServletContainerInitializer.class, MonitoringReportingInitializer.class));
+    }
+
+    @ArquillianResource
+    private URL base;
+
+    private Counter.Key key;
+
+    @Before
+    public void init() {
+        Repository.INSTANCE.clear();
+        key = new Counter.Key(new Role("role", Unit.UNARY), "counter");
+        Repository.INSTANCE.getCounter(key).add(55);
+    }
+
+    @After
+    public void reset() {
+        Repository.INSTANCE.clear();
+    }
+
+    @Test
+    public void generalList() throws IOException {
+        final WebClient client = newClient();
+        final HtmlPage page = client.getPage(base.toExternalForm() + "monitoring/report");
+        WebAssert.assertElementPresent(page, "report-table");
+
+        final String text = page.getElementById("report-table").asText();
+        assertEquals("Counter\tRole\tHits\tMax\tMean\tMin\tStandardDeviation\tSum\tVariance\tValue\tConcurrency\tMaxConcurrency\n"
+
+            "counter \t role (u) \t 1.00 \t 55.00 \t 55.00 \t 55.00 \t 0.00 \t 55.00 \t 0.00
\t 55.00 \t 0.00 \t 0.00", text);
+    }
+
+    @Test
+    public void detail() throws IOException {
+        final WebClient client = newClient();
+        final HtmlPage page = client.getPage(base.toExternalForm() + "monitoring/report/counter/"
+ MapFormat.generateCounterKeyString(key));
+        WebAssert.assertElementPresent(page, "counter");
+
+        final String text = page.getElementById("counter").asText();
+        assertEquals("Counter\tRole\tHits\tMax\tMean\tMin\tStandardDeviation\tSum\tVariance\tValue\tConcurrency\tMaxConcurrency\n"
+
+            "counter\trole (u)\t1.00\t55.00\t55.00\t55.00\t0.00\t55.00\t0.00\t55.00\t0.00\t0.00",
text);
+    }
+
+    private static WebClient newClient() {
+        final WebClient webClient = new WebClient();
+        webClient.getOptions().setJavaScriptEnabled(false);
+        webClient.getOptions().setCssEnabled(false);
+        webClient.getOptions().setAppletEnabled(false);
+        return webClient;
+    }
+}

Added: commons/sandbox/monitoring/trunk/reporting/src/test/resources/arquillian.xml
URL: http://svn.apache.org/viewvc/commons/sandbox/monitoring/trunk/reporting/src/test/resources/arquillian.xml?rev=1534205&view=auto
==============================================================================
--- commons/sandbox/monitoring/trunk/reporting/src/test/resources/arquillian.xml (added)
+++ commons/sandbox/monitoring/trunk/reporting/src/test/resources/arquillian.xml Mon Oct 21
15:07:43 2013
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+<!--
+
+    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.
+-->
+<arquillian xmlns="http://jboss.org/schema/arquillian"
+            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+            xsi:schemaLocation="http://jboss.org/schema/arquillian
+                                http://jboss.org/schema/arquillian/arquillian_1_0.xsd">
+  <container qualifier="tomcat7" default="true">
+    <configuration>
+      <property name="tomcatHome">target/tomcat7</property>
+      <property name="workDir">target/arquillian-work</property>
+      <property name="unpackArchive">true</property>
+      <property name="bindHttpPort">1234</property>
+    </configuration>
+  </container>
+</arquillian>



Mime
View raw message