labs-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From psm...@apache.org
Subject svn commit: r567236 - in /labs/pinpoint/trunk: pinpoint-cli/ pinpoint-core/ pinpoint-importer/ pinpoint-metric/ pinpoint-metric/src/main/java/org/apache/logging/pinpoint/metric/ pinpoint-search/ pinpoint-search/src/main/java/org/apache/logging/pinpoint...
Date Sat, 18 Aug 2007 05:20:32 GMT
Author: psmith
Date: Fri Aug 17 22:20:30 2007
New Revision: 567236

URL: http://svn.apache.org/viewvc?view=rev&rev=567236
Log:
Now Service layer creates a JPG graph of the current reception and indexing rates in the current
directory.

This JPG is in placeof the Restlet stuff that will come later.

Added:
    labs/pinpoint/trunk/pinpoint-metric/src/main/java/org/apache/logging/pinpoint/metric/MetricChartUtils.java
Removed:
    labs/pinpoint/trunk/pinpoint-core/.classpath
    labs/pinpoint/trunk/pinpoint-search/.classpath
    labs/pinpoint/trunk/pinpoint-service/.classpath
Modified:
    labs/pinpoint/trunk/pinpoint-cli/   (props changed)
    labs/pinpoint/trunk/pinpoint-core/   (props changed)
    labs/pinpoint/trunk/pinpoint-importer/   (props changed)
    labs/pinpoint/trunk/pinpoint-metric/pom.xml
    labs/pinpoint/trunk/pinpoint-metric/src/main/java/org/apache/logging/pinpoint/metric/Counter.java
    labs/pinpoint/trunk/pinpoint-metric/src/main/java/org/apache/logging/pinpoint/metric/MetricRegistry.java
    labs/pinpoint/trunk/pinpoint-metric/src/main/java/org/apache/logging/pinpoint/metric/ObservedValue.java
    labs/pinpoint/trunk/pinpoint-search/   (props changed)
    labs/pinpoint/trunk/pinpoint-search/src/main/java/org/apache/logging/pinpoint/search/PinpointSearchUtils.java
    labs/pinpoint/trunk/pinpoint-service/   (props changed)
    labs/pinpoint/trunk/pinpoint-service/src/main/java/org/apache/logging/pinpoint/service/Service.java
    labs/pinpoint/trunk/pinpoint-service/src/main/resources/org/apache/logging/pinpoint/service/pinpoint-context.xml
    labs/pinpoint/trunk/pinpoint-web/   (props changed)

Propchange: labs/pinpoint/trunk/pinpoint-cli/
------------------------------------------------------------------------------
--- svn:ignore (original)
+++ svn:ignore Fri Aug 17 22:20:30 2007
@@ -1 +1,4 @@
 target
+.settings
+.classpath
+.project

Propchange: labs/pinpoint/trunk/pinpoint-core/
------------------------------------------------------------------------------
--- svn:ignore (original)
+++ svn:ignore Fri Aug 17 22:20:30 2007
@@ -1,2 +1,5 @@
 target
 hsql*
+.settings
+.classpath
+.project

Propchange: labs/pinpoint/trunk/pinpoint-importer/
------------------------------------------------------------------------------
--- svn:ignore (original)
+++ svn:ignore Fri Aug 17 22:20:30 2007
@@ -1 +1,4 @@
 target
+.settings
+.classpath
+.project

Modified: labs/pinpoint/trunk/pinpoint-metric/pom.xml
URL: http://svn.apache.org/viewvc/labs/pinpoint/trunk/pinpoint-metric/pom.xml?view=diff&rev=567236&r1=567235&r2=567236
==============================================================================
--- labs/pinpoint/trunk/pinpoint-metric/pom.xml (original)
+++ labs/pinpoint/trunk/pinpoint-metric/pom.xml Fri Aug 17 22:20:30 2007
@@ -29,10 +29,15 @@
       <artifactId>spring</artifactId>
       <version>2.0.5</version>
     </dependency>
-	<dependency>
-	    <groupId>jfree</groupId>
-	    <artifactId>jfreechart</artifactId>
-	    <version>1.0.5</version>
-	</dependency>
+    <dependency>
+      <groupId>commons-lang</groupId>
+      <artifactId>commons-lang</artifactId>
+      <version>2.3</version>
+    </dependency>
+    <dependency>
+      <groupId>jfree</groupId>
+      <artifactId>jfreechart</artifactId>
+      <version>1.0.5</version>
+    </dependency>
   </dependencies>
 </project>

