[logback-dev] svn commit: r990 - logback/trunk/logback-access/src/main/java/ch/qos/logback/access/filter

noreply.ceki at qos.ch noreply.ceki at qos.ch
Wed Nov 22 21:57:37 CET 2006


Author: ceki
Date: Wed Nov 22 21:57:37 2006
New Revision: 990

Added:
   logback/trunk/logback-access/src/main/java/ch/qos/logback/access/filter/StatisticalView.java
      - copied, changed from r987, /logback/trunk/logback-access/src/main/java/ch/qos/logback/access/filter/AccessStats.java
   logback/trunk/logback-access/src/main/java/ch/qos/logback/access/filter/StatisticalViewImpl.java
      - copied, changed from r987, /logback/trunk/logback-access/src/main/java/ch/qos/logback/access/filter/AccessStatsImpl.java
   logback/trunk/logback-access/src/main/java/ch/qos/logback/access/filter/StatsByHour.java
   logback/trunk/logback-access/src/main/java/ch/qos/logback/access/filter/StatsByMinute.java
Removed:
   logback/trunk/logback-access/src/main/java/ch/qos/logback/access/filter/AccessStats.java
   logback/trunk/logback-access/src/main/java/ch/qos/logback/access/filter/AccessStatsImpl.java
Modified:
   logback/trunk/logback-access/src/main/java/ch/qos/logback/access/filter/CountingFilter.java

Log:
Adding stats by minute and by hour

