labs-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From psm...@apache.org
Subject svn commit: r602074 - in /labs/pinpoint/trunk: ./ pinpoint-core/ pinpoint-core/src/test/java/org/apache/logging/pinpoint/converter/ pinpoint-metric/ pinpoint-reports/ pinpoint-reports/src/main/java/org/apache/logging/pinpoint/report/ pinpoint-reports/s...
Date Fri, 07 Dec 2007 11:47:09 GMT
Author: psmith
Date: Fri Dec  7 03:47:01 2007
New Revision: 602074

URL: http://svn.apache.org/viewvc?rev=602074&view=rev
Log:

Added the basic componentry to create Graph visualization from logging data.  By providing
some regular expression
patterns one can now visualize data from log files, or potentially a stream of LoggingEvent
objects.

Provided a socked-based server application that accepts input stream from sockets and parses
it for interesting data, which
for now is only 'time period information' since we're currently interested in scanning logs
for how long operations might take.
Have tested this using 'netcat' over a remote ssh tunnel back to my local laptop from a distant
server, which works a treat.

Testing out the affects of using Gzip compression on the LoggingEvent data as it is stored.
 Cuts the store size by half, which is interesting.

Tidied up pom's extracting shared version dependencies into the parent

Added:
    labs/pinpoint/trunk/pinpoint-reports/src/main/java/org/apache/logging/pinpoint/report/DataSetParser.java
    labs/pinpoint/trunk/pinpoint-reports/src/main/java/org/apache/logging/pinpoint/report/InputStreamTimeSeriesDataSetParser.java
    labs/pinpoint/trunk/pinpoint-reports/src/main/java/org/apache/logging/pinpoint/report/LoggingEventDataProvider.java
    labs/pinpoint/trunk/pinpoint-reports/src/main/java/org/apache/logging/pinpoint/report/PinpointStreamingGraphServer.java
    labs/pinpoint/trunk/pinpoint-reports/src/main/java/org/apache/logging/pinpoint/report/TimeSeriesCollectionSeriesProvider.java
    labs/pinpoint/trunk/pinpoint-reports/src/main/java/org/apache/logging/pinpoint/report/provider/
    labs/pinpoint/trunk/pinpoint-reports/src/main/java/org/apache/logging/pinpoint/report/provider/DataProvider.java
    labs/pinpoint/trunk/pinpoint-reports/src/main/java/org/apache/logging/pinpoint/report/provider/HistogramSeriesProvider.java
    labs/pinpoint/trunk/pinpoint-reports/src/main/java/org/apache/logging/pinpoint/report/provider/ScalingValueSeriesProvider.java
    labs/pinpoint/trunk/pinpoint-reports/src/main/java/org/apache/logging/pinpoint/report/provider/SeriesProvider.java
    labs/pinpoint/trunk/pinpoint-reports/src/main/java/org/apache/logging/pinpoint/report/provider/StringDataProvider.java
Modified:
    labs/pinpoint/trunk/pinpoint-core/pom.xml
    labs/pinpoint/trunk/pinpoint-core/src/test/java/org/apache/logging/pinpoint/converter/EventWriterTest.java
    labs/pinpoint/trunk/pinpoint-metric/pom.xml
    labs/pinpoint/trunk/pinpoint-reports/pom.xml
    labs/pinpoint/trunk/pom.xml

Modified: labs/pinpoint/trunk/pinpoint-core/pom.xml
URL: http://svn.apache.org/viewvc/labs/pinpoint/trunk/pinpoint-core/pom.xml?rev=602074&r1=602073&r2=602074&view=diff
==============================================================================
--- labs/pinpoint/trunk/pinpoint-core/pom.xml (original)
+++ labs/pinpoint/trunk/pinpoint-core/pom.xml Fri Dec  7 03:47:01 2007
@@ -10,13 +10,6 @@
   <artifactId>pinpoint-core</artifactId>
   <name>Pinpoint Core</name>
   <version>1.0-SNAPSHOT</version>
-  <properties>
-    <lucene.version>2.2.0</lucene.version>
-    <log4j.version>1.2.15</log4j.version>
-    <log4j.companion.version>1.0-SNAPSHOT</log4j.companion.version>
-    <commonscli.version>1.1</commonscli.version>
-    <jline.version>0.9.91</jline.version>
-  </properties>
   <dependencies>
     <dependency>
       <groupId>log4j</groupId>