Modified: labs/pinpoint/trunk/pinpoint-metric/src/main/java/org/apache/logging/pinpoint/metric/Counter.java
URL: http://svn.apache.org/viewvc/labs/pinpoint/trunk/pinpoint-metric/src/main/java/org/apache/logging/pinpoint/metric/Counter.java?view=diff&rev=567236&r1=567235&r2=567236
==============================================================================
--- labs/pinpoint/trunk/pinpoint-metric/src/main/java/org/apache/logging/pinpoint/metric/Counter.java
(original)
+++ labs/pinpoint/trunk/pinpoint-metric/src/main/java/org/apache/logging/pinpoint/metric/Counter.java
Fri Aug 17 22:20:30 2007
@@ -5,12 +5,16 @@
 import java.util.List;
 import java.util.concurrent.atomic.AtomicLong;
 
+import org.apache.commons.lang.builder.ToStringBuilder;
+import org.apache.log4j.Logger;
 import org.springframework.jmx.export.annotation.ManagedAttribute;
 import org.springframework.jmx.export.annotation.ManagedResource;
 
 @ManagedResource
 public class Counter {
 
+    private static final Logger LOG = Logger.getLogger(Counter.class);
+
     /**
      * Default value should hold enough data for 1 hours worth of data sampled
      * every 5 seconds.
@@ -52,11 +56,22 @@
      * store it with the internally buffered statistics
      */
     public synchronized void observe() {
-        observations.add(new ObservedValue(System.currentTimeMillis(),
-                getValue()));
+        ObservedValue observedValue = new ObservedValue(System
+                .currentTimeMillis(), getValue());
+        if (LOG.isDebugEnabled()) {
+            LOG.debug("Observed value: " + observedValue);
+            LOG.debug("observations.size():" + observations.size());
+        }
+        observations.add(observedValue);
+
         while (observations.size() > this.windowSize) {
             observations.removeFirst();
         }
+    }
+
+    @Override
+    public String toString() {
+        return ToStringBuilder.reflectionToString(this);
     }
 
 }

Added: labs/pinpoint/trunk/pinpoint-metric/src/main/java/org/apache/logging/pinpoint/metric/MetricChartUtils.java
URL: http://svn.apache.org/viewvc/labs/pinpoint/trunk/pinpoint-metric/src/main/java/org/apache/logging/pinpoint/metric/MetricChartUtils.java?view=auto&rev=567236
==============================================================================
--- labs/pinpoint/trunk/pinpoint-metric/src/main/java/org/apache/logging/pinpoint/metric/MetricChartUtils.java
(added)
+++ labs/pinpoint/trunk/pinpoint-metric/src/main/java/org/apache/logging/pinpoint/metric/MetricChartUtils.java
Fri Aug 17 22:20:30 2007
@@ -0,0 +1,57 @@
+package org.apache.logging.pinpoint.metric;
+
+import java.util.Collection;
+import java.util.List;
+
+import org.apache.log4j.Logger;
+import org.jfree.chart.ChartFactory;
+import org.jfree.chart.JFreeChart;
+import org.jfree.data.time.FixedMillisecond;
+import org.jfree.data.time.TimeSeries;
+import org.jfree.data.time.TimeSeriesCollection;
+import org.jfree.data.time.TimeSeriesDataItem;
+
+public class MetricChartUtils {
+
+    private static final Logger LOG = Logger.getLogger(MetricChartUtils.class);
+
+    public static JFreeChart createChart(Collection<Counter> counters,
+            String title) {
+        TimeSeriesCollection collection = new TimeSeriesCollection();
+
+        for (Counter counter : counters) {
+            TimeSeries series = new TimeSeries(counter.getMetricName(),
+                    FixedMillisecond.class);
+            List<ObservedValue> observations = counter.getObservations();
+            ObservedValue lastValue = null;
+            for (ObservedValue observedValue : observations) {
+                if (lastValue != null) {
+                    long difference = observedValue.getObservedValue() -
+                            lastValue.getObservedValue();
+                    double rate = ((double) difference) /
+                            ((observedValue.getTimestamp() - lastValue
+                                    .getTimestamp()) / 1000);
+                    if (LOG.isDebugEnabled()) {
+                        LOG.debug(counter.getMetricName() + ": rate=" + rate);
+                    }
+                    series.add(new TimeSeriesDataItem(new FixedMillisecond(
+                            observedValue.getTimestamp()), rate));
+                }
+                lastValue = observedValue;
+            }
+
+            collection.addSeries(series);
+        }
+        boolean urls = false;
+        boolean tooltips = true;
+        boolean legend = true;
+        String valueAxisLabel = "Rate/second";
+        String timeAxisLabel = "";
+        JFreeChart chart = ChartFactory.createTimeSeriesChart(title,
+                timeAxisLabel, valueAxisLabel, collection, legend, tooltips,
+                urls);
+
+        return chart;
+
+    }
+}

