Author: rmannibucau
Date: Tue Oct 15 10:10:27 2013
New Revision: 1532271

URL: http://svn.apache.org/r1532271
Log:
adding web plugin - Note: js graph part should be reworked to be centralized

Added:
    
commons/sandbox/monitoring/trunk/reporting/src/main/java/org/apache/commons/monitoring/reporting/web/plugin/web/
    
commons/sandbox/monitoring/trunk/reporting/src/main/java/org/apache/commons/monitoring/reporting/web/plugin/web/WebEndpoints.java
    
commons/sandbox/monitoring/trunk/reporting/src/main/java/org/apache/commons/monitoring/reporting/web/plugin/web/WebPlugin.java
    commons/sandbox/monitoring/trunk/reporting/src/main/resources/templates/web/
    
commons/sandbox/monitoring/trunk/reporting/src/main/resources/templates/web/web.vm
      - copied, changed from r1532191, 
commons/sandbox/monitoring/trunk/reporting/src/main/resources/templates/jta/jta.vm
Modified:
    
commons/sandbox/monitoring/trunk/reporting/src/main/resources/META-INF/services/org.apache.commons.monitoring.reporting.web.plugin.Plugin
    
commons/sandbox/monitoring/trunk/web/src/main/java/org/apache/commons/monitoring/web/session/SessionGauge.java

Added: 
commons/sandbox/monitoring/trunk/reporting/src/main/java/org/apache/commons/monitoring/reporting/web/plugin/web/WebEndpoints.java
URL: 
http://svn.apache.org/viewvc/commons/sandbox/monitoring/trunk/reporting/src/main/java/org/apache/commons/monitoring/reporting/web/plugin/web/WebEndpoints.java?rev=1532271&view=auto
==============================================================================
--- 
commons/sandbox/monitoring/trunk/reporting/src/main/java/org/apache/commons/monitoring/reporting/web/plugin/web/WebEndpoints.java
 (added)
+++ 
commons/sandbox/monitoring/trunk/reporting/src/main/java/org/apache/commons/monitoring/reporting/web/plugin/web/WebEndpoints.java
 Tue Oct 15 10:10:27 2013