Modified: labs/pinpoint/trunk/pinpoint-core/src/test/java/org/apache/logging/pinpoint/converter/EventWriterTest.java
URL: http://svn.apache.org/viewvc/labs/pinpoint/trunk/pinpoint-core/src/test/java/org/apache/logging/pinpoint/converter/EventWriterTest.java?rev=602074&r1=602073&r2=602074&view=diff
==============================================================================
--- labs/pinpoint/trunk/pinpoint-core/src/test/java/org/apache/logging/pinpoint/converter/EventWriterTest.java
(original)
+++ labs/pinpoint/trunk/pinpoint-core/src/test/java/org/apache/logging/pinpoint/converter/EventWriterTest.java
Fri Dec  7 03:47:01 2007
@@ -15,9 +15,17 @@
  */
 package org.apache.logging.pinpoint.converter;
 
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
 import java.io.File;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
 import java.util.ArrayList;
 import java.util.List;
+import java.util.zip.GZIPInputStream;
+import java.util.zip.GZIPOutputStream;
+import java.util.zip.ZipOutputStream;
 
 import junit.framework.TestCase;
 
@@ -103,6 +111,53 @@
         }
 
         eventStore.close();
+    }
+
+    public void testCompression() throws IOException, Exception {
+        LoggingEvent event = PinpointTestUtils.createEvent(Level.DEBUG, Logger
+                .getLogger("com.foo.bar.eek"),
+                "on the third stroke, it will be 9:34 and 14 seconds",
+                new Exception());
+
+        ByteArrayOutputStream baos1 = new ByteArrayOutputStream(4096);
+        ObjectOutputStream oos1 = new ObjectOutputStream(baos1);
+
+        oos1.writeObject(event);
+        oos1.close();
+
+        int length1 = baos1.toByteArray().length;
+
+        ByteArrayOutputStream baos2 = new ByteArrayOutputStream(4096);
+        GZIPOutputStream gzipStream = new GZIPOutputStream(baos2);
+        ObjectOutputStream oos2 = new ObjectOutputStream(gzipStream);
+
+        oos2.writeObject(event);
+        oos2.close();
+        byte[] byteArray = baos2.toByteArray();
+        int length2 = byteArray.length;
+
+        ObjectInputStream ois1 = new ObjectInputStream(new GZIPInputStream(
+                new ByteArrayInputStream(byteArray)));
+        LoggingEvent comparison = (LoggingEvent) ois1.readObject();
+
+        ois1.close();
+
+        assertEquals(event.getLevel(), comparison.getLevel());
+        assertEquals(event.getMessage(), event.getMessage());
+        assertEquals(event.timeStamp, comparison.timeStamp);
+
+        ByteArrayOutputStream baos3 = new ByteArrayOutputStream(4096);
+        ZipOutputStream zipStream3 = new ZipOutputStream(baos3);
+        ObjectOutputStream oos3 = new ObjectOutputStream(zipStream3);
+
+        oos3.writeObject(event);
+        oos3.close();
+        byte[] byteArray3 = baos3.toByteArray();
+        int length3 = byteArray3.length;
+
+        System.out.printf("Length 1: %s, Length 2: %s, Length 3: %s", length1,
+                length2, length3);
+
     }
 
 }

Modified: labs/pinpoint/trunk/pinpoint-metric/pom.xml
URL: http://svn.apache.org/viewvc/labs/pinpoint/trunk/pinpoint-metric/pom.xml?rev=602074&r1=602073&r2=602074&view=diff
==============================================================================
--- labs/pinpoint/trunk/pinpoint-metric/pom.xml (original)
+++ labs/pinpoint/trunk/pinpoint-metric/pom.xml Fri Dec  7 03:47:01 2007
@@ -11,13 +11,6 @@
   <name>Pinpoint Metric</name>
   <description>Provides performance metric infrastructure for observing metric data
over time</description>
   <version>1.0-SNAPSHOT</version>
-  <properties>
-    <lucene.version>2.2.0</lucene.version>
-    <log4j.version>1.2.15</log4j.version>
-    <log4j.companion.version>1.0-SNAPSHOT</log4j.companion.version>
-    <commonscli.version>1.1</commonscli.version>
-    <jline.version>0.9.91</jline.version>
-  </properties>
   <dependencies>
     <dependency>
       <groupId>junit</groupId>