Modified: labs/pinpoint/trunk/pinpoint-metric/src/main/java/org/apache/logging/pinpoint/metric/MetricRegistry.java
URL: http://svn.apache.org/viewvc/labs/pinpoint/trunk/pinpoint-metric/src/main/java/org/apache/logging/pinpoint/metric/MetricRegistry.java?view=diff&rev=567236&r1=567235&r2=567236
==============================================================================
--- labs/pinpoint/trunk/pinpoint-metric/src/main/java/org/apache/logging/pinpoint/metric/MetricRegistry.java
(original)
+++ labs/pinpoint/trunk/pinpoint-metric/src/main/java/org/apache/logging/pinpoint/metric/MetricRegistry.java
Fri Aug 17 22:20:30 2007
@@ -1,7 +1,8 @@
 package org.apache.logging.pinpoint.metric;
 
 import java.util.ArrayList;
-import java.util.List;
+import java.util.Collection;
+import java.util.Collections;
 import java.util.Timer;
 import java.util.TimerTask;
 
@@ -15,7 +16,7 @@
 
     private static final Logger LOG = Logger.getLogger(MetricRegistry.class);
 
-    private List<Counter> counters = new ArrayList<Counter>();
+    private Collection<Counter> counters = new ArrayList<Counter>();
     private Timer timer = new Timer("MetricRegistry", true);
     private boolean running = true;
 
@@ -32,7 +33,8 @@
         counters.add(counter);
     }
 
