Author: rmannibucau
Date: Mon Aug 12 10:57:22 2013
New Revision: 1513101

URL: http://svn.apache.org/r1513101
Log:
adding session listener to monitor sessions

Added:
    commons/sandbox/monitoring/trunk/src/site/markdown/web.md
      - copied, changed from r1513099, 
commons/sandbox/monitoring/trunk/src/site/markdown/reporting.md
    
commons/sandbox/monitoring/trunk/web/src/main/java/org/apache/commons/monitoring/web/session/
    
commons/sandbox/monitoring/trunk/web/src/main/java/org/apache/commons/monitoring/web/session/MonitoringSessionListener.java
Modified:
    commons/sandbox/monitoring/trunk/src/site/site.xml

Copied: commons/sandbox/monitoring/trunk/src/site/markdown/web.md (from 
r1513099, commons/sandbox/monitoring/trunk/src/site/markdown/reporting.md)
URL: 
http://svn.apache.org/viewvc/commons/sandbox/monitoring/trunk/src/site/markdown/web.md?p2=commons/sandbox/monitoring/trunk/src/site/markdown/web.md&p1=commons/sandbox/monitoring/trunk/src/site/markdown/reporting.md&r1=1513099&r2=1513101&rev=1513101&view=diff
==============================================================================
--- commons/sandbox/monitoring/trunk/src/site/markdown/reporting.md (original)
+++ commons/sandbox/monitoring/trunk/src/site/markdown/web.md Mon Aug 12 
10:57:22 2013
@@ -16,69 +16,36 @@ KIND, either express or implied.  See th
 specific language governing permissions and limitations
 under the License.
 -->
-## Reporting module
+## Web module
 
-Reporting module provides a lightweight GUI to visualize monitoring 
information.
+Reporting module provides web listener to monitor servlet containers.
 
 ## Installation
-### The webapp
 
-commons-monitoring-reporting is available as a webapp (.war) so you can just 
drop it in your servlet container.
+Add commons-monitoring-web to your webapp.
 
-Note 1: commons-monitoring-core is not provided and should be in the container.
-Note 2: if you use commons-monitoring-jdbc put it in the container too.
+## Monitor requests
 
-### Embeded in your web application
+Simply add the filter 
`org.apache.commons.monitoring.web.servlet.MonitoringFilter`:
 
-Just adding commons-monitoring-reporting jar (classifier `classes` if you use 
maven) in your application
-you can embed it. You'll need to update your web.xml to declare the monitoring 
filter:
+    <filter>
+        <filter-name>monitoring-request</filter-name>
+        
<filter-class>org.apache.commons.monitoring.web.servlet.MonitoringFilter</filter-class>
+    </filter>
+    <filter-mapping>
+        <filter-name>monitoring-request</filter-name>
+        <url-pattern>/*</url-pattern>
+    </filter-mapping>
 
-    <web-app xmlns="http://java.sun.com/xml/ns/javaee";
-             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
-             xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd";
-             version="2.5">
+## Monitor sessions
 
-      <listener>
-        
<listener-class>org.apache.commons.monitoring.reporting.web.listener.MonitoringListener</listener-class>
-      </listener>
+Simply add the listener 
`org.apache.commons.monitoring.web.servlet.MonitoringFilter`:
 
-      <filter>
-        <filter-name>Monitoring</filter-name>
-        
<filter-class>org.apache.commons.monitoring.reporting.web.MonitoringController</filter-class>
-        <init-param> <!-- should match your filter mapping base -->
-          <param-name>monitoring-mapping</param-name>
-          <param-value>/monitoring/</param-value>
-        </init-param>
-      </filter>
+    <listener>
+      
<listener-class>org.apache.commons.monitoring.web.servlet.MonitoringFilter</listener-class>
+    </listener>
 
-      <filter-mapping>
-        <filter-name>Monitoring</filter-name>
-        <url-pattern>/monitoring/*</url-pattern>
-      </filter-mapping>
 
-    </web-app>
+## Accessing results
 
-## Usage
-
-Once started you'll arrive on the home page which should look like:
-
-![Home](images/gui/home.png)
-
-By default you have three activated plugins:
-
-* Report: view to work with counter data
-* JMX: access to MBeans (read attribute, invoke operations)
-* JVM: basic measure of CPU and used heap memory
-
-### Report
-
-![Report](images/gui/report.png)
-
-### JMX
-
-![JMX](images/gui/mbean-attributes.png)
-![JMX](images/gui/mbean-operations.png)
-
-### JVM
-
-![JVM](images/gui/jvm.png)
+If you installed the reporting webapp you should be able to get the result 
under the report tab.
\ No newline at end of file

Modified: commons/sandbox/monitoring/trunk/src/site/site.xml
URL: 
http://svn.apache.org/viewvc/commons/sandbox/monitoring/trunk/src/site/site.xml?rev=1513101&r1=1513100&r2=1513101&view=diff
==============================================================================
--- commons/sandbox/monitoring/trunk/src/site/site.xml (original)
+++ commons/sandbox/monitoring/trunk/src/site/site.xml Mon Aug 12 10:57:22 2013
@@ -51,6 +51,7 @@
       <item name="Reporting" href="/reporting.html"/>
       <item name="Plugins" href="/plugins.html"/>
       <item name="JTA" href="/jta.html"/>
+      <item name="Web" href="/web.html"/>
     </menu>
   </body>
 </project>

Added: 
commons/sandbox/monitoring/trunk/web/src/main/java/org/apache/commons/monitoring/web/session/MonitoringSessionListener.java
URL: 
http://svn.apache.org/viewvc/commons/sandbox/monitoring/trunk/web/src/main/java/org/apache/commons/monitoring/web/session/MonitoringSessionListener.java?rev=1513101&view=auto
==============================================================================
--- 
commons/sandbox/monitoring/trunk/web/src/main/java/org/apache/commons/monitoring/web/session/MonitoringSessionListener.java
 (added)
+++ 
commons/sandbox/monitoring/trunk/web/src/main/java/org/apache/commons/monitoring/web/session/MonitoringSessionListener.java
 Mon Aug 12 10:57:22 2013
@@ -0,0 +1,52 @@
+/*
+ * 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.web.session;
+
+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.repositories.Repository;
+import org.apache.commons.monitoring.stopwatches.StopWatch;
+
+import javax.servlet.http.HttpSessionEvent;
+import javax.servlet.http.HttpSessionListener;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+public class MonitoringSessionListener implements HttpSessionListener {
+    private final Map<String, StopWatch> watches = new 
ConcurrentHashMap<String, StopWatch>();
+
+    private final Counter counter;
+
+    public MonitoringSessionListener() {
+        counter = Repository.INSTANCE.getCounter(new Counter.Key(new 
Role("session", Unit.UNARY), "session"));
+    }
+
+    @Override
+    public void sessionCreated(final HttpSessionEvent httpSessionEvent) {
+        final StopWatch watch = Repository.INSTANCE.start(counter);
+        watches.put(httpSessionEvent.getSession().getId(), watch);
+    }
+
+    @Override
+    public void sessionDestroyed(final HttpSessionEvent httpSessionEvent) {
+        final StopWatch watch = 
watches.remove(httpSessionEvent.getSession().getId());
+        if (watch != null) {
+            watch.stop();
+        }
+    }
+}


Reply via email to