@@ -33,7 +26,7 @@
     <dependency>
       <groupId>org.springframework</groupId>
       <artifactId>spring</artifactId>
-      <version>2.0.5</version>
+      <version>${spring.version}</version>
       <exclusions>
         <exclusion>
           <groupId>log4j</groupId>
@@ -54,7 +47,7 @@
     <dependency>
       <groupId>jfree</groupId>
       <artifactId>jfreechart</artifactId>
-      <version>1.0.5</version>
+      <version>${jfreechart.version}</version>
     </dependency>
   </dependencies>
 </project>

Modified: labs/pinpoint/trunk/pinpoint-reports/pom.xml
URL: http://svn.apache.org/viewvc/labs/pinpoint/trunk/pinpoint-reports/pom.xml?rev=602074&r1=602073&r2=602074&view=diff
==============================================================================
--- labs/pinpoint/trunk/pinpoint-reports/pom.xml (original)
+++ labs/pinpoint/trunk/pinpoint-reports/pom.xml Fri Dec  7 03:47:01 2007
@@ -1,4 +1,4 @@
-<?xml version="1.0"?><project>
+<?xml version="1.0" encoding="UTF-8"?><project>
   <parent>
     <artifactId>pinpoint</artifactId>
     <groupId>org.apache.logging</groupId>
@@ -17,10 +17,10 @@
       <version>3.8.1</version>
       <scope>test</scope>
     </dependency>
-	<dependency>
-		<groupId>org.apache.logging</groupId>
-		<artifactId>pinpoint-core</artifactId>
-		<version>1.0-SNAPSHOT</version>
-	</dependency>
+    <dependency>
+      <groupId>org.apache.logging</groupId>
+      <artifactId>pinpoint-core</artifactId>
+      <version>1.0-SNAPSHOT</version>
+    </dependency>
   </dependencies>
 </project>

Added: labs/pinpoint/trunk/pinpoint-reports/src/main/java/org/apache/logging/pinpoint/report/DataSetParser.java
URL: http://svn.apache.org/viewvc/labs/pinpoint/trunk/pinpoint-reports/src/main/java/org/apache/logging/pinpoint/report/DataSetParser.java?rev=602074&view=auto
==============================================================================
--- labs/pinpoint/trunk/pinpoint-reports/src/main/java/org/apache/logging/pinpoint/report/DataSetParser.java
(added)
+++ labs/pinpoint/trunk/pinpoint-reports/src/main/java/org/apache/logging/pinpoint/report/DataSetParser.java
Fri Dec  7 03:47:01 2007
@@ -0,0 +1,48 @@
+package org.apache.logging.pinpoint.report;
+
+import org.apache.log4j.spi.LoggingEvent;
+import org.apache.logging.pinpoint.report.provider.DataProvider;
+import org.apache.logging.pinpoint.report.provider.SeriesProvider;
+import org.jfree.data.general.Dataset;
+import org.jfree.data.time.FixedMillisecond;
+
+/**
+ * 
+ * Analyses a specified type of object and builds a {@link Dataset} object for graph visualization,
+ * using a {@link DataProvider} that can convert the object into the specified set of values
+ * and a SeriesProvider that converts them into a Dataset.
+ * 
+ * @author psmith
+ *
+ * @param <T> the type of Object that is being parsed to create the Dataset, which
+ * might be a String or a {@link LoggingEvent} or anything that might contain data
+ * worthy of a graph.
+ */
+public class DataSetParser<T> {
+
+    private final DataProvider<T> dataProvider;
+    private final SeriesProvider seriesProvider;
+
+    public DataSetParser(DataProvider<T> provider, SeriesProvider seriesProvider) {
+        this.dataProvider = provider;
+        this.seriesProvider = seriesProvider;
+    }
+
+    public void analyse(T object) {
+        int index = 0;
+
+        for (Double value : dataProvider.provideValue(object)) {
+
+            FixedMillisecond millisecond = new FixedMillisecond(dataProvider
+                    .provideDate(object).getTime());
+            seriesProvider.addOrUpdate(index++, millisecond, value);
+
+        }
+
+    }
+
+    public final Dataset getDataSet() {
+        return seriesProvider.getDataSet();
+    }
+
+}