-    public void setCounters(List<Counter> counters) {
+    public void setCounters(Collection<Counter> counters) {
+        LOG.info("Registering counters: " + counters);
         this.counters = counters;
     }
 
@@ -67,6 +69,10 @@
     @ManagedAttribute(description = "The number of seconds between observations of all registered
metrics")
     public final int getSampleInterval() {
         return sampleInterval;
+    }
+
+    public Collection<Counter> getCounters() {
+        return Collections.unmodifiableCollection(counters);
     }
 
 }

Modified: labs/pinpoint/trunk/pinpoint-metric/src/main/java/org/apache/logging/pinpoint/metric/ObservedValue.java
URL: http://svn.apache.org/viewvc/labs/pinpoint/trunk/pinpoint-metric/src/main/java/org/apache/logging/pinpoint/metric/ObservedValue.java?view=diff&rev=567236&r1=567235&r2=567236
==============================================================================
--- labs/pinpoint/trunk/pinpoint-metric/src/main/java/org/apache/logging/pinpoint/metric/ObservedValue.java
(original)
+++ labs/pinpoint/trunk/pinpoint-metric/src/main/java/org/apache/logging/pinpoint/metric/ObservedValue.java
Fri Aug 17 22:20:30 2007
@@ -1,5 +1,7 @@
 package org.apache.logging.pinpoint.metric;
 
+import org.apache.commons.lang.builder.ToStringBuilder;
+
 public class ObservedValue {
 
     private long timestamp;
@@ -16,5 +18,10 @@
 
     public final long getObservedValue() {
         return observedValue;
+    }
+
+    @Override
+    public String toString() {
+        return ToStringBuilder.reflectionToString(this);
     }
 }

Propchange: labs/pinpoint/trunk/pinpoint-search/
------------------------------------------------------------------------------
--- svn:ignore (original)
+++ svn:ignore Fri Aug 17 22:20:30 2007
@@ -1 +1,4 @@
 target
+.settings
+.project
+.classpath

Modified: labs/pinpoint/trunk/pinpoint-search/src/main/java/org/apache/logging/pinpoint/search/PinpointSearchUtils.java
URL: http://svn.apache.org/viewvc/labs/pinpoint/trunk/pinpoint-search/src/main/java/org/apache/logging/pinpoint/search/PinpointSearchUtils.java?view=diff&rev=567236&r1=567235&r2=567236
==============================================================================
--- labs/pinpoint/trunk/pinpoint-search/src/main/java/org/apache/logging/pinpoint/search/PinpointSearchUtils.java
(original)
+++ labs/pinpoint/trunk/pinpoint-search/src/main/java/org/apache/logging/pinpoint/search/PinpointSearchUtils.java
Fri Aug 17 22:20:30 2007
@@ -63,8 +63,8 @@
          * timestamp Perform new search using that time range Display all events
          */
         LoggingEvent loggingEvent = eventStore.restore(eventLocation);
-        Interval interval = ContextRange.createDefaultContextRange(loggingEvent
-                .getTimeStamp());
+        Interval interval = ContextRange
+                .createDefaultContextRange(loggingEvent.timeStamp);
 
         // TODO check the interval spans the same day? Usual PinpointContext
         // won't span.

Propchange: labs/pinpoint/trunk/pinpoint-service/
------------------------------------------------------------------------------
--- svn:ignore (original)
+++ svn:ignore Fri Aug 17 22:20:30 2007
@@ -1 +1,4 @@
 target
+.settings
+.classpath
+.project

Modified: labs/pinpoint/trunk/pinpoint-service/src/main/java/org/apache/logging/pinpoint/service/Service.java
URL: http://svn.apache.org/viewvc/labs/pinpoint/trunk/pinpoint-service/src/main/java/org/apache/logging/pinpoint/service/Service.java?view=diff&rev=567236&r1=567235&r2=567236
==============================================================================
--- labs/pinpoint/trunk/pinpoint-service/src/main/java/org/apache/logging/pinpoint/service/Service.java
(original)
+++ labs/pinpoint/trunk/pinpoint-service/src/main/java/org/apache/logging/pinpoint/service/Service.java
Fri Aug 17 22:20:30 2007
@@ -8,8 +8,17 @@
  */
 package org.apache.logging.pinpoint.service;
 
+import java.io.File;
+import java.util.concurrent.CopyOnWriteArrayList;
+
 import org.apache.commons.daemon.Daemon;
 import org.apache.commons.daemon.DaemonContext;
+import org.apache.commons.lang.SystemUtils;
+import org.apache.logging.pinpoint.metric.Counter;
+import org.apache.logging.pinpoint.metric.MetricChartUtils;
+import org.apache.logging.pinpoint.metric.MetricRegistry;
+import org.jfree.chart.ChartUtilities;
+import org.jfree.chart.JFreeChart;
 import org.springframework.context.support.ClassPathXmlApplicationContext;
 
 public class Service implements Daemon {
@@ -26,8 +35,17 @@
 
         service.start();
 
-        synchronized (service) {
-            service.wait();
+        MetricRegistry registry = (MetricRegistry) service.ctx
+                .getBean("metricRegistry");
+
+        File graphLocation = new File(SystemUtils.USER_DIR, "metricGraph.jpg");
+        while (true) {
+
+            Thread.sleep(1000);
+            JFreeChart chart = MetricChartUtils.createChart(
+                    new CopyOnWriteArrayList<Counter>(registry.getCounters()),
+                    "Event Rates");
+            ChartUtilities.saveChartAsJPEG(graphLocation, chart, 640, 480);
         }
 
     }

Modified: labs/pinpoint/trunk/pinpoint-service/src/main/resources/org/apache/logging/pinpoint/service/pinpoint-context.xml
URL: http://svn.apache.org/viewvc/labs/pinpoint/trunk/pinpoint-service/src/main/resources/org/apache/logging/pinpoint/service/pinpoint-context.xml?view=diff&rev=567236&r1=567235&r2=567236
==============================================================================
--- labs/pinpoint/trunk/pinpoint-service/src/main/resources/org/apache/logging/pinpoint/service/pinpoint-context.xml
(original)
+++ labs/pinpoint/trunk/pinpoint-service/src/main/resources/org/apache/logging/pinpoint/service/pinpoint-context.xml
Fri Aug 17 22:20:30 2007
@@ -62,7 +62,7 @@
   	<constructor-arg value="Number of Indexed Events" />
   </bean>  
   
-  <bean id="metricRegistry" class="org.apache.logging.pinpoint.metric.MetricRegistry"
>
+  <bean id="metricRegistry" class="org.apache.logging.pinpoint.metric.MetricRegistry"
init-method="start" >
   	<meta key="jmxObjectName" value="Pinpoint:type=Metrics,name=MetricRegistry" />
     <constructor-arg value="5" />
 	<property name="counters">

Propchange: labs/pinpoint/trunk/pinpoint-web/
------------------------------------------------------------------------------
--- svn:ignore (original)
+++ svn:ignore Fri Aug 17 22:20:30 2007
@@ -1 +1,4 @@
 target
+.settings
+.project
+.classpath



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@labs.apache.org
For additional commands, e-mail: commits-help@labs.apache.org


Mime
View raw message