Modified: logback/trunk/logback-access/src/main/java/ch/qos/logback/access/filter/CountingFilter.java
==============================================================================
--- logback/trunk/logback-access/src/main/java/ch/qos/logback/access/filter/CountingFilter.java	(original)
+++ logback/trunk/logback-access/src/main/java/ch/qos/logback/access/filter/CountingFilter.java	Wed Nov 22 21:57:37 2006
@@ -12,10 +12,10 @@
 public class CountingFilter extends Filter {
 
   long total = 0;
-  final AccessStatsImpl accessStatsImpl;
+  final StatisticalViewImpl accessStatsImpl;
   
   CountingFilter() {
-    accessStatsImpl = new AccessStatsImpl(this);
+    accessStatsImpl = new StatisticalViewImpl(this);
   }
   
   @Override
@@ -34,7 +34,7 @@
     MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
     try {
       ObjectName on = new ObjectName("totp:Filter=1");
-      StandardMBean mbean = new StandardMBean(accessStatsImpl, AccessStats.class);
+      StandardMBean mbean = new StandardMBean(accessStatsImpl, StatisticalView.class);
       mbs.registerMBean(mbean, on);
       super.start();
     } catch (Exception e) {

Copied: logback/trunk/logback-access/src/main/java/ch/qos/logback/access/filter/StatisticalView.java (from r987, /logback/trunk/logback-access/src/main/java/ch/qos/logback/access/filter/AccessStats.java)
==============================================================================
--- /logback/trunk/logback-access/src/main/java/ch/qos/logback/access/filter/AccessStats.java	(original)
+++ logback/trunk/logback-access/src/main/java/ch/qos/logback/access/filter/StatisticalView.java	Wed Nov 22 21:57:37 2006
@@ -1,10 +1,18 @@
 package ch.qos.logback.access.filter;
 
-public interface AccessStats {
+public interface StatisticalView {
 
   
   long getTotal();
   
+  long getLastMinuteCount();
+  double getMinuteAverage();
+  
+  
+  long getLastHoursCount();
+  double getHourlyAverage();
+  
+  
   long getLastDaysCount();
   double getDailyAverage();
  

Copied: logback/trunk/logback-access/src/main/java/ch/qos/logback/access/filter/StatisticalViewImpl.java (from r987, /logback/trunk/logback-access/src/main/java/ch/qos/logback/access/filter/AccessStatsImpl.java)
==============================================================================
--- /logback/trunk/logback-access/src/main/java/ch/qos/logback/access/filter/AccessStatsImpl.java	(original)
+++ logback/trunk/logback-access/src/main/java/ch/qos/logback/access/filter/StatisticalViewImpl.java	Wed Nov 22 21:57:37 2006
@@ -2,16 +2,18 @@
 
 import ch.qos.logback.core.spi.LifeCycle;
 
-public class AccessStatsImpl implements AccessStats, LifeCycle {
+public class StatisticalViewImpl implements StatisticalView, LifeCycle {
 
   final CountingFilter countingFilter;
   boolean started;
 
+  StatsByMinute statsByMinute = new StatsByMinute();
+  StatsByHour statsByHour = new StatsByHour();
   StatsByDay statsByDay = new StatsByDay();
   StatsByWeek statsByWeek = new StatsByWeek();
   StatsByMonth statsByMonth = new StatsByMonth();
   
-  AccessStatsImpl(CountingFilter countingFilter) {
+  StatisticalViewImpl(CountingFilter countingFilter) {
     this.countingFilter = countingFilter;
   }
 
@@ -45,6 +47,8 @@
 
   void refresh(long now) {
     long total = getTotal();
+    statsByMinute.update(now, total);
+    statsByHour.update(now, total);
     statsByDay.update(now, total);
     statsByWeek.update(now, total);
     statsByMonth.update(now, total);
@@ -59,6 +63,8 @@
   public void start() {
     started = true;
     long now = System.currentTimeMillis();
+    statsByMinute = new StatsByMinute(now);
+    statsByHour = new StatsByHour(now);
     statsByDay = new StatsByDay(now);
     statsByWeek = new StatsByWeek(now);
     statsByMonth = new StatsByMonth(now);
@@ -70,9 +76,27 @@
 
   public void stop() {
     started = false;
+    statsByMinute.reset();
+    statsByHour.reset();
     statsByDay.reset();
     statsByWeek.reset();
     statsByMonth.reset();
   }
 
+  public long getLastMinuteCount() {
+    return statsByMinute.getLastCount();
+  }
+
+  public double getMinuteAverage() {
+    return statsByMinute.getAverage();
+  }
+
+  public double getHourlyAverage() {
+    return statsByHour.getAverage();
+  }
+
+  public long getLastHoursCount() {
+    return  statsByHour.getLastCount();
+  }
+
 }

Added: logback/trunk/logback-access/src/main/java/ch/qos/logback/access/filter/StatsByHour.java
==============================================================================
--- (empty file)
+++ logback/trunk/logback-access/src/main/java/ch/qos/logback/access/filter/StatsByHour.java	Wed Nov 22 21:57:37 2006
@@ -0,0 +1,20 @@
+package ch.qos.logback.access.filter;
+
+import ch.qos.logback.core.util.TimeUtil;
+
+public class StatsByHour extends PeriodicStats {
+
+  StatsByHour() {
+    super();
+  }
+
+  StatsByHour(long now) {
+    super(now);
+  }
+
+  @Override
+  long computeStartOfNextPeriod(long now) {
+    return TimeUtil.computeStartOfNextHour(now);
+  }
+
+}

Added: logback/trunk/logback-access/src/main/java/ch/qos/logback/access/filter/StatsByMinute.java
==============================================================================
--- (empty file)
+++ logback/trunk/logback-access/src/main/java/ch/qos/logback/access/filter/StatsByMinute.java	Wed Nov 22 21:57:37 2006
@@ -0,0 +1,20 @@
+package ch.qos.logback.access.filter;
+
+import ch.qos.logback.core.util.TimeUtil;
+
+public class StatsByMinute extends PeriodicStats {
+
+  StatsByMinute() {
+    super();
+  }
+
+  StatsByMinute(long now) {
+    super(now);
+  }
+
+  @Override
+  long computeStartOfNextPeriod(long now) {
+    return TimeUtil.computeStartOfNextDay(now);
+  }
+
+}



More information about the logback-dev mailing list