Added: labs/pinpoint/trunk/pinpoint-reports/src/main/java/org/apache/logging/pinpoint/report/InputStreamTimeSeriesDataSetParser.java
URL: http://svn.apache.org/viewvc/labs/pinpoint/trunk/pinpoint-reports/src/main/java/org/apache/logging/pinpoint/report/InputStreamTimeSeriesDataSetParser.java?rev=602074&view=auto
==============================================================================
--- labs/pinpoint/trunk/pinpoint-reports/src/main/java/org/apache/logging/pinpoint/report/InputStreamTimeSeriesDataSetParser.java
(added)
+++ labs/pinpoint/trunk/pinpoint-reports/src/main/java/org/apache/logging/pinpoint/report/InputStreamTimeSeriesDataSetParser.java
Fri Dec  7 03:47:01 2007
@@ -0,0 +1,74 @@
+/*
+ * Copyright 1999-2005 The Apache Software Foundation.
+ * 
+ * Licensed 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.logging.pinpoint.report;
+
+import java.io.BufferedInputStream;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.util.concurrent.Callable;
+
+import javax.swing.ProgressMonitorInputStream;
+
+import org.apache.commons.io.LineIterator;
+import org.apache.logging.pinpoint.report.provider.ScalingValueSeriesProvider;
+import org.apache.logging.pinpoint.report.provider.SeriesProvider;
+import org.apache.logging.pinpoint.report.provider.StringDataProvider;
+import org.jfree.chart.ChartFactory;
+import org.jfree.chart.JFreeChart;
+import org.jfree.data.xy.XYDataset;
+
+public class InputStreamTimeSeriesDataSetParser implements
+        Callable<JFreeChart> {
+
+    private final InputStream stream;
+
+    public InputStreamTimeSeriesDataSetParser(InputStream stream) {
+        this.stream = new BufferedInputStream(
+                new ProgressMonitorInputStream(null, "Analysing...", stream));
+    }
+
+    public JFreeChart call() throws Exception {
+        String valueFragment = "[ =](\\d+)[ ]*ms";
+        LineIterator lineIterator = new LineIterator(new InputStreamReader(
+                stream));
+
+        SeriesProvider seriesProvider = new ScalingValueSeriesProvider(
+                new TimeSeriesCollectionSeriesProvider(), 0.001);
+
+        //            SeriesProvider seriesProvider = new HistogramSeriesProvider();
+
+        DataSetParser<String> dataSetParser = new DataSetParser<String>(
+                new StringDataProvider(valueFragment), seriesProvider);
+
+        while (lineIterator.hasNext()) {
+            String line = lineIterator.nextLine();
+            dataSetParser.analyse(line);
+        }
+
+        //            JFreeChart chart = ChartFactory.createHistogram("", "", "",
+        //                    (IntervalXYDataset) dataSetParser.getDataSet(),
+        //                    PlotOrientation.VERTICAL, false, true, false);
+
+        JFreeChart chart = ChartFactory.createTimeSeriesChart("", "", "",
+                (XYDataset) dataSetParser.getDataSet(), false, true, false);
+
+        //            JFreeChart chart = ChartFactory.createHighLowChart("", "", "",
+        //                    new SubSeriesDataset((SeriesDataset) dataSetParser
+        //                            .getDataSet(), 0), false);
+
+        return chart;
+    }
+}
\ No newline at end of file

Added: labs/pinpoint/trunk/pinpoint-reports/src/main/java/org/apache/logging/pinpoint/report/LoggingEventDataProvider.java
URL: http://svn.apache.org/viewvc/labs/pinpoint/trunk/pinpoint-reports/src/main/java/org/apache/logging/pinpoint/report/LoggingEventDataProvider.java?rev=602074&view=auto
==============================================================================
--- labs/pinpoint/trunk/pinpoint-reports/src/main/java/org/apache/logging/pinpoint/report/LoggingEventDataProvider.java
(added)
+++ labs/pinpoint/trunk/pinpoint-reports/src/main/java/org/apache/logging/pinpoint/report/LoggingEventDataProvider.java
Fri Dec  7 03:47:01 2007
@@ -0,0 +1,35 @@
+package org.apache.logging.pinpoint.report;
+
+import java.util.Collection;
+import java.util.Date;
+import java.util.regex.Pattern;
+
+import org.apache.log4j.spi.LoggingEvent;
+import org.apache.logging.pinpoint.report.provider.DataProvider;
+import org.apache.logging.pinpoint.report.provider.StringDataProvider;
+
+/**
+ * Given a RegExp, extracts the timestamp, and series of data values extracted
+ * from the rendered message of the {@link LoggingEvent} object.
+ * 
+ * @author psmith
+ *
+ */
+public class LoggingEventDataProvider implements DataProvider<LoggingEvent> {
+
+    private final Pattern valuePattern;
+
+    public LoggingEventDataProvider(String valuePattern) {
+        this.valuePattern = Pattern.compile(valuePattern);
+    }
+
+    public Date provideDate(LoggingEvent object) {
+        return new Date(object.getTimeStamp());
+    }
+
+    public Collection<Double> provideValue(LoggingEvent event) {
+        return StringDataProvider.extractValues(valuePattern, event
+                .getRenderedMessage());
+    }
+
+}