@@ -0,0 +1,48 @@
+/*
+ * 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.web.plugin.web;
+
+import org.apache.commons.monitoring.Role;
+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.json.Jsons;
+import org.apache.commons.monitoring.repositories.Repository;
+import org.apache.commons.monitoring.web.session.SessionGauge;
+
+public class WebEndpoints {
+    @Regex
+    public Template home() {
+        return new Template("web/web.vm");
+    }
+
+    @Regex("/sessions/([0-9]*)/([0-9]*)")
+    public String sessions(final long start, final long end) {
+        final StringBuilder builder = new StringBuilder();
+        for (final Role gauge : SessionGauge.gauges().keySet()) {
+            builder.append("{ \"data\": ")
+                .append(Jsons.toJson(Repository.INSTANCE.getGaugeValues(start, 
end, gauge)))
+                .append(", \"label\": \"").append(gauge.getName()).append("\", 
\"color\": \"#317eac\" }")
+                .append(",");
+        }
+
+        final int length = builder.length();
+        if (length > 0) {
+            return builder.toString().substring(0, length - 1);
+        }
+        return builder.toString();
+    }
+}

Added: 
commons/sandbox/monitoring/trunk/reporting/src/main/java/org/apache/commons/monitoring/reporting/web/plugin/web/WebPlugin.java
URL: 
http://svn.apache.org/viewvc/commons/sandbox/monitoring/trunk/reporting/src/main/java/org/apache/commons/monitoring/reporting/web/plugin/web/WebPlugin.java?rev=1532271&view=auto
==============================================================================
--- 
commons/sandbox/monitoring/trunk/reporting/src/main/java/org/apache/commons/monitoring/reporting/web/plugin/web/WebPlugin.java
 (added)
+++ 
commons/sandbox/monitoring/trunk/reporting/src/main/java/org/apache/commons/monitoring/reporting/web/plugin/web/WebPlugin.java
 Tue Oct 15 10:10:27 2013
@@ -0,0 +1,36 @@
+/*
+ * 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.web.plugin.web;
+
+import org.apache.commons.monitoring.reporting.web.plugin.Plugin;
+
+public class WebPlugin implements Plugin {
+    @Override
+    public String name() {
+        return "Web";
+    }
+
+    @Override
+    public Class<?> endpoints() {
+        return WebEndpoints.class;
+    }
+
+    @Override
+    public String mapping() {
+        return "/web";
+    }
+}

Modified: 
commons/sandbox/monitoring/trunk/reporting/src/main/resources/META-INF/services/org.apache.commons.monitoring.reporting.web.plugin.Plugin
URL: 
http://svn.apache.org/viewvc/commons/sandbox/monitoring/trunk/reporting/src/main/resources/META-INF/services/org.apache.commons.monitoring.reporting.web.plugin.Plugin?rev=1532271&r1=1532270&r2=1532271&view=diff
==============================================================================
--- 
commons/sandbox/monitoring/trunk/reporting/src/main/resources/META-INF/services/org.apache.commons.monitoring.reporting.web.plugin.Plugin
 (original)
+++ 
commons/sandbox/monitoring/trunk/reporting/src/main/resources/META-INF/services/org.apache.commons.monitoring.reporting.web.plugin.Plugin
 Tue Oct 15 10:10:27 2013
@@ -3,3 +3,4 @@ org.apache.commons.monitoring.reporting.
 org.apache.commons.monitoring.reporting.web.plugin.jvm.JVMPlugin
 org.apache.commons.monitoring.reporting.web.plugin.jta.JTAPlugin
 org.apache.commons.monitoring.reporting.web.plugin.thread.ThreadPlugin
+org.apache.commons.monitoring.reporting.web.plugin.web.WebPlugin

Copied: 
commons/sandbox/monitoring/trunk/reporting/src/main/resources/templates/web/web.vm
 (from r1532191, 
commons/sandbox/monitoring/trunk/reporting/src/main/resources/templates/jta/jta.vm)
URL: 
http://svn.apache.org/viewvc/commons/sandbox/monitoring/trunk/reporting/src/main/resources/templates/web/web.vm?p2=commons/sandbox/monitoring/trunk/reporting/src/main/resources/templates/web/web.vm&p1=commons/sandbox/monitoring/trunk/reporting/src/main/resources/templates/jta/jta.vm&r1=1532191&r2=1532271&rev=1532271&view=diff
==============================================================================
--- 
commons/sandbox/monitoring/trunk/reporting/src/main/resources/templates/jta/jta.vm
 (original)
+++ 
commons/sandbox/monitoring/trunk/reporting/src/main/resources/templates/web/web.vm
 Tue Oct 15 10:10:27 2013
@@ -14,24 +14,16 @@
   See the License for the specific language governing permissions and
   limitations under the License.
 *#
-#macro ( graph $name )
-<div class="span4">
-    <div class="page-header">
-        <h2>$name</h2>
-    </div>
-
-    <div id="${name}-graph" class="plot"></div>
-    #dateForm($name)
-</div>
-#end
-
 #set ( $parts = ["Commits", "Rollbacks", "Actives"])
 
 <div class="container-fluid">
     <div class="row-fluid">
-        #foreach ($item in $parts )
-            #graph($item)
-        #end
+        <div class="page-header">
+            <h2>Sessions</h2>
+        </div>
+
+        <div id="sessions-graph" class="plot"></div>
+        #dateForm("sessions")
     </div>
 </div>
 
@@ -40,10 +32,8 @@
 <script type="text/javascript" 
src="$mapping/resources/js/jquery.flot.time.min.js"></script>
 <script type="text/javascript">
     $(function() {
-        #foreach ($item in $parts )
-            $('#${item}-datetimepicker-start').datetimepicker();
-            $('#${item}-datetimepicker-end').datetimepicker();
-        #end
+        $('#sessions-datetimepicker-start').datetimepicker();
+        $('#sessions-datetimepicker-end').datetimepicker();
 
         var options = {
             canvas: true,
@@ -53,13 +43,13 @@
             yaxes: [ { min: 0 } ]
         };
 
-        var updateGraph = function (graph, start, end, options) {
+        var updateGraph = function (start, end, options) {
             $.ajax({
-                url: "$mapping/jta/" + graph + "/" + start + "/" + end,
+                url: "$mapping/web/sessions/" + start + "/" + end,
                 type: "GET",
                 dataType: "json",
                 success: function (data) {
-                    $.plot("#" + graph + "-graph", [ data ], options);
+                    $.plot("#sessions-graph", [ data ], options);
                 }
             });
         };
@@ -76,17 +66,13 @@
             var start = yesterday.getTime();
             var end = now.getTime();
 
-            #foreach ($item in $parts )
-                updateGraph("$item", start, end, options);
-            #end
+            updateGraph(start, end, options);
         })();
 
         // update diagram when clicking on update buttons
-        #foreach ($item in $parts )
-        $("#update-$item").submit(function () {
-            updateGraph("$item", 
extractTime($("#${item}-datetimepicker-start")), 
extractTime($("#${item}-datetimepicker-end")), options);
+        $("#update-sessions").submit(function () {
+            updateGraph(extractTime($("#sessions-datetimepicker-start")), 
extractTime($("#sessions-datetimepicker-end")), options);
             return false;
         });
-        #end
     });
 </script>

Modified: 
commons/sandbox/monitoring/trunk/web/src/main/java/org/apache/commons/monitoring/web/session/SessionGauge.java
URL: 
http://svn.apache.org/viewvc/commons/sandbox/monitoring/trunk/web/src/main/java/org/apache/commons/monitoring/web/session/SessionGauge.java?rev=1532271&r1=1532270&r2=1532271&view=diff
==============================================================================
--- 
commons/sandbox/monitoring/trunk/web/src/main/java/org/apache/commons/monitoring/web/session/SessionGauge.java
 (original)
+++ 
commons/sandbox/monitoring/trunk/web/src/main/java/org/apache/commons/monitoring/web/session/SessionGauge.java
 Tue Oct 15 10:10:27 2013
@@ -21,15 +21,28 @@ import org.apache.commons.monitoring.con
 import org.apache.commons.monitoring.counters.Unit;
 import org.apache.commons.monitoring.gauges.Gauge;
 
+import java.util.HashMap;
+import java.util.Map;
+import java.util.WeakHashMap;
 import java.util.concurrent.atomic.AtomicLong;
 
 public class SessionGauge implements Gauge {
+    private static final WeakHashMap<Role, SessionGauge> GAUGES = new 
WeakHashMap<Role, SessionGauge>();
+
+    public static Map<Role, SessionGauge> gauges() {
+        return new HashMap<Role, SessionGauge>(GAUGES);
+    }
+
     private final Role role;
     private final AtomicLong counter;
 
     public SessionGauge(final String ctx, final AtomicLong counter) {
         this.role = new Role("sessions-" + ctx, Unit.UNARY);
         this.counter = counter;
+
+        synchronized (GAUGES) {
+            GAUGES.put(role, this);
+        }
     }
 
     @Override


Reply via email to