Added: labs/pinpoint/trunk/pinpoint-reports/src/main/java/org/apache/logging/pinpoint/report/PinpointStreamingGraphServer.java
URL: http://svn.apache.org/viewvc/labs/pinpoint/trunk/pinpoint-reports/src/main/java/org/apache/logging/pinpoint/report/PinpointStreamingGraphServer.java?rev=602074&view=auto
==============================================================================
--- labs/pinpoint/trunk/pinpoint-reports/src/main/java/org/apache/logging/pinpoint/report/PinpointStreamingGraphServer.java
(added)
+++ labs/pinpoint/trunk/pinpoint-reports/src/main/java/org/apache/logging/pinpoint/report/PinpointStreamingGraphServer.java
Fri Dec  7 03:47:01 2007
@@ -0,0 +1,94 @@
+package org.apache.logging.pinpoint.report;
+
+import java.io.FileNotFoundException;
+import java.net.ServerSocket;
+import java.net.Socket;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ThreadFactory;
+import java.util.concurrent.atomic.AtomicLong;
+
+import javax.swing.JFrame;
+
+import org.jfree.chart.ChartPanel;
+import org.jfree.chart.JFreeChart;
+import org.jfree.data.general.Dataset;
+
+/**
+ * Starts a socket-based server application that accepts requests on a port (default 7777)
+ * where all input is consider text-based log data, which is scanned for particular
+ * patterned data (default 'time period' text, such as "took 234ms").  The value(s) identified
+ * are converted into a {@link Dataset} that is then plotted on a graph (default is a TimeSeries
based
+ * line graph).
+ * 
+ * This class is very useful in a production environment where the remote server that contains
the log files
+ * does not have any graphicas capability, or access to it is limited.  For example, after
starting this 
+ * class as an application, you might do the following:
+ * 
+ * <pre>
+ *      mylocalcomputer> ssh bob@www.myhost.com -R7777:localhost:7777
+ *      www.myhost.com> grep 'Search' mylog.log | nc localhost 7777
+ * </pre>
+ * 
+ * This does 2 things:
+ * <ol>
+ * <li>Created an SSH reverse tunnel from the remote host to your local computer on
the specified port (which matechs the port this class
+ * might be listening on</li>
+ * <li>Performed a grep pattern scan of the log file and sent it to 'nc' (netcat, copies
the characters over the network, which is now tunnelled to
+ * your local computer</li>
+ * </ol>
+ * As the character data is streamed into this class it is scanned and parsed for data, and
a graph pops up at the end to visualize the results.
+ * 
+ * @author psmith
+ *
+ */
+public class PinpointStreamingGraphServer {
+    public static void main(String[] args) throws Exception,
+            FileNotFoundException {
+
+        ServerSocket serverSocket = new ServerSocket(7777);
+
+        ExecutorService threadPool = Executors.newFixedThreadPool(4,
+                new ThreadFactory() {
+                    private AtomicLong sequence = new AtomicLong();
+
+                    public Thread newThread(Runnable r) {
+                        Thread thread = new Thread(r, "ChartProcessor-" +
+                                sequence.getAndIncrement());
+                        thread.setDaemon(true);
+                        return thread;
+                    }
+                });
+
+        System.out.println("Listening on 7777");
+        while (true) {
+            final Socket socket = serverSocket.accept();
+            threadPool.execute(new Runnable() {
+
+                public void run() {
+                    try {
+
+                        InputStreamTimeSeriesDataSetParser parser = new InputStreamTimeSeriesDataSetParser(
+                                socket.getInputStream());
+                        JFreeChart chart = parser.call();
+                        ChartPanel chartPanel = new ChartPanel(chart);
+                        JFrame frame = new JFrame();
+                        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
+
+                        frame.getContentPane().add(chartPanel);
+
+                        frame.pack();
+                        frame.setVisible(true);
+
+                    } catch (Exception e) {
+                        e.printStackTrace();
+                    }
+                }
+
+            });
+
+        }
+
+    }
+
+}

Added: labs/pinpoint/trunk/pinpoint-reports/src/main/java/org/apache/logging/pinpoint/report/TimeSeriesCollectionSeriesProvider.java
URL: http://svn.apache.org/viewvc/labs/pinpoint/trunk/pinpoint-reports/src/main/java/org/apache/logging/pinpoint/report/TimeSeriesCollectionSeriesProvider.java?rev=602074&view=auto
==============================================================================
--- labs/pinpoint/trunk/pinpoint-reports/src/main/java/org/apache/logging/pinpoint/report/TimeSeriesCollectionSeriesProvider.java
(added)
+++ labs/pinpoint/trunk/pinpoint-reports/src/main/java/org/apache/logging/pinpoint/report/TimeSeriesCollectionSeriesProvider.java
Fri Dec  7 03:47:01 2007
@@ -0,0 +1,50 @@
+/*
+ * Copyright 1999-2005 The Apache Software Foundation.
+ * 
+ * Licensed 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.logging.pinpoint.report;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.logging.pinpoint.report.provider.SeriesProvider;
+import org.jfree.data.general.Dataset;
+import org.jfree.data.time.RegularTimePeriod;
+import org.jfree.data.time.TimeSeries;
+import org.jfree.data.time.TimeSeriesCollection;
+
+final class TimeSeriesCollectionSeriesProvider implements
+        SeriesProvider {
+    private final TimeSeriesCollection dataSet = new TimeSeriesCollection();
+    private final List<TimeSeries> seriesList = new ArrayList<TimeSeries>();
+
+    public void addOrUpdate(int index, RegularTimePeriod timePeriod,
+            Double value) {
+        TimeSeries series;
+        if (seriesList.size() <= index) {
+            series = new TimeSeries("Series " + String.valueOf(index),
+                    timePeriod.getClass());
+            seriesList.add(index, series);
+            dataSet.addSeries((TimeSeries) series);
+        } else {
+            series = seriesList.get(index);
+        }
+        series.addOrUpdate(timePeriod, value);
+
+    }
+
+    public Dataset getDataSet() {
+        return dataSet;
+    }
+}
\ No newline at end of file

Added: labs/pinpoint/trunk/pinpoint-reports/src/main/java/org/apache/logging/pinpoint/report/provider/DataProvider.java
URL: http://svn.apache.org/viewvc/labs/pinpoint/trunk/pinpoint-reports/src/main/java/org/apache/logging/pinpoint/report/provider/DataProvider.java?rev=602074&view=auto
==============================================================================
--- labs/pinpoint/trunk/pinpoint-reports/src/main/java/org/apache/logging/pinpoint/report/provider/DataProvider.java
(added)
+++ labs/pinpoint/trunk/pinpoint-reports/src/main/java/org/apache/logging/pinpoint/report/provider/DataProvider.java
Fri Dec  7 03:47:01 2007
@@ -0,0 +1,25 @@
+/*
+ * Copyright 1999-2005 The Apache Software Foundation.
+ * 
+ * Licensed 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.logging.pinpoint.report.provider;
+
+import java.util.Collection;
+import java.util.Date;
+
+public interface DataProvider<T> {
+    public Date provideDate(T object);
+
+    public Collection<Double> provideValue(T object);
+}
\ No newline at end of file

Added: labs/pinpoint/trunk/pinpoint-reports/src/main/java/org/apache/logging/pinpoint/report/provider/HistogramSeriesProvider.java
URL: http://svn.apache.org/viewvc/labs/pinpoint/trunk/pinpoint-reports/src/main/java/org/apache/logging/pinpoint/report/provider/HistogramSeriesProvider.java?rev=602074&view=auto
==============================================================================
--- labs/pinpoint/trunk/pinpoint-reports/src/main/java/org/apache/logging/pinpoint/report/provider/HistogramSeriesProvider.java
(added)
+++ labs/pinpoint/trunk/pinpoint-reports/src/main/java/org/apache/logging/pinpoint/report/provider/HistogramSeriesProvider.java
Fri Dec  7 03:47:01 2007
@@ -0,0 +1,58 @@
+/*
+ * Copyright 1999-2005 The Apache Software Foundation.
+ * 
+ * Licensed 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.logging.pinpoint.report.provider;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.commons.lang.ArrayUtils;
+import org.jfree.data.general.Dataset;
+import org.jfree.data.statistics.HistogramDataset;
+import org.jfree.data.time.RegularTimePeriod;
+
+public class HistogramSeriesProvider implements SeriesProvider {
+    private final HistogramDataset dataSet = new HistogramDataset();
+    private final Map<Integer, Collection<Double>> observedValues = new HashMap<Integer,
Collection<Double>>();
+    private int numberBins = 100;
+
+    public void addOrUpdate(int seriesIndex, RegularTimePeriod timePeriod,
+            Double value) {
+        Integer index = Integer.valueOf(seriesIndex);
+        Collection<Double> values;
+        if (observedValues.containsKey(index)) {
+            values = observedValues.get(index);
+        } else {
+            values = new ArrayList<Double>();
+            observedValues.put(index, values);
+        }
+        values.add(value);
+    }
+
+    public Dataset getDataSet() {
+        for (Map.Entry<Integer, Collection<Double>> entry : observedValues
+                .entrySet()) {
+            double[] primitiveValues = ArrayUtils.toPrimitive(entry.getValue()
+                    .toArray(new Double[0]));
+            Arrays.sort(primitiveValues);
+            dataSet.addSeries("Series-" + String.valueOf(entry.getKey()),
+                    primitiveValues, numberBins);
+        }
+        return dataSet;
+    }
+}
\ No newline at end of file

Added: labs/pinpoint/trunk/pinpoint-reports/src/main/java/org/apache/logging/pinpoint/report/provider/ScalingValueSeriesProvider.java
URL: http://svn.apache.org/viewvc/labs/pinpoint/trunk/pinpoint-reports/src/main/java/org/apache/logging/pinpoint/report/provider/ScalingValueSeriesProvider.java?rev=602074&view=auto
==============================================================================
--- labs/pinpoint/trunk/pinpoint-reports/src/main/java/org/apache/logging/pinpoint/report/provider/ScalingValueSeriesProvider.java
(added)
+++ labs/pinpoint/trunk/pinpoint-reports/src/main/java/org/apache/logging/pinpoint/report/provider/ScalingValueSeriesProvider.java
Fri Dec  7 03:47:01 2007
@@ -0,0 +1,41 @@
+/*
+ * Copyright 1999-2005 The Apache Software Foundation.
+ * 
+ * Licensed 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.logging.pinpoint.report.provider;
+
+import org.jfree.data.general.Dataset;
+import org.jfree.data.time.RegularTimePeriod;
+
+public class ScalingValueSeriesProvider implements SeriesProvider {
+
+    private final SeriesProvider innerSeriesProvider;
+    private final double scale;
+
+    public ScalingValueSeriesProvider(SeriesProvider seriesProvider,
+            double scaleValue) {
+        this.innerSeriesProvider = seriesProvider;
+        this.scale = scaleValue;
+    }
+
+    public void addOrUpdate(int seriesIndex, RegularTimePeriod timePeriod,
+            Double value) {
+        innerSeriesProvider.addOrUpdate(seriesIndex, timePeriod, value * scale);
+    }
+
+    public Dataset getDataSet() {
+        return this.innerSeriesProvider.getDataSet();
+    }
+
+}
\ No newline at end of file

Added: labs/pinpoint/trunk/pinpoint-reports/src/main/java/org/apache/logging/pinpoint/report/provider/SeriesProvider.java
URL: http://svn.apache.org/viewvc/labs/pinpoint/trunk/pinpoint-reports/src/main/java/org/apache/logging/pinpoint/report/provider/SeriesProvider.java?rev=602074&view=auto
==============================================================================
--- labs/pinpoint/trunk/pinpoint-reports/src/main/java/org/apache/logging/pinpoint/report/provider/SeriesProvider.java
(added)
+++ labs/pinpoint/trunk/pinpoint-reports/src/main/java/org/apache/logging/pinpoint/report/provider/SeriesProvider.java
Fri Dec  7 03:47:01 2007
@@ -0,0 +1,27 @@
+/*
+ * Copyright 1999-2005 The Apache Software Foundation.
+ * 
+ * Licensed 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.logging.pinpoint.report.provider;
+
+import org.jfree.data.general.Dataset;
+import org.jfree.data.time.RegularTimePeriod;
+
+public interface SeriesProvider {
+
+    public void addOrUpdate(int seriesIndex, RegularTimePeriod timePeriod,
+            Double value);
+
+    public Dataset getDataSet();
+}
\ No newline at end of file

Added: labs/pinpoint/trunk/pinpoint-reports/src/main/java/org/apache/logging/pinpoint/report/provider/StringDataProvider.java
URL: http://svn.apache.org/viewvc/labs/pinpoint/trunk/pinpoint-reports/src/main/java/org/apache/logging/pinpoint/report/provider/StringDataProvider.java?rev=602074&view=auto
==============================================================================
--- labs/pinpoint/trunk/pinpoint-reports/src/main/java/org/apache/logging/pinpoint/report/provider/StringDataProvider.java
(added)
+++ labs/pinpoint/trunk/pinpoint-reports/src/main/java/org/apache/logging/pinpoint/report/provider/StringDataProvider.java
Fri Dec  7 03:47:01 2007
@@ -0,0 +1,78 @@
+/*
+ * Copyright 1999-2005 The Apache Software Foundation.
+ * 
+ * Licensed 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.logging.pinpoint.report.provider;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Date;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import org.joda.time.DateTime;
+import org.joda.time.format.DateTimeFormatter;
+import org.joda.time.format.DateTimeFormatterBuilder;
+
+public class StringDataProvider implements DataProvider<String> {
+    private static final DateTimeFormatter LOG4J_ISO8601_TIMEPARSER = new DateTimeFormatterBuilder()
+            .appendYear(4, 4).appendLiteral('-').appendMonthOfYear(2)
+            .appendLiteral('-').appendDayOfMonth(2).appendLiteral(' ')
+            .appendHourOfDay(2).appendLiteral(':').appendMinuteOfHour(2)
+            .appendLiteral(':').appendSecondOfMinute(2).appendLiteral(',')
+            .appendMillisOfSecond(3).toFormatter();
+    private final static String LOG4J_ISOTIME_FORMAT_AS_REGEXP = "(\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2},\\d{3})";
+
+    private final Pattern valuePattern;
+    private final Pattern timePattern;
+
+    private DateTimeFormatter timeParser;
+
+    public StringDataProvider(String valuePattern) {
+        this(LOG4J_ISOTIME_FORMAT_AS_REGEXP, LOG4J_ISO8601_TIMEPARSER,
+                valuePattern);
+    }
+
+    public StringDataProvider(String timePattern, DateTimeFormatter timeParser,
+            String valuePattern) {
+        this.valuePattern = Pattern.compile(valuePattern);
+        this.timePattern = Pattern.compile(timePattern);
+        this.timeParser = timeParser;
+    }
+
+    public Date provideDate(String object) {
+        Matcher timeMatcher = timePattern.matcher(object);
+        if (!timeMatcher.find()) {
+            return null;
+        }
+        String timeString = timeMatcher.group(1);
+        DateTime time = timeParser.parseDateTime(timeString);
+        return new Date(time.getMillis());
+    }
+
+    public Collection<Double> provideValue(String object) {
+        return extractValues(valuePattern, object);
+    }
+
+    public static Collection<Double> extractValues(Pattern pattern,
+            String object) {
+        Matcher matcher = pattern.matcher(object);
+        Collection<Double> values = new ArrayList<Double>();
+        while (matcher.find()) {
+            values.add(Double.valueOf(matcher.group(1)));
+        }
+        return values;
+    }
+
+}
\ No newline at end of file

Modified: labs/pinpoint/trunk/pom.xml
URL: http://svn.apache.org/viewvc/labs/pinpoint/trunk/pom.xml?rev=602074&r1=602073&r2=602074&view=diff
==============================================================================
--- labs/pinpoint/trunk/pom.xml (original)
+++ labs/pinpoint/trunk/pom.xml Fri Dec  7 03:47:01 2007
@@ -30,6 +30,8 @@
     <log4j.companion.version>1.0-SNAPSHOT</log4j.companion.version>
     <commonscli.version>1.1</commonscli.version>
     <jline.version>0.9.91</jline.version>
+	<spring.version>2.0.6</spring.version>
+	<jfreechart.version>1.0.7</jfreechart.version>
   </properties>
   <modules>
     <module>pinpoint-cli</module>



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


Mime
View raw message