You can subscribe to this list here.
2003 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
(11) |
Oct
(60) |
Nov
(68) |
Dec
(10) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2004 |
Jan
(10) |
Feb
(15) |
Mar
(30) |
Apr
(20) |
May
(32) |
Jun
(30) |
Jul
(61) |
Aug
(13) |
Sep
(14) |
Oct
(13) |
Nov
(28) |
Dec
(10) |
2005 |
Jan
(7) |
Feb
(5) |
Mar
|
Apr
(2) |
May
|
Jun
|
Jul
|
Aug
|
Sep
(4) |
Oct
|
Nov
|
Dec
|
2006 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
(15) |
2007 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
(20) |
Aug
(35) |
Sep
(3) |
Oct
(2) |
Nov
|
Dec
|
2008 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
(14) |
Sep
(2) |
Oct
|
Nov
|
Dec
|
2010 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
(3) |
2011 |
Jan
|
Feb
|
Mar
|
Apr
(5) |
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
From: Arne V. <cob...@us...> - 2004-07-11 22:03:00
|
Update of /cvsroot/jrobin/src/org/jrobin/core In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv6890/org/jrobin/core Modified Files: XmlTemplate.java Log Message: JRobin 1.4.0 - Several tweaks - Added print() option to ExportData - Added time() option to RrdGraphDef - Added variables options to XmlTemplate Index: XmlTemplate.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/core/XmlTemplate.java,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** XmlTemplate.java 20 May 2004 10:29:33 -0000 1.8 --- XmlTemplate.java 11 Jul 2004 22:02:52 -0000 1.9 *************** *** 32,39 **** import java.io.IOException; import java.io.File; ! import java.util.HashMap; ! import java.util.HashSet; ! import java.util.Date; ! import java.util.GregorianCalendar; import java.util.regex.Pattern; import java.util.regex.Matcher; --- 32,36 ---- import java.io.IOException; import java.io.File; ! import java.util.*; import java.util.regex.Pattern; import java.util.regex.Matcher; *************** *** 163,166 **** --- 160,193 ---- } + /** + * Searches the XML template to see if there are variables in there that + * will need to be set. + * + * @return True if variables were detected, false if not. + */ + public boolean hasVariables() { + return PATTERN.matcher( root.toString() ).find(); + } + + /** + * Returns the list of variables that should be set in this template. + * + * @return List of variable names as an array of strings. + */ + public String[] getVariables() + { + ArrayList list = new ArrayList(); + Matcher m = PATTERN.matcher( root.toString() ); + + while ( m.find() ) + { + String var = m.group(1); + if ( !list.contains( var ) ) + list.add( var ); + } + + return (String[]) list.toArray( new String[list.size()] ); + } + protected static Node[] getChildNodes(Node parentNode, String childName) { return Util.Xml.getChildNodes(parentNode, childName); |
From: Arne V. <cob...@us...> - 2004-07-10 00:07:26
|
Update of /cvsroot/jrobin/src/org/jrobin/graph In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv11053/org/jrobin/graph Modified Files: ExportData.java Grapher.java Pdef.java RrdExport.java RrdExportDef.java RrdExporter.java RrdGraphDef.java Source.java ValueAxisUnit.java ValueGrid.java Log Message: JRobin 1.4.0 - Value grid tweaking - Fixed graph generation - Modified setExportData into addExportData on RrdExportDef level - Added getStep() to RrdDataSet interface Index: ValueAxisUnit.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/graph/ValueAxisUnit.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** ValueAxisUnit.java 9 Jul 2004 12:22:15 -0000 1.6 --- ValueAxisUnit.java 10 Jul 2004 00:07:03 -0000 1.7 *************** *** 175,184 **** long lmMod = lmValue % lmGridStep; ! /*if ( ovalue < 0 ) { ! } else ! {*/ if ( lmMod < ( mGridStep * 0.5 ) ) return ((double) (sign*lmValue - lmMod) / mGridFactor); --- 175,189 ---- long lmMod = lmValue % lmGridStep; ! if ( ovalue < 0 ) { ! if ( lmMod > ( mGridStep * 0.5 ) ) ! return ((double) (sign*lmValue + lmMod - lmGridStep ) / mGridFactor); ! else if ( lMod > 0 ) ! return ((double) (sign*lValue + lMod - lGridStep) / gridFactor); ! else ! return ((double) (sign*lValue - lGridStep) / gridFactor); } else ! { if ( lmMod < ( mGridStep * 0.5 ) ) return ((double) (sign*lmValue - lmMod) / mGridFactor); *************** *** 187,191 **** else return ((double) (sign*lValue) / gridFactor); ! //} } --- 192,196 ---- else return ((double) (sign*lValue) / gridFactor); ! } } *************** *** 225,232 **** long lmMod = lmValue % lmGridStep; ! if ( lmMod > ( mGridStep * 0.5 ) ) ! return ((double) ( sign * lmValue - lmMod + lmGridStep) / mGridFactor); else ! return ((double) ( sign * lValue - lMod + lGridStep) / gridFactor); } --- 230,248 ---- long lmMod = lmValue % lmGridStep; ! if ( ovalue < 0 ) ! { ! if ( lmMod < ( mGridStep * 0.5 ) ) ! return ((double) (sign*lmValue + lmMod ) / mGridFactor); ! else ! return ((double) (sign*lValue + lMod ) / gridFactor); ! } else ! { ! if ( lmMod > ( mGridStep * 0.5 ) ) ! return ((double) ( sign * lmValue - lmMod + lmGridStep) / mGridFactor); ! else ! return ((double) ( sign * lValue - lMod + lGridStep) / gridFactor); ! } ! } Index: RrdExporter.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/graph/RrdExporter.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** RrdExporter.java 9 Jul 2004 12:22:15 -0000 1.1 --- RrdExporter.java 10 Jul 2004 00:07:03 -0000 1.2 *************** *** 26,33 **** import java.io.IOException; - import java.io.File; - import java.io.OutputStream; import java.util.HashMap; ! import java.awt.*; import org.jrobin.core.*; --- 26,31 ---- import java.io.IOException; import java.util.HashMap; ! import java.util.ArrayList; import org.jrobin.core.*; *************** *** 111,117 **** int numPdefs = pdefList.length; // Set up the array with all datasources (both Def, Cdef and Pdef) ! sources = new Source[ numDefs + numCdefs + numPdefs ]; ! sourceIndex = new HashMap( numDefs + numCdefs + numPdefs ); int tblPos = 0; int vePos = 0; --- 109,144 ---- int numPdefs = pdefList.length; + ExportData[] edata = def.getExportData(); + int[] edefTs; + Source[] edefList; + if ( edata.length > 0 ) + { + ArrayList tsList = new ArrayList( 30 ); + ArrayList list = new ArrayList( 30 ); + for ( int i = 0; i < edata.length; i++ ) + { + Source[] esrc = edata[i].getSources(); + + for ( int j = 0; j < esrc.length; j++ ) + { + list.add( esrc[j] ); + tsList.add( new Integer(i) ); + } + } + edefTs = new int[ tsList.size() ]; + for ( int i = 0; i < edefTs.length; i++ ) + edefTs[i] = ((Integer) tsList.get(i)).intValue(); + edefList = (Source[]) list.toArray( new Source[] {} ); + } + else + { + edefTs = new int[0]; + edefList = new Source[0]; + } + int numEdefs = edefList.length; + // Set up the array with all datasources (both Def, Cdef and Pdef) ! sources = new Source[ numDefs + numEdefs + numCdefs + numPdefs ]; ! sourceIndex = new HashMap( numDefs + numEdefs + numCdefs + numPdefs ); int tblPos = 0; int vePos = 0; *************** *** 125,130 **** long minStep = Integer.MAX_VALUE, maxStep = Integer.MIN_VALUE, vStartTime, vEndTime, fetchEndTime; ! // Open all datasources ! if ( fetchSources.size() > 0 ) { try --- 152,157 ---- long minStep = Integer.MAX_VALUE, maxStep = Integer.MIN_VALUE, vStartTime, vEndTime, fetchEndTime; ! // -- Open all fetch datasources ! if ( fetchSources.size() > 0 || numEdefs > 0 ) { try *************** *** 148,152 **** // Calculate the step for data retrieval ! long[] steps = src.getFetchStep( startTime, endTime, def.getResolution() ); int reduceFactor = (int) Math.ceil( (double) requestedStep / (double) steps[0] ); --- 175,179 ---- // Calculate the step for data retrieval ! long[] steps = src.getFetchStep( startTime, endTime, def.getResolution() ); int reduceFactor = (int) Math.ceil( (double) requestedStep / (double) steps[0] ); *************** *** 162,165 **** --- 189,208 ---- } + for ( int i = 0; i < edata.length; i++ ) + { + long step = edata[i].getStep(); + + int reduceFactor = (int) Math.ceil( (double) requestedStep / (double) step ); + step = step * reduceFactor; + + if ( step < minStep ) + { + minStep = step; + minReduceFactor = reduceFactor; + } + if ( step > maxStep ) + maxStep = step; + } + vStartTime = Util.normalize( startTime, minStep ); vStartTime = ( vStartTime > startTime ? vStartTime - minStep : vStartTime ); *************** *** 218,224 **** { // The range should be used exactly as specified ! minStep = requestedStep; ! vStartTime = Util.normalize( startTime, minStep ); ! vStartTime = ( vStartTime > startTime ? vStartTime - minStep : vStartTime ); if ( !changingEndTime ) --- 261,267 ---- { // The range should be used exactly as specified ! minStep = requestedStep; ! vStartTime = Util.normalize( startTime, minStep ); ! vStartTime = ( vStartTime > startTime ? vStartTime - minStep : vStartTime ); if ( !changingEndTime ) *************** *** 238,244 **** reducedNumRows = (int) ((reducedEndTime - reducedStartTime) / reducedStep) + 1; finalEndTime = endTime; } ! // Add all Pdefs to the source table for ( int i = 0; i < pdefList.length; i++ ) { --- 281,298 ---- reducedNumRows = (int) ((reducedEndTime - reducedStartTime) / reducedStep) + 1; finalEndTime = endTime; + + vEndTime += minStep; + numRows = (int) ((vEndTime - vStartTime) / minStep) + 1; } ! // -- Add all Export datasources to the source table ! for ( int i = 0; i < edefList.length; i++ ) ! { ! sources[tblPos] = new Def( edefList[i].getName(), numRows, reducedNumRows ); ! sources[tblPos].setFetchedStep( edefList[i].getStep() ); ! sourceIndex.put( edefList[i].getName(), new Integer(tblPos++) ); ! } ! ! // -- Add all Pdefs to the source table for ( int i = 0; i < pdefList.length; i++ ) { *************** *** 252,256 **** int cdefStart = tblPos; // First Cdef element, necessary for tree descend calculation ! // Add all Cdefs to the source table // Reparse all RPN datasources to use indices of the correct variables for ( int i = 0; i < cdefList.length; i++ ) --- 306,310 ---- int cdefStart = tblPos; // First Cdef element, necessary for tree descend calculation ! // -- Add all Cdefs to the source table // Reparse all RPN datasources to use indices of the correct variables for ( int i = 0; i < cdefList.length; i++ ) *************** *** 322,325 **** --- 376,384 ---- pos = veList[j].extract( t, sources, i, pos ); + // Get all export datasources + for (int j = pos; j < pos + numEdefs; j++ ) + sources[j].set( i, t, edefList[j - pos].get( t, edata[ edefTs[j - pos] ].getTimestamps() ) ); + pos += numEdefs; + // Get all custom datasources for (int j = pos; j < pos + numPdefs; j++) *************** *** 360,363 **** --- 419,427 ---- pos = veList[j].extract( t, sources, i, pos ); + // Get all export datasources + for (int j = pos; j < pos + numEdefs; j++ ) + sources[j].set( i, t, edefList[j - pos].get( t, edata[ edefTs[j - pos] ].getTimestamps() ) ); + pos += numEdefs; + // Get all custom datasources for (int j = pos; j < pos + numPdefs; j++) Index: Pdef.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/graph/Pdef.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** Pdef.java 9 Jul 2004 12:22:15 -0000 1.4 --- Pdef.java 10 Jul 2004 00:07:03 -0000 1.5 *************** *** 53,56 **** --- 53,57 ---- * Constructs a new Plottable Def: a custom external datasource * (represented as a Plottable class) that can be graphed by JRobin. + * * @param name Name of the datasource in the graph definition. * @param plottable Reference to the class extending Plottable and providing the datapoints. *************** *** 65,68 **** --- 66,70 ---- * Constructs a new Plottable Def: a custom external datasource * (represented as a Plottable class) that can be graphed by JRobin. + * * @param name Name of the datasource in the graph definition. * @param plottable Reference to the class extending Plottable and providing the datapoints. *************** *** 80,83 **** --- 82,86 ---- * Constructs a new Plottable Def: a custom external datasource * (represented as a Plottable class) that can be graphed by JRobin. + * * @param name Name of the datasource in the graph definition. * @param plottable Reference to the class extending Plottable and providing the datapoints. *************** *** 98,101 **** --- 101,105 ---- /** * Prepares the array that will hold the values. + * * @param numPoints Number of datapoints that will be used. */ *************** *** 112,115 **** --- 116,120 ---- * Sets the value of a specific datapoint for this Pdef. The Pdef gets the datapoint by retrieving * the value from the Plottable interface using an appropriate getValue() method. + * * @param pos Position (index in the value table) of the new datapoint. * @param timestamp Timestamp of the new datapoint in number of seconds. *************** *** 118,129 **** { double val = Double.NaN; ! if ( indexed ) ! val = plottable.getValue( timestamp, index ); else if ( named ) ! val = plottable.getValue( timestamp, sourceName ); else ! val = plottable.getValue( timestamp ); ! super.set( pos, timestamp, val ); --- 123,141 ---- { double val = Double.NaN; ! ! /** ! * With the new calculation algorithm we expect the value for a period to be defined ! * by the first timestamp AFTER that period. The implementation of Pdef is different, ! * and works with 'point' value instead of period. Converted to period this would mean ! * that the period is defined by the starting timestamp, or another timestamp IN that ! * period. As a result, we shift the requested timestamp one step back in time. ! */ if ( indexed ) ! val = plottable.getValue( timestamp - step, index ); else if ( named ) ! val = plottable.getValue( timestamp - step, sourceName ); else ! val = plottable.getValue( timestamp - step ); ! super.set( pos, timestamp, val ); Index: ExportData.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/graph/ExportData.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** ExportData.java 9 Jul 2004 12:22:15 -0000 1.1 --- ExportData.java 10 Jul 2004 00:07:03 -0000 1.2 *************** *** 72,75 **** --- 72,82 ---- } + /** + * Create an ExportData object based on export XML string.. + * + * @param xportXml File containing export xml. + * @throws RrdException Thrown in case of JRobin specific exception. + * @throws IOException Thrown in case of I/O related exception. + */ public ExportData( String xportXml ) throws RrdException, IOException { *************** *** 79,82 **** --- 86,97 ---- } + /** + * Create an ExportData object based on export XML string.. + * + * @param xportXml File containing export xml. + * @param useLegendNames Map datasources to legend items in the export xml. + * @throws RrdException Thrown in case of JRobin specific exception. + * @throws IOException Thrown in case of I/O related exception. + */ public ExportData( String xportXml, boolean useLegendNames ) throws RrdException, IOException { *************** *** 86,89 **** --- 101,111 ---- } + /** + * Create an ExportData object based on export XML file. + * + * @param xmlFile File containing export xml. + * @throws RrdException Thrown in case of JRobin specific exception. + * @throws IOException Thrown in case of I/O related exception. + */ public ExportData( File xmlFile ) throws RrdException, IOException { *************** *** 93,96 **** --- 115,126 ---- } + /** + * Create an ExportData object based on export XML file. + * + * @param xmlFile File containing export xml. + * @param useLegendNames Map datasources to legend items in the export xml. + * @throws RrdException Thrown in case of JRobin specific exception. + * @throws IOException Thrown in case of I/O related exception. + */ public ExportData( File xmlFile, boolean useLegendNames ) throws RrdException, IOException { *************** *** 135,138 **** --- 165,177 ---- /** + * Returns the step with which this data was fetched. + * @return Step as long. + */ + public long getStep() + { + return timestamps[1] - timestamps[0]; + } + + /** * Returns all values for a single datasource, the returned values * correspond to the timestamps returned with the {@link #getTimestamps() getTimestamps()} method. Index: RrdExport.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/graph/RrdExport.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** RrdExport.java 9 Jul 2004 12:22:15 -0000 1.1 --- RrdExport.java 10 Jul 2004 00:07:03 -0000 1.2 *************** *** 31,35 **** /** ! * <p>ExportData represents a reduced dataset that is the result of a JRobin rrd export.</p> * * @author Arne Vandamme (cob...@jr...) --- 31,39 ---- /** ! * <p>RrdExport can be used to export graph-like datasources to XML format, ! * by means of the ExportData object. More information about Export can be ! * found in the RRDtool XPORT man page.</p> ! * ! * <p>RrdExport needs a RrdExportDef that holds the configuration.</p> * * @author Arne Vandamme (cob...@jr...) *************** *** 40,44 **** // -- Members // ================================================================ ! private int maxRows = 400; // Default width of a graph --- 44,48 ---- // -- Members // ================================================================ ! private int maxRows = 400; // Default width of a graph Index: Source.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/graph/Source.java,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** Source.java 9 Jul 2004 12:22:15 -0000 1.9 --- Source.java 10 Jul 2004 00:07:03 -0000 1.10 *************** *** 56,60 **** private double nextValue = Double.POSITIVE_INFINITY; ! private long step = 0; private long lastTime = 0; private long totalTime = 0; --- 56,60 ---- private double nextValue = Double.POSITIVE_INFINITY; ! protected long step = 0; private long lastTime = 0; private long totalTime = 0; *************** *** 110,114 **** double get( int pos ) { ! if ( pos < 0 ) return Double.NaN; double val = values[pos]; --- 110,117 ---- double get( int pos ) { ! if ( pos < 0 ) ! return Double.NaN; ! if ( pos > values.length ) ! return Double.NaN; double val = values[pos]; *************** *** 155,159 **** } ! if ( stPos < reducedTimestamps.length && reducedTimestamps[stPos] <= t ) return get( stPos ); --- 158,162 ---- } ! if ( t <= reducedTimestamps[stPos] ) return get( stPos ); Index: Grapher.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/graph/Grapher.java,v retrieving revision 1.16 retrieving revision 1.17 diff -C2 -d -r1.16 -r1.17 *** Grapher.java 9 Jul 2004 12:22:15 -0000 1.16 --- Grapher.java 10 Jul 2004 00:07:03 -0000 1.17 *************** *** 310,317 **** { // Do the actual graphing ! if ( graphDef.useExportData() ) ! calculateSeries( graphDef.getExportData() ); ! else ! calculateSeries(); // calculate all datasources plotImageBackground( graphics ); // draw the image background --- 310,314 ---- { // Do the actual graphing ! calculateSeries(); // calculate all datasources plotImageBackground( graphics ); // draw the image background *************** *** 367,413 **** /** - * Calculates graphing values based on a ExportData object. - * - * @param dataSet ExportData holding the values. - * @throws RrdException Thrown in case of a JRobin specific error. - * @throws IOException Thrown in case of a I/O related error. - */ - private void calculateSeries( ExportData dataSet ) throws RrdException, IOException - { - numPoints = dataSet.getRowCount(); - - startTime = graphDef.getStartTime(); - endTime = graphDef.getEndTime(); - - tsChart = new long[ chartWidth ]; - plotDefs = graphDef.getPlotDefs(); - - timestamps = dataSet.getTimestamps(); - sources = dataSet.getSources(); - sourceIndex = new HashMap( sources.length ); - - for ( int i = 0; i < sources.length; i++ ) - sourceIndex.put( sources[i].getName(), new Integer(i) ); - - for ( int i = 0; i < plotDefs.length; i++ ) - { - plotDefs[i].setSource( sources, sourceIndex ); - plotDefs[i].prepareValues( chartWidth ); - } - - for ( int i = 0; i < chartWidth; i++ ) - { - long t = (long) (startTime + i * ((endTime - startTime) / (double) (chartWidth - 1))); - - for ( int j = 0; j < plotDefs.length; j++ ) - plotDefs[j].setValue( i, t, timestamps ); - - tsChart[i] = t; - } - - - } - - /** * Draws the image background, title and value axis label. * @param g Handle of a Graphics2D context to draw on. --- 364,367 ---- *************** *** 580,587 **** int lastPlotType = PlotDef.PLOT_LINE; ! double[] parentSeries = new double[chartWidth]; // Pre calculate x positions of the corresponding timestamps ! int[] xValues = new int[tsChart.length]; for (int i = 0; i < tsChart.length; i++) xValues[i] = g.getX(tsChart[i]); --- 534,541 ---- int lastPlotType = PlotDef.PLOT_LINE; ! double[] parentSeries = new double[tsChart.length]; // Pre calculate x positions of the corresponding timestamps ! int[] xValues = new int[tsChart.length]; for (int i = 0; i < tsChart.length; i++) xValues[i] = g.getX(tsChart[i]); Index: RrdExportDef.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/graph/RrdExportDef.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** RrdExportDef.java 9 Jul 2004 12:22:15 -0000 1.1 --- RrdExportDef.java 10 Jul 2004 00:07:03 -0000 1.2 *************** *** 66,70 **** protected ArrayList cdefList = new ArrayList( 10 ); // holds the list of Cdef datasources protected ArrayList exportList = new ArrayList( 10 ); // holds the list of datasources to export ! // ================================================================ --- 66,70 ---- protected ArrayList cdefList = new ArrayList( 10 ); // holds the list of Cdef datasources protected ArrayList exportList = new ArrayList( 10 ); // holds the list of datasources to export ! protected ArrayList edefList = new ArrayList( 3 ); // holds the list of export data objects // ================================================================ *************** *** 309,312 **** --- 309,322 ---- /** + * Adds a set of ExportData to the datasource list. + * + * @param edata ExportData to add. + */ + public void addExportData( ExportData edata ) + { + edefList.add( edata ); + } + + /** * Sets a specific datasource to be exported (if export is strict). * The expor legend for this datasource will be empty. *************** *** 387,390 **** --- 397,405 ---- } + protected ExportData[] getExportData() + { + return (ExportData[]) edefList.toArray( new ExportData[] {} ); + } + protected int getNumSdefs() { Index: ValueGrid.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/graph/ValueGrid.java,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** ValueGrid.java 9 Jul 2004 12:22:15 -0000 1.9 --- ValueGrid.java 10 Jul 2004 00:07:03 -0000 1.10 *************** *** 161,169 **** // Create nice grid based on 'fixed' ranges ! if ( shifted <= 1.5 ) vAxis = new ValueAxisUnit( 0.1 * mod * scaleValues[scaleIndex], 0.5 * mod * scaleValues[scaleIndex] ); ! else if ( shifted <= 3 ) vAxis = new ValueAxisUnit( 0.2 * mod * scaleValues[scaleIndex], 1.0 * mod * scaleValues[scaleIndex] ); ! else if ( shifted <= 5 ) vAxis = new ValueAxisUnit( 0.5 * mod * scaleValues[scaleIndex], 1.0 * mod * scaleValues[scaleIndex] ); else --- 161,169 ---- // Create nice grid based on 'fixed' ranges ! if ( shifted <= 2 ) vAxis = new ValueAxisUnit( 0.1 * mod * scaleValues[scaleIndex], 0.5 * mod * scaleValues[scaleIndex] ); ! else if ( shifted <= 4 ) vAxis = new ValueAxisUnit( 0.2 * mod * scaleValues[scaleIndex], 1.0 * mod * scaleValues[scaleIndex] ); ! else if ( shifted <= 6 ) vAxis = new ValueAxisUnit( 0.5 * mod * scaleValues[scaleIndex], 1.0 * mod * scaleValues[scaleIndex] ); else Index: RrdGraphDef.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/graph/RrdGraphDef.java,v retrieving revision 1.17 retrieving revision 1.18 diff -C2 -d -r1.17 -r1.18 *** RrdGraphDef.java 9 Jul 2004 12:22:15 -0000 1.17 --- RrdGraphDef.java 10 Jul 2004 00:07:03 -0000 1.18 *************** *** 105,109 **** private ValueAxisUnit vAxis = null; // custom value axis grid, defaults to no custom private GridRange gridRange = null; // custom value range definition, defaults to auto-scale - private ExportData exportData = null; // possible export data set to use for graphing // -- Non-settable members --- 105,108 ---- *************** *** 177,188 **** } - public void setExportData( ExportData dataSet ) { - exportData = dataSet; - } - - public void setUseExportData( boolean flag ) { - useExportDataFlag = flag; - } - /** * Sets graph title. --- 176,179 ---- *************** *** 978,989 **** return lazyGeneration; } - - protected boolean useExportData() { - return useExportDataFlag; - } - - protected ExportData getExportData() { - return exportData; - } protected Title getTitle() { --- 969,972 ---- |
From: Arne V. <cob...@us...> - 2004-07-10 00:06:37
|
Update of /cvsroot/jrobin/src/org/jrobin/core In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10998/org/jrobin/core Modified Files: FetchData.java RrdDataSet.java Log Message: JRobin 1.4.0 - Value grid tweaking - Fixed graph generation - Modified setExportData into addExportData on RrdExportDef level - Added getStep() to RrdDataSet interface Index: FetchData.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/core/FetchData.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** FetchData.java 9 Jul 2004 12:20:10 -0000 1.6 --- FetchData.java 10 Jul 2004 00:06:29 -0000 1.7 *************** *** 122,125 **** --- 122,133 ---- /** + * Returns the step with which this data was fetched. + * @return Step as long. + */ + public long getStep() { + return timestamps[1] - timestamps[0]; + } + + /** * Returns all archived values for a single datasource. * Returned values correspond to timestamps Index: RrdDataSet.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/core/RrdDataSet.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** RrdDataSet.java 9 Jul 2004 12:20:11 -0000 1.1 --- RrdDataSet.java 10 Jul 2004 00:06:29 -0000 1.2 *************** *** 117,120 **** --- 117,127 ---- /** + * Returns the step of these datasources. + * + * @return Step as long. + */ + public long getStep(); + + /** * Returns aggregated value from the dataset for a single datasource. * |
Update of /cvsroot/jrobin/src/org/jrobin/graph In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18371/org/jrobin/graph Modified Files: Area.java Cdef.java ChartGraphics.java CustomArea.java CustomLine.java Def.java FetchSource.java Grapher.java Line.java Pdef.java PlotDef.java RrdGraph.java RrdGraphDef.java Sdef.java Source.java Stack.java ValueAxisUnit.java ValueExtractor.java ValueGrid.java Added Files: ExportData.java RrdExport.java RrdExportDef.java RrdExporter.java Log Message: JRobin 1.4.0 - Major graph datapoint calculation rewrite - Added elaborate Export support with RRDtool like functionality - New classes: RrdExport, RrdExporter, RrdExportDef, ExportData - New interface: RrdDataSet - Value grid tweaking - Several minor tweaks Index: CustomArea.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/graph/CustomArea.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** CustomArea.java 4 Jul 2004 09:54:32 -0000 1.4 --- CustomArea.java 9 Jul 2004 12:22:15 -0000 1.5 *************** *** 142,146 **** stackValues[i] = g.getInverseY(ny); } ! /** * Retrieves the value for a specific point of the CustomArea. The CustomArea is always a rectangle, --- 142,146 ---- stackValues[i] = g.getInverseY(ny); } ! /** * Retrieves the value for a specific point of the CustomArea. The CustomArea is always a rectangle, *************** *** 169,173 **** void setSource( Source[] sources, HashMap sourceIndex ) throws RrdException { } ! void exportXmlTemplate( XmlWriter xml, String legend ) { xml.startTag("area"); --- 169,177 ---- void setSource( Source[] sources, HashMap sourceIndex ) throws RrdException { } ! ! // Stubbed, we don't need to set value for a Custom plotdef ! void setValue( int tableRow, long preciseTime, long[] reducedTimestamps ) { ! } ! void exportXmlTemplate( XmlWriter xml, String legend ) { xml.startTag("area"); Index: ValueExtractor.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/graph/ValueExtractor.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** ValueExtractor.java 30 May 2004 19:49:56 -0000 1.2 --- ValueExtractor.java 9 Jul 2004 12:22:15 -0000 1.3 *************** *** 27,30 **** --- 27,31 ---- import org.jrobin.core.FetchData; import org.jrobin.core.RrdException; + import org.jrobin.core.Util; /** *************** *** 40,48 **** private String[] varNames; // Name of the variable, NOT it's dsName in the file private int[] tPos; private long[][] timestamps; private double[][][] dsValues; ! ! // ================================================================ // -- Constructors --- 41,53 ---- private String[] varNames; // Name of the variable, NOT it's dsName in the file + private int reduceFactor = 1; + private int[] tPos; + private long[] steps; private long[][] timestamps; + private double[][][] dsValues; ! ! // ================================================================ // -- Constructors *************** *** 53,69 **** * @param values Array of FetchData objects holding all fetched datasources for a specific RRD file. */ ! ValueExtractor( String[] names, FetchData[] values ) { ! this.varNames = names; ! // Set timestamps ! tPos = new int[values.length]; ! timestamps = new long[values.length][]; ! dsValues = new double[values.length][][]; ! ! for (int i = 0; i < timestamps.length; i++) { ! if ( values[i] != null ) { timestamps[i] = values[i].getTimestamps(); dsValues[i] = values[i].getValues(); } } --- 58,82 ---- * @param values Array of FetchData objects holding all fetched datasources for a specific RRD file. */ ! ValueExtractor( String[] names, FetchData[] values, int reduceFactor ) { ! this.varNames = names; ! this.reduceFactor = reduceFactor; ! // Set timestamps ! tPos = new int[values.length]; ! steps = new long[values.length]; ! timestamps = new long[values.length][]; ! ! dsValues = new double[values.length][][]; ! ! for (int i = 0; i < timestamps.length; i++) ! { ! if ( values[i] != null ) ! { timestamps[i] = values[i].getTimestamps(); dsValues[i] = values[i].getValues(); + + if ( timestamps[i].length > 2 ) + steps[i] = (timestamps[i][1] - timestamps[i][0]); } } *************** *** 73,77 **** // ================================================================ // -- Protected methods ! // ================================================================ /** * Extracts a number of values out of the fetched values, and approximates them --- 86,106 ---- // ================================================================ // -- Protected methods ! // ================================================================ ! int prepareSources( Source[] sources, int offset ) ! { ! int tblPos = offset; ! ! for ( int i = 0; i < dsValues.length; i++ ) ! { ! if ( dsValues[i] != null ) ! { ! for (int x = 0; x < dsValues[i].length; x++) ! sources[tblPos++].setFetchedStep( steps[i] ); ! } ! } ! ! return tblPos; ! } ! /** * Extracts a number of values out of the fetched values, and approximates them *************** *** 87,119 **** { int tblPos = offset; ! ! for ( int i = 0; i < dsValues.length; i++ ) { if ( dsValues[i] == null ) continue; ! ! int tIndex = tPos[i]; ! ! if ( timestamp < timestamps[i][ tIndex ] ) ! throw new RrdException("Backward reading not allowed"); ! ! while ( tIndex < timestamps[i].length - 1 ) { ! if ( timestamps[i][ tIndex ] <= timestamp && timestamp < timestamps[i][ tIndex + 1] ) { ! for (int j = 0; j < dsValues[i].length; j++) ! sources[tblPos++].set( row, timestamp, dsValues[i][j][ tIndex + 1 ] ); ! break; } ! else { ! tIndex++; } } ! tPos[i] = tIndex; } ! return tblPos; } ! String[] getNames() { return varNames; --- 116,193 ---- { int tblPos = offset; ! ! for ( int i = 0; i < dsValues.length; i++ ) { if ( dsValues[i] == null ) continue; ! ! int tIndex = tPos[i]; ! ! double[] nValue = new double[ dsValues[i].length ]; ! int[] vValue = new int[ nValue.length ]; // Counts the actual valid values ! ! for ( int j = 0; j < nValue.length; j++ ) ! nValue[j] = Double.NaN; ! ! // Combine the rows ! int j; ! ! for ( j = 0; j < reduceFactor && timestamps[i][tIndex] <= timestamp; j++ ) { ! for (int x = 0; x < dsValues[i].length; x++) ! { ! if ( Double.isNaN(dsValues[i][x][tIndex]) ) ! continue; ! ! vValue[x]++; ! ! if ( Double.isNaN(nValue[x]) ) ! nValue[x] = dsValues[i][x][tIndex]; ! else ! { ! switch ( i ) ! { ! case FetchSource.AVG: ! nValue[x] += dsValues[i][x][tIndex]; ! break; ! case FetchSource.MAX: ! nValue[x] = Util.max( nValue[x], dsValues[i][x][tIndex] ); ! break; ! case FetchSource.MIN: ! nValue[x] = Util.min( nValue[x], dsValues[i][x][tIndex] ); ! break; ! case FetchSource.LAST: ! nValue[x] = dsValues[i][x][tIndex]; ! break; ! } ! } } ! ! tIndex++; ! } ! ! // See if we are using a stretched timespan ! if ( j == 0 && row > 0 ) ! { ! sources[tblPos++].set( row, timestamp, Double.POSITIVE_INFINITY ); ! } ! else ! { ! // Finalize ! for (int x = 0; x < dsValues[i].length; x++) ! { ! if ( i == FetchSource.AVG ) ! nValue[x] /= vValue[x]; ! ! sources[tblPos++].set( row, timestamp, nValue[x] ); } } ! tPos[i] = tIndex; } ! return tblPos; } ! String[] getNames() { return varNames; Index: Grapher.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/graph/Grapher.java,v retrieving revision 1.15 retrieving revision 1.16 diff -C2 -d -r1.15 -r1.16 *** Grapher.java 4 Jul 2004 09:54:32 -0000 1.15 --- Grapher.java 9 Jul 2004 12:22:15 -0000 1.16 *************** *** 37,41 **** import java.awt.image.BufferedImage; - import org.jrobin.core.RrdDb; import org.jrobin.core.RrdException; --- 37,40 ---- *************** *** 45,49 **** * @author Arne Vandamme (cob...@jr...) */ ! class Grapher { // ================================================================ --- 44,48 ---- * @author Arne Vandamme (cob...@jr...) */ ! class Grapher extends RrdExporter { // ================================================================ *************** *** 88,95 **** private RrdGraphDef graphDef; ! private long[] timestamps; ! private Source[] sources; ! private HashMap sourceIndex; ! private FetchSourceList fetchSources; private ValueFormatter valueFormat; --- 87,92 ---- private RrdGraphDef graphDef; ! private PlotDef[] plotDefs; ! private long[] tsChart; private ValueFormatter valueFormat; *************** *** 97,104 **** private ValueGrid vGrid; private TimeGrid tGrid; ! ! private long calculatedEndTime; ! ! // ================================================================ // -- Constructors --- 94,98 ---- private ValueGrid vGrid; private TimeGrid tGrid; ! // ================================================================ // -- Constructors *************** *** 112,115 **** --- 106,110 ---- Grapher( RrdGraphDef graphDef, RrdGraph rrdGraph ) { + super( graphDef, rrdGraph ); this.graphDef = graphDef; *************** *** 134,140 **** defaultStroke = new BasicStroke(); ! // Get the fetch sources list ! fetchSources = graphDef.getFetchSources(); ! fetchSources.setRrdOpener( rrdGraph ); // Set the RrdOpener } --- 129,134 ---- defaultStroke = new BasicStroke(); ! startTime = graphDef.getStartTime(); ! endTime = graphDef.getStartTime(); } *************** *** 316,320 **** { // Do the actual graphing ! calculateSeries(); // calculate all datasources plotImageBackground( graphics ); // draw the image background --- 310,317 ---- { // Do the actual graphing ! if ( graphDef.useExportData() ) ! calculateSeries( graphDef.getExportData() ); ! else ! calculateSeries(); // calculate all datasources plotImageBackground( graphics ); // draw the image background *************** *** 334,337 **** --- 331,335 ---- /** * Fetches and calculates all datasources used in the graph. + * * @throws RrdException Thrown in case of a JRobin specific error. * @throws IOException Thrown in case of a I/O related error. *************** *** 339,539 **** private void calculateSeries() throws RrdException, IOException { ! ValueExtractor ve; ! FetchSource src; ! RrdDb rrd; ! String[] varList; ! ! long finalEndTime = 0; ! boolean changingEndTime = false; ! ! long startTime = graphDef.getStartTime(); ! long endTime = graphDef.getEndTime(); ! changingEndTime = (endTime == 0); ! ! int numDefs = graphDef.getNumDefs(); ! int numSdefs = graphDef.getNumSdefs(); ! ! Cdef[] cdefList = graphDef.getCdefs(); ! int numCdefs = cdefList.length; ! ! Pdef[] pdefList = graphDef.getPdefs(); ! int numPdefs = pdefList.length; ! ! // Set up the array with all datasources (both Def, Cdef and Pdef) ! sources = new Source[ numDefs + numCdefs + numPdefs ]; ! sourceIndex = new HashMap( numDefs + numCdefs + numPdefs ); ! int tblPos = 0; ! int vePos = 0; ! ! ValueExtractor[] veList = new ValueExtractor[ fetchSources.size() ]; ! ! // Open all datasources ! try ! { ! fetchSources.openAll(); ! ! for ( int i = 0; i < fetchSources.size(); i++ ) ! { ! src = fetchSources.get( i ); ! ! if ( changingEndTime ) ! { ! endTime = src.getLastSampleTime( startTime, endTime, graphDef.getResolution() ); ! ! if ( endTime > finalEndTime ) ! finalEndTime = endTime; ! } ! ! // Fetch all required datasources ! ve = src.fetch( startTime, endTime, graphDef.getResolution() ); ! varList = ve.getNames(); ! for (int j= 0; j < varList.length; j++) { ! sources[tblPos] = new Def(varList[j], numPoints); ! sourceIndex.put( varList[j], new Integer(tblPos++) ); ! } ! veList[ vePos++ ] = ve; ! } ! } ! finally ! { ! // Release all datasources again ! fetchSources.releaseAll(); ! } ! // Add all Pdefs to the source table ! for ( int i = 0; i < pdefList.length; i++ ) { ! pdefList[i].prepare( numPoints ); ! ! sources[tblPos] = pdefList[i]; ! sourceIndex.put( pdefList[i].getName(), new Integer(tblPos++) ); } ! int cdefStart = tblPos; // First Cdef element, necessary for tree descend calculation ! ! // Add all Cdefs to the source table ! // Reparse all RPN datasources to use indices of the correct variables ! for ( int i = 0; i < cdefList.length; i++ ) { ! cdefList[i].prepare( sourceIndex, numPoints ); ! ! sources[tblPos] = cdefList[i]; ! sourceIndex.put( cdefList[i].getName(), new Integer(tblPos++) ); ! } ! // Fill the array for all datasources ! timestamps = new long[numPoints]; ! if ( changingEndTime ) { ! endTime = finalEndTime; ! calculatedEndTime = endTime; } ! // RPN calculator for the Cdefs ! RpnCalculator rpnCalc = new RpnCalculator( sources, (endTime - startTime) / (double) numPoints ); ! ! // **************************************************************************************** // ! // If there are Sdefs, we should determine a tree-descend order for calculation. // ! // An Sdef is completely dependant on another datasource and can only be calculated // ! // after the datasource it depends on has been calculated itself entirely. // ! // e.g. The Sdef giving the AVG of a Def should be one lower in the calculation tree // ! // than the corresponding Def. Lower = higher level. // ! // Since Sdefs can be nested and combined into new Cdefs and possibly resulting in new // ! // Sdefs, the worst case calculation could result in every datasource being calculated // ! // separately, resulting in more overhead. However the impact of this should remain fairly // ! // small in CPU time. // ! // **************************************************************************************** // ! if ( numSdefs > 0 ) ! { ! // Initalize level for each def on 0 ! int treeDepth = 0; ! int[] treeLevel = new int[ sources.length ]; ! ! // First level contains all fetched datasources, custom datasources and combined datasources that use other first levels ! for ( int i = cdefStart; i < sources.length; i++ ) ! { ! // Get the level of all defs needed, take the maximum level ! int level = ((Cdef) sources[i]).calculateLevel( treeLevel ); ! treeDepth = (level > treeDepth ? level : treeDepth); ! ! treeLevel[i] = level; ! } ! ! // Run through each level of the tree ! long t; ! int pos; ! ! for ( int l = 0; l <= treeDepth; l++ ) ! { ! for (int i = 0; i < numPoints; i++) ! { ! pos = cdefStart; ! // First level of the tree includes fetched datasources and pdefs, ! // since these values can never depend on others in the list. ! if ( l == 0 ) ! { ! // Calculate new timestamp ! pos = 0; ! t = (long) (startTime + i * ((endTime - startTime) / (double) (numPoints - 1))); ! // Get all fetched datasources ! for (int j = 0; j < veList.length; j++) ! pos = veList[j].extract( t, sources, i, pos ); ! // Get all custom datasources ! for (int j = pos; j < pos + numPdefs; j++) ! ((Pdef) sources[j]).set( i, t ); ! pos += numPdefs; ! timestamps[i] = t; ! } ! else ! t = timestamps[i]; ! // Calculate the cdefs of this level ! for ( int j = pos; j < sources.length; j++ ) ! { ! if ( treeLevel[j] == l ) ! { ! // This Cdef/Sdef can be calculated ! if ( sources[j] instanceof Sdef ) ! ((Sdef) sources[j]).set( sources ); ! else ! sources[j].set( i, t, rpnCalc.evaluate( (Cdef) sources[j], i, t ) ); ! } ! } ! } ! } ! } ! else { ! // Traditional way of calculating all datasources, slightly faster ! for (int i = 0; i < numPoints; i++) ! { ! long t = (long) (startTime + i * ((endTime - startTime) / (double) (numPoints - 1))); ! int pos = 0; ! ! // Get all fetched datasources ! for (int j = 0; j < veList.length; j++) ! pos = veList[j].extract( t, sources, i, pos ); ! // Get all custom datasources ! for (int j = pos; j < pos + numPdefs; j++) ! ((Pdef) sources[j]).set( i, t ); ! pos += numPdefs; ! // Get all combined datasources ! for (int j = pos; j < sources.length; j++) ! sources[j].set(i, t, rpnCalc.evaluate( (Cdef) sources[j], i, t ) ); ! timestamps[i] = t; ! } } ! // Clean up the fetched datasources forcibly ! veList = null; } --- 337,410 ---- private void calculateSeries() throws RrdException, IOException { ! // Calculate the reduced set of datasources ! super.calculateSeries( chartWidth ); ! numPoints = numRows; ! /** ! * Expand the reduced set back to a set matching the chart width, ! * this allows for much nicer graphing. ! */ ! tsChart = new long[ chartWidth ]; ! plotDefs = graphDef.getPlotDefs(); ! for ( int i = 0; i < plotDefs.length; i++ ) { ! plotDefs[i].setSource( sources, sourceIndex ); ! plotDefs[i].prepareValues( chartWidth ); } ! for ( int i = 0; i < chartWidth; i++ ) { ! long t = (long) (startTime + i * ((endTime - startTime) / (double) (chartWidth - 1))); ! for ( int j = 0; j < plotDefs.length; j++ ) ! plotDefs[j].setValue( i, t, timestamps ); ! tsChart[i] = t; } + } ! /** ! * Calculates graphing values based on a ExportData object. ! * ! * @param dataSet ExportData holding the values. ! * @throws RrdException Thrown in case of a JRobin specific error. ! * @throws IOException Thrown in case of a I/O related error. ! */ ! private void calculateSeries( ExportData dataSet ) throws RrdException, IOException ! { ! numPoints = dataSet.getRowCount(); ! startTime = graphDef.getStartTime(); ! endTime = graphDef.getEndTime(); ! tsChart = new long[ chartWidth ]; ! plotDefs = graphDef.getPlotDefs(); ! timestamps = dataSet.getTimestamps(); ! sources = dataSet.getSources(); ! sourceIndex = new HashMap( sources.length ); ! for ( int i = 0; i < sources.length; i++ ) ! sourceIndex.put( sources[i].getName(), new Integer(i) ); ! for ( int i = 0; i < plotDefs.length; i++ ) { ! plotDefs[i].setSource( sources, sourceIndex ); ! plotDefs[i].prepareValues( chartWidth ); ! } ! for ( int i = 0; i < chartWidth; i++ ) ! { ! long t = (long) (startTime + i * ((endTime - startTime) / (double) (chartWidth - 1))); ! for ( int j = 0; j < plotDefs.length; j++ ) ! plotDefs[j].setValue( i, t, timestamps ); ! tsChart[i] = t; } ! } *************** *** 630,637 **** // For autoscale, detect lower and upper limit of values - PlotDef[] plotDefs = graphDef.getPlotDefs(); for ( int i = 0; i < plotDefs.length; i++ ) { - plotDefs[i].setSource( sources, sourceIndex ); Source src = plotDefs[i].getSource(); --- 501,506 ---- *************** *** 641,645 **** double min = src.getAggregate( Source.AGG_MINIMUM ); double max = src.getAggregate( Source.AGG_MAXIMUM ); ! // If the plotdef is a stack, evaluate ALL previous values to find a possible max if ( plotDefs[i].plotType == PlotDef.PLOT_STACK && i >= 1 ) --- 510,514 ---- double min = src.getAggregate( Source.AGG_MINIMUM ); double max = src.getAggregate( Source.AGG_MAXIMUM ); ! // If the plotdef is a stack, evaluate ALL previous values to find a possible max if ( plotDefs[i].plotType == PlotDef.PLOT_STACK && i >= 1 ) *************** *** 681,685 **** vGrid = new ValueGrid( range, lowerValue, upperValue, graphDef.getValueAxis(), graphDef.getBaseValue() ); ! tGrid = new TimeGrid( graphDef.getStartTime(), ( graphDef.getEndTime() != 0 ? graphDef.getEndTime() : calculatedEndTime ), graphDef.getTimeAxis(), graphDef.getFirstDayOfWeek() ); lowerValue = vGrid.getLowerValue(); --- 550,554 ---- vGrid = new ValueGrid( range, lowerValue, upperValue, graphDef.getValueAxis(), graphDef.getBaseValue() ); ! tGrid = new TimeGrid( startTime, endTime, graphDef.getTimeAxis(), graphDef.getFirstDayOfWeek() ); lowerValue = vGrid.getLowerValue(); *************** *** 691,695 **** g.setXRange( tGrid.getStartTime(), tGrid.getEndTime() ); g.setYRange( lowerValue, upperValue ); ! // Set the chart origin point double diff = 1.0d; --- 560,564 ---- g.setXRange( tGrid.getStartTime(), tGrid.getEndTime() ); g.setYRange( lowerValue, upperValue ); ! // Set the chart origin point double diff = 1.0d; *************** *** 711,720 **** int lastPlotType = PlotDef.PLOT_LINE; ! double[] parentSeries = new double[numPoints]; // Pre calculate x positions of the corresponding timestamps ! int[] xValues = new int[timestamps.length]; ! for (int i = 0; i < timestamps.length; i++) ! xValues[i] = g.getX(timestamps[i]); // Draw all graphed values --- 580,589 ---- int lastPlotType = PlotDef.PLOT_LINE; ! double[] parentSeries = new double[chartWidth]; // Pre calculate x positions of the corresponding timestamps ! int[] xValues = new int[tsChart.length]; ! for (int i = 0; i < tsChart.length; i++) ! xValues[i] = g.getX(tsChart[i]); // Draw all graphed values --- NEW FILE: RrdExportDef.java --- /* ============================================================ * JRobin : Pure java implementation of RRDTool's functionality * ============================================================ * * Project Info: http://www.jrobin.org * Project Lead: Sasa Markovic (sa...@jr...) * * Developers: Sasa Markovic (sa...@jr...) * Arne Vandamme (cob...@jr...) * * (C) Copyright 2003, by Sasa Markovic. * * This library is free software; you can redistribute it and/or modify it under the terms * of the GNU Lesser General Public License as published by the Free Software Foundation; * either version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License along with this * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, * Boston, MA 02111-1307, USA. */ package org.jrobin.graph; import java.io.Serializable; import java.util.ArrayList; import java.util.Date; import java.util.GregorianCalendar; import org.jrobin.core.Util; import org.jrobin.core.RrdException; /** * <p>Class used to collect information for a JRobin export.</p> * * <p>JRobin export works the same way as Rrdtool XPORT does, to learn * more about the XPORT functionality, see RRDTool's * <a href="../../../../man/rrdxport.html" target="man">rrdxport man page</a>.</p> * * @author Arne Vandamme (cob...@jr...) */ public class RrdExportDef implements Serializable { // ================================================================ // -- Members // ================================================================ public final static int STRICT_IMPLICIT_OFF = 0; public final static int STRICT_IMPLICIT_ON = 1; public final static int STRICT_EXPLICIT_OFF = 2; public final static int STRICT_EXPLICIT_ON = 3; private long endTime = Util.getTime(); // default time span of the last 24 hours private long startTime = Util.getTime() - 86400L; private long resolution = 1; // resolution to fetch from the RRD databases private int strict = STRICT_IMPLICIT_OFF; // -- Non-settable members private int numSdefs = 0; private int numDefs = 0; // number of Def datasources added protected FetchSourceList fetchSources = new FetchSourceList( 10 ); // holds the list of FetchSources protected ArrayList pdefList = new ArrayList( 10 ); // holds the list of Plottable datasources protected ArrayList cdefList = new ArrayList( 10 ); // holds the list of Cdef datasources protected ArrayList exportList = new ArrayList( 10 ); // holds the list of datasources to export // ================================================================ // -- Constructors // ================================================================ public RrdExportDef() { } /** * Constructs a new JRobin graph object, with a specified time span to be presented on the graph. * Using timestamps defined as number of seconds since the epoch. * * @param startTime Starting timestamp in seconds. * @param endTime Ending timestamp in seconds. * @throws org.jrobin.core.RrdException Thrown if invalid parameters are supplied. */ public RrdExportDef( long startTime, long endTime ) throws RrdException { setTimePeriod( startTime, endTime ); } /** * Constructs a new JRobin graph object, with a specified time span to be presented on the graph. * Time spam defined using <code>java.util.Date</code> objects. * * @param start Starting time. * @param end Ending time. * @throws RrdException Thrown in case of invalid parameters. */ public RrdExportDef( Date start, Date end) throws RrdException { setTimePeriod( start, end ); } /** * Constructs a new JRobin graph object, with a specified time span to be presented on the graph. * Time spam defined using <code>java.util.GregorianCalendar</code> objects. * * @param start Starting time. * @param end Ending time. * @throws RrdException Thrown in case of invalid parameters. */ public RrdExportDef( GregorianCalendar start, GregorianCalendar end ) throws RrdException { setTimePeriod( start, end ); } // ================================================================ // -- Public methods // ================================================================ /** * Sets time span to be presented on the graph using timestamps in number of seconds. * An end time of 0 means JRobin will try to use the last available update time. * * @param startTime Starting timestamp in seconds. * @param endTime Ending timestamp in secons. * @throws RrdException Thrown if invalid parameters are supplied. */ public void setTimePeriod( long startTime, long endTime ) throws RrdException { if ( startTime < 0 || ( endTime != 0 && endTime <= startTime ) ) throw new RrdException( "Invalid start/end time: " + startTime + "/" + endTime ); this.startTime = startTime; this.endTime = endTime; } /** * Sets time span to be presented on the graph using <code>java.util.Date</code> objects. * * @param start Starting time. * @param end Ending time. * @throws RrdException Thrown in case of invalid parameters. */ public void setTimePeriod( Date start, Date end ) throws RrdException { setTimePeriod( start.getTime() / 1000L, end.getTime() / 1000L ); } /** * Sets time span to be presented on the graph using <code>java.util.GregorianCalendar</code> objects. * * @param start Starting time. * @param end Ending time * @throws RrdException Thrown if invalid parameters are supplied. */ public void setTimePeriod( GregorianCalendar start, GregorianCalendar end ) throws RrdException { setTimePeriod( start.getTime(), end.getTime() ); } /** * Sets the resolution with which data will be fetched from the RRD sources. * JRobin will try to match the requested resolution as closely as possible. * * @param resolution Resolution (data step) in seconds. */ public void setResolution( long resolution ) { this.resolution = resolution; } /** * <p>Adds simple graph source to graph definition. Graph source <code>name</code> * can be used:</p> * <ul> * <li>To specify sources for line, area and stack plots.</li> * <li>To define complex graph sources * (see {@link #datasource(java.lang.String, java.lang.String) complex graph * source definition}).</li> * </ul> * * @param name Graph source name. * @param file Path to RRD file. * @param dsName Data source name defined in the RRD file. * @param consolFunc Consolidation function that will be used to extract data from the RRD * file ("AVERAGE", "MIN", "MAX" or "LAST"). */ public void datasource( String name, String file, String dsName, String consolFunc ) throws RrdException { fetchSources.add( name, file, dsName, consolFunc ); numDefs++; } /** * <p>Adds simple graph source to graph definition. Graph source <code>name</code> * can be used:</p> * <ul> * <li>To specify sources for line, area and stack plots.</li> * <li>To define complex graph sources * (see {@link #datasource(java.lang.String, java.lang.String) complex graph * source definition}).</li> * </ul> * * @param name Graph source name. * @param file Path to RRD file. * @param dsName Data source name defined in the RRD file. * @param consolFunc Consolidation function that will be used to extract data from the RRD * file ("AVERAGE", "MIN", "MAX" or "LAST"). * @param backend Name of the RrdBackendFactory that should be used for this RrdDb. */ public void datasource( String name, String file, String dsName, String consolFunc, String backend ) throws RrdException { fetchSources.add( name, file, dsName, consolFunc, backend ); numDefs++; } /** * <p>Clears the list of RRD datasources for this GraphDef and sets it to the FetchSourceList * passed as aparameter. This does not alter any Cdef, Sdef or Pdef definitions. The datasources * should be passed on as a FetchSourceList {@link FetchSourceList}.</p> * @param datasourceList FetchSourceList of the datasources to use. */ public void setDatasources( FetchSourceList datasourceList ) { fetchSources = datasourceList; numDefs = fetchSources.defCount(); } /** * <p>Adds complex graph source with the given name to the graph definition. * Complex graph sources are evaluated using the supplied <code>rpn</code> expression. * * <p>Complex graph source <code>name</code> can be used:</p> * <ul> * <li>To specify sources for line, area and stack plots.</li> * <li>To define other complex graph sources.</li> * </ul> * * <p>JRobin supports the following RPN functions, operators and constants: +, -, *, /, * %, SIN, COS, LOG, EXP, FLOOR, CEIL, ROUND, POW, ABS, SQRT, RANDOM, LT, LE, GT, GE, EQ, * IF, MIN, MAX, LIMIT, DUP, EXC, POP, UN, UNKN, NOW, TIME, PI and E. JRobin does not * force you to specify at least one simple graph source name as RRDTool.</p> * * <p>For more details on RPN see RRDTool's * <a href="http://people.ee.ethz.ch/~oetiker/webtools/rrdtool/manual/rrdgraph.html" target="man">rrdgraph man page</a>.</p> * * @param name Graph source name. * @param rpn RPN expression containig comma delmited simple and complex graph * source names, RPN constants, functions and operators. */ public void datasource( String name, String rpn ) { cdefList.add( new Cdef(name, rpn) ); } /** * <p>Adds static graph source with the given name to the graph definition. * Static graph sources are the result of a consolidation function applied * to *any* other graph source that has been defined previously.</p> * * @param name Graph source name. * @param defName Name of the datasource to calculate the value from. * @param consolFunc Consolidation function to use for value calculation */ public void datasource( String name, String defName, String consolFunc ) throws RrdException { cdefList.add( new Sdef(name, defName, consolFunc) ); numSdefs++; } /** * <p>Adds a custom graph source with the given name to the graph definition. * The datapoints should be made available by a class extending Plottable.</p> * * @param name Graph source name. * @param plottable Class that extends Plottable class and is suited for graphing. */ public void datasource( String name, Plottable plottable ) { pdefList.add( new Pdef(name, plottable) ); } /** * <p>Adds a custom graph source with the given name to the graph definition. * The datapoints should be made available by a class extending Plottable.</p> * * @param name Graph source name. * @param plottable Class that extends Plottable class and is suited for graphing. * @param index Integer referring to the datasource in the Plottable class. */ public void datasource( String name, Plottable plottable, int index ) { pdefList.add( new Pdef(name, plottable, index) ); } /** * <p>Adds a custom graph source with the given name to the graph definition. * The datapoints should be made available by a class extending Plottable.</p> * * @param name Graph source name. * @param plottable Class that extends Plottable class and is suited for graphing. * @param sourceName String name referring to the datasource in the Plottable class. */ public void datasource( String name, Plottable plottable, String sourceName ) { pdefList.add( new Pdef(name, plottable, sourceName) ); } /** * Sets a specific datasource to be exported (if export is strict). * The expor legend for this datasource will be empty. * * @param name Name of the datasource */ public void export( String name ) { export( name, "" ); } /** * Sets a specific datasource to be exported (if export is strict). * And maps an export legend to this datasource. * * @param name Name of the datasource * @param legend Legend text */ public void export( String name, String legend ) { if ( strict == STRICT_IMPLICIT_OFF ) strict = STRICT_IMPLICIT_ON; exportList.add( new String[] { name, legend } ); } /** * <p>Sets the strict flag for the export functionality. By default, the * export is in implicit not-strict, this means that by default, all * datasources specified in the RrdExportDef will be exported into * the ExportData.</p> * * <p>If the strict flag is not specified explicitly by calling this method, * the export will convert to implicitly strict as soon as a particular * export() mapping is defined. Explicit settings will override implicit.</p> * * <p>When explicit is off, the legend for datasources will by default be * the same as the datasource name, the legend can be overridden by setting * mappings using export() method.</p> * * <p>Strict export is the same behaviour as RRDtool's XPORT.</p> * * @param strict True if strict export should on, false if not. */ public void setStrictExport( boolean strict ) { this.strict = ( strict ? STRICT_EXPLICIT_ON : STRICT_EXPLICIT_OFF ); } // ================================================================ // -- Protected (package) methods // ================================================================ protected long getStartTime() { return startTime; } protected long getEndTime() { return endTime; } protected long getResolution() { return resolution; } protected int getNumDefs() { return numDefs; } protected Cdef[] getCdefs() { return (Cdef[]) cdefList.toArray( new Cdef[] {} ); } protected Pdef[] getPdefs() { return (Pdef[]) pdefList.toArray( new Pdef[] {} ); } protected int getNumSdefs() { return numSdefs; } protected FetchSourceList getFetchSources() { return fetchSources; } protected boolean isStrict() { return ( strict == STRICT_IMPLICIT_ON || strict == STRICT_EXPLICIT_ON ); } protected String[][] getExportDatasources() { return (String[][]) exportList.toArray( new String[0][2] ); } } Index: Area.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/graph/Area.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** Area.java 4 Jul 2004 09:54:32 -0000 1.5 --- Area.java 9 Jul 2004 12:22:14 -0000 1.6 *************** *** 27,31 **** import org.jrobin.core.XmlWriter; ! import java.awt.Color; /** --- 27,31 ---- import org.jrobin.core.XmlWriter; ! import java.awt.*; /** *************** *** 59,65 **** * @param visible True if this PlotDef should be graphed, false if not. */ ! Area( Source source, Color color, boolean stacked, boolean visible ) { ! super( source, color, stacked, visible ); } --- 59,65 ---- * @param visible True if this PlotDef should be graphed, false if not. */ ! Area( Source source, double[] values, Color color, boolean stacked, boolean visible ) { ! super( source, values, color, stacked, visible); } *************** *** 78,84 **** { g.setColor( color ); ! ! double[] values = source.getValues(); ! int len = xValues.length; double value; --- 78,83 ---- { g.setColor( color ); ! ! int len = values.length; double value; *************** *** 87,94 **** for ( int i = 0; i < len; i++ ) { value = values[i]; - py = 0; - - nx = xValues[i]; if ( !Double.isNaN(value) ) --- 86,92 ---- for ( int i = 0; i < len; i++ ) { + py = 0; + nx = xValues[i]; value = values[i]; if ( !Double.isNaN(value) ) *************** *** 117,124 **** g.drawLine( nx, py, nx, ny ); } - - } ! // Special case with NaN doubles stackValues[i] = value; --- 115,120 ---- g.drawLine( nx, py, nx, ny ); } } ! // Special case with NaN doubles stackValues[i] = value; *************** *** 127,131 **** } } ! void exportXmlTemplate( XmlWriter xml, String legend ) { --- 123,127 ---- } } ! void exportXmlTemplate( XmlWriter xml, String legend ) { Index: RrdGraph.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/graph/RrdGraph.java,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** RrdGraph.java 29 Jun 2004 09:34:39 -0000 1.10 --- RrdGraph.java 9 Jul 2004 12:22:15 -0000 1.11 *************** *** 400,403 **** --- 400,443 ---- } + /** + * This retrieves the ExportData object associated with the reduced dataset of this Graph. + * This method assumes the graph or at least the dataset has already been calculated. + * + * @return ExportData object containing the reduced dataset. + * @throws RrdException Thrown in case of JRobin specific error. + */ + public ExportData getExportData() throws RrdException { + return grapher.createExportData(); + } + + /** + * This retrieves the ExportData object associated with the reduced dataset of this Graph, + * by calculating the dataset on the spot. Use this if you want to retrieve the associated + * ExportData without generating the actual graph. + * + * @return ExportData object containing the reduced dataset. + * @throws RrdException Thrown in case of JRobin specific error. + * @throws IOException Thrown in case of I/O error + */ + public ExportData fetchExportData() throws RrdException, IOException { + return grapher.fetch( Grapher.DEFAULT_WIDTH ); + } + + /** + * This retrieves the ExportData object associated with the reduced dataset of this Graph, + * by calculating the dataset on the spot. Use this if you want to retrieve the associated + * ExportData without generating the actual graph, or if you wish to re-calculate the + * associated dataset for a different number of rows. + * + * @param maxRows Ballpark figure 'maximum number of rows' that the dataset can contain. + * Note that this is not an absolute maximum and can be overruled in some cases. + * @return ExportData object containing the reduced dataset. + * @throws RrdException Thrown in case of JRobin specific error. + * @throws IOException Thrown in case of I/O error + */ + public ExportData fetchExportData( int maxRows ) throws RrdException, IOException { + return grapher.fetch( maxRows ); + } + // ================================================================ // -- Private methods Index: Def.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/graph/Def.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** Def.java 7 Nov 2003 09:53:35 -0000 1.2 --- Def.java 9 Jul 2004 12:22:15 -0000 1.3 *************** *** 41,48 **** * @param numPoints Number of points used as graph resolution (size of the value table). */ ! Def( String name, int numPoints ) { super(name); ! values = new double[ numPoints ]; } --- 41,49 ---- * @param numPoints Number of points used as graph resolution (size of the value table). */ ! Def( String name, int numPoints, int aggregatePoints ) { super(name); ! values = new double[ numPoints ]; ! this.aggregatePoints = aggregatePoints; } Index: PlotDef.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/graph/PlotDef.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** PlotDef.java 4 Jul 2004 09:54:32 -0000 1.4 --- PlotDef.java 9 Jul 2004 12:22:15 -0000 1.5 *************** *** 55,60 **** protected Source source = null; protected Color color = Color.BLACK; // Default color is black ! ! // ================================================================ // -- Constructors --- 55,61 ---- protected Source source = null; protected Color color = Color.BLACK; // Default color is black ! ! protected double[] values = null; ! // ================================================================ // -- Constructors *************** *** 87,99 **** * @param visible True if this PlotDef should be graphed, false if not. */ ! PlotDef( Source source, Color color, boolean stacked, boolean visible ) { this.source = source; this.color = color; this.stacked = stacked; this.visible = visible; } ! ! // ================================================================ // -- Protected methods --- 88,100 ---- * @param visible True if this PlotDef should be graphed, false if not. */ ! PlotDef( Source source, double[] values, Color color, boolean stacked, boolean visible ) { this.source = source; + this.values = values; this.color = color; this.stacked = stacked; this.visible = visible; } ! // ================================================================ // -- Protected methods *************** *** 113,117 **** throw new RrdException( "Invalid DEF or CDEF: " + sourceName ); } ! /** * Retrieves the value for a specific datapoint of the PlotDef. --- 114,128 ---- throw new RrdException( "Invalid DEF or CDEF: " + sourceName ); } ! ! void prepareValues( int arraySize ) ! { ! values = new double[ arraySize ]; ! } ! ! void setValue( int tableRow, long preciseTime, long[] reducedTimestamps ) ! { ! values[ tableRow ] = source.get( preciseTime, reducedTimestamps ); ! } ! /** * Retrieves the value for a specific datapoint of the PlotDef. Index: CustomLine.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/graph/CustomLine.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** CustomLine.java 4 Jul 2004 09:54:32 -0000 1.3 --- CustomLine.java 9 Jul 2004 12:22:15 -0000 1.4 *************** *** 73,77 **** this.yVal1 = startValue; this.yVal2 = endValue; ! try { --- 73,77 ---- this.yVal1 = startValue; this.yVal2 = endValue; ! try { *************** *** 119,123 **** int ax, ay, nx, ny; ! // Get X positions if ( xVal1 == Long.MIN_VALUE ) --- 119,123 ---- int ax, ay, nx, ny; ! // Get X positions if ( xVal1 == Long.MIN_VALUE ) *************** *** 171,175 **** g.setStroke( STROKE ); } ! /** * Retrieves the value for a specific point of the CustomLine. The corresponding value is calculated based --- 171,175 ---- g.setStroke( STROKE ); } ! /** * Retrieves the value for a specific point of the CustomLine. The corresponding value is calculated based *************** *** 207,210 **** --- 207,214 ---- } + // Stubbed, we don't need to set value for a Custom plotdef + void setValue( int tableRow, long preciseTime, long[] reducedTimestamps ) { + } + void exportXmlTemplate( XmlWriter xml, String legend ) { if(yVal1 == yVal2 && xVal1 != xVal2) { Index: ChartGraphics.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/graph/ChartGraphics.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** ChartGraphics.java 4 Jul 2004 09:54:32 -0000 1.3 --- ChartGraphics.java 9 Jul 2004 12:22:15 -0000 1.4 *************** *** 58,62 **** ChartGraphics( Graphics2D graphics ) { ! g = graphics; } --- 58,62 ---- ChartGraphics( Graphics2D graphics ) { ! g = graphics; } *************** *** 91,95 **** void fillRect(int x1, int y1, int x2, int y2) { ! g.fillRect( x1, -y2, x2 - x1, y2 - y1 ); } --- 91,95 ---- void fillRect(int x1, int y1, int x2, int y2) { ! g.fillRect( x1, -y2, x2 - x1, - (y2 - y1) ); } *************** *** 186,190 **** g.setStroke( s ); } ! /** * Retrieves the lowest X coordinate of the chart area. --- 186,190 ---- g.setStroke( s ); } ! /** * Retrieves the lowest X coordinate of the chart area. Index: ValueAxisUnit.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/graph/ValueAxisUnit.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** ValueAxisUnit.java 19 Apr 2004 22:35:00 -0000 1.5 --- ValueAxisUnit.java 9 Jul 2004 12:22:15 -0000 1.6 *************** *** 42,46 **** // -- Members // ================================================================ - private double gridStep = 2; private double labelStep = 10; --- 42,45 ---- *************** *** 85,89 **** double minPoint = 0.0d; double majPoint = 0.0d; ! // Find the first visible gridpoint if ( lower > 0 ) { --- 84,88 ---- double minPoint = 0.0d; double majPoint = 0.0d; ! // Find the first visible gridpoint if ( lower > 0 ) { *************** *** 151,201 **** double gridFactor = 1.0; double mGridFactor = 1.0; ! double gridStep = this.gridStep; double mGridStep = this.labelStep; ! ! if ( gridStep < 1.0 ) { ! gridStep *= 100; ! gridFactor = 100; } ! ! if ( mGridStep < 1.0 ) { ! mGridStep *= 100; ! mGridFactor = 100; } ! ! double value = ovalue * gridFactor; ! int valueInt = new Double(value).intValue(); ! int roundStep = new Double(gridStep).intValue(); ! if ( roundStep == 0 ) roundStep = 1; ! int num = valueInt / roundStep; ! // int mod = valueInt % roundStep; ! double gridValue = (roundStep * num) * 1.0d; ! if ( gridValue > value ) ! gridValue -= roundStep; ! ! if ( num == 0 && value >= 0 ) ! gridValue = 0.0; ! else if ( Math.abs(gridValue - value) < (gridStep) / 16 ) ! gridValue -= roundStep; ! ! value = ovalue * mGridFactor; ! roundStep = new Double(mGridStep).intValue(); ! if ( roundStep == 0 ) roundStep = 1; ! num = valueInt / roundStep; ! // mod = valueInt % roundStep; ! double mGridValue = (roundStep * num) * 1.0d; ! if ( mGridValue > value ) ! mGridValue -= roundStep; ! ! if ( value != 0.0d ) { - if ( Math.abs(mGridValue - gridValue) < (mGridStep) / 2) - return mGridValue / mGridFactor; - else - return gridValue / gridFactor; - } ! return ovalue; } --- 150,191 ---- double gridFactor = 1.0; double mGridFactor = 1.0; ! double gridStep = this.gridStep; double mGridStep = this.labelStep; ! ! while ( gridStep < 10.0 ) { ! gridStep *= 10; ! gridFactor *= 10; } ! ! while ( mGridStep < 10.0 ) { ! mGridStep *= 10; ! mGridFactor *= 10; } ! ! int sign = ( ovalue > 0 ? 1 : -1 ); ! ! long lGridStep = new Double( gridStep ).longValue(); ! long lmGridStep = new Double( mGridStep ).longValue(); ! ! long lValue = new Double(sign * ovalue * gridFactor).longValue(); ! long lmValue = new Double(sign * ovalue * mGridFactor).longValue(); ! ! long lMod = lValue % lGridStep; ! long lmMod = lmValue % lmGridStep; ! ! /*if ( ovalue < 0 ) { ! } ! else ! {*/ ! if ( lmMod < ( mGridStep * 0.5 ) ) ! return ((double) (sign*lmValue - lmMod) / mGridFactor); ! else if ( lMod > 0 ) ! return ((double) (sign*lValue - lMod) / gridFactor); ! else ! return ((double) (sign*lValue) / gridFactor); ! //} } *************** *** 208,260 **** double getNiceHigher( double ovalue ) { - // Add some checks double gridFactor = 1.0; double mGridFactor = 1.0; ! double gridStep = this.gridStep; double mGridStep = this.labelStep; ! ! if ( gridStep < 1.0 ) { ! gridStep *= 100; ! gridFactor = 100; ! } ! ! if ( mGridStep < 1.0 ) { ! mGridStep *= 100; ! mGridFactor = 100; } ! ! double value = ovalue * gridFactor; ! long valueInt = new Double(value).longValue(); ! long roundStep = new Double(gridStep).longValue(); ! if ( roundStep == 0 ) roundStep = 1; ! long num = valueInt / roundStep; ! // int mod = valueInt % roundStep; ! double gridValue = (roundStep * (num + 1)) * 1.0d; ! if ( gridValue - value < (gridStep) / 8 ) ! gridValue += roundStep; ! ! value = ovalue * mGridFactor; ! roundStep = new Double(mGridStep).longValue(); ! if ( roundStep == 0 ) roundStep = 1; ! num = valueInt / roundStep; ! // mod = valueInt % roundStep; ! double mGridValue = (roundStep * (num + 1)) * 1.0d; ! ! if ( value != 0.0d ) ! { ! if ( Math.abs(mGridValue - gridValue) < (mGridStep) / 2) ! return mGridValue / mGridFactor; ! else ! return gridValue / gridFactor; } ! ! return ovalue; } ! ! // ================================================================ // -- Private methods ! // ================================================================ /** * Rounds a specific double value to 14 decimals. This is used to avoid strange double values due to the --- 198,238 ---- double getNiceHigher( double ovalue ) { double gridFactor = 1.0; double mGridFactor = 1.0; ! double gridStep = this.gridStep; double mGridStep = this.labelStep; ! ! while ( gridStep < 10.0 ) { ! gridStep *= 10; ! gridFactor *= 10; } ! ! while ( mGridStep < 10.0 ) { ! mGridStep *= 10; ! mGridFactor *= 10; } ! ! int sign = ( ovalue > 0 ? 1 : -1 ); ! ! long lGridStep = new Double( gridStep ).longValue(); ! long lmGridStep = new Double( mGridStep ).longValue(); ! ! long lValue = new Double(sign * ovalue * gridFactor).longValue(); ! long lmValue = new Double(sign * ovalue * mGridFactor).longValue(); ! ! long lMod = lValue % lGridStep; ! long lmMod = lmValue % lmGridStep; ! ! if ( lmMod > ( mGridStep * 0.5 ) ) ! return ((double) ( sign * lmValue - lmMod + lmGridStep) / mGridFactor); ! else ! return ((double) ( sign * lValue - lMod + lGridStep) / gridFactor); } ! ! // ================================================================ // -- Private methods ! // ================================================================ /** * Rounds a specific double value to 14 decimals. This is used to avoid strange double values due to the Index: Sdef.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/graph/Sdef.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** Sdef.java 30 May 2004 19:49:56 -0000 1.1 --- Sdef.java 9 Jul 2004 12:22:15 -0000 1.2 *************** *** 68,72 **** // ================================================================ /** ! * Prepares the Sef for faster value calculation by setting the internal * array and references. Override from Cdef parent class. * --- 68,72 ---- // ================================================================ /** ! * Prepares the Sdef for faster value calculation by setting the internal * array and references. Override from Cdef parent class. * *************** *** 75,79 **** * @throws RrdException Thrown in case of the requested datasource is not available in the sourceIndex */ ! void prepare( HashMap sourceIndex, int numPoints ) throws RrdException { if ( sourceIndex.containsKey( defName ) ) --- 75,79 ---- * @throws RrdException Thrown in case of the requested datasource is not available in the sourceIndex */ ! void prepare( HashMap sourceIndex, int numPoints, int aggregatePoints ) throws RrdException { if ( sourceIndex.containsKey( defName ) ) *************** *** 82,86 **** throw new RrdException( "Datasource not found: " + defName ); ! values = new double[ numPoints ]; } --- 82,87 ---- throw new RrdException( "Datasource not found: " + defName ); ! values = new double[ numPoints ]; ! this.aggregatePoints = aggregatePoints; } Index: Source.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/graph/Source.java,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** Source.java 4 Jul 2004 09:54:32 -0000 1.8 --- Source.java 9 Jul 2004 12:22:15 -0000 1.9 *************** *** 46,49 **** --- 46,51 ---- protected static final String[] aggregates = { "MINIMUM", "MAXIMUM", "AVERAGE", "FIRST", "LAST", "TOTAL" }; private String name; + + protected int aggregatePoints; protected double[] values; *************** *** 52,59 **** private double lastValue = Double.NaN; private double totalValue = 0; ! private long lastTime = 0; ! private long totalTime = 0; ! // ================================================================ // -- Constructors --- 54,65 ---- private double lastValue = Double.NaN; private double totalValue = 0; ! private double nextValue = Double.POSITIVE_INFINITY; ! ! private long step = 0; private long lastTime = 0; ! private long totalTime = 0; ! ! private int stPos = 0; ! // ================================================================ // -- Constructors *************** *** 81,89 **** void set( int pos, long time, double val ) { ! aggregate( time, val ); } ! /** * Get the double value of a datapoint. * @param pos Index in the value table of the datapoint. * @return The double value of the requested datapoint. --- 87,108 ---- void set( int pos, long time, double val ) { ! // The first sample is before the time range we want, and as such ! // should not be counted for data aggregation ! if ( pos > 0 && pos < aggregatePoints ) ! aggregate( time, val ); } ! ! void setFetchedStep( long step ) ! { ! this.step = step; ! } ! ! long getStep() { ! return step; ! } ! /** * Get the double value of a datapoint. + * * @param pos Index in the value table of the datapoint. * @return The double value of the requested datapoint. *************** *** 91,97 **** double get( int pos ) { return values[pos]; } ! /** * Gets a specific aggregate of this datasource. --- 110,164 ---- double get( int pos ) { + if ( pos < 0 ) return Double.NaN; + + double val = values[pos]; + + if ( Double.isInfinite(val) ) + { + // Return the next value if we fetched it before + if ( !Double.isInfinite(nextValue) ) + return nextValue; + + // Try to fetch the next value + for ( int i = pos + 1; i < values.length; i++ ) + { + if ( !Double.isInfinite(values[i]) ) + { + nextValue = values[i]; + + return nextValue; + } + } + + // No more next value + nextValue = Double.NaN; + + return nextValue; + } + else + nextValue = Double.POSITIVE_INFINITY; + return values[pos]; } ! ! double get( long preciseTime, long[] reducedTimestamps ) ! { ! long t = Util.normalize( preciseTime, step ); ! t = ( t < preciseTime ? t + step : t ); ! ! while ( stPos < reducedTimestamps.length - 1 ) ! { ! if ( reducedTimestamps[ stPos + 1 ] <= t ) ! stPos++; ! else ! return get( stPos ); ! } ! ! if ( stPos < reducedTimestamps.length && reducedTimestamps[stPos] <= t ) ! return get( stPos ); ! ! return Double.NaN; ! } ! /** * Gets a specific aggregate of this datasource. *************** *** 157,160 **** --- 224,230 ---- private void aggregate( long time, double value ) { + if ( Double.isInfinite(value) ) + return; + min = Util.min( min, value ); max = Util.max( max, value ); Index: FetchSource.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/graph/FetchSource.java,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** FetchSource.java 4 Jul 2004 09:54:32 -0000 1.8 --- FetchSource.java 9 Jul 2004 12:22:15 -0000 1.9 *************** *** 165,169 **** * @throws RrdException Thrown in case of a JRobin specific error. */ ! protected ValueExtractor fetch ( long startTime, long endTime, long resolution ) throws IOException, RrdException { if ( rrd == null ) --- 165,169 ---- * @throws RrdException Thrown in case of a JRobin specific error. */ ! protected ValueExtractor fetch ( long startTime, long endTime, long resolution, int reduceFactor ) throws IOException, RrdException { if ( rrd == null ) *************** *** 197,202 **** // Fetch datasources FetchRequest request = rrd.createFetchRequest( cfNames[i], startTime, endTime + rrdStep, resolution ); request.setFilter( dsNames ); ! FetchData data = request.fetchData(); --- 197,204 ---- // Fetch datasources FetchRequest request = rrd.createFetchRequest( cfNames[i], startTime, endTime + rrdStep, resolution ); + long arcStep = rrd.findMatchingArchive( request ).getArcStep(); + request = rrd.createFetchRequest( cfNames[i], startTime, endTime + arcStep, resolution ); request.setFilter( dsNames ); ! FetchData data = request.fetchData(); *************** *** 209,213 **** } ! return new ValueExtractor( names, result ); } --- 211,215 ---- } ! return new ValueExtractor( names, result, reduceFactor ); } *************** *** 296,300 **** openRrd(); ! long maxSampleTime = 0, sampleTime = 0; for ( int i = 0; i < datasources.length; i++ ) --- 298,302 ---- openRrd(); ! long minSampleTime = Long.MAX_VALUE, sampleTime = 0; for ( int i = 0; i < datasources.length; i++ ) *************** *** 303,313 **** { sampleTime = rrd.findStartMatchArchive( cfNames[i], startTime, resolution ).getEndTime(); ! if ( sampleTime > maxSampleTime ) ! maxSampleTime = sampleTime; } } ! // Remove a single sample step (we'll add it again later on) ! return maxSampleTime - rrdDef.getStep(); } --- 305,349 ---- { sampleTime = rrd.findStartMatchArchive( cfNames[i], startTime, resolution ).getEndTime(); ! ! if ( sampleTime < minSampleTime ) ! minSa... [truncated message content] |
From: Arne V. <cob...@us...> - 2004-07-09 12:20:21
|
Update of /cvsroot/jrobin/src/org/jrobin/core In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv17847/org/jrobin/core Modified Files: FetchData.java RrdDb.java Util.java Added Files: RrdDataSet.java Log Message: JRobin 1.4.0 - Major graph datapoint calculation rewrite - Added elaborate Export support with RRDtool like functionality - New classes: RrdExport, RrdExporter, RrdExportDef, ExportData - New interface: RrdDataSet - Value grid tweaking - Several minor tweaks Index: FetchData.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/core/FetchData.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** FetchData.java 20 May 2004 10:29:32 -0000 1.5 --- FetchData.java 9 Jul 2004 12:20:10 -0000 1.6 *************** *** 53,57 **** * the values returned with {@link #getTimestamps() getTimestamps()} method.<p> */ ! public class FetchData { private FetchRequest request; private Archive matchingArchive; --- 53,57 ---- * the values returned with {@link #getTimestamps() getTimestamps()} method.<p> */ ! public class FetchData implements RrdDataSet { private FetchRequest request; private Archive matchingArchive; --- NEW FILE: RrdDataSet.java --- /* ============================================================ * JRobin : Pure java implementation of RRDTool's functionality * ============================================================ * * Project Info: http://www.jrobin.org * Project Lead: Sasa Markovic (sa...@jr...) * * Developers: Sasa Markovic (sa...@jr...) * Arne Vandamme (cob...@jr...) * * (C) Copyright 2003, by Sasa Markovic. * * This library is free software; you can redistribute it and/or modify it under the terms * of the GNU Lesser General Public License as published by the Free Software Foundation; * either version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License along with this * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, * Boston, MA 02111-1307, USA. */ package org.jrobin.core; import java.io.IOException; import java.io.OutputStream; /** * <p>Interface to represent a JRobin dataset. A dataset is nothing but a table of datasources, indexed * by equidistant timestamps. A dataset allows access to the internal datasources with aggregatoin methods.</p> * * @author Arne Vandamme (cob...@jr...) */ public interface RrdDataSet { /** * Returns the number of rows in this dataset. * * @return Number of rows (data samples). */ public int getRowCount(); /** * Returns the number of columns in this dataset. * * @return Number of columns (datasources). */ public int getColumnCount(); /** * Returns an array of timestamps covering the whole range specified in the * dataset object. * * @return Array of equidistant timestamps. */ public long[] getTimestamps(); /** * Returns all values for a single datasource, the returned values * correspond to the timestamps returned with the {@link #getTimestamps() getTimestamps()} method. * * @param dsIndex Datasource index. * @return Array of single datasource values. */ public double[] getValues( int dsIndex ); /** * Returns all values for all datasources, the returned values * correspond to the timestamps returned with the {@link #getTimestamps() getTimestamps()} method. * * @return Two-dimensional aray of all datasource values. */ public double[][] getValues(); /** * Returns all values for a single datasource, the returned values * correspond to the timestamps returned with the {@link #getTimestamps() getTimestamps()} method. * * @param dsName Datasource name. * @return Array of single datasource values. * @throws RrdException Thrown if no matching datasource name is found. */ public double[] getValues( String dsName ) throws RrdException; /** * Returns the first timestamp in the dataset. * * @return The smallest timestamp. */ public long getFirstTimestamp(); /** * Returns the last timestamp in the dataset. * * @return The biggest timestamp. */ public long getLastTimestamp(); /** * Returns array of the names of all datasources in the set. * * @return Array of datasource names. */ public String[] getDsNames(); /** * Retrieve the table index number of a datasource by name. * Names are case sensitive. * * @param dsName Name of the datasource for which to find the index. * @return Index number of the datasource in the value table. * @throws RrdException Thrown if the given datasource name cannot be found in the dataset. */ public int getDsIndex( String dsName ) throws RrdException; /** * Returns aggregated value from the dataset for a single datasource. * * @param dsName Datasource name * @param consolFun Consolidation function to be applied to set datasource values datasource. * Valid consolidation functions are MIN, MAX, LAST and AVERAGE * @return MIN, MAX, LAST or AVERAGE value calculated from the dataset for the given datasource name * @throws RrdException Thrown if the given datasource name cannot be found in the dataset. */ public double getAggregate( String dsName, String consolFun ) throws RrdException; /** * Dumps fetch data to output stream in XML format. * * @param outputStream Output stream to dump dataset to * @throws RrdException Thrown in case of JRobin specific error. * @throws IOException Thrown in case of I/O error */ public void exportXml( OutputStream outputStream ) throws RrdException, IOException; /** * Dumps dataset to file in XML format. * * @param filepath Path to destination file * @throws RrdException Thrown in case of JRobin specific error. * @throws IOException Thrown in case of I/O error */ public void exportXml( String filepath ) throws RrdException, IOException; /** * Dumps the dataset to XML. * * @return XML string format of the dataset. * @throws RrdException Thrown in case of JRobin specific error. * @throws IOException Thrown in case of an I/O related error. */ public String exportXml() throws RrdException, IOException; } Index: Util.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/core/Util.java,v retrieving revision 1.16 retrieving revision 1.17 diff -C2 -d -r1.16 -r1.17 *** Util.java 20 May 2004 10:29:33 -0000 1.16 --- Util.java 9 Jul 2004 12:20:11 -0000 1.17 *************** *** 76,80 **** } ! static long normalize(long timestamp, long step) { return timestamp - timestamp % step; } --- 76,80 ---- } ! public static long normalize(long timestamp, long step) { return timestamp - timestamp % step; } *************** *** 199,203 **** } ! static double parseDouble(String valueStr) { double value; try { --- 199,203 ---- } ! public static double parseDouble(String valueStr) { double value; try { *************** *** 210,214 **** } ! static boolean parseBoolean(String valueStr) { return valueStr.equalsIgnoreCase("true") || valueStr.equalsIgnoreCase("on") || --- 210,214 ---- } ! public static boolean parseBoolean(String valueStr) { return valueStr.equalsIgnoreCase("true") || valueStr.equalsIgnoreCase("on") || *************** *** 330,339 **** * Various DOM utility functions */ ! static class Xml { ! static Node[] getChildNodes(Node parentNode) { return getChildNodes(parentNode, null); } ! static Node[] getChildNodes(Node parentNode, String childName) { ArrayList nodes = new ArrayList(); NodeList nodeList = parentNode.getChildNodes(); --- 330,339 ---- * Various DOM utility functions */ ! public static class Xml { ! public static Node[] getChildNodes(Node parentNode) { return getChildNodes(parentNode, null); } ! public static Node[] getChildNodes(Node parentNode, String childName) { ArrayList nodes = new ArrayList(); NodeList nodeList = parentNode.getChildNodes(); *************** *** 347,351 **** } ! static Node getFirstChildNode(Node parentNode, String childName) throws RrdException { Node[] childs = getChildNodes(parentNode, childName); if (childs.length > 0) { --- 347,351 ---- } ! public static Node getFirstChildNode(Node parentNode, String childName) throws RrdException { Node[] childs = getChildNodes(parentNode, childName); if (childs.length > 0) { *************** *** 355,359 **** } ! static boolean hasChildNode(Node parentNode, String childName) { Node[] childs = getChildNodes(parentNode, childName); return childs.length > 0; --- 355,359 ---- } ! public static boolean hasChildNode(Node parentNode, String childName) { Node[] childs = getChildNodes(parentNode, childName); return childs.length > 0; *************** *** 361,369 **** // -- Wrapper around getChildValue with trim ! static String getChildValue( Node parentNode, String childName ) throws RrdException { return getChildValue( parentNode, childName, true ); } ! static String getChildValue( Node parentNode, String childName, boolean trim ) throws RrdException { NodeList children = parentNode.getChildNodes(); for (int i = 0; i < children.getLength(); i++) { --- 361,369 ---- // -- Wrapper around getChildValue with trim ! public static String getChildValue( Node parentNode, String childName ) throws RrdException { return getChildValue( parentNode, childName, true ); } ! public static String getChildValue( Node parentNode, String childName, boolean trim ) throws RrdException { NodeList children = parentNode.getChildNodes(); for (int i = 0; i < children.getLength(); i++) { *************** *** 377,385 **** // -- Wrapper around getValue with trim ! static String getValue(Node node) { return getValue( node, true ); } ! static String getValue(Node node, boolean trimValue ) { String value = null; Node child = node.getFirstChild(); --- 377,385 ---- // -- Wrapper around getValue with trim ! public static String getValue(Node node) { return getValue( node, true ); } ! public static String getValue(Node node, boolean trimValue ) { String value = null; Node child = node.getFirstChild(); *************** *** 393,437 **** } ! static int getChildValueAsInt(Node parentNode, String childName) throws RrdException { String valueStr = getChildValue(parentNode, childName); return Integer.parseInt(valueStr); } ! static int getValueAsInt(Node node) { String valueStr = getValue(node); return Integer.parseInt(valueStr); } ! static long getChildValueAsLong(Node parentNode, String childName) throws RrdException { String valueStr = getChildValue(parentNode, childName); return Long.parseLong(valueStr); } ! static long getValueAsLong(Node node) { String valueStr = getValue(node); return Long.parseLong(valueStr); } ! static double getChildValueAsDouble(Node parentNode, String childName) throws RrdException { String valueStr = getChildValue(parentNode, childName); return Util.parseDouble(valueStr); } ! static double getValueAsDouble(Node node) { String valueStr = getValue(node); return Util.parseDouble(valueStr); } ! static boolean getChildValueAsBoolean(Node parentNode, String childName) throws RrdException { String valueStr = getChildValue(parentNode, childName); return Util.parseBoolean(valueStr); } ! static boolean getValueAsBoolean(Node node) { String valueStr = getValue(node); return Util.parseBoolean(valueStr); } ! static Element getRootElement(InputSource inputSource) throws RrdException, IOException { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setValidating(false); --- 393,437 ---- } ! public static int getChildValueAsInt(Node parentNode, String childName) throws RrdException { String valueStr = getChildValue(parentNode, childName); return Integer.parseInt(valueStr); } ! public static int getValueAsInt(Node node) { String valueStr = getValue(node); return Integer.parseInt(valueStr); } ! public static long getChildValueAsLong(Node parentNode, String childName) throws RrdException { String valueStr = getChildValue(parentNode, childName); return Long.parseLong(valueStr); } ! public static long getValueAsLong(Node node) { String valueStr = getValue(node); return Long.parseLong(valueStr); } ! public static double getChildValueAsDouble(Node parentNode, String childName) throws RrdException { String valueStr = getChildValue(parentNode, childName); return Util.parseDouble(valueStr); } ! public static double getValueAsDouble(Node node) { String valueStr = getValue(node); return Util.parseDouble(valueStr); } ! public static boolean getChildValueAsBoolean(Node parentNode, String childName) throws RrdException { String valueStr = getChildValue(parentNode, childName); return Util.parseBoolean(valueStr); } ! public static boolean getValueAsBoolean(Node node) { String valueStr = getValue(node); return Util.parseBoolean(valueStr); } ! public static Element getRootElement(InputSource inputSource) throws RrdException, IOException { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setValidating(false); *************** *** 448,456 **** } ! static Element getRootElement(String xmlString) throws RrdException, IOException { return getRootElement(new InputSource(new StringReader(xmlString))); } ! static Element getRootElement(File xmlFile) throws RrdException, IOException { Reader reader = null; try { --- 448,456 ---- } ! public static Element getRootElement(String xmlString) throws RrdException, IOException { return getRootElement(new InputSource(new StringReader(xmlString))); } ! public static Element getRootElement(File xmlFile) throws RrdException, IOException { Reader reader = null; try { *************** *** 480,484 **** return "[" + seconds + " sec]"; } ! } ! ! --- 480,483 ---- return "[" + seconds + " sec]"; } ! ! } \ No newline at end of file Index: RrdDb.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/core/RrdDb.java,v retrieving revision 1.22 retrieving revision 1.23 diff -C2 -d -r1.22 -r1.23 *** RrdDb.java 29 Jun 2004 11:30:55 -0000 1.22 --- RrdDb.java 9 Jul 2004 12:20:10 -0000 1.23 *************** *** 503,507 **** } ! private Archive findMatchingArchive(FetchRequest request) throws RrdException, IOException { String consolFun = request.getConsolFun(); long fetchStart = request.getFetchStart(); --- 503,507 ---- } ! public Archive findMatchingArchive(FetchRequest request) throws RrdException, IOException { String consolFun = request.getConsolFun(); long fetchStart = request.getFetchStart(); *************** *** 560,564 **** * @throws IOException Thrown in case of I/O related error. */ ! public Archive findStartMatchArchive( String consolFun, long startTime, long resolution ) throws IOException { long arcStep, diff; int fallBackIndex = 0; --- 560,565 ---- * @throws IOException Thrown in case of I/O related error. */ ! public Archive findStartMatchArchive( String consolFun, long startTime, long resolution ) throws IOException ! { long arcStep, diff; int fallBackIndex = 0; |
From: Arne V. <cob...@us...> - 2004-07-04 09:54:45
|
Update of /cvsroot/jrobin/src/org/jrobin/graph In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv22218/org/jrobin/graph Modified Files: Area.java ChartGraphics.java CustomArea.java CustomLine.java FetchSource.java Grapher.java Line.java PlotDef.java Source.java Stack.java Removed Files: RrdOpener.java Log Message: JRobin 1.4.0 - Fixed bug #0000042 - Minor tweaks Index: CustomLine.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/graph/CustomLine.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** CustomLine.java 1 Mar 2004 08:50:25 -0000 1.2 --- CustomLine.java 4 Jul 2004 09:54:32 -0000 1.3 *************** *** 113,120 **** * @param lastPlotType Type of the previous PlotDef, used to determine PlotDef type of a stack. */ ! void draw( ChartGraphics g, int[] xValues, int[] stackValues, int lastPlotType ) throws RrdException { g.setColor( color ); ! g.setStroke( new BasicStroke(lineWidth) ); int ax, ay, nx, ny; --- 113,120 ---- * @param lastPlotType Type of the previous PlotDef, used to determine PlotDef type of a stack. */ ! void draw( ChartGraphics g, int[] xValues, double[] stackValues, int lastPlotType ) throws RrdException { g.setColor( color ); ! g.setStroke( lineWidth != 1 ? new BasicStroke(lineWidth) : DEF_LINE_STROKE ); int ax, ay, nx, ny; *************** *** 161,174 **** for (int i = 0; i < xValues.length; i++) { if ( xValues[i] < ax || xValues[i] > nx ) ! stackValues[i] = 0; else if ( ay == ny ) ! stackValues[i] = ay; else ! stackValues[i] = new Double(rc * (xValues[i] - ax) + ay).intValue(); } } ! ! ! g.setStroke( new BasicStroke() ); } --- 161,173 ---- for (int i = 0; i < xValues.length; i++) { if ( xValues[i] < ax || xValues[i] > nx ) ! stackValues[i] = g.getInverseY(0); else if ( ay == ny ) ! stackValues[i] = g.getInverseY(ay); else ! stackValues[i] = g.getInverseY( (int) (rc * (xValues[i] - ax) + ay) ); } } ! ! g.setStroke( STROKE ); } Index: ChartGraphics.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/graph/ChartGraphics.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** ChartGraphics.java 19 Apr 2004 22:35:00 -0000 1.2 --- ChartGraphics.java 4 Jul 2004 09:54:32 -0000 1.3 *************** *** 49,53 **** private double widthDelta = 1.0d, heightDelta = 3.0d; - // ================================================================ // -- Constructors --- 49,52 ---- *************** *** 146,149 **** --- 145,150 ---- else heightDelta = 1.0d; + + yStart = (yStart < 0 ? 0 : Math.abs(yStart)); } *************** *** 155,159 **** int getX( long timestamp ) { ! return new Double((timestamp - xStart) * widthDelta).intValue(); } --- 156,160 ---- int getX( long timestamp ) { ! return (int) ((timestamp - xStart) * widthDelta); } *************** *** 166,175 **** { if ( Double.isNaN(value) ) return Integer.MIN_VALUE; ! ! int tmp = new Double( (value - ( yStart < 0 ? 0 : Math.abs(yStart) ) ) * heightDelta).intValue(); ! ! return ( tmp > value * heightDelta ? tmp - 1 : tmp ); } ! /** * Sets the Stroke to use for graphing on the graphics context. --- 167,181 ---- { if ( Double.isNaN(value) ) return Integer.MIN_VALUE; ! ! return (int) ((value - yStart ) * heightDelta); } ! ! double getInverseY( int value ) ! { ! if ( value == Integer.MIN_VALUE ) return Double.NaN; ! ! return (value * 1.0d/heightDelta) + yStart; ! } ! /** * Sets the Stroke to use for graphing on the graphics context. Index: CustomArea.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/graph/CustomArea.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** CustomArea.java 1 Mar 2004 08:50:25 -0000 1.3 --- CustomArea.java 4 Jul 2004 09:54:32 -0000 1.4 *************** *** 88,92 **** * @param lastPlotType Type of the previous PlotDef, used to determine PlotDef type of a stack. */ ! void draw( ChartGraphics g, int[] xValues, int[] stackValues, int lastPlotType ) throws RrdException { g.setColor( color ); --- 88,92 ---- * @param lastPlotType Type of the previous PlotDef, used to determine PlotDef type of a stack. */ ! void draw( ChartGraphics g, int[] xValues, double[] stackValues, int lastPlotType ) throws RrdException { g.setColor( color ); *************** *** 138,144 **** for (int i = 0; i < stackValues.length; i++) if ( xValues[i] < ax || xValues[i] > nx ) ! stackValues[i] = 0; else ! stackValues[i] = ny; } --- 138,144 ---- for (int i = 0; i < stackValues.length; i++) if ( xValues[i] < ax || xValues[i] > nx ) ! stackValues[i] = g.getInverseY(0); else ! stackValues[i] = g.getInverseY(ny); } Index: Source.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/graph/Source.java,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** Source.java 26 Apr 2004 22:28:33 -0000 1.7 --- Source.java 4 Jul 2004 09:54:32 -0000 1.8 *************** *** 167,171 **** totalTime += timeDelta; } ! lastTime = time; lastValue = value; --- 167,171 ---- totalTime += timeDelta; } ! lastTime = time; lastValue = value; Index: FetchSource.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/graph/FetchSource.java,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** FetchSource.java 29 Jun 2004 09:34:39 -0000 1.7 --- FetchSource.java 4 Jul 2004 09:54:32 -0000 1.8 *************** *** 200,204 **** FetchData data = request.fetchData(); ! for (int j = 0; j < dsSize; j++) names[ data.getDsIndex(dsNames[j]) + tblPos ] = vNames[j]; --- 200,204 ---- FetchData data = request.fetchData(); ! for (int j = 0; j < dsSize; j++) names[ data.getDsIndex(dsNames[j]) + tblPos ] = vNames[j]; Index: Stack.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/graph/Stack.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** Stack.java 1 Mar 2004 08:50:25 -0000 1.3 --- Stack.java 4 Jul 2004 09:54:32 -0000 1.4 *************** *** 64,68 **** * @param lastPlotType Type of the previous PlotDef, used to determine PlotDef type of a stack. */ ! void draw( ChartGraphics g, int[] xValues, int[] stackValues, int lastPlotType ) throws RrdException { PlotDef stack = null; --- 64,68 ---- * @param lastPlotType Type of the previous PlotDef, used to determine PlotDef type of a stack. */ ! void draw( ChartGraphics g, int[] xValues, double[] stackValues, int lastPlotType ) throws RrdException { PlotDef stack = null; Index: Area.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/graph/Area.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** Area.java 1 Mar 2004 08:50:25 -0000 1.4 --- Area.java 4 Jul 2004 09:54:32 -0000 1.5 *************** *** 75,109 **** * @param lastPlotType Type of the previous PlotDef, used to determine PlotDef type of a stack. */ ! void draw( ChartGraphics g, int[] xValues, int[] stackValues, int lastPlotType ) { g.setColor( color ); double[] values = source.getValues(); ! ! int ax = 0, ay = 0, py; ! int nx = 0, ny = 0, last = -1; ! for (int i = 0; i < xValues.length; i++) { py = 0; nx = xValues[i]; ! ny = g.getY( values[i] ); ! ! if ( !Double.isNaN(values[i]) ) { ! if ( stacked ) { ! py = stackValues[i]; ! ny += ( stackValues[i] == Integer.MIN_VALUE ? Integer.MIN_VALUE : stackValues[i] ); } ! if ( visible ) { ! if (nx > ax + 1) // More than one pixel hop, draw intermediate pixels too { // For each pixel between nx and ax, calculate the y, plot the line int co = (ny - ay) / (nx - ax); ! int j = (ax > 0 ? ax : 1 ); // Skip 0 ! for (j = ax; j <= nx; j++) if ( ay != Integer.MIN_VALUE && ny != Integer.MIN_VALUE ) --- 75,113 ---- * @param lastPlotType Type of the previous PlotDef, used to determine PlotDef type of a stack. */ ! void draw( ChartGraphics g, int[] xValues, double[] stackValues, int lastPlotType ) { g.setColor( color ); double[] values = source.getValues(); ! int len = xValues.length; ! double value; ! int ax = 0, ay = 0, nx = 0, ny = 0, py; ! ! for ( int i = 0; i < len; i++ ) { + value = values[i]; py = 0; nx = xValues[i]; ! ! if ( !Double.isNaN(value) ) { ! if ( stacked ) ! { ! py = g.getY( stackValues[i] ); ! value += stackValues[i]; } ! ! ny = g.getY( value ); ! if ( visible ) { ! if ( nx > ax + 1 ) // More than one pixel hop, draw intermediate pixels too { // For each pixel between nx and ax, calculate the y, plot the line int co = (ny - ay) / (nx - ax); ! int j = (ax > 0 ? ax : 1 ); // Skip 0 ! for (j = ax; j <= nx; j++) if ( ay != Integer.MIN_VALUE && ny != Integer.MIN_VALUE ) *************** *** 113,123 **** g.drawLine( nx, py, nx, ny ); } ! ! } // Special case with NaN doubles ! ! stackValues[i] = ny; ax = nx; ay = ny; --- 117,126 ---- g.drawLine( nx, py, nx, ny ); } ! ! } // Special case with NaN doubles ! stackValues[i] = value; ax = nx; ay = ny; Index: Grapher.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/graph/Grapher.java,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** Grapher.java 29 Jun 2004 09:34:39 -0000 1.14 --- Grapher.java 4 Jul 2004 09:54:32 -0000 1.15 *************** *** 317,327 **** // Do the actual graphing calculateSeries(); // calculate all datasources ! plotImageBackground( graphics ); // draw the image background ! plotChart( graphics ); // draw the actual chart ! plotComments( graphics ); // draw all comment lines ! plotOverlay( graphics ); // draw a possible image overlay --- 317,327 ---- // Do the actual graphing calculateSeries(); // calculate all datasources ! plotImageBackground( graphics ); // draw the image background ! plotChart( graphics ); // draw the actual chart ! plotComments( graphics ); // draw all comment lines ! plotOverlay( graphics ); // draw a possible image overlay *************** *** 610,614 **** graphics.setColor( graphDef.getFrameColor() ); graphics.drawRect( lux, luy, chartWidth, chartHeight ); ! double val; double[] tmpSeries = new double[numPoints]; --- 610,614 ---- graphics.setColor( graphDef.getFrameColor() ); graphics.drawRect( lux, luy, chartWidth, chartHeight ); ! double val; double[] tmpSeries = new double[numPoints]; *************** *** 679,683 **** } ! vGrid = new ValueGrid( range, lowerValue, upperValue, graphDef.getValueAxis(), graphDef.getBaseValue() ); tGrid = new TimeGrid( graphDef.getStartTime(), ( graphDef.getEndTime() != 0 ? graphDef.getEndTime() : calculatedEndTime ), graphDef.getTimeAxis(), graphDef.getFirstDayOfWeek() ); --- 679,683 ---- } ! vGrid = new ValueGrid( range, lowerValue, upperValue, graphDef.getValueAxis(), graphDef.getBaseValue() ); tGrid = new TimeGrid( graphDef.getStartTime(), ( graphDef.getEndTime() != 0 ? graphDef.getEndTime() : calculatedEndTime ), graphDef.getTimeAxis(), graphDef.getFirstDayOfWeek() ); *************** *** 685,689 **** lowerValue = vGrid.getLowerValue(); upperValue = vGrid.getUpperValue(); ! // Use a special graph 'object' that takes care of resizing and reversing y coordinates ChartGraphics g = new ChartGraphics( graphics ); --- 685,689 ---- lowerValue = vGrid.getLowerValue(); upperValue = vGrid.getUpperValue(); ! // Use a special graph 'object' that takes care of resizing and reversing y coordinates ChartGraphics g = new ChartGraphics( graphics ); *************** *** 710,715 **** graphics.translate( graphOriginX, graphOriginY ); ! int lastPlotType = PlotDef.PLOT_LINE; ! int[] parentSeries = new int[numPoints]; // Pre calculate x positions of the corresponding timestamps --- 710,715 ---- graphics.translate( graphOriginX, graphOriginY ); ! int lastPlotType = PlotDef.PLOT_LINE; ! double[] parentSeries = new double[numPoints]; // Pre calculate x positions of the corresponding timestamps *************** *** 717,730 **** for (int i = 0; i < timestamps.length; i++) xValues[i] = g.getX(timestamps[i]); ! // Draw all graphed values ! for (int i = 0; i < plotDefs.length; i++) { plotDefs[i].draw( g, xValues, parentSeries, lastPlotType ); ! if(plotDefs[i].plotType != PlotDef.PLOT_STACK) { lastPlotType = plotDefs[i].plotType; - } } ! // Reset clipping area, origin and AA settings graphics.translate( -graphOriginX, -graphOriginY ); --- 717,729 ---- for (int i = 0; i < timestamps.length; i++) xValues[i] = g.getX(timestamps[i]); ! // Draw all graphed values ! for ( int i = 0; i < plotDefs.length; i++ ) { plotDefs[i].draw( g, xValues, parentSeries, lastPlotType ); ! if( plotDefs[i].plotType != PlotDef.PLOT_STACK ) lastPlotType = plotDefs[i].plotType; } ! // Reset clipping area, origin and AA settings graphics.translate( -graphOriginX, -graphOriginY ); Index: Line.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/graph/Line.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** Line.java 1 Mar 2004 08:50:25 -0000 1.4 --- Line.java 4 Jul 2004 09:54:32 -0000 1.5 *************** *** 25,33 **** package org.jrobin.graph; ! import java.awt.Color; ! import java.awt.BasicStroke; import org.jrobin.core.RrdException; import org.jrobin.core.XmlWriter; /** --- 25,33 ---- package org.jrobin.graph; ! import java.awt.*; import org.jrobin.core.RrdException; import org.jrobin.core.XmlWriter; + import org.jrobin.core.Util; /** *************** *** 41,45 **** // -- Members // ================================================================ ! protected int lineWidth = 1; // Default line width of 1 pixel --- 41,46 ---- // -- Members // ================================================================ ! protected static BasicStroke DEF_LINE_STROKE = new BasicStroke(1.0f); ! protected int lineWidth = 1; // Default line width of 1 pixel *************** *** 99,130 **** * @param lastPlotType Type of the previous PlotDef, used to determine PlotDef type of a stack. */ ! void draw( ChartGraphics g, int[] xValues, int[] stackValues, int lastPlotType ) throws RrdException { g.setColor( color ); ! g.setStroke( new BasicStroke(lineWidth) ); double[] values = source.getValues(); ! ! int ax = 0, ay = 0; ! int nx = 0, ny = 0, last = -1; ! ! for (int i = 0; i < xValues.length; i++) { ! nx = xValues[i]; ! ny = g.getY( values[i] ); ! ! if ( stacked && ny != Integer.MIN_VALUE ) ! ny += stackValues[i]; ! ! if ( visible && ny != Double.NaN && nx != 0 && ay != Integer.MIN_VALUE && ny != Integer.MIN_VALUE ) ! g.drawLine( ax, ay, nx, ny ); ! ! ! stackValues[i] = ny; ax = nx; ay = ny; } ! ! g.setStroke( new BasicStroke() ); } --- 100,135 ---- * @param lastPlotType Type of the previous PlotDef, used to determine PlotDef type of a stack. */ ! void draw( ChartGraphics g, int[] xValues, double[] stackValues, int lastPlotType ) throws RrdException { g.setColor( color ); ! g.setStroke( lineWidth != 1 ? new BasicStroke(lineWidth) : DEF_LINE_STROKE ); + Graphics2D gd = g.getGraphics(); double[] values = source.getValues(); ! int len = xValues.length; ! ! double value; ! int ax = 0, ay = 0, nx = 0, ny = 0; ! ! for ( int i = 0; i < len; i++ ) { ! value = values[i]; ! ! nx = xValues[i]; ! ! if ( stacked ) ! value += stackValues[i]; ! ! ny = g.getY( value ); ! ! if ( visible && !Double.isNaN(ny) && nx != 0 && ay != Integer.MIN_VALUE && ny != Integer.MIN_VALUE ) ! gd.drawLine(ax, -ay, nx, -ny); ! ! stackValues[i] = value; ax = nx; ay = ny; } ! ! g.setStroke( STROKE ); } Index: PlotDef.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/graph/PlotDef.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** PlotDef.java 1 Mar 2004 08:50:25 -0000 1.3 --- PlotDef.java 4 Jul 2004 09:54:32 -0000 1.4 *************** *** 25,29 **** package org.jrobin.graph; ! import java.awt.Color; import java.util.HashMap; --- 25,29 ---- package org.jrobin.graph; ! import java.awt.*; import java.util.HashMap; *************** *** 43,57 **** // -- Members // ================================================================ ! protected static final int PLOT_LINE = 0; ! protected static final int PLOT_AREA = 1; ! protected static final int PLOT_STACK = 2; ! ! protected boolean visible = true; ! protected boolean stacked = false; ! protected int plotType = PLOT_LINE; // Unknown plotdef is a line ! protected String sourceName = ""; ! protected Source source = null; ! protected Color color = Color.BLACK; // Default color is black --- 43,58 ---- // -- Members // ================================================================ ! protected static final int PLOT_LINE = 0; ! protected static final int PLOT_AREA = 1; ! protected static final int PLOT_STACK = 2; ! protected static final BasicStroke STROKE = new BasicStroke(); ! ! protected boolean visible = true; ! protected boolean stacked = false; ! protected int plotType = PLOT_LINE; // Unknown plotdef is a line ! protected String sourceName = ""; ! protected Source source = null; ! protected Color color = Color.BLACK; // Default color is black *************** *** 128,132 **** * This method is responsible for the actual drawing of the PlotDef. */ ! abstract void draw( ChartGraphics g, int[] xValues, int[] stackValues, int lastPlotType ) throws RrdException; Source getSource() { --- 129,133 ---- * This method is responsible for the actual drawing of the PlotDef. */ ! abstract void draw( ChartGraphics g, int[] xValues, double[] stackValues, int lastPlotType ) throws RrdException; Source getSource() { --- RrdOpener.java DELETED --- |
From: Sasa M. <sa...@us...> - 2004-06-29 12:59:44
|
Update of /cvsroot/jrobin/src/org/jrobin/core In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10839/org/jrobin/core Modified Files: RrdCacher.java RrdDouble.java RrdInt.java RrdLong.java RrdPrimitive.java RrdString.java Log Message: Minor improvements of primitive classes (cache moved to the base class) Index: RrdCacher.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/core/RrdCacher.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** RrdCacher.java 2 Jun 2004 08:55:48 -0000 1.2 --- RrdCacher.java 29 Jun 2004 12:59:35 -0000 1.3 *************** *** 93,95 **** --- 93,99 ---- } + final void clearCache() { + cached = false; + } + } Index: RrdString.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/core/RrdString.java,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** RrdString.java 20 May 2004 10:29:33 -0000 1.8 --- RrdString.java 29 Jun 2004 12:59:35 -0000 1.9 *************** *** 29,34 **** class RrdString extends RrdPrimitive { - private RrdCacher cache = new RrdCacher(); - RrdString(RrdUpdater updater) throws IOException { super(updater, RrdPrimitive.RRD_STRING); --- 29,32 ---- Index: RrdLong.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/core/RrdLong.java,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** RrdLong.java 20 May 2004 10:29:33 -0000 1.8 --- RrdLong.java 29 Jun 2004 12:59:35 -0000 1.9 *************** *** 29,34 **** class RrdLong extends RrdPrimitive { - private RrdCacher cache = new RrdCacher(); - RrdLong(RrdUpdater updater) throws IOException { super(updater, RrdPrimitive.RRD_LONG); --- 29,32 ---- Index: RrdPrimitive.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/core/RrdPrimitive.java,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** RrdPrimitive.java 21 May 2004 10:40:50 -0000 1.7 --- RrdPrimitive.java 29 Jun 2004 12:59:35 -0000 1.8 *************** *** 37,40 **** --- 37,42 ---- private final long pointer; + protected RrdCacher cache = new RrdCacher(); + RrdPrimitive(RrdUpdater updater, int type) throws IOException { this(updater, type, 1); *************** *** 109,111 **** --- 111,117 ---- backend.writeString(pointer, value); } + + void clearCache() { + cache.clearCache(); + } } Index: RrdInt.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/core/RrdInt.java,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** RrdInt.java 20 May 2004 10:29:33 -0000 1.8 --- RrdInt.java 29 Jun 2004 12:59:35 -0000 1.9 *************** *** 29,34 **** class RrdInt extends RrdPrimitive { - RrdCacher cache = new RrdCacher(); - RrdInt(RrdUpdater updater) throws IOException { super(updater, RrdPrimitive.RRD_INT); --- 29,32 ---- Index: RrdDouble.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/core/RrdDouble.java,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** RrdDouble.java 20 May 2004 10:29:33 -0000 1.8 --- RrdDouble.java 29 Jun 2004 12:59:35 -0000 1.9 *************** *** 29,34 **** class RrdDouble extends RrdPrimitive { - private RrdCacher cache = new RrdCacher(); - RrdDouble(RrdUpdater updater) throws IOException { super(updater, RrdDouble.RRD_DOUBLE); --- 29,32 ---- |
From: Sasa M. <sa...@us...> - 2004-06-29 12:28:18
|
Update of /cvsroot/jrobin/src/org/jrobin/core In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4370/org/jrobin/core Modified Files: RrdMemoryBackend.java Log Message: Fixed problem with thread synchronization with in-memory backends Index: RrdMemoryBackend.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/core/RrdMemoryBackend.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** RrdMemoryBackend.java 29 Jun 2004 09:02:22 -0000 1.3 --- RrdMemoryBackend.java 29 Jun 2004 12:28:09 -0000 1.4 *************** *** 38,42 **** } ! protected void write(long offset, byte[] b) throws IOException { int pos = (int) offset; for(int i = 0; i < b.length; i++) { --- 38,42 ---- } ! protected synchronized void write(long offset, byte[] b) throws IOException { int pos = (int) offset; for(int i = 0; i < b.length; i++) { *************** *** 45,49 **** } ! protected void read(long offset, byte[] b) throws IOException { int pos = (int) offset; if(pos + b.length <= buffer.length) { --- 45,49 ---- } ! protected synchronized void read(long offset, byte[] b) throws IOException { int pos = (int) offset; if(pos + b.length <= buffer.length) { |
From: Sasa M. <sa...@us...> - 2004-06-29 12:21:13
|
Update of /cvsroot/jrobin/src/org/jrobin/core In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv3086/org/jrobin/core Modified Files: RrdFileBackend.java Log Message: Minor change in the code to disallow R/W access to the same file from two different RrdDb objects Index: RrdFileBackend.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/core/RrdFileBackend.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** RrdFileBackend.java 29 Jun 2004 09:02:22 -0000 1.5 --- RrdFileBackend.java 29 Jun 2004 12:20:55 -0000 1.6 *************** *** 31,34 **** --- 31,35 ---- import java.nio.channels.FileChannel; import java.nio.channels.FileLock; + import java.util.HashSet; /** *************** *** 41,44 **** --- 42,47 ---- static final long LOCK_DELAY = 100; // 0.1sec + private static HashSet openFiles = new HashSet(); + protected RandomAccessFile file; protected FileLock fileLock; *************** *** 46,49 **** --- 49,55 ---- protected RrdFileBackend(String path, boolean readOnly, int lockMode) throws IOException { super(path); + if(!readOnly) { + registerWriter(path); + } file = new RandomAccessFile(path, readOnly? "r": "rw"); // We'll try to lock the file only in "rw" mode *************** *** 54,57 **** --- 60,74 ---- } + private static synchronized void registerWriter(String path) throws IOException { + String canonicalPath = getCanonicalPath(path); + if(openFiles.contains(canonicalPath)) { + throw new IOException("File \"" + path + "\" already open for R/W access. " + + "You cannot open the same file for R/W access twice"); + } + else { + openFiles.add(canonicalPath); + } + } + private void lockFile(int lockMode) throws IOException { if(lockMode == RrdDb.WAIT_IF_LOCKED || lockMode == RrdDb.EXCEPTION_IF_LOCKED) { *************** *** 86,89 **** --- 103,112 ---- unlockFile(); file.close(); + unregisterWriter(getPath()); + } + + private static synchronized void unregisterWriter(String path) throws IOException { + String canonicalPath = getCanonicalPath(path); + openFiles.remove(canonicalPath); } |
From: Sasa M. <sa...@us...> - 2004-06-29 11:31:05
|
Update of /cvsroot/jrobin/src/org/jrobin/core In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv26513/org/jrobin/core Modified Files: RrdDb.java Log Message: minor changes Index: RrdDb.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/core/RrdDb.java,v retrieving revision 1.21 retrieving revision 1.22 diff -C2 -d -r1.21 -r1.22 *** RrdDb.java 29 Jun 2004 09:34:38 -0000 1.21 --- RrdDb.java 29 Jun 2004 11:30:55 -0000 1.22 *************** *** 914,921 **** * memory or with custom backends. * @return Canonical path to RRD file; ! * @throws IOException Thrown in case of I/O error. */ public String getCanonicalPath() throws IOException { ! return ((RrdFileBackend) backend).getCanonicalPath(); } --- 914,927 ---- * memory or with custom backends. * @return Canonical path to RRD file; ! * @throws IOException Thrown in case of I/O error or if the underlying backend is ! * not derived from RrdFileBackend. */ public String getCanonicalPath() throws IOException { ! if(backend instanceof RrdFileBackend) { ! return ((RrdFileBackend) backend).getCanonicalPath(); ! } ! else { ! throw new IOException("The underlying backend has no canonical path"); ! } } |
From: Arne V. <cob...@us...> - 2004-06-29 11:30:31
|
Update of /cvsroot/jrobin/src/org/jrobin/core In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv26403/org/jrobin/core Added Files: RrdOpener.java Log Message: JRobin 1.4.0 - Added RrdOpener to core --- NEW FILE: RrdOpener.java --- /* ============================================================ * JRobin : Pure java implementation of RRDTool's functionality * ============================================================ * * Project Info: http://www.jrobin.org * Project Lead: Sasa Markovic (sa...@jr...) * * Developers: Sasa Markovic (sa...@jr...) * Arne Vandamme (cob...@jr...) * * (C) Copyright 2003, by Sasa Markovic. * * This library is free software; you can redistribute it and/or modify it under the terms * of the GNU Lesser General Public License as published by the Free Software Foundation; * either version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License along with this * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, * Boston, MA 02111-1307, USA. */ package org.jrobin.core; import java.io.IOException; /** * <p>Class that represents an object that can be used to perform the actual * opening and closing of RRD files, using different methods. Other objects * like the FetchSourceList representing the Graph datasources * ({@link org.jrobin.graph.FetchSourceList}) use a RrdOpener to retrieve the RrdDb instances of * RRD datasources.</p> * <p>Overriding the RrdOpener class allows finetuned access on the level * of RrdDb retrieval and release. An child class could for example add * log or debug statements, gather statistics on RRD access, or provide * a transparent way to to access RRD datasources in an alternative way * like through a DBMS. </p> * * @author Arne Vandamme (cob...@jr...) */ public class RrdOpener { // ================================================================ // -- Members // ================================================================ protected RrdDbPool pool; protected boolean readOnly = false; protected boolean usePool = false; // ================================================================ // -- Constructors // ================================================================ /** * Creates a new RrdOpener that will open RrdDb objects with read/write * access. If the usePool flag is set, the RrdOpener will use the RrdDbPool * to retrieve RrdDb instances. * @param usePool True if the RrdOpener should use the RrdDbPool. */ public RrdOpener( boolean usePool ) { this.usePool = usePool; if ( usePool ) pool = RrdDbPool.getInstance(); } /** * Creates a new RrdOpener that will open RrdDb objects with read/write * or read-only access, depending on the readOnly flag.. If the usePool * flag is set, the RrdOpener will use the RrdDbPool to retrieve RrdDb * instances. * @param usePool True if the RrdOpener should use the RrdDbPool. * @param readOnly True if the RrdOpener should open RrdDb objects as read-only. */ public RrdOpener( boolean usePool, boolean readOnly ) { this( usePool ); this.readOnly = readOnly; } // ================================================================ // -- Public methods // ================================================================ /** * Retrieves the RrdDb instance matching a specific RRD datasource name * (usually a file name) and using a specified RrdBackendFactory. * * @param rrdFile Name of the RRD datasource. * @param backendFactory BackendFactory to use for retrieval. * @return RrdDb instance of the datasource. * @throws IOException Thrown in case of I/O error. * @throws RrdException Thrown in case of a JRobin specific error. */ public RrdDb getRrd( String rrdFile, RrdBackendFactory backendFactory ) throws IOException, RrdException { if ( pool != null ) return pool.requestRrdDb( rrdFile ); else return new RrdDb( rrdFile, readOnly, backendFactory ); } /** * Releases an RrdDb instance. Depending on the settings of the RrdOpener, * this either closes the RrdDb, or releases it back into the RrdDbPool. * @param rrdDb RrdDb object that should be released. * @throws IOException Thrown in case of I/O error. * @throws RrdException Thrown in case of a JRobin specific error. */ public void releaseRrd(RrdDb rrdDb) throws IOException, RrdException { if ( pool != null ) pool.release(rrdDb); else rrdDb.close(); } } |
From: Arne V. <cob...@us...> - 2004-06-29 09:34:54
|
Update of /cvsroot/jrobin/src/org/jrobin/graph In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4435/org/jrobin/graph Modified Files: FetchSource.java FetchSourceList.java Grapher.java RrdGraph.java RrdGraphDef.java TimeAxisLabel.java Log Message: JRobin 1.4.0 - Moved RrdOpener to core package - Fixed Javadoc comments - Fixed 0 end timestamp Index: Grapher.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/graph/Grapher.java,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** Grapher.java 9 Jun 2004 07:35:36 -0000 1.13 --- Grapher.java 29 Jun 2004 09:34:39 -0000 1.14 *************** *** 379,383 **** if ( changingEndTime ) { ! endTime = src.getLastSampleTime( endTime ); if ( endTime > finalEndTime ) --- 379,383 ---- if ( changingEndTime ) { ! endTime = src.getLastSampleTime( startTime, endTime, graphDef.getResolution() ); if ( endTime > finalEndTime ) Index: FetchSourceList.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/graph/FetchSourceList.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** FetchSourceList.java 9 Jun 2004 07:43:15 -0000 1.1 --- FetchSourceList.java 29 Jun 2004 09:34:39 -0000 1.2 *************** *** 31,34 **** --- 31,35 ---- import org.jrobin.core.RrdException; import org.jrobin.core.RrdDb; + import org.jrobin.core.RrdOpener; /** *************** *** 248,253 **** /** ! * Adds a datasource for graphing purposes to the list, ! * {@see RrdGraphDef#datasource( java.lang.String, java.lang.String, * java.lang.String, java.lang.String, java.lang.String )}. --- 249,254 ---- /** ! * Adds a datasource for graphing purposes to the list, see ! * {@link RrdGraphDef#datasource( java.lang.String, java.lang.String, * java.lang.String, java.lang.String, java.lang.String )}. *************** *** 278,283 **** /** ! * Adds a datasource for graphing purposes to the list, ! * {@see RrdGraphDef#datasource( java.lang.String, java.lang.String, * java.lang.String, java.lang.String )}. * --- 279,284 ---- /** ! * Adds a datasource for graphing purposes to the list, see ! * {@link RrdGraphDef#datasource( java.lang.String, java.lang.String, * java.lang.String, java.lang.String )}. * Index: RrdGraph.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/graph/RrdGraph.java,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** RrdGraph.java 9 Jun 2004 07:35:36 -0000 1.9 --- RrdGraph.java 29 Jun 2004 09:34:39 -0000 1.10 *************** *** 25,29 **** package org.jrobin.graph; - import javax.swing.JPanel; import java.util.Iterator; import java.io.File; --- 25,28 ---- *************** *** 41,48 **** import java.awt.*; ! import org.jrobin.core.RrdDb; ! import org.jrobin.core.RrdDbPool; import org.jrobin.core.RrdException; - import org.jrobin.core.RrdBackendFactory; /** --- 40,45 ---- import java.awt.*; ! import org.jrobin.core.RrdOpener; import org.jrobin.core.RrdException; /** Index: TimeAxisLabel.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/graph/TimeAxisLabel.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** TimeAxisLabel.java 1 Mar 2004 08:50:25 -0000 1.3 --- TimeAxisLabel.java 29 Jun 2004 09:34:39 -0000 1.4 *************** *** 53,60 **** if ( !super.isCompleteLine() ) { oList.add( "" ); ! oList.add( super.TKN_ACF ); oList.add( "" ); ! oList.add( super.TKN_ALF ); this.lineCount += 2; --- 53,60 ---- if ( !super.isCompleteLine() ) { oList.add( "" ); ! oList.add( TimeAxisLabel.TKN_ACF ); oList.add( "" ); ! oList.add( TimeAxisLabel.TKN_ALF ); this.lineCount += 2; Index: FetchSource.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/graph/FetchSource.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** FetchSource.java 9 Jun 2004 07:35:36 -0000 1.6 --- FetchSource.java 29 Jun 2004 09:34:39 -0000 1.7 *************** *** 53,56 **** --- 53,57 ---- private RrdDb rrd; + private RrdDef rrdDef; private String rrdFile; // Holds the name of the RRD file *************** *** 172,176 **** String[] dsNames, vNames; ! long rrdStep = rrd.getRrdDef().getStep(); FetchData[] result = new FetchData[datasources.length]; --- 173,177 ---- String[] dsNames, vNames; ! long rrdStep = rrdDef.getStep(); FetchData[] result = new FetchData[datasources.length]; *************** *** 182,186 **** dsSize = datasources[i].size(); ! if ( dsSize > 0 ) { // Set the list of ds names dsNames = new String[ dsSize ]; --- 183,188 ---- dsSize = datasources[i].size(); ! if ( dsSize > 0 ) ! { // Set the list of ds names dsNames = new String[ dsSize ]; *************** *** 223,227 **** if ( rrd == null ) { ! RrdOpener opener = listReference.getRrdOpener(); if ( opener == null ) --- 225,229 ---- if ( rrd == null ) { ! org.jrobin.core.RrdOpener opener = listReference.getRrdOpener(); if ( opener == null ) *************** *** 231,234 **** --- 233,238 ---- if ( rrd == null ) rrd = opener.getRrd( rrdFile, getRrdBackendFactory() ); + + rrdDef = rrd.getRrdDef(); } } *************** *** 263,267 **** if ( rrd != null ) { ! RrdOpener opener = listReference.getRrdOpener(); if ( opener == null ) --- 267,271 ---- if ( rrd != null ) { ! org.jrobin.core.RrdOpener opener = listReference.getRrdOpener(); if ( opener == null ) *************** *** 280,296 **** * timestamp of the last non-unknown sample! * * @param endTime Timestamp for which the last sample time should be calculated. * @return Last sample timestamp in seconds. * @throws IOException Thrown in case of fetching I/O error. * @throws RrdException Thrown in case of a JRobin specific error. */ ! protected long getLastSampleTime( long endTime ) throws RrdException, IOException { if ( rrd == null ) openRrd(); ! long step = rrd.getRrdDef().getStep(); ! return endTime = rrd.getLastUpdateTime() - (endTime % step) - step; } --- 284,313 ---- * timestamp of the last non-unknown sample! * + * @param startTime Timestamp for which the last sample time should be calculated. * @param endTime Timestamp for which the last sample time should be calculated. + * @param resolution Last timestamp for this particular fetch resolution. * @return Last sample timestamp in seconds. * @throws IOException Thrown in case of fetching I/O error. * @throws RrdException Thrown in case of a JRobin specific error. */ ! protected long getLastSampleTime( long startTime, long endTime, long resolution ) throws RrdException, IOException { if ( rrd == null ) openRrd(); ! long maxSampleTime = 0, sampleTime = 0; ! for ( int i = 0; i < datasources.length; i++ ) ! { ! if ( datasources[i].size() > 0 ) ! { ! sampleTime = rrd.findStartMatchArchive( cfNames[i], startTime, resolution ).getEndTime(); ! if ( sampleTime > maxSampleTime ) ! maxSampleTime = sampleTime; ! } ! } ! ! // Remove a single sample step (we'll add it again later on) ! return maxSampleTime - rrdDef.getStep(); } Index: RrdGraphDef.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/graph/RrdGraphDef.java,v retrieving revision 1.15 retrieving revision 1.16 diff -C2 -d -r1.15 -r1.16 *** RrdGraphDef.java 9 Jun 2004 07:35:36 -0000 1.15 --- RrdGraphDef.java 29 Jun 2004 09:34:39 -0000 1.16 *************** *** 586,590 **** /** ! * This sets the lower limit of the grid to the specified value {@see setGridRange}. * This is the equivalent of: <code>setGridRange( lower, Double.NaN, false );</code> * @param lower Lower limit. --- 586,590 ---- /** ! * This sets the lower limit of the grid to the specified value, see {@link RrdGraphDef#setGridRange(double, double, boolean)}. * This is the equivalent of: <code>setGridRange( lower, Double.NaN, false );</code> * @param lower Lower limit. *************** *** 704,708 **** * <p>Clears the list of RRD datasources for this GraphDef and sets it to the FetchSourceList * passed as aparameter. This does not alter any Cdef, Sdef or Pdef definitions. The datasources ! * should be passed on as a FetchSourceList {@see FetchSourceList}.</p> * @param datasourceList FetchSourceList of the datasources to use. */ --- 704,708 ---- * <p>Clears the list of RRD datasources for this GraphDef and sets it to the FetchSourceList * passed as aparameter. This does not alter any Cdef, Sdef or Pdef definitions. The datasources ! * should be passed on as a FetchSourceList {@link FetchSourceList}.</p> * @param datasourceList FetchSourceList of the datasources to use. */ *************** *** 1131,1137 **** /** ! * Exports RrdGraphDef (graph definition) object in XML format to string. ! * Generated code can be parsed with {@link RrdGraphDefTemplate} class ! * {@see exportXmlTemplate}. * * @return String representing graph definition in XML format --- 1131,1137 ---- /** ! * Exports RrdGraphDef (graph definition) object in XML format to string. ! * Generated code can be parsed with {@link RrdGraphDefTemplate} class, see ! * {@link RrdGraphDef#exportXmlTemplate()}. * * @return String representing graph definition in XML format *************** *** 1140,1143 **** --- 1140,1144 ---- return exportXmlTemplate(); } + /** * Exports RrdGraphDef (graph definition) object in XML format to string. |
From: Arne V. <cob...@us...> - 2004-06-29 09:34:53
|
Update of /cvsroot/jrobin/src/org/jrobin/core In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4435/org/jrobin/core Modified Files: RrdDb.java Log Message: JRobin 1.4.0 - Moved RrdOpener to core package - Fixed Javadoc comments - Fixed 0 end timestamp Index: RrdDb.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/core/RrdDb.java,v retrieving revision 1.20 retrieving revision 1.21 diff -C2 -d -r1.20 -r1.21 *** RrdDb.java 9 Jun 2004 12:10:29 -0000 1.20 --- RrdDb.java 29 Jun 2004 09:34:38 -0000 1.21 *************** *** 552,555 **** --- 552,598 ---- /** + * Finds the archive that best matches to the start time (time period being start-time until now) + * and requested resolution. + * @param consolFun Consolidation function of the datasource. + * @param startTime Start time of the time period in seconds. + * @param resolution Requested fetch resolution. + * @return Reference to the best matching archive. + * @throws IOException Thrown in case of I/O related error. + */ + public Archive findStartMatchArchive( String consolFun, long startTime, long resolution ) throws IOException { + long arcStep, diff; + int fallBackIndex = 0; + int arcIndex = -1; + long minDiff = Long.MAX_VALUE; + long fallBackDiff = Long.MAX_VALUE; + + for ( int i = 0; i < archives.length; i++ ) + { + if ( archives[i].getConsolFun().equals(consolFun) ) + { + arcStep = archives[i].getArcStep(); + diff = Math.abs( resolution - arcStep ); + + // Now compare start time, see if this archive encompasses the requested interval + if ( startTime >= archives[i].getStartTime() ) + { + if ( diff == 0 ) // Best possible match either way + return archives[i]; + else if ( diff < minDiff ) { + minDiff = diff; + arcIndex = i; + } + } + else if ( diff < fallBackDiff ) { + fallBackDiff = diff; + fallBackIndex = i; + } + } + } + + return ( arcIndex >= 0 ? archives[arcIndex] : archives[fallBackIndex] ); + } + + /** * <p>Returns string representing complete internal RRD state. The returned * string can be printed to <code>stdout</code> and/or used for debugging purposes.</p> |
From: Sasa M. <sa...@us...> - 2004-06-29 09:02:37
|
Update of /cvsroot/jrobin/src/org/jrobin/core In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30557/org/jrobin/core Modified Files: RrdBackend.java RrdFileBackend.java RrdMemoryBackend.java RrdNioBackend.java Log Message: minor changes Index: RrdBackend.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/core/RrdBackend.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** RrdBackend.java 2 Jun 2004 07:20:12 -0000 1.6 --- RrdBackend.java 29 Jun 2004 09:02:22 -0000 1.7 *************** *** 188,192 **** * @throws IOException Thrown in case of I/O error */ ! protected void sync() throws IOException { } --- 188,192 ---- * @throws IOException Thrown in case of I/O error */ ! public void sync() throws IOException { } Index: RrdNioBackend.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/core/RrdNioBackend.java,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** RrdNioBackend.java 2 Jun 2004 07:20:13 -0000 1.7 --- RrdNioBackend.java 29 Jun 2004 09:02:22 -0000 1.8 *************** *** 43,47 **** private TimerTask syncTask; ! RrdNioBackend(String path, boolean readOnly, int lockMode, int syncMode, int syncPeriod) throws IOException { super(path, readOnly, lockMode); --- 43,47 ---- private TimerTask syncTask; ! protected RrdNioBackend(String path, boolean readOnly, int lockMode, int syncMode, int syncPeriod) throws IOException { super(path, readOnly, lockMode); *************** *** 116,120 **** * method is called. In other words, you don't have to call sync() before you call close().<p> */ ! protected void sync() { synchronized(byteBuffer) { // System.out.println("** SYNC **"); --- 116,120 ---- * method is called. In other words, you don't have to call sync() before you call close().<p> */ ! public void sync() { synchronized(byteBuffer) { // System.out.println("** SYNC **"); Index: RrdMemoryBackend.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/core/RrdMemoryBackend.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** RrdMemoryBackend.java 21 May 2004 10:40:50 -0000 1.2 --- RrdMemoryBackend.java 29 Jun 2004 09:02:22 -0000 1.3 *************** *** 34,38 **** private byte[] buffer = new byte[0]; ! RrdMemoryBackend(String path) { super(path); } --- 34,38 ---- private byte[] buffer = new byte[0]; ! protected RrdMemoryBackend(String path) { super(path); } Index: RrdFileBackend.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/core/RrdFileBackend.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** RrdFileBackend.java 1 Jun 2004 14:41:01 -0000 1.4 --- RrdFileBackend.java 29 Jun 2004 09:02:22 -0000 1.5 *************** *** 44,48 **** protected FileLock fileLock; ! RrdFileBackend(String path, boolean readOnly, int lockMode) throws IOException { super(path); file = new RandomAccessFile(path, readOnly? "r": "rw"); --- 44,48 ---- protected FileLock fileLock; ! protected RrdFileBackend(String path, boolean readOnly, int lockMode) throws IOException { super(path); file = new RandomAccessFile(path, readOnly? "r": "rw"); |
From: Sasa M. <sa...@us...> - 2004-06-11 07:59:06
|
Update of /cvsroot/jrobin/src/org/jrobin/demo In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv1827/org/jrobin/demo Modified Files: PlottableDemo.java Log Message: minor changes Index: PlottableDemo.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/demo/PlottableDemo.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** PlottableDemo.java 9 Jun 2004 12:09:23 -0000 1.1 --- PlottableDemo.java 11 Jun 2004 07:58:51 -0000 1.2 *************** *** 74,77 **** --- 74,78 ---- createGraph15(); createGraph16(); + createGraph17(); } *************** *** 96,114 **** CubicSplineInterpolator i2 = new CubicSplineInterpolator(t, x); // graph definition ! RrdGraphDef gdef = new RrdGraphDef(t0, t1); ! gdef.setTitle("Plottable demonstration"); ! gdef.setTimeAxisLabel("days of our lives"); ! gdef.setVerticalLabel("inspiration"); ! gdef.datasource("real", p); ! gdef.datasource("linear", i1); ! gdef.datasource("spline", i2); ! gdef.line("real", Color.BLUE, "Real values", 1); ! gdef.line("linear", Color.RED, "Linear interpolation", 1); ! gdef.line("spline", Color.MAGENTA, "Spline interpolation@r", 1); ! gdef.setTimeAxis(TimeAxisUnit.DAY, 1, TimeAxisUnit.DAY, 1, "dd", true); ! RrdGraph g = new RrdGraph(gdef); ! String filename = Util.getJRobinDemoPath("plottable1.png"); ! g.saveAsPNG(filename, 400, 200); ! System.out.println("Graph1 saved to " + filename); } --- 97,112 ---- CubicSplineInterpolator i2 = new CubicSplineInterpolator(t, x); // graph definition ! RrdGraphDef gDef = new RrdGraphDef(t0, t1); ! gDef.setTitle("Plottable demonstration"); ! gDef.setTimeAxisLabel("days of our lives"); ! gDef.setVerticalLabel("inspiration"); ! gDef.datasource("real", p); ! gDef.datasource("linear", i1); ! gDef.datasource("spline", i2); ! gDef.line("real", Color.BLUE, "Real values", 1); ! gDef.line("linear", Color.RED, "Linear interpolation", 1); ! gDef.line("spline", Color.MAGENTA, "Spline interpolation@r", 1); ! gDef.setTimeAxis(TimeAxisUnit.DAY, 1, TimeAxisUnit.DAY, 1, "dd", true); ! createGraph(gDef); } *************** *** 138,145 **** gDef.gprint("spline", "AVERAGE", "Average spline value: @0 inches@r"); gDef.gprint("linear", "AVERAGE", "Average linear value: @0 inches@r"); ! RrdGraph graph = new RrdGraph(gDef); ! String filename = Util.getJRobinDemoPath("plottable2.png"); ! graph.saveAsPNG(filename, 300, 100); ! System.out.println("Graph2 saved to " + filename); } --- 136,140 ---- gDef.gprint("spline", "AVERAGE", "Average spline value: @0 inches@r"); gDef.gprint("linear", "AVERAGE", "Average linear value: @0 inches@r"); ! createGraph(gDef); } *************** *** 156,163 **** gDef.setTimeAxis(TimeAxisUnit.MONTH, 1, TimeAxisUnit.MONTH, 1, "MMM", false); gDef.comment("Data provided by SourceForge.net@r"); ! RrdGraph graph = new RrdGraph(gDef); ! String filename = Util.getJRobinDemoPath("plottable3.png"); ! graph.saveAsPNG(filename, 400, 200); ! System.out.println("Graph3 saved to " + filename); } --- 151,155 ---- gDef.setTimeAxis(TimeAxisUnit.MONTH, 1, TimeAxisUnit.MONTH, 1, "MMM", false); gDef.comment("Data provided by SourceForge.net@r"); ! createGraph(gDef); } *************** *** 174,181 **** gDef.setTimeAxis(TimeAxisUnit.MONTH, 1, TimeAxisUnit.MONTH, 1, "MMM", false); gDef.comment("Data provided by SourceForge.net@r"); ! RrdGraph graph = new RrdGraph(gDef); ! String filename = Util.getJRobinDemoPath("plottable4.png"); ! graph.saveAsPNG(filename, 400, 200); ! System.out.println("Graph4 saved to " + filename); } --- 166,170 ---- gDef.setTimeAxis(TimeAxisUnit.MONTH, 1, TimeAxisUnit.MONTH, 1, "MMM", false); gDef.comment("Data provided by SourceForge.net@r"); ! createGraph(gDef); } *************** *** 200,215 **** gDef.gprint("ratio", "AVERAGE", "Average number of page hits per download: @0@r"); gDef.comment("Data provided by SourceForge.net@r"); ! RrdGraph graph = new RrdGraph(gDef); ! String filename = Util.getJRobinDemoPath("plottable5.png"); ! graph.saveAsPNG(filename, 400, 200); ! System.out.println("Graph5 saved to " + filename); } private void createGraph6() throws RrdException, IOException { CubicSplineInterpolator hitsInterpolator = new CubicSplineInterpolator(SF_TIMESTAMPS, SF_PAGE_HITS); RrdGraphDef gDef = new RrdGraphDef(SF_TIMESTAMPS[0], SF_TIMESTAMPS[SF_TIMESTAMPS.length - 1]); ! gDef.setTitle("Trick graph 1"); gDef.setTimeAxisLabel("month"); gDef.setVerticalLabel("hits"); --- 189,223 ---- gDef.gprint("ratio", "AVERAGE", "Average number of page hits per download: @0@r"); gDef.comment("Data provided by SourceForge.net@r"); ! createGraph(gDef); } private void createGraph6() throws RrdException, IOException { + LinearInterpolator hitsInterpolator = + new LinearInterpolator(SF_TIMESTAMPS, SF_PAGE_HITS); + LinearInterpolator trendInterpolator = new LinearInterpolator(SF_TIMESTAMPS, SF_PAGE_HITS); + trendInterpolator.setInterpolationMethod(LinearInterpolator.INTERPOLATE_REGRESSION); + RrdGraphDef gDef = new RrdGraphDef(SF_TIMESTAMPS[0], SF_TIMESTAMPS[SF_TIMESTAMPS.length - 1]); + gDef.setTitle("Trend report"); + gDef.setTimeAxisLabel("month"); + gDef.setVerticalLabel("hits"); + gDef.datasource("hits", hitsInterpolator); + gDef.datasource("trend", trendInterpolator); + gDef.datasource("diff", "hits,trend,-"); + gDef.datasource("absdiff", "diff,ABS"); + gDef.area("trend", null, null); + gDef.stack("diff", Color.YELLOW, "difference"); + gDef.line("hits", Color.RED, "real page hits"); + gDef.line("trend", Color.BLUE, "trend@L"); + gDef.gprint("absdiff", "AVERAGE", "Average difference: @0@r"); + gDef.setTimeAxis(TimeAxisUnit.MONTH, 1, TimeAxisUnit.MONTH, 1, "MMM", false); + createGraph(gDef); + } + + private void createGraph7() throws RrdException, IOException { CubicSplineInterpolator hitsInterpolator = new CubicSplineInterpolator(SF_TIMESTAMPS, SF_PAGE_HITS); RrdGraphDef gDef = new RrdGraphDef(SF_TIMESTAMPS[0], SF_TIMESTAMPS[SF_TIMESTAMPS.length - 1]); ! gDef.setTitle("Trick graph"); gDef.setTimeAxisLabel("month"); gDef.setVerticalLabel("hits"); *************** *** 223,238 **** gDef.line("hits", Color.WHITE, null, 1); gDef.setTimeAxis(TimeAxisUnit.MONTH, 1, TimeAxisUnit.MONTH, 1, "MMM", false); ! RrdGraph graph = new RrdGraph(gDef); ! String filename = Util.getJRobinDemoPath("plottable6.png"); ! graph.saveAsPNG(filename, 400, 200); ! System.out.println("Graph6 saved to " + filename); } ! private void createGraph7() throws RrdException, IOException { CubicSplineInterpolator hitsInterpolator = ! new CubicSplineInterpolator(SF_TIMESTAMPS, SF_PAGE_HITS); RrdGraphDef gDef = new RrdGraphDef(SF_TIMESTAMPS[0], SF_TIMESTAMPS[SF_TIMESTAMPS.length - 1]); ! gDef.setTitle("Trick graph 2"); gDef.setTimeAxisLabel("month"); gDef.setVerticalLabel("hits"); --- 231,243 ---- gDef.line("hits", Color.WHITE, null, 1); gDef.setTimeAxis(TimeAxisUnit.MONTH, 1, TimeAxisUnit.MONTH, 1, "MMM", false); ! createGraph(gDef); } ! private void createGraph8() throws RrdException, IOException { CubicSplineInterpolator hitsInterpolator = ! new CubicSplineInterpolator(SF_TIMESTAMPS, SF_PAGE_HITS); RrdGraphDef gDef = new RrdGraphDef(SF_TIMESTAMPS[0], SF_TIMESTAMPS[SF_TIMESTAMPS.length - 1]); ! gDef.setTitle("Trick graph"); gDef.setTimeAxisLabel("month"); gDef.setVerticalLabel("hits"); *************** *** 251,261 **** gDef.setTimeAxis(TimeAxisUnit.MONTH, 1, TimeAxisUnit.MONTH, 1, "MMM", false); gDef.gprint("hits", "AVERAGE", "Average: @0@r"); ! RrdGraph graph = new RrdGraph(gDef); ! String filename = Util.getJRobinDemoPath("plottable7.png"); ! graph.saveAsPNG(filename, 400, 200); ! System.out.println("Graph7 saved to " + filename); } ! private void createGraph8() throws RrdException, IOException { GregorianCalendar[] times = { SF_TIMESTAMPS[0], SF_TIMESTAMPS[SF_TIMESTAMPS.length - 1] }; double[] values = { SF_PAGE_HITS[0], SF_PAGE_HITS[SF_PAGE_HITS.length - 1] }; --- 256,263 ---- gDef.setTimeAxis(TimeAxisUnit.MONTH, 1, TimeAxisUnit.MONTH, 1, "MMM", false); gDef.gprint("hits", "AVERAGE", "Average: @0@r"); ! createGraph(gDef); } ! private void createGraph9() throws RrdException, IOException { GregorianCalendar[] times = { SF_TIMESTAMPS[0], SF_TIMESTAMPS[SF_TIMESTAMPS.length - 1] }; double[] values = { SF_PAGE_HITS[0], SF_PAGE_HITS[SF_PAGE_HITS.length - 1] }; *************** *** 265,269 **** RrdGraphDef gDef = new RrdGraphDef(SF_TIMESTAMPS[0], SF_TIMESTAMPS[SF_TIMESTAMPS.length - 1]); ! gDef.setTitle("Trick graph 3"); gDef.setTimeAxisLabel("month"); gDef.setVerticalLabel("hits"); --- 267,271 ---- RrdGraphDef gDef = new RrdGraphDef(SF_TIMESTAMPS[0], SF_TIMESTAMPS[SF_TIMESTAMPS.length - 1]); ! gDef.setTitle("Trick graph"); gDef.setTimeAxisLabel("month"); gDef.setVerticalLabel("hits"); *************** *** 276,286 **** gDef.line("trend", Color.RED, "trend@L"); gDef.setTimeAxis(TimeAxisUnit.MONTH, 1, TimeAxisUnit.MONTH, 1, "MMM", false); ! RrdGraph graph = new RrdGraph(gDef); ! String filename = Util.getJRobinDemoPath("plottable8.png"); ! graph.saveAsPNG(filename, 400, 200); ! System.out.println("Graph8 saved to " + filename); } ! private void createGraph9() throws RrdException, IOException { final int GRADIENT_STEPS = 30; final Color color1 = Color.RED, color2 = Color.YELLOW; --- 278,285 ---- gDef.line("trend", Color.RED, "trend@L"); gDef.setTimeAxis(TimeAxisUnit.MONTH, 1, TimeAxisUnit.MONTH, 1, "MMM", false); ! createGraph(gDef); } ! private void createGraph10() throws RrdException, IOException { final int GRADIENT_STEPS = 30; final Color color1 = Color.RED, color2 = Color.YELLOW; *************** *** 288,292 **** new CubicSplineInterpolator(SF_TIMESTAMPS, SF_PAGE_HITS); RrdGraphDef gDef = new RrdGraphDef(SF_TIMESTAMPS[0], SF_TIMESTAMPS[SF_TIMESTAMPS.length - 1]); ! gDef.setTitle("Trick graph 4"); gDef.setTimeAxisLabel("month"); gDef.setVerticalLabel("hits"); --- 287,291 ---- new CubicSplineInterpolator(SF_TIMESTAMPS, SF_PAGE_HITS); RrdGraphDef gDef = new RrdGraphDef(SF_TIMESTAMPS[0], SF_TIMESTAMPS[SF_TIMESTAMPS.length - 1]); ! gDef.setTitle("Trick graph"); gDef.setTimeAxisLabel("month"); gDef.setVerticalLabel("hits"); *************** *** 301,311 **** gDef.line("hits", Color.BLACK, "Number of page hits"); gDef.setTimeAxis(TimeAxisUnit.MONTH, 1, TimeAxisUnit.MONTH, 1, "MMM", false); ! RrdGraph graph = new RrdGraph(gDef); ! String filename = Util.getJRobinDemoPath("plottable9.png"); ! graph.saveAsPNG(filename, 400, 200); ! System.out.println("Graph9 saved to " + filename); } ! private void createGraph10() throws RrdException, IOException { final int GRADIENT_STEPS = 30; final Color color1 = Color.RED, color2 = Color.YELLOW; --- 300,307 ---- gDef.line("hits", Color.BLACK, "Number of page hits"); gDef.setTimeAxis(TimeAxisUnit.MONTH, 1, TimeAxisUnit.MONTH, 1, "MMM", false); ! createGraph(gDef); } ! private void createGraph11() throws RrdException, IOException { final int GRADIENT_STEPS = 30; final Color color1 = Color.RED, color2 = Color.YELLOW; *************** *** 313,317 **** new CubicSplineInterpolator(SF_TIMESTAMPS, SF_PAGE_HITS); RrdGraphDef gDef = new RrdGraphDef(SF_TIMESTAMPS[0], SF_TIMESTAMPS[SF_TIMESTAMPS.length - 1]); ! gDef.setTitle("Trick graph 5"); gDef.setTimeAxisLabel("month"); gDef.setVerticalLabel("hits"); --- 309,313 ---- new CubicSplineInterpolator(SF_TIMESTAMPS, SF_PAGE_HITS); RrdGraphDef gDef = new RrdGraphDef(SF_TIMESTAMPS[0], SF_TIMESTAMPS[SF_TIMESTAMPS.length - 1]); ! gDef.setTitle("Trick graph"); gDef.setTimeAxisLabel("month"); gDef.setVerticalLabel("hits"); *************** *** 327,337 **** gDef.setTimeAxis(TimeAxisUnit.MONTH, 1, TimeAxisUnit.MONTH, 1, "MMM", false); gDef.setCanvasColor(color1); ! RrdGraph graph = new RrdGraph(gDef); ! String filename = Util.getJRobinDemoPath("plottable10.png"); ! graph.saveAsPNG(filename, 400, 200); ! System.out.println("Graph10 saved to " + filename); } ! private void createGraph11() throws RrdException, IOException { final int GRADIENT_STEPS = 30; final Color color1 = Color.YELLOW, color2 = Color.RED; --- 323,330 ---- gDef.setTimeAxis(TimeAxisUnit.MONTH, 1, TimeAxisUnit.MONTH, 1, "MMM", false); gDef.setCanvasColor(color1); ! createGraph(gDef); } ! private void createGraph12() throws RrdException, IOException { final int GRADIENT_STEPS = 30; final Color color1 = Color.YELLOW, color2 = Color.RED; *************** *** 339,343 **** new CubicSplineInterpolator(SF_TIMESTAMPS, SF_PAGE_HITS); RrdGraphDef gDef = new RrdGraphDef(SF_TIMESTAMPS[0], SF_TIMESTAMPS[SF_TIMESTAMPS.length - 1]); ! gDef.setTitle("Trick graph 6"); gDef.setTimeAxisLabel("month"); gDef.setVerticalLabel("hits"); --- 332,336 ---- new CubicSplineInterpolator(SF_TIMESTAMPS, SF_PAGE_HITS); RrdGraphDef gDef = new RrdGraphDef(SF_TIMESTAMPS[0], SF_TIMESTAMPS[SF_TIMESTAMPS.length - 1]); ! gDef.setTitle("Trick graph"); gDef.setTimeAxisLabel("month"); gDef.setVerticalLabel("hits"); *************** *** 353,363 **** gDef.line("hits", color2, "Estimated number of page hits"); gDef.setTimeAxis(TimeAxisUnit.MONTH, 1, TimeAxisUnit.MONTH, 1, "MMM", false); ! RrdGraph graph = new RrdGraph(gDef); ! String filename = Util.getJRobinDemoPath("plottable11.png"); ! graph.saveAsPNG(filename, 400, 200); ! System.out.println("Graph11 saved to " + filename); } ! private void createGraph12() throws RrdException, IOException { final int GRADIENT_STEPS = 15; final Color color1 = Color.LIGHT_GRAY, color2 = Color.WHITE; --- 346,353 ---- gDef.line("hits", color2, "Estimated number of page hits"); gDef.setTimeAxis(TimeAxisUnit.MONTH, 1, TimeAxisUnit.MONTH, 1, "MMM", false); ! createGraph(gDef); } ! private void createGraph13() throws RrdException, IOException { final int GRADIENT_STEPS = 15; final Color color1 = Color.LIGHT_GRAY, color2 = Color.WHITE; *************** *** 365,369 **** new CubicSplineInterpolator(SF_TIMESTAMPS, SF_PAGE_HITS); RrdGraphDef gDef = new RrdGraphDef(SF_TIMESTAMPS[0], SF_TIMESTAMPS[SF_TIMESTAMPS.length - 1]); ! gDef.setTitle("Trick graph 7"); gDef.setTimeAxisLabel("month"); gDef.setVerticalLabel("hits"); --- 355,359 ---- new CubicSplineInterpolator(SF_TIMESTAMPS, SF_PAGE_HITS); RrdGraphDef gDef = new RrdGraphDef(SF_TIMESTAMPS[0], SF_TIMESTAMPS[SF_TIMESTAMPS.length - 1]); ! gDef.setTitle("Trick graph"); gDef.setTimeAxisLabel("month"); gDef.setVerticalLabel("hits"); *************** *** 375,385 **** gDef.line("hits", color1, "Estimated number of page hits"); gDef.setTimeAxis(TimeAxisUnit.MONTH, 1, TimeAxisUnit.MONTH, 1, "MMM", false); ! RrdGraph graph = new RrdGraph(gDef); ! String filename = Util.getJRobinDemoPath("plottable12.png"); ! graph.saveAsPNG(filename, 400, 200); ! System.out.println("Graph12 saved to " + filename); } ! private void createGraph13() throws RrdException, IOException { final int GRADIENT_STEPS = 20; final double GRADIENT_WIDTH = 2000.0; --- 365,372 ---- gDef.line("hits", color1, "Estimated number of page hits"); gDef.setTimeAxis(TimeAxisUnit.MONTH, 1, TimeAxisUnit.MONTH, 1, "MMM", false); ! createGraph(gDef); } ! private void createGraph14() throws RrdException, IOException { final int GRADIENT_STEPS = 20; final double GRADIENT_WIDTH = 2000.0; *************** *** 388,392 **** new CubicSplineInterpolator(SF_TIMESTAMPS, SF_PAGE_HITS); RrdGraphDef gDef = new RrdGraphDef(SF_TIMESTAMPS[0], SF_TIMESTAMPS[SF_TIMESTAMPS.length - 1]); ! gDef.setTitle("Trick graph 8"); gDef.setTimeAxisLabel("month"); gDef.setVerticalLabel("hits"); --- 375,379 ---- new CubicSplineInterpolator(SF_TIMESTAMPS, SF_PAGE_HITS); RrdGraphDef gDef = new RrdGraphDef(SF_TIMESTAMPS[0], SF_TIMESTAMPS[SF_TIMESTAMPS.length - 1]); ! gDef.setTitle("Trick graph"); gDef.setTimeAxisLabel("month"); gDef.setVerticalLabel("hits"); *************** *** 400,410 **** } gDef.setTimeAxis(TimeAxisUnit.MONTH, 1, TimeAxisUnit.MONTH, 1, "MMM", false); ! RrdGraph graph = new RrdGraph(gDef); ! String filename = Util.getJRobinDemoPath("plottable13.png"); ! graph.saveAsPNG(filename, 400, 200); ! System.out.println("Graph13 saved to " + filename); } ! private void createGraph14() throws RrdException, IOException { final int STEPS = 20; final Color color1 = Color.BLACK, color2 = Color.RED; --- 387,394 ---- } gDef.setTimeAxis(TimeAxisUnit.MONTH, 1, TimeAxisUnit.MONTH, 1, "MMM", false); ! createGraph(gDef); } ! private void createGraph15() throws RrdException, IOException { final int STEPS = 20; final Color color1 = Color.BLACK, color2 = Color.RED; *************** *** 412,416 **** new CubicSplineInterpolator(SF_TIMESTAMPS, SF_PAGE_HITS); RrdGraphDef gDef = new RrdGraphDef(SF_TIMESTAMPS[0], SF_TIMESTAMPS[SF_TIMESTAMPS.length - 1]); ! gDef.setTitle("Trick graph 9"); gDef.setTimeAxisLabel("month"); gDef.setVerticalLabel("hits"); --- 396,400 ---- new CubicSplineInterpolator(SF_TIMESTAMPS, SF_PAGE_HITS); RrdGraphDef gDef = new RrdGraphDef(SF_TIMESTAMPS[0], SF_TIMESTAMPS[SF_TIMESTAMPS.length - 1]); ! gDef.setTitle("Trick graph"); gDef.setTimeAxisLabel("month"); gDef.setVerticalLabel("hits"); *************** *** 425,435 **** gDef.line("hits", Color.BLUE, "page hits", 2); gDef.setTimeAxis(TimeAxisUnit.MONTH, 1, TimeAxisUnit.MONTH, 1, "MMM", false); ! RrdGraph graph = new RrdGraph(gDef); ! String filename = Util.getJRobinDemoPath("plottable14.png"); ! graph.saveAsPNG(filename, 400, 200); ! System.out.println("Graph14 saved to " + filename); } ! private void createGraph15() throws RrdException, IOException { final int STEPS = 20; final Color color1 = Color.BLACK, color2 = Color.RED; --- 409,416 ---- gDef.line("hits", Color.BLUE, "page hits", 2); gDef.setTimeAxis(TimeAxisUnit.MONTH, 1, TimeAxisUnit.MONTH, 1, "MMM", false); ! createGraph(gDef); } ! private void createGraph16() throws RrdException, IOException { final int STEPS = 20; final Color color1 = Color.BLACK, color2 = Color.RED; *************** *** 438,442 **** hitsInterpolator.setInterpolationMethod(LinearInterpolator.INTERPOLATE_LEFT); RrdGraphDef gDef = new RrdGraphDef(SF_TIMESTAMPS[0], SF_TIMESTAMPS[SF_TIMESTAMPS.length - 1]); ! gDef.setTitle("Trick graph 10"); gDef.setTimeAxisLabel("month"); gDef.setVerticalLabel("hits"); --- 419,423 ---- hitsInterpolator.setInterpolationMethod(LinearInterpolator.INTERPOLATE_LEFT); RrdGraphDef gDef = new RrdGraphDef(SF_TIMESTAMPS[0], SF_TIMESTAMPS[SF_TIMESTAMPS.length - 1]); ! gDef.setTitle("Trick graph"); gDef.setTimeAxisLabel("month"); gDef.setVerticalLabel("hits"); *************** *** 451,461 **** gDef.line("hits", Color.BLUE, "page hits", 2); gDef.setTimeAxis(TimeAxisUnit.MONTH, 1, TimeAxisUnit.MONTH, 1, "MMM", false); ! RrdGraph graph = new RrdGraph(gDef); ! String filename = Util.getJRobinDemoPath("plottable15.png"); ! graph.saveAsPNG(filename, 400, 200); ! System.out.println("Graph15 saved to " + filename); } ! private void createGraph16() throws RrdException, IOException { LinearInterpolator hitsInterpolator = new LinearInterpolator(SF_TIMESTAMPS, SF_PAGE_HITS); --- 432,441 ---- gDef.line("hits", Color.BLUE, "page hits", 2); gDef.setTimeAxis(TimeAxisUnit.MONTH, 1, TimeAxisUnit.MONTH, 1, "MMM", false); ! createGraph(gDef); } ! private void createGraph17() throws RrdException, IOException { ! final int STEPS = 20; ! final Color color1 = Color.YELLOW, color2 = Color.RED; LinearInterpolator hitsInterpolator = new LinearInterpolator(SF_TIMESTAMPS, SF_PAGE_HITS); *************** *** 463,483 **** trendInterpolator.setInterpolationMethod(LinearInterpolator.INTERPOLATE_REGRESSION); RrdGraphDef gDef = new RrdGraphDef(SF_TIMESTAMPS[0], SF_TIMESTAMPS[SF_TIMESTAMPS.length - 1]); ! gDef.setTitle("Trend report"); gDef.setTimeAxisLabel("month"); ! gDef.setVerticalLabel("hits"); gDef.datasource("hits", hitsInterpolator); gDef.datasource("trend", trendInterpolator); gDef.datasource("diff", "hits,trend,-"); ! gDef.datasource("absdiff", "diff,ABS"); ! gDef.area("trend", null, null); ! gDef.stack("diff", Color.YELLOW, "difference"); ! gDef.line("hits", Color.RED, "real page hits"); ! gDef.line("trend", Color.BLUE, "trend@L"); ! gDef.gprint("absdiff", "AVERAGE", "Average difference: @0@r"); gDef.setTimeAxis(TimeAxisUnit.MONTH, 1, TimeAxisUnit.MONTH, 1, "MMM", false); ! RrdGraph graph = new RrdGraph(gDef); ! String filename = Util.getJRobinDemoPath("plottable16.png"); ! graph.saveAsPNG(filename, 400, 200); ! System.out.println("Graph16 saved to " + filename); } --- 443,464 ---- trendInterpolator.setInterpolationMethod(LinearInterpolator.INTERPOLATE_REGRESSION); RrdGraphDef gDef = new RrdGraphDef(SF_TIMESTAMPS[0], SF_TIMESTAMPS[SF_TIMESTAMPS.length - 1]); ! gDef.setTitle("Trick graph"); gDef.setTimeAxisLabel("month"); ! gDef.setVerticalLabel("difference"); gDef.datasource("hits", hitsInterpolator); gDef.datasource("trend", trendInterpolator); gDef.datasource("diff", "hits,trend,-"); ! for(int i = 1; i <= STEPS; i++) { ! gDef.datasource("diff" + i, "diff," + i + ",*," + STEPS + ",/"); ! } ! for(int i = STEPS; i >= 1; i--) { ! String ds = "diff" + i; ! Color c = interpolateColor(color1, color2, i / (double) STEPS); ! String legend = (i == 1)? "dissipation": null; ! gDef.area(ds, c, legend); ! } ! gDef.setCanvasColor(color2); gDef.setTimeAxis(TimeAxisUnit.MONTH, 1, TimeAxisUnit.MONTH, 1, "MMM", false); ! createGraph(gDef); } *************** *** 489,492 **** --- 470,482 ---- } + private static int count; + + private static void createGraph(RrdGraphDef gDef) throws IOException, RrdException { + RrdGraph graph = new RrdGraph(gDef); + String filename = Util.getJRobinDemoPath("plottable" + (++count) + ".png"); + graph.saveAsPNG(filename, 400, 200); + System.out.println("Saved to: " + filename); + } + public static void main(String[] args) throws RrdException, IOException { new PlottableDemo(); |
From: Sasa M. <sa...@us...> - 2004-06-09 12:14:38
|
Update of /cvsroot/jrobin/ant In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv25023 Modified Files: build.xml Log Message: Added 'demo' target to build jrobin-demo-*.jar library Index: build.xml =================================================================== RCS file: /cvsroot/jrobin/ant/build.xml,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** build.xml 9 Jun 2004 10:22:26 -0000 1.1 --- build.xml 9 Jun 2004 12:14:28 -0000 1.2 *************** *** 43,47 **** <property name="lib-snmp" value="snmp-1.3.jar"/> <property name="lib-xmlrpc" value="xmlrpc-1.2-b1.jar"/> ! <property name="lib-jrobin" value="JRobin-${version}.jar"/> <property name="lib-mrtg-client" value="mrtg-client-${version}.jar"/> <property name="lib-mrtg-server" value="mrtg-server-${version}.jar"/> --- 43,48 ---- <property name="lib-snmp" value="snmp-1.3.jar"/> <property name="lib-xmlrpc" value="xmlrpc-1.2-b1.jar"/> ! <property name="lib-jrobin" value="jrobin-${version}.jar"/> ! <property name="lib-demo" value="jrobin-demo-${version}.jar"/> <property name="lib-mrtg-client" value="mrtg-client-${version}.jar"/> <property name="lib-mrtg-server" value="mrtg-server-${version}.jar"/> *************** *** 51,56 **** <property name="res-mrtg" value="${res}/mrtg"/> <property name="classpath" value="${cwd}/${libs}/${lib-snmp}:${cwd}/${libs}/${lib-xmlrpc}"/> ! <property name="tarfile" value="JRobin-${version}.tar"/> ! <property name="tgzfile" value="JRobin-${version}.tar.gz"/> <!-- TARGETS --> --- 52,57 ---- <property name="res-mrtg" value="${res}/mrtg"/> <property name="classpath" value="${cwd}/${libs}/${lib-snmp}:${cwd}/${libs}/${lib-xmlrpc}"/> ! <property name="tarfile" value="jrobin-${version}.tar"/> ! <property name="tgzfile" value="jrobin-${version}.tar.gz"/> <!-- TARGETS --> *************** *** 63,67 **** <fileset dir="${cwd}" > <include name="${classes}/**/*"/> ! <include name="${dist}/JRobin*.tar.gz"/> <include name="${javadoc}/**/*"/> <include name="${libs}/${lib-jrobin}" /> --- 64,68 ---- <fileset dir="${cwd}" > <include name="${classes}/**/*"/> ! <include name="${dist}/jrobin*.tar.gz"/> <include name="${javadoc}/**/*"/> <include name="${libs}/${lib-jrobin}" /> *************** *** 87,95 **** <jar jarfile="${cwd}/${libs}/${lib-jrobin}" basedir="${cwd}/${classes}"> <manifest> ! <attribute name="Main-Class" value="Demo"/> </manifest> <include name="org/jrobin/core/**/*.class"/> <include name="org/jrobin/graph/**/*.class"/> ! <include name="*.class"/> </jar> </target> --- 88,106 ---- <jar jarfile="${cwd}/${libs}/${lib-jrobin}" basedir="${cwd}/${classes}"> <manifest> ! <attribute name="Main-Class" value="org.jrobin.core.RrdDb"/> </manifest> <include name="org/jrobin/core/**/*.class"/> <include name="org/jrobin/graph/**/*.class"/> ! </jar> ! </target> ! ! <target name="demo-lib" depends="core-lib"> ! <delete file="${cwd}/${libs}/${lib-demo}" /> ! <jar jarfile="${cwd}/${libs}/${lib-demo}" basedir="${cwd}/${classes}"> ! <manifest> ! <attribute name="Main-Class" value="org.jrobin.demo.Demo"/> ! <attribute name="Class-Path" value="${lib-jrobin}"/> ! </manifest> ! <include name="org/jrobin/demo/**/*.class"/> </jar> </target> *************** *** 144,148 **** </target> ! <target name="all-libs" depends="core-lib,mrtg-server-lib,mrtg-client-lib,inspector-lib,convertor-lib"/> <target name="javadoc" depends="compile"> --- 155,159 ---- </target> ! <target name="all-libs" depends="core-lib,demo-lib,mrtg-server-lib,mrtg-client-lib,inspector-lib,convertor-lib"/> <target name="javadoc" depends="compile"> *************** *** 170,174 **** </tarfileset> <tarfileset dir="${cwd}/${src}" prefix="${prefix}/${src}"> ! <exclude name="**/test/**/*"/> <include name="**/*.java"/> </tarfileset> --- 181,185 ---- </tarfileset> <tarfileset dir="${cwd}/${src}" prefix="${prefix}/${src}"> ! <exclude name="**/test/**/*"/> <include name="**/*.java"/> </tarfileset> |
From: Sasa M. <sa...@us...> - 2004-06-09 12:12:54
|
Update of /cvsroot/jrobin/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv23916 Removed Files: ComplexDemo.java Demo.java PlottableDemo.java StressTest.java TemplatesDemo.java Log Message: Demo files deleted and moved to org.jrobin.demo package --- Demo.java DELETED --- --- StressTest.java DELETED --- --- TemplatesDemo.java DELETED --- --- ComplexDemo.java DELETED --- --- PlottableDemo.java DELETED --- |
From: Sasa M. <sa...@us...> - 2004-06-09 12:10:44
|
Update of /cvsroot/jrobin/src/org/jrobin/core In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv22416/org/jrobin/core Modified Files: RrdDb.java Log Message: Index: RrdDb.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/core/RrdDb.java,v retrieving revision 1.19 retrieving revision 1.20 diff -C2 -d -r1.19 -r1.20 *** RrdDb.java 1 Jun 2004 14:41:01 -0000 1.19 --- RrdDb.java 9 Jun 2004 12:10:29 -0000 1.20 *************** *** 937,939 **** --- 937,945 ---- } + public static void main(String[] args) { + System.out.println("JRobin Java Library :: RRDTool choice for the Java world"); + System.out.println("http://www.jrobin.org"); + System.out.println("(C) 2004 Sasa Markovic & Arne Vandamme"); + } + } |
From: Sasa M. <sa...@us...> - 2004-06-09 12:09:35
|
Update of /cvsroot/jrobin/src/org/jrobin/demo In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21595/org/jrobin/demo Added Files: ComplexDemo.java Demo.java PlottableDemo.java StressTest.java TemplatesDemo.java Log Message: Demo files shifted to org.jrobin.demo package --- NEW FILE: Demo.java --- package org.jrobin.demo; /* ============================================================ * JRobin : Pure java implementation of RRDTool's functionality * ============================================================ * * Project Info: http://www.jrobin.org * Project Lead: Sasa Markovic (sa...@jr...); * * (C) Copyright 2003, by Sasa Markovic. * * This library is free software; you can redistribute it and/or modify it under the terms * of the GNU Lesser General Public License as published by the Free Software Foundation; * either version 2.1 of the License, or (at your option) any later version. * * Developers: Sasa Markovic (sa...@jr...) * Arne Vandamme (cob...@jr...) * * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License along with this * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, * Boston, MA 02111-1307, USA. */ import org.jrobin.core.*; import org.jrobin.graph.RrdGraph; import org.jrobin.graph.RrdGraphDef; import java.awt.*; import java.io.BufferedOutputStream; import java.io.FileOutputStream; import java.io.IOException; import java.io.PrintWriter; import java.util.Random; class Demo { // static final String FACTORY_NAME = "NIO"; static final long SEED = 1909752002L; static final Random RANDOM = new Random(SEED); static final String FILE = "demo"; static final long START = Util.getTimestamp(2003, 4, 1); static final long END = Util.getTimestamp(2003, 5, 1); static final int MAX_STEP = 300; public static void main(String[] args) throws RrdException, IOException { // RrdDb.setDefaultFactory(FACTORY_NAME); // setup println("== Starting demo"); RrdDb.setLockMode(RrdDb.NO_LOCKS); long startMillis = System.currentTimeMillis(); long start = START; long end = END; String rrdPath = Util.getJRobinDemoPath(FILE + ".rrd"); String xmlPath = Util.getJRobinDemoPath(FILE + ".xml"); String rrdRestoredPath = Util.getJRobinDemoPath(FILE + "_restored.rrd"); String pngPath = Util.getJRobinDemoPath(FILE + ".png"); String jpegPath = Util.getJRobinDemoPath(FILE + ".jpeg"); String gifPath = Util.getJRobinDemoPath(FILE + ".gif"); String logPath = Util.getJRobinDemoPath(FILE + ".log"); PrintWriter log = new PrintWriter( new BufferedOutputStream(new FileOutputStream(logPath, false)) ); // creation println("== Creating RRD file " + rrdPath); RrdDef rrdDef = new RrdDef(rrdPath, start - 1, 300); rrdDef.addDatasource("sun", "GAUGE", 600, 0, Double.NaN); rrdDef.addDatasource("shade", "GAUGE", 600, 0, Double.NaN); rrdDef.addArchive("AVERAGE", 0.5, 1, 600); rrdDef.addArchive("AVERAGE", 0.5, 6, 700); rrdDef.addArchive("AVERAGE", 0.5, 24, 775); rrdDef.addArchive("AVERAGE", 0.5, 288, 797); rrdDef.addArchive("MAX", 0.5, 1, 600); rrdDef.addArchive("MAX", 0.5, 6, 700); rrdDef.addArchive("MAX", 0.5, 24, 775); rrdDef.addArchive("MAX", 0.5, 288, 797); println(rrdDef.dump()); log.println(rrdDef.dump()); println("Estimated file size: " + rrdDef.getEstimatedSize()); RrdDb rrdDb = new RrdDb(rrdDef); println("== RRD file created."); rrdDb.close(); println("== RRD file closed."); // update database GaugeSource sunSource = new GaugeSource(1200, 20); GaugeSource shadeSource = new GaugeSource(300, 10); println("== Simulating one month of RRD file updates with step not larger than " + MAX_STEP + " seconds (* denotes 1000 updates)"); long t = start; int n = 0; rrdDb = new RrdDb(rrdPath); Sample sample = rrdDb.createSample(); while(t <= end + 86400L) { //rrdDb = new RrdDb(rrdPath); //Sample sample = rrdDb.createSample(); sample.setTime(t); sample.setValue("sun", sunSource.getValue()); sample.setValue("shade", shadeSource.getValue()); log.println(sample.dump()); sample.update(); t += RANDOM.nextDouble() * MAX_STEP + 1; if(((++n) % 1000) == 0) { System.out.print("*"); }; //rrdDb.close(); } println(""); println("== Finished. RRD file updated " + n + " times"); println("== Last update time was: " + rrdDb.getLastUpdateTime()); rrdDb.close(); // test read-only access! rrdDb = new RrdDb(rrdPath, true); println("File reopen in read-only mode"); // fetch data println("== Fetching data for the whole month"); FetchRequest request = rrdDb.createFetchRequest("AVERAGE", start, end); println(request.dump()); log.println(request.dump()); FetchData fetchData = request.fetchData(); println("== Data fetched. " + fetchData.getRowCount() + " points obtained"); for(int i = 0; i < fetchData.getRowCount(); i++) { println(fetchData.getRow(i).dump()); } println("== Dumping fetch data to XML format"); println(fetchData.exportXml()); println("== Fetch completed"); // dump to XML file println("== Dumping RRD file to XML file " + xmlPath + " (can be restored with RRDTool)"); rrdDb.exportXml(xmlPath); println("== Creating RRD file " + rrdRestoredPath + " from XML file " + xmlPath); RrdDb rrdRestoredDb = new RrdDb(rrdRestoredPath, xmlPath); // close files println("== Closing both RRD files"); rrdDb.close(); println("== First file closed"); rrdRestoredDb.close(); println("== Second file closed"); // create graph println("== Creating graph from the second file"); RrdGraphDef gDef = new RrdGraphDef(); gDef.setTimePeriod(start, end); gDef.setTitle("Temperatures in May 2003"); gDef.setVerticalLabel("temperature"); gDef.datasource("sun", rrdRestoredPath, "sun", "AVERAGE"); gDef.datasource("shade", rrdRestoredPath, "shade", "AVERAGE"); gDef.datasource("median", "sun,shade,+,2,/"); gDef.datasource("diff", "sun,shade,-,ABS,-1,*"); gDef.datasource("sine", "TIME," + start + ",-," + (end - start) + ",/,2,PI,*,*,SIN,1000,*"); gDef.line("sun", Color.GREEN, "sun temp"); gDef.line("shade", Color.BLUE, "shade temp"); gDef.line("median", Color.MAGENTA, "median value@L"); gDef.area("diff", Color.YELLOW, "difference@r"); gDef.line("diff", Color.RED, null); gDef.line("sine", Color.CYAN, "sine function demo@L"); gDef.gprint("sun", "MAX", "maxSun = @3@s"); gDef.gprint("sun", "AVERAGE", "avgSun = @3@S@r"); gDef.gprint("shade", "MAX", "maxShade = @3@S"); gDef.gprint("shade", "AVERAGE", "avgShade = @3@S@r"); // create graph finally RrdGraph graph = new RrdGraph(gDef); println("== Graph created"); graph.saveAsPNG(pngPath, 400, 250); println("== Graph saved as a PNG file " + pngPath); graph.saveAsJPEG(jpegPath, 400, 250, 0.5F); println("== Graph saved as a JPEG file " + jpegPath); graph.saveAsGIF(gifPath, 400, 250); println("== Graph saved as a GIF file " + gifPath); // demo ends log.close(); println("== Demo completed in " + ((System.currentTimeMillis() - startMillis) / 1000.0) + " sec"); } static void println(String msg) { //System.out.println(msg + " " + Util.getLapTime()); System.out.println(msg); } static void print(String msg) { System.out.print(msg); } static class GaugeSource { private double value; private double step; GaugeSource(double value, double step) { this.value = value; this.step = step; } long getValue() { double oldValue = value; double increment = RANDOM.nextDouble() * step; if(RANDOM.nextDouble() > 0.5) { increment *= -1; } value += increment; if(value <= 0) { value = 0; } return Math.round(oldValue); } } } --- NEW FILE: StressTest.java --- package org.jrobin.demo; /* ============================================================ * JRobin : Pure java implementation of RRDTool's functionality * ============================================================ * * Project Info: http://www.jrobin.org * Project Lead: Sasa Markovic (sa...@jr...); * * (C) Copyright 2003, by Sasa Markovic. * * This library is free software; you can redistribute it and/or modify it under the terms * of the GNU Lesser General Public License as published by the Free Software Foundation; * either version 2.1 of the License, or (at your option) any later version. * * Developers: Sasa Markovic (sa...@jr...) * Arne Vandamme (cob...@jr...) * * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License along with this * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, * Boston, MA 02111-1307, USA. */ import org.jrobin.core.*; import org.jrobin.graph.RrdGraphDef; import org.jrobin.graph.RrdGraph; import java.io.IOException; import java.io.BufferedReader; import java.io.FileReader; import java.util.Date; import java.awt.*; class StressTest { static final String FACTORY_NAME = "NIO"; static final String RRD_PATH = Util.getJRobinDemoPath("stress.rrd"); static final long RRD_START = 946710000L; static final long RRD_STEP = 30; static final String RRD_DATASOURCE_NAME = "T"; static final int RRD_DATASOURCE_COUNT = 6; static final long TIME_START = 1060142010L; static final long TIME_END = 1080013472L; static final String PNG_PATH = Util.getJRobinDemoPath("stress.png"); static final int PNG_WIDTH = 400; static final int PNG_HEIGHT = 250; static void printLapTime(String message) { System.out.println(message + " " + Util.getLapTime()); } public static void main(String[] args) throws RrdException, IOException { if(args.length == 0) { System.out.println("Usage: StressTest [path to stress-test.txt file]"); System.out.println("You can download separate stress-test.txt file from:"); System.out.println("http://www.sourceforge.net/projects/jrobin"); System.exit(-1); } System.out.println("********************************************************************"); System.out.println("* JRobinStressTest *"); System.out.println("* *"); System.out.println("* This demo creates single RRD file and tries to update it *"); System.out.println("* more than 600.000 times. Real data (> 20Mb) is obtained from the *"); System.out.println("* stress-test.txt file provided by Vadim Tkachenko *"); System.out.println("* (http://diy-zoning.sourceforge.net). *"); System.out.println("* *"); System.out.println("* Finally, a single PNG graph will be created from the RRD file. *"); System.out.println("* The stress test takes about one hour to complete on a 1.6GHz *"); System.out.println("* computer with 256MB of RAM. *"); System.out.println("********************************************************************"); printLapTime("Starting demo at " + new Date()); RrdDb.setDefaultFactory(FACTORY_NAME); printLapTime("Backend factory set to " + FACTORY_NAME); // create RRD database printLapTime("Creating RRD definition"); RrdDef def = new RrdDef(RRD_PATH); def.setStartTime(RRD_START); def.setStep(RRD_STEP); for(int i = 0; i < RRD_DATASOURCE_COUNT; i++) { def.addDatasource(RRD_DATASOURCE_NAME + i, "GAUGE", 90, -60, 85); } def.addArchive("LAST", 0.5, 1, 5760); def.addArchive("MIN", 0.5, 1, 5760); def.addArchive("MAX", 0.5, 1, 5760); def.addArchive("AVERAGE", 0.5, 5, 13824); def.addArchive("MIN", 0.5, 5, 13824); def.addArchive("MAX", 0.5, 5, 13824); def.addArchive("AVERAGE", 0.5, 60, 16704); def.addArchive("MIN", 0.5, 60, 16704); def.addArchive("MAX", 0.5, 60, 16704); def.addArchive("AVERAGE", 0.5, 1440, 50000); def.addArchive("MIN", 0.5, 1440, 50000); def.addArchive("MAX", 0.5, 1440, 50000); printLapTime("Definition created, creating RRD file"); RrdDb rrd = RrdDbPool.getInstance().requestRrdDb(def); printLapTime("RRD file created: " + RRD_PATH); BufferedReader r = new BufferedReader(new FileReader(args[0])); printLapTime("Buffered reader created, processing data"); int count = 0; Date updateStart = new Date(); for(String line; (line = r.readLine()) != null;) { Sample sample = rrd.createSample(); try { sample.setAndUpdate(line); if(++count % 1000 == 0) { Date now = new Date(); long speed = (long)(count * 1000.0 / (now.getTime() - updateStart.getTime())); printLapTime(count + " samples stored, " + speed + " updates/sec"); } } catch(RrdException e) { printLapTime("RRD ERROR: " + line); } } RrdDbPool.getInstance().release(rrd); printLapTime("FINISHED: " + count + " samples stored"); // GRAPH printLapTime("Creating composite graph definition"); RrdGraphDef gdef = new RrdGraphDef(TIME_START, TIME_END); gdef.setTitle("Temperatures"); gdef.setVerticalLabel("Fahrenheits"); final Color[] colors = { Color.RED, Color.GREEN, Color.BLUE, Color.MAGENTA, Color.CYAN, Color.ORANGE }; // datasources for(int i = 0; i < RRD_DATASOURCE_COUNT; i++) { String name = RRD_DATASOURCE_NAME + i; gdef.datasource(name, RRD_PATH, name, "AVERAGE"); } // lines for(int i = 0; i < RRD_DATASOURCE_COUNT; i++) { String name = RRD_DATASOURCE_NAME + i; gdef.line(name, colors[i], name); } gdef.comment("@c"); gdef.comment("\nOriginal data provided by diy-zoning.sf.net@c"); printLapTime("Graph definition created"); RrdGraph g = new RrdGraph(gdef, true); g.saveAsPNG(PNG_PATH, PNG_WIDTH, PNG_HEIGHT); printLapTime("Graph saved: " + PNG_PATH); printLapTime("Finished at " + new Date()); } } --- NEW FILE: TemplatesDemo.java --- package org.jrobin.demo; /* ============================================================ * JRobin : Pure java implementation of RRDTool's functionality * ============================================================ * * Project Info: http://www.jrobin.org * Project Lead: Sasa Markovic (sa...@jr...); * * (C) Copyright 2003, by Sasa Markovic. * * This library is free software; you can redistribute it and/or modify it under the terms * of the GNU Lesser General Public License as published by the Free Software Foundation; * either version 2.1 of the License, or (at your option) any later version. * * Developers: Sasa Markovic (sa...@jr...) * Arne Vandamme (cob...@jr...) * * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License along with this * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, * Boston, MA 02111-1307, USA. */ import org.jrobin.core.*; import org.jrobin.graph.RrdGraph; import org.jrobin.graph.RrdGraphDef; import org.jrobin.graph.RrdGraphDefTemplate; import java.io.BufferedOutputStream; import java.io.FileOutputStream; import java.io.IOException; import java.io.PrintWriter; import java.util.Random; class TemplatesDemo { static final String RRD_TEMPLATE = "<rrd_def> " + " <path>${path}</path> " + " <start>${start}</start> " + " <step>300</step> " + " <datasource> " + " <name>sun</name> " + " <type>GAUGE</type> " + " <heartbeat>600</heartbeat> " + " <min>0</min> " + " <max>U</max> " + " </datasource> " + " <datasource> " + " <name>shade</name> " + " <type>GAUGE</type> " + " <heartbeat>600</heartbeat> " + " <min>0</min> " + " <max>U</max> " + " </datasource> " + " <archive> " + " <cf>AVERAGE</cf> " + " <xff>0.5</xff> " + " <steps>1</steps> " + " <rows>600</rows> " + " </archive> " + " <archive> " + " <cf>AVERAGE</cf> " + " <xff>0.5</xff> " + " <steps>6</steps> " + " <rows>700</rows> " + " </archive> " + " <archive> " + " <cf>AVERAGE</cf> " + " <xff>0.5</xff> " + " <steps>24</steps> " + " <rows>775</rows> " + " </archive> " + " <archive> " + " <cf>AVERAGE</cf> " + " <xff>0.5</xff> " + " <steps>288</steps> " + " <rows>797</rows> " + " </archive> " + " <archive> " + " <cf>MAX</cf> " + " <xff>0.5</xff> " + " <steps>1</steps> " + " <rows>600</rows> " + " </archive> " + " <archive> " + " <cf>MAX</cf> " + " <xff>0.5</xff> " + " <steps>6</steps> " + " <rows>700</rows> " + " </archive> " + " <archive> " + " <cf>MAX</cf> " + " <xff>0.5</xff> " + " <steps>24</steps> " + " <rows>775</rows> " + " </archive> " + " <archive> " + " <cf>MAX</cf> " + " <xff>0.5</xff> " + " <steps>288</steps> " + " <rows>797</rows> " + " </archive> " + "</rrd_def> " ; static final String GRAPH_TEMPLATE = "<rrd_graph_def> " + " <span> " + " <start>${start}</start> " + " <end>${end}</end> " + " </span> " + " <options> " + " <title>${title}</title> " + " <vertical_label>temperature</vertical_label> " + " </options> " + " <datasources> " + " <def> " + " <name>sun</name> " + " <rrd>${rrd}</rrd> " + " <source>sun</source> " + " <cf>AVERAGE</cf> " + " </def> " + " <def> " + " <name>shade</name> " + " <rrd>${rrd}</rrd> " + " <source>shade</source> " + " <cf>AVERAGE</cf> " + " </def> " + " <def> " + " <name>median</name> " + " <rpn>sun,shade,+,2,/</rpn> " + " </def> " + " <def> " + " <name>diff</name> " + " <rpn>sun,shade,-,ABS,-1,*</rpn> " + " </def> " + " <def> " + " <name>sine</name> " + " <rpn>${sine}</rpn> " + " </def> " + " </datasources> " + " <graph> " + " <line> " + " <datasource>sun</datasource> " + " <color>#00FF00</color> " + " <legend>sun temp</legend> " + " </line> " + " <line> " + " <datasource>shade</datasource> " + " <color>#0000FF</color> " + " <legend>shade temp</legend> " + " </line> " + " <line> " + " <datasource>median</datasource> " + " <color>#FF00FF</color> " + " <legend>median value@L</legend> " + " </line> " + " <area> " + " <datasource>diff</datasource> " + " <color>#FFFF00</color> " + " <legend>difference@r</legend> " + " </area> " + " <line> " + " <datasource>diff</datasource> " + " <color>#FF0000</color> " + " <legend/> " + " </line> " + " <line> " + " <datasource>sine</datasource> " + " <color>#00FFFF</color> " + " <legend>sine function demo@L</legend> " + " </line> " + " <gprint> " + " <datasource>sun</datasource> " + " <cf>MAX</cf> " + " <format>maxSun = @3@s</format> " + " </gprint> " + " <gprint> " + " <datasource>sun</datasource> " + " <cf>AVERAGE</cf> " + " <format>avgSun = @3@S@r</format> " + " </gprint> " + " <gprint> " + " <datasource>shade</datasource> " + " <cf>MAX</cf> " + " <format>maxShade = @3@S</format> " + " </gprint> " + " <gprint> " + " <datasource>shade</datasource> " + " <cf>AVERAGE</cf> " + " <format>avgShade = @3@S@r</format> " + " </gprint> " + " </graph> " + "</rrd_graph_def> " ; static final long SEED = 1909752002L; static final Random RANDOM = new Random(SEED); static final String FILE = "templates_demo"; static final long START = Util.getTimestamp(2003, 4, 1); static final long END = Util.getTimestamp(2003, 5, 1); static final int MAX_STEP = 300; public static void main(String[] args) throws RrdException, IOException { // setup println("== Starting demo"); RrdDb.setLockMode(RrdDb.NO_LOCKS); long startMillis = System.currentTimeMillis(); long start = START; long end = END; String rrdPath = Util.getJRobinDemoPath(FILE + ".rrd"); String xmlPath = Util.getJRobinDemoPath(FILE + ".xml"); String rrdRestoredPath = Util.getJRobinDemoPath(FILE + "_restored.rrd"); String pngPath = Util.getJRobinDemoPath(FILE + ".png"); String jpegPath = Util.getJRobinDemoPath(FILE + ".jpeg"); String gifPath = Util.getJRobinDemoPath(FILE + ".gif"); String logPath = Util.getJRobinDemoPath(FILE + ".log"); PrintWriter log = new PrintWriter( new BufferedOutputStream(new FileOutputStream(logPath, false)) ); // creation from the template println("== Creating RRD file " + rrdPath); RrdDefTemplate defTemplate = new RrdDefTemplate(RRD_TEMPLATE); defTemplate.setVariable("path", rrdPath); defTemplate.setVariable("start", start - 1); RrdDef rrdDef = defTemplate.getRrdDef(); println(rrdDef.dump()); log.println(rrdDef.dump()); RrdDb rrdDb = new RrdDb(rrdDef); rrdDb.close(); println("== RRD file created and closed."); // update database GaugeSource sunSource = new GaugeSource(1200, 20); GaugeSource shadeSource = new GaugeSource(300, 10); println("== Simulating one month of RRD file updates with step not larger than " + MAX_STEP + " seconds (* denotes 1000 updates)"); long t = start; int n = 0; rrdDb = new RrdDb(rrdPath); Sample sample = rrdDb.createSample(); while(t <= end + 86400L) { sample.setTime(t); sample.setValue("sun", sunSource.getValue()); sample.setValue("shade", shadeSource.getValue()); log.println(sample.dump()); sample.update(); t += RANDOM.nextDouble() * MAX_STEP + 1; if(((++n) % 1000) == 0) { System.out.print("*"); }; } System.out.println(""); println("== Finished. RRD file updated " + n + " times"); println("== Last update time was: " + rrdDb.getLastUpdateTime()); // fetch data println("== Fetching data for the whole month"); FetchRequest request = rrdDb.createFetchRequest("AVERAGE", start, end); println(request.dump()); log.println(request.dump()); FetchData fetchData = request.fetchData(); println("== Data fetched. " + fetchData.getRowCount() + " points obtained"); for(int i = 0; i < fetchData.getRowCount(); i++) { println(fetchData.getRow(i).dump()); } println("== Dumping fetch data to XML format"); println(fetchData.exportXml()); println("== Fetch completed"); // dump to XML file println("== Dumping RRD file to XML file " + xmlPath + " (can be restored with RRDTool)"); rrdDb.exportXml(xmlPath); println("== Creating RRD file " + rrdRestoredPath + " from XML file " + xmlPath); RrdDb rrdRestoredDb = new RrdDb(rrdRestoredPath, xmlPath); // close files println("== Closing both RRD files"); rrdDb.close(); rrdRestoredDb.close(); // create graph println("== Creating graph from the second file"); RrdGraphDefTemplate graphTemplate = new RrdGraphDefTemplate(GRAPH_TEMPLATE); graphTemplate.setVariable("start", start); graphTemplate.setVariable("end", end); graphTemplate.setVariable("title", "Temperatures in May 2003"); graphTemplate.setVariable("rrd", rrdRestoredPath); // RPN expressions can be created at runtime and put into a template graphTemplate.setVariable("sine", "TIME," + start + ",-," + (end - start) + ",/,2,PI,*,*,SIN,1000,*"); // create graph finally RrdGraphDef gDef = graphTemplate.getRrdGraphDef(); RrdGraph graph = new RrdGraph(gDef); println("== Graph created"); println("== Saving graph as PNG file " + pngPath); graph.saveAsPNG(pngPath, 400, 250); println("== Saving graph as JPEG file " + jpegPath); graph.saveAsJPEG(jpegPath, 400, 250, 0.5F); println("== Saving graph as GIF file " + gifPath); graph.saveAsGIF(gifPath, 400, 250); // demo ends log.close(); println("== Demo completed in " + ((System.currentTimeMillis() - startMillis) / 1000.0) + " sec"); } static void println(String msg) { System.out.println(msg); } static class GaugeSource { private double value; private double step; GaugeSource(double value, double step) { this.value = value; this.step = step; } long getValue() { double oldValue = value; double increment = RANDOM.nextDouble() * step; if (RANDOM.nextDouble() > 0.5) { increment *= -1; } value += increment; if (value <= 0) { value = 0; } return Math.round(oldValue); } } } --- NEW FILE: ComplexDemo.java --- package org.jrobin.demo; /* ============================================================ * JRobin : Pure java implementation of RRDTool's functionality * ============================================================ * * Project Info: http://www.jrobin.org * Project Lead: Sasa Markovic (sa...@jr...); * * (C) Copyright 2003, by Sasa Markovic. * * This library is free software; you can redistribute it and/or modify it under the terms * of the GNU Lesser General Public License as published by the Free Software Foundation; * either version 2.1 of the License, or (at your option) any later version. * * Developers: Sasa Markovic (sa...@jr...) * Arne Vandamme (cob...@jr...) * * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License along with this * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, * Boston, MA 02111-1307, USA. */ import java.awt.Color; import java.util.Date; import java.util.GregorianCalendar; import java.text.SimpleDateFormat; import java.io.IOException; import org.jrobin.core.*; import org.jrobin.graph.*; /** * <p>Extended graphing demo for JRobin.</p> * * @author Arne Vandamme (cob...@jr...) */ class ComplexDemo { private static final String filename = "complexdemo"; private static String getPath(String ext) { return Util.getJRobinDemoPath(filename + "." + ext); } private static String getPath(int version, String ext) { return Util.getJRobinDemoPath(filename + version + "." + ext); } private static void println(String msg) { System.out.println(msg); } private static void createDatabase(String xmlPath) throws IOException, RrdException { // Import database from XML String rrdPath = getPath("rrd"); println("-- Importing XML file: " + xmlPath); println("-- to RRD file: " + rrdPath); RrdDbPool pool = RrdDbPool.getInstance(); RrdDb rrd = pool.requestRrdDb(rrdPath, xmlPath); println("-- RRD file created"); pool.release(rrd); } private static void createGraphs() throws RrdException, IOException { GregorianCalendar start, stop; RrdGraph graph = new RrdGraph(true); String rrdPath = getPath("rrd"); // Create traffic overview of a week println("-- Creating graph 1"); start = new GregorianCalendar(2003, 7, 20); stop = new GregorianCalendar(2003, 7, 27); RrdGraphDef def = new RrdGraphDef(start, stop); def.setImageBorder(Color.GRAY, 1); def.setTitle("JRobinComplexDemo@Ldemo graph 1@r\nNetwork traffic overview"); def.setVerticalLabel("bits per second"); def.datasource("ifInOctets", rrdPath, "ifInOctets", "AVERAGE"); def.datasource("ifOutOctets", rrdPath, "ifOutOctets", "AVERAGE"); def.datasource("bitIn", "ifInOctets,8,*"); def.datasource("bitOut", "ifOutOctets,8,*"); def.comment(" "); def.area("bitIn", new Color(0x00, 0xFF, 0x00), "Incoming traffic "); def.line("bitOut", new Color(0x00, 0x00, 0x33), "Outgoing traffic\n\n"); def.gprint("bitIn", "MAX", "Max: @6.1 @sbit/s"); def.gprint("bitOut", "MAX", " @6.1 @sbit/s\n"); def.gprint("bitIn", "MIN", "Min: @6.1 @sbit/s"); def.gprint("bitOut", "MIN", " @6.1 @sbit/s"); def.comment(" Connection: 100 Mbit/s\n"); def.gprint("bitIn", "AVG", "Avg: @6.1 @sbit/s"); def.gprint("bitOut", "AVG", " @6.1 @sbit/s"); def.comment(" Duplex mode: FD - fixed\n\n"); def.gprint("bitIn", "LAST", "Cur: @6.1 @sbit/s"); def.gprint("bitOut", "LAST", " @6.1 @sbit/s\n\n"); def.comment("[ courtesy of www.cherrymon.org ]@L"); def.comment("Generated: " + timestamp() + " @r"); graph.setGraphDef(def); String pngFile = getPath(1, "png"); graph.saveAsPNG(pngFile); String gifFile = getPath(1, "gif"); graph.saveAsGIF(gifFile); String jpgFile = getPath(1, "jpg"); graph.saveAsJPEG(jpgFile, 0.6F); // Create server load and cpu usage of a day println("-- Creating graph 2"); start = new GregorianCalendar(2003, 7, 19); stop = new GregorianCalendar(2003, 7, 20); def = new RrdGraphDef(start, stop); def.setImageBorder(Color.GRAY, 1); def.setTitle("JRobinComplexDemo@Ldemo graph 2@r\nServer load and CPU utilization"); def.datasource("load", rrdPath, "serverLoad", "AVERAGE"); def.datasource("user", rrdPath, "serverCPUUser", "AVERAGE"); def.datasource("nice", rrdPath, "serverCPUNice", "AVERAGE"); def.datasource("system", rrdPath, "serverCPUSystem", "AVERAGE"); def.datasource("idle", rrdPath, "serverCPUIdle", "AVERAGE"); def.datasource("total", "user,nice,+,system,+,idle,+"); def.datasource("busy", "user,nice,+,system,+,total,/,100,*"); def.datasource("p25t50", "busy,25,GT,busy,50,LE,load,0,IF,0,IF"); def.datasource("p50t75", "busy,50,GT,busy,75,LE,load,0,IF,0,IF"); def.datasource("p75t90", "busy,75,GT,busy,90,LE,load,0,IF,0,IF"); def.datasource("p90t100", "busy,90,GT,load,0,IF"); def.comment("CPU utilization (%)\n "); def.area("load", new Color(0x66, 0x99, 0xcc), " 0 - 25%"); def.area("p25t50", new Color(0x00, 0x66, 0x99), "25 - 50%@L"); def.gprint("busy", "MIN", "Minimum:@5.1@s%"); def.gprint("busy", "MAX", "Maximum:@5.1@s% @r "); def.area("p50t75", new Color(0x66, 0x66, 0x00), "50 - 75%"); def.area("p75t90", new Color(0xff, 0x66, 0x00), "75 - 90%"); def.area("p90t100", new Color(0xcc, 0x33, 0x00), "90 - 100%@L"); def.gprint("busy", "AVG", " Average:@5.1@s%"); def.gprint("busy", "LAST", "Current:@5.1@s% @r "); def.comment("\nServer load\n "); def.line("load", new Color(0x00, 0x00, 0x00), "Load average (5 min)@L"); def.gprint("load", "MIN", "Minimum:@5.2@s%"); def.gprint("load", "MAX", "Maximum:@5.2@s% @r "); def.gprint("load", "AVG", "Average:@5.2@s%"); def.gprint("load", "LAST", "Current:@5.2@s% @r"); def.comment("\n\n[ courtesy of www.cherrymon.org ]@L"); def.comment("Generated: " + timestamp() + " @r"); graph.setGraphDef(def); pngFile = getPath(2, "png"); graph.saveAsPNG(pngFile); gifFile = getPath(2, "gif"); graph.saveAsGIF(gifFile); jpgFile = getPath(2, "jpg"); graph.saveAsJPEG(jpgFile, 0.6F); // Create ftp graph for a month println("-- Creating graph 3"); start = new GregorianCalendar(2003, 7, 19, 12, 00); stop = new GregorianCalendar(2003, 7, 20, 12, 00); def = new RrdGraphDef(start, stop); def.setImageBorder(Color.GRAY, 1); def.setFrontGrid(false); def.setTitle("JRobinComplexDemo@Ldemo graph 3@r\nFTP Usage"); def.datasource("ftp", rrdPath, "ftpUsers", "AVERAGE"); def.line("ftp", new Color(0x00, 0x00, 0x33), "FTP connections"); def.gprint("ftp", "AVG", "( average: @0,"); def.gprint("ftp", "MIN", "never below: @0 )\n\n"); def.comment(" Usage spread:"); def.area(new GregorianCalendar(2003, 7, 19, 17, 00), Double.MIN_VALUE, new GregorianCalendar(2003, 7, 19, 23, 00), Double.MAX_VALUE, Color.RED, "peak period"); def.area(new GregorianCalendar(2003, 7, 20, 5, 00), Double.MIN_VALUE, new GregorianCalendar(2003, 7, 20, 8, 30), Double.MAX_VALUE, Color.LIGHT_GRAY, "quiet period\n"); def.comment(" Rise/descend:"); def.area("ftp", new Color(0x00, 0x00, 0x33), null); def.line(new GregorianCalendar(2003, 7, 19, 12, 00), 110, new GregorianCalendar(2003, 7, 19, 20, 30), 160, Color.PINK, "climb slope", 2); def.line(new GregorianCalendar(2003, 7, 19, 20, 30), 160, new GregorianCalendar(2003, 7, 20, 8, 00), 45, Color.CYAN, "fall-back slope\n", 2); def.vrule(new GregorianCalendar(2003, 7, 20), Color.YELLOW, null); def.comment("\n\n[ courtesy of www.cherrymon.org ]@L"); def.comment("Generated: " + timestamp() + " @r"); graph.setGraphDef(def); pngFile = getPath(3, "png"); graph.saveAsPNG(pngFile, 500, 300); gifFile = getPath(3, "gif"); graph.saveAsGIF(gifFile, 500, 300); jpgFile = getPath(3, "jpg"); graph.saveAsJPEG(jpgFile, 500, 300, 0.6F); println("-- Finished"); println("**************************************"); println("Check your " + Util.getJRobinDemoDirectory() + " directory."); println("You should see nine nice looking graphs starting with [" + filename + "],"); println("three different graphs, each in three different image formats"); println("**************************************"); } private static String timestamp() { SimpleDateFormat df = new SimpleDateFormat("dd/MM/yyyy HH:mm"); return df.format(new Date()); } public static void main(String[] args) throws IOException, RrdException { if(args.length == 0) { println("Usage: ComplexDemo [path to rrdtool_dump.xml file]"); println("You can download separate rrdtool_dump.xml file from:"); println("http://www.sourceforge.net/projects/jrobin"); System.exit(-1); } long start = System.currentTimeMillis(); println("********************************************************************"); println("* JRobinComplexDemo *"); println("* *"); println("* This demo creates 3 separate graphs and stores them under *"); println("* several formats in 9 files. Values are selected from a large *"); println("* RRD file that will be created by importing an XML dump *"); println("* of approx. 7 MB. *"); println("* *"); println("* Graphs are created using real-life values, original RRD file *"); println("* provided by www.cherrymon.org. See the ComplexDemo *"); println("* sourcecode on how to create the graphs generated by this demo. *"); println("********************************************************************"); createDatabase(args[0]); createGraphs(); long stop = System.currentTimeMillis(); println("-- Demo finished in " + ((stop - start) / 1000.0) + " seconds."); } } --- NEW FILE: PlottableDemo.java --- package org.jrobin.demo; /* ============================================================ * JRobin : Pure java implementation of RRDTool's functionality * ============================================================ * * Project Info: http://www.jrobin.org * Project Lead: Sasa Markovic (sa...@jr...); * * (C) Copyright 2003, by Sasa Markovic. * * This library is free software; you can redistribute it and/or modify it under the terms * of the GNU Lesser General Public License as published by the Free Software Foundation; * either version 2.1 of the License, or (at your option) any later version. * * Developers: Sasa Markovic (sa...@jr...) * Arne Vandamme (cob...@jr...) * * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License along with this * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, * Boston, MA 02111-1307, USA. */ import org.jrobin.graph.*; import org.jrobin.core.RrdException; import org.jrobin.core.Util; import java.awt.*; import java.io.IOException; import java.util.Date; import java.util.GregorianCalendar; import java.util.Calendar; class PlottableDemo { static final double[] SF_DOWNLOAD_COUNT = { 0, 0, 13, 34, 76, 72, 255, 144, 135, 194, 358, 304, 293 }; static final double[] SF_PAGE_HITS = { 0, 1072, 517, 979, 2132, 2532, 5515, 3519, 3500, 4942, 7858, 7797, 6570 }; static final GregorianCalendar[] SF_TIMESTAMPS = new GregorianCalendar[SF_DOWNLOAD_COUNT.length]; static final Date SF_START_DATE = new GregorianCalendar(2003, 4, 1).getTime(); // May 1st 2004. static { for(int i = 0; i < SF_TIMESTAMPS.length; i++) { GregorianCalendar gc = new GregorianCalendar(); gc.setTime(SF_START_DATE); gc.add(Calendar.MONTH, i); SF_TIMESTAMPS[i] = gc; } } private PlottableDemo() throws RrdException, IOException { createGraph1(); createGraph2(); createGraph3(); createGraph4(); createGraph5(); createGraph6(); createGraph7(); createGraph8(); createGraph9(); createGraph10(); createGraph11(); createGraph12(); createGraph13(); createGraph14(); createGraph15(); createGraph16(); } private void createGraph1() throws RrdException, IOException { final long t0 = new Date().getTime() / 1000L, dt = 86400L; final int n = 10; final long t1 = t0 + (n - 1) * dt; Plottable p = new Plottable() { public double getValue(long t) { double x = (t - t0) / (double) (t1 - t0); return Math.exp(-x * 2) * Math.cos(x * 7 * Math.PI); } }; long t[] = new long[n]; double x[] = new double[n]; for (int i = 0; i < n; i++) { t[i] = t0 + i * dt; x[i] = p.getValue(t[i]); } LinearInterpolator i1 = new LinearInterpolator(t, x); // defaults to INTERPOLATE_LINEAR CubicSplineInterpolator i2 = new CubicSplineInterpolator(t, x); // graph definition RrdGraphDef gdef = new RrdGraphDef(t0, t1); gdef.setTitle("Plottable demonstration"); gdef.setTimeAxisLabel("days of our lives"); gdef.setVerticalLabel("inspiration"); gdef.datasource("real", p); gdef.datasource("linear", i1); gdef.datasource("spline", i2); gdef.line("real", Color.BLUE, "Real values", 1); gdef.line("linear", Color.RED, "Linear interpolation", 1); gdef.line("spline", Color.MAGENTA, "Spline interpolation@r", 1); gdef.setTimeAxis(TimeAxisUnit.DAY, 1, TimeAxisUnit.DAY, 1, "dd", true); RrdGraph g = new RrdGraph(gdef); String filename = Util.getJRobinDemoPath("plottable1.png"); g.saveAsPNG(filename, 400, 200); System.out.println("Graph1 saved to " + filename); } private void createGraph2() throws RrdException, IOException { GregorianCalendar[] timestamps = { new GregorianCalendar(2004, 2, 1, 0, 0, 0), new GregorianCalendar(2004, 2, 1, 2, 0, 0), new GregorianCalendar(2004, 2, 1, 7, 0, 0), new GregorianCalendar(2004, 2, 1, 14, 0, 0), new GregorianCalendar(2004, 2, 1, 17, 0, 0), new GregorianCalendar(2004, 2, 1, 19, 0, 0), new GregorianCalendar(2004, 2, 1, 23, 0, 0), new GregorianCalendar(2004, 2, 1, 24, 0, 0) }; double[] values = {100, 250, 230, 370, 350, 300, 340, 350}; LinearInterpolator linear = new LinearInterpolator(timestamps, values); linear.setInterpolationMethod(LinearInterpolator.INTERPOLATE_LEFT); CubicSplineInterpolator spline = new CubicSplineInterpolator(timestamps, values); RrdGraphDef gDef = new RrdGraphDef(timestamps[0], timestamps[timestamps.length - 1]); gDef.setTitle("Plottable demonstration"); gDef.setTimeAxisLabel("time"); gDef.setVerticalLabel("water level [inches]"); gDef.datasource("linear", linear); gDef.datasource("spline", spline); gDef.area("spline", Color.ORANGE, "Spline interpolation"); gDef.line("linear", Color.RED, "Linear inteprolation@r", 2); gDef.gprint("spline", "AVERAGE", "Average spline value: @0 inches@r"); gDef.gprint("linear", "AVERAGE", "Average linear value: @0 inches@r"); RrdGraph graph = new RrdGraph(gDef); String filename = Util.getJRobinDemoPath("plottable2.png"); graph.saveAsPNG(filename, 300, 100); System.out.println("Graph2 saved to " + filename); } private void createGraph3() throws RrdException, IOException { LinearInterpolator linear = new LinearInterpolator(SF_TIMESTAMPS, SF_PAGE_HITS); RrdGraphDef gDef = new RrdGraphDef(SF_TIMESTAMPS[0], SF_TIMESTAMPS[SF_TIMESTAMPS.length - 1]); gDef.setTitle("JRobin page hits per month"); gDef.setTimeAxisLabel("month"); gDef.setVerticalLabel("page hits"); gDef.datasource("linear", linear); gDef.area("linear", Color.GREEN, null); gDef.line("linear", Color.RED, "page hits@L", 2); gDef.vrule(new GregorianCalendar(2004, 0, 1), Color.BLUE, null, 3); gDef.setTimeAxis(TimeAxisUnit.MONTH, 1, TimeAxisUnit.MONTH, 1, "MMM", false); gDef.comment("Data provided by SourceForge.net@r"); RrdGraph graph = new RrdGraph(gDef); String filename = Util.getJRobinDemoPath("plottable3.png"); graph.saveAsPNG(filename, 400, 200); System.out.println("Graph3 saved to " + filename); } private void createGraph4() throws RrdException, IOException { LinearInterpolator linear = new LinearInterpolator(SF_TIMESTAMPS, SF_DOWNLOAD_COUNT); RrdGraphDef gDef = new RrdGraphDef(SF_TIMESTAMPS[0], SF_TIMESTAMPS[SF_TIMESTAMPS.length - 1]); gDef.setTitle("JRobin download count per month"); gDef.setTimeAxisLabel("month"); gDef.setVerticalLabel("download count"); gDef.datasource("linear", linear); gDef.area("linear", Color.GREEN, null); gDef.line("linear", Color.RED, "download count@L", 2); gDef.vrule(new GregorianCalendar(2004, 0, 1), Color.BLUE, null, 3); gDef.setTimeAxis(TimeAxisUnit.MONTH, 1, TimeAxisUnit.MONTH, 1, "MMM", false); gDef.comment("Data provided by SourceForge.net@r"); RrdGraph graph = new RrdGraph(gDef); String filename = Util.getJRobinDemoPath("plottable4.png"); graph.saveAsPNG(filename, 400, 200); System.out.println("Graph4 saved to " + filename); } private void createGraph5() throws RrdException, IOException { LinearInterpolator hitsInterpolator = new LinearInterpolator(SF_TIMESTAMPS, SF_PAGE_HITS); LinearInterpolator downloadsInterpolator = new LinearInterpolator(SF_TIMESTAMPS, SF_DOWNLOAD_COUNT); RrdGraphDef gDef = new RrdGraphDef(SF_TIMESTAMPS[0], SF_TIMESTAMPS[SF_TIMESTAMPS.length - 1]); gDef.setTitle("JRobin statistics at SourceForge"); gDef.setTimeAxisLabel("month"); gDef.setVerticalLabel("hits/downloads"); gDef.datasource("hits", hitsInterpolator); gDef.datasource("downloads", downloadsInterpolator); gDef.datasource("ratio", "downloads,0,EQ,UNKN,hits,downloads,/,IF"); gDef.area("hits", Color.GREEN, null); gDef.line("hits", Color.RED, "page hits", 2); gDef.area("downloads", Color.MAGENTA, "downloads@L"); gDef.vrule(new GregorianCalendar(2004, 0, 1), Color.BLUE, null, 3); gDef.setTimeAxis(TimeAxisUnit.MONTH, 1, TimeAxisUnit.MONTH, 1, "MMM", false); gDef.gprint("ratio", "AVERAGE", "Average number of page hits per download: @0@r"); gDef.comment("Data provided by SourceForge.net@r"); RrdGraph graph = new RrdGraph(gDef); String filename = Util.getJRobinDemoPath("plottable5.png"); graph.saveAsPNG(filename, 400, 200); System.out.println("Graph5 saved to " + filename); } private void createGraph6() throws RrdException, IOException { CubicSplineInterpolator hitsInterpolator = new CubicSplineInterpolator(SF_TIMESTAMPS, SF_PAGE_HITS); RrdGraphDef gDef = new RrdGraphDef(SF_TIMESTAMPS[0], SF_TIMESTAMPS[SF_TIMESTAMPS.length - 1]); gDef.setTitle("Trick graph 1"); gDef.setTimeAxisLabel("month"); gDef.setVerticalLabel("hits"); gDef.datasource("hits", hitsInterpolator); gDef.datasource("hits2", "hits,1000,-"); gDef.datasource("invisible", "hits2,0,GE,hits2,0,IF"); gDef.datasource("margin", "hits,invisible,-"); gDef.area("invisible", null, null); gDef.stack("margin", Color.YELLOW, "yellow margin"); gDef.line("hits", Color.RED, "page hits", 3); gDef.line("hits", Color.WHITE, null, 1); gDef.setTimeAxis(TimeAxisUnit.MONTH, 1, TimeAxisUnit.MONTH, 1, "MMM", false); RrdGraph graph = new RrdGraph(gDef); String filename = Util.getJRobinDemoPath("plottable6.png"); graph.saveAsPNG(filename, 400, 200); System.out.println("Graph6 saved to " + filename); } private void createGraph7() throws RrdException, IOException { CubicSplineInterpolator hitsInterpolator = new CubicSplineInterpolator(SF_TIMESTAMPS, SF_PAGE_HITS); RrdGraphDef gDef = new RrdGraphDef(SF_TIMESTAMPS[0], SF_TIMESTAMPS[SF_TIMESTAMPS.length - 1]); gDef.setTitle("Trick graph 2"); gDef.setTimeAxisLabel("month"); gDef.setVerticalLabel("hits"); gDef.datasource("hits", hitsInterpolator); gDef.datasource("avg", "hits", "AVERAGE"); gDef.datasource("diff", "avg,hits,-"); gDef.datasource("diffpos", "diff,0,GE,diff,0,IF"); gDef.datasource("diffneg", "diff,0,LT,diff,0,IF"); gDef.area("hits", null, null); gDef.stack("diffpos", Color.RED, "bad"); gDef.stack("diffneg", Color.GREEN, "good"); gDef.line("hits", Color.BLUE, "hits", 3); gDef.line("hits", Color.WHITE, null, 1); gDef.line("avg", Color.MAGENTA, "average@L", 3); gDef.line("avg", Color.WHITE, null, 1); gDef.setTimeAxis(TimeAxisUnit.MONTH, 1, TimeAxisUnit.MONTH, 1, "MMM", false); gDef.gprint("hits", "AVERAGE", "Average: @0@r"); RrdGraph graph = new RrdGraph(gDef); String filename = Util.getJRobinDemoPath("plottable7.png"); graph.saveAsPNG(filename, 400, 200); System.out.println("Graph7 saved to " + filename); } private void createGraph8() throws RrdException, IOException { GregorianCalendar[] times = { SF_TIMESTAMPS[0], SF_TIMESTAMPS[SF_TIMESTAMPS.length - 1] }; double[] values = { SF_PAGE_HITS[0], SF_PAGE_HITS[SF_PAGE_HITS.length - 1] }; LinearInterpolator trendLine = new LinearInterpolator(times, values); CubicSplineInterpolator hitsInterpolator = new CubicSplineInterpolator(SF_TIMESTAMPS, SF_PAGE_HITS); RrdGraphDef gDef = new RrdGraphDef(SF_TIMESTAMPS[0], SF_TIMESTAMPS[SF_TIMESTAMPS.length - 1]); gDef.setTitle("Trick graph 3"); gDef.setTimeAxisLabel("month"); gDef.setVerticalLabel("hits"); gDef.datasource("hits", hitsInterpolator); gDef.datasource("trend", trendLine); gDef.datasource("diff", "trend,hits,-"); gDef.area("hits", null, null); gDef.stack("diff", Color.YELLOW, "difference"); gDef.line("hits", Color.BLUE, "hits"); gDef.line("trend", Color.RED, "trend@L"); gDef.setTimeAxis(TimeAxisUnit.MONTH, 1, TimeAxisUnit.MONTH, 1, "MMM", false); RrdGraph graph = new RrdGraph(gDef); String filename = Util.getJRobinDemoPath("plottable8.png"); graph.saveAsPNG(filename, 400, 200); System.out.println("Graph8 saved to " + filename); } private void createGraph9() throws RrdException, IOException { final int GRADIENT_STEPS = 30; final Color color1 = Color.RED, color2 = Color.YELLOW; CubicSplineInterpolator hitsInterpolator = new CubicSplineInterpolator(SF_TIMESTAMPS, SF_PAGE_HITS); RrdGraphDef gDef = new RrdGraphDef(SF_TIMESTAMPS[0], SF_TIMESTAMPS[SF_TIMESTAMPS.length - 1]); gDef.setTitle("Trick graph 4"); gDef.setTimeAxisLabel("month"); gDef.setVerticalLabel("hits"); gDef.datasource("hits", hitsInterpolator); for(int i = 0; i <= GRADIENT_STEPS; i++) { gDef.datasource("hits" + i, "hits," + i + ",*," + GRADIENT_STEPS + ",/"); } for(int i = GRADIENT_STEPS; i >=0 ; i--) { Color c = interpolateColor(color1, color2, i / (double) GRADIENT_STEPS); gDef.area("hits" + i, c, null); } gDef.line("hits", Color.BLACK, "Number of page hits"); gDef.setTimeAxis(TimeAxisUnit.MONTH, 1, TimeAxisUnit.MONTH, 1, "MMM", false); RrdGraph graph = new RrdGraph(gDef); String filename = Util.getJRobinDemoPath("plottable9.png"); graph.saveAsPNG(filename, 400, 200); System.out.println("Graph9 saved to " + filename); } private void createGraph10() throws RrdException, IOException { final int GRADIENT_STEPS = 30; final Color color1 = Color.RED, color2 = Color.YELLOW; CubicSplineInterpolator hitsInterpolator = new CubicSplineInterpolator(SF_TIMESTAMPS, SF_PAGE_HITS); RrdGraphDef gDef = new RrdGraphDef(SF_TIMESTAMPS[0], SF_TIMESTAMPS[SF_TIMESTAMPS.length - 1]); gDef.setTitle("Trick graph 5"); gDef.setTimeAxisLabel("month"); gDef.setVerticalLabel("hits"); gDef.datasource("hits", hitsInterpolator); for(int i = 0; i <= GRADIENT_STEPS; i++) { gDef.datasource("hits" + i, "hits," + i + ",*," + GRADIENT_STEPS + ",/"); } for(int i = GRADIENT_STEPS; i >= 0 ; i--) { Color c = interpolateColor(color1, color2, i / (double) GRADIENT_STEPS); gDef.area("hits" + i, c, null); } gDef.line("hits", color2, "Estimated number of page hits"); gDef.setTimeAxis(TimeAxisUnit.MONTH, 1, TimeAxisUnit.MONTH, 1, "MMM", false); gDef.setCanvasColor(color1); RrdGraph graph = new RrdGraph(gDef); String filename = Util.getJRobinDemoPath("plottable10.png"); graph.saveAsPNG(filename, 400, 200); System.out.println("Graph10 saved to " + filename); } private void createGraph11() throws RrdException, IOException { final int GRADIENT_STEPS = 30; final Color color1 = Color.YELLOW, color2 = Color.RED; CubicSplineInterpolator hitsInterpolator = new CubicSplineInterpolator(SF_TIMESTAMPS, SF_PAGE_HITS); RrdGraphDef gDef = new RrdGraphDef(SF_TIMESTAMPS[0], SF_TIMESTAMPS[SF_TIMESTAMPS.length - 1]); gDef.setTitle("Trick graph 6"); gDef.setTimeAxisLabel("month"); gDef.setVerticalLabel("hits"); gDef.datasource("hits", hitsInterpolator); gDef.datasource("top", "hits", "MAX"); for(int i = 1; i <= GRADIENT_STEPS; i++) { gDef.datasource("hits" + i, "hits,top," + i + ",*," + GRADIENT_STEPS + ",/,MIN"); } for(int i = GRADIENT_STEPS; i >= 1 ; i--) { Color c = i % 2 == 0? color1: color2; gDef.area("hits" + i, c, null); } gDef.line("hits", color2, "Estimated number of page hits"); gDef.setTimeAxis(TimeAxisUnit.MONTH, 1, TimeAxisUnit.MONTH, 1, "MMM", false); RrdGraph graph = new RrdGraph(gDef); String filename = Util.getJRobinDemoPath("plottable11.png"); graph.saveAsPNG(filename, 400, 200); System.out.println("Graph11 saved to " + filename); } private void createGraph12() throws RrdException, IOException { final int GRADIENT_STEPS = 15; final Color color1 = Color.LIGHT_GRAY, color2 = Color.WHITE; CubicSplineInterpolator hitsInterpolator = new CubicSplineInterpolator(SF_TIMESTAMPS, SF_PAGE_HITS); RrdGraphDef gDef = new RrdGraphDef(SF_TIMESTAMPS[0], SF_TIMESTAMPS[SF_TIMESTAMPS.length - 1]); gDef.setTitle("Trick graph 7"); gDef.setTimeAxisLabel("month"); gDef.setVerticalLabel("hits"); gDef.datasource("hits", hitsInterpolator); for(int i = GRADIENT_STEPS; i >= 1 ; i--) { Color c = interpolateColor(color1, color2, i / (double) GRADIENT_STEPS); gDef.line("hits", c, null, i); } gDef.line("hits", color1, "Estimated number of page hits"); gDef.setTimeAxis(TimeAxisUnit.MONTH, 1, TimeAxisUnit.MONTH, 1, "MMM", false); RrdGraph graph = new RrdGraph(gDef); String filename = Util.getJRobinDemoPath("plottable12.png"); graph.saveAsPNG(filename, 400, 200); System.out.println("Graph12 saved to " + filename); } private void createGraph13() throws RrdException, IOException { final int GRADIENT_STEPS = 20; final double GRADIENT_WIDTH = 2000.0; final Color color1 = Color.RED, color2 = Color.WHITE; CubicSplineInterpolator hitsInterpolator = new CubicSplineInterpolator(SF_TIMESTAMPS, SF_PAGE_HITS); RrdGraphDef gDef = new RrdGraphDef(SF_TIMESTAMPS[0], SF_TIMESTAMPS[SF_TIMESTAMPS.length - 1]); gDef.setTitle("Trick graph 8"); gDef.setTimeAxisLabel("month"); gDef.setVerticalLabel("hits"); gDef.datasource("hits", hitsInterpolator); for(int i = 0; i <= GRADIENT_STEPS; i++) { gDef.datasource("hits" + i, "hits," + GRADIENT_WIDTH + "," + i + ",*," + GRADIENT_STEPS + ",/,-,0,MAX"); } for(int i = 0; i <= GRADIENT_STEPS; i++) { gDef.area("hits" + i, interpolateColor(color1, color2, i / (double) GRADIENT_STEPS), null); } gDef.setTimeAxis(TimeAxisUnit.MONTH, 1, TimeAxisUnit.MONTH, 1, "MMM", false); RrdGraph graph = new RrdGraph(gDef); String filename = Util.getJRobinDemoPath("plottable13.png"); graph.saveAsPNG(filename, 400, 200); System.out.println("Graph13 saved to " + filename); } private void createGraph14() throws RrdException, IOException { final int STEPS = 20; final Color color1 = Color.BLACK, color2 = Color.RED; CubicSplineInterpolator hitsInterpolator = new CubicSplineInterpolator(SF_TIMESTAMPS, SF_PAGE_HITS); RrdGraphDef gDef = new RrdGraphDef(SF_TIMESTAMPS[0], SF_TIMESTAMPS[SF_TIMESTAMPS.length - 1]); gDef.setTitle("Trick graph 9"); gDef.setTimeAxisLabel("month"); gDef.setVerticalLabel("hits"); gDef.datasource("hits", hitsInterpolator); gDef.datasource("maxhits", "hits", "MAX"); for(int i = 1; i <= STEPS; i++) { gDef.datasource("hits" + i, "maxhits," + i + ",*," + STEPS + ",/,hits,GE,hits,0,IF"); } for(int i = STEPS; i >= 1; i--) { gDef.area("hits" + i, interpolateColor(color1, color2, i / (double) STEPS), null); } gDef.line("hits", Color.BLUE, "page hits", 2); gDef.setTimeAxis(TimeAxisUnit.MONTH, 1, TimeAxisUnit.MONTH, 1, "MMM", false); RrdGraph graph = new RrdGraph(gDef); String filename = Util.getJRobinDemoPath("plottable14.png"); graph.saveAsPNG(filename, 400, 200); System.out.println("Graph14 saved to " + filename); } private void createGraph15() throws RrdException, IOException { final int STEPS = 20; final Color color1 = Color.BLACK, color2 = Color.RED; LinearInterpolator hitsInterpolator = new LinearInterpolator(SF_TIMESTAMPS, SF_PAGE_HITS); hitsInterpolator.setInterpolationMethod(LinearInterpolator.INTERPOLATE_LEFT); RrdGraphDef gDef = new RrdGraphDef(SF_TIMESTAMPS[0], SF_TIMESTAMPS[SF_TIMESTAMPS.length - 1]); gDef.setTitle("Trick graph 10"); gDef.setTimeAxisLabel("month"); gDef.setVerticalLabel("hits"); gDef.datasource("hits", hitsInterpolator); gDef.datasource("maxhits", "hits", "MAX"); for(int i = 1; i <= STEPS; i++) { gDef.datasource("hits" + i, "maxhits," + i + ",*," + STEPS + ",/,hits,GE,hits,0,IF"); } for(int i = STEPS; i >= 1; i--) { gDef.area("hits" + i, interpolateColor(color1, color2, i / (double) STEPS), null); } gDef.line("hits", Color.BLUE, "page hits", 2); gDef.setTimeAxis(TimeAxisUnit.MONTH, 1, TimeAxisUnit.MONTH, 1, "MMM", false); RrdGraph graph = new RrdGraph(gDef); String filename = Util.getJRobinDemoPath("plottable15.png"); graph.saveAsPNG(filename, 400, 200); System.out.println("Graph15 saved to " + filename); } private void createGraph16() throws RrdException, IOException { LinearInterpolator hitsInterpolator = new LinearInterpolator(SF_TIMESTAMPS, SF_PAGE_HITS); LinearInterpolator trendInterpolator = new LinearInterpolator(SF_TIMESTAMPS, SF_PAGE_HITS); trendInterpolator.setInterpolationMethod(LinearInterpolator.INTERPOLATE_REGRESSION); RrdGraphDef gDef = new RrdGraphDef(SF_TIMESTAMPS[0], SF_TIMESTAMPS[SF_TIMESTAMPS.length - 1]); gDef.setTitle("Trend report"); gDef.setTimeAxisLabel("month"); gDef.setVerticalLabel("hits"); gDef.datasource("hits", hitsInterpolator); gDef.datasource("trend", trendInterpolator); gDef.datasource("diff", "hits,trend,-"); gDef.datasource("absdiff", "diff,ABS"); gDef.area("trend", null, null); gDef.stack("diff", Color.YELLOW, "difference"); gDef.line("hits", Color.RED, "real page hits"); gDef.line("trend", Color.BLUE, "trend@L"); gDef.gprint("absdiff", "AVERAGE", "Average difference: @0@r"); gDef.setTimeAxis(TimeAxisUnit.MONTH, 1, TimeAxisUnit.MONTH, 1, "MMM", false); RrdGraph graph = new RrdGraph(gDef); String filename = Util.getJRobinDemoPath("plottable16.png"); graph.saveAsPNG(filename, 400, 200); System.out.println("Graph16 saved to " + filename); } private Color interpolateColor(Color c1, Color c2, double factor) { int r = c1.getRed() + (int)((c2.getRed() - c1.getRed()) * factor); int g = c1.getGreen() + (int)((c2.getGreen() - c1.getGreen()) *... [truncated message content] |
From: Sasa M. <sa...@us...> - 2004-06-09 12:08:26
|
Update of /cvsroot/jrobin/src/org/jrobin/demo In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21065/demo Log Message: Directory /cvsroot/jrobin/src/org/jrobin/demo added to the repository |
Update of /cvsroot/jrobin/res/mrtg In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31589/mrtg Added Files: help.html icon.png link.png link_inactive.png logo.png mrtg.png robin-bird.png router.png router_inactive.png Log Message: resource files for MRTG client --- NEW FILE: logo.png --- (This appears to be a binary file; contents omitted.) --- NEW FILE: icon.png --- (This appears to be a binary file; contents omitted.) --- NEW FILE: robin-bird.png --- (This appears to be a binary file; contents omitted.) --- NEW FILE: link_inactive.png --- (This appears to be a binary file; contents omitted.) --- NEW FILE: help.html --- <h1>JRobin-MRTG</h1> <p>Once upon a time Tobi Oetiker created <b>The Multi Router Traffic Grapher (MRTG)</b>:</p> <blockquote style="MARGIN-RIGHT: 0px"> <p><em>...a tool to monitor the traffic load on network-links. MRTG generates HTML pages containing graphical images which provide a LIVE visual representation of this traffic</em>... <em>MRTG is based on Perl and C and works under UNIX and Windows NT...</em> </p></blockquote> <p>MRTG runs as a scheduled task: <em>cron</em> daemon is used on UNIX systems to run MRTG each 5 minutes, for example. MRTG creates traffic graphs as PNG files embedded in simple HTML pages. All pages (with daily, weekly, monthly and yearly graphs) are created in a single directory backed by (Apache) web server: you can watch your Internet traffic (almost) LIVE by means of any web browser.</p> <p>Under the hood, you'll find that Tobi's MRTG uses some kind of RRD files to store traffic data (MRTG native format or RRDTool file format). So, I thought, it should be possible to create a similar application in pure Java using JRobin. <strong>I did not want to compete with MRTG</strong>, <strong>I just wanted to prove that JRobin is useful for the same purposes as Tobi's famous RRDTool and MRTG</strong>. But if you want to measure your internet traffic in a simple and efficient way, you'll be probably satisfied.</p> <p>So, JRobin-MRTG is finally here. It consists of two separate applications: the client and the server one. These two applications communicate through protocol. You can run one server application and as many client applications on as many different machines as you want. Client applications are used to control the server: to remotely add, edit, update or delete monitored network interfaces and to request specific traffic graphs.</p> <h2>JRobin-MRTG server</h2> <p>Server application is used to:</p> <ul> <li>collect information about Internet traffic load from various network devices supporting SNMP protocol (routers, switches, network servers); <li>store traffic information into JRobin RRD files; <li>create graphs and other information for any number of JRobin-MRTG client applications;</li> </ul> <p>To run server application, issue the following command from the command line:</p><pre> java -jar mrtg-server-[version].jar </pre> <p>The command line could be more complex if you don't have X-server (windows) installed and you don't want to be interrupted once you log out (common situation on many network servers). In that case use the following command:</p><pre> nohup java -Djava.awt.headless=true -jar mrtg-server-[version].jar > /dev/null 2>&1 & </pre> <p>The server application uses port 35353 to communicate with unlimited number of client applications. It can be reached with any JRobin-MRTG client from the internet (unless firewall blocks XMLRPC communication between clients and the server application). If you want to restrict access to the server application, add IP addresses of trusted clients to the command line. For example:</p><pre> java -Djava.awt.headless=true -jar mrtg-server-[version].jar 192.168.1.23 192.168.1.24 </pre> <p>When server application is run for the first time, <strong>mrtg</strong> directory will be created in your <strong>$HOME</strong> directory. Newly created directory has two subdirectories: <strong>conf</strong> and <strong>rrd</strong>. The first directory (<strong>conf</strong>) containts a single XML file - <strong>hardware.dat. </strong> It holds complete information about monitored internet devices and interfaces. The second directory (<strong>rrd</strong>) contains RRD files, one file per each monitored network interface. If you monitor internet traffic through interface <em>Serial2</em> on the router <em>belgrade2.eunet.yu</em>, you will find a file named <em>Se...@be....rrd</em><em> </em> in this directory.</p> <p>Server application requires the following libraries to be present:</p> <ul> <li>Jakarta XML-RPC library for communication between the server and client applications; <li>SNMP library for communication with network devices (actual traffic load measurement); <li>JFreeChart library for graph creation; <li>JRobin library for RRD files manipulation and graph creation.</li> </ul> <p>All requested libraries can be found in the <strong>libs</strong> directory of this distribution.</p> <h2>JRobin-MRTG client</h2> <p>Client application is used to control the work of the server application. Java swing library is used to create the client UI. This UI is used to:</p> <ul> <li>remotely add/edit/update/delete monitored network devices (routers, switches, network stations) and associated network interfaces; <li>remotely create daily, weekly, monthly, yearly and custom-period traffic graphs on the server side, bring them to the client side and show them on the screen; <li>store these graphs in PNG files.</li> </ul> <p>Client application requires already mentioned Jakarta XML-RPC library for communication with the server (it can be found in the <strong>libs</strong> directory of this distribution). To run client application issue the following command from the command line:</p><pre> java -jar mrtg-client-[version].jar </pre> <p>You will be asked to specify the address of the host on which JRobin-MRTG server application is running. Once you are connected, you will see the client application's UI.</p> <p>Client UI has two preview panes: the left (tree) pane contains information about monitored network interfaces. The right (text) pane contains information about the selected element of the tree on the left side. Network devices (like routers and switches) are commonly denoted as 'routers'.</p> <p><strong>Note: </strong> Displayed information is not constantly updated! It gets updated whenever you add, update or remove a single router or its interface. If you want to refresh the displayed data so that it corresponds with the actual data on the server, right click anywhere on the client or choose <em>Reload data from MRTG host </em> from the <em>MRTG</em> menu. However, all kind of graphs are always generated using the latest available information from the server. And the graphs are constantly refreshed if necessary. They are as LIVE as Tobi's MRTG graphs are :)</p> <p>In my humble opinion, client UI is simple and intuitive. You should have no problem to start monitoring your internet traffic load in a matter of minutes. I will explain only a few of the most interesting operations here.</p> <h2>How to add a router</h2> <ul> <li>From the client menu, choose <em>Router actions / Add router...</em> New router dialog appears. <li>Supply router address (like <em>belgrade2.eunet.yu</em> or 123.000.111.222). <li>Supply router <em>community</em>. Communities are something like passwords for SNMP access to the router. If not sure about which community to use, ask your network administrator. <li>Supply some description of the router if necessary for future reference. <li>Checkbox <em>Active</em> should be already checked by default. <li>Click OK. Newly defined router appears on the left side of the screen.</li> </ul> <h2>How to add a network interface</h2> <ul> <li>Select the router with the desired interface in the tree pane. <li>From the menu, choose <em>Interface actions / Add interface... </em>New interface dialog appears. <li>Select the desired interface from the list of all available interfaces on the router. <li>Specify description if necessary for future reference. <li>Specify sampling interval in seconds. It represents the amount of time that should pass before the server applications checks the traffic load for the specific interface on the router once again. Valid values are between 10 seconds and 600 seconds (10 minutes). <li>Checkbox <em>Active</em> should be already checked by default. <li>Click OK.</li> </ul> <p>Newly defined interface appears on the left side of the screen, probably with [-1] number added to its name. It means that MRTG server still does not know the real number of the interface on the router. But if you reload data from MRTG sever a few seconds later, you will probably see some positive number instead of [-1]. It means that the new interface exists on the router. You can be sure that the traffic monitoring process has started successfully.</p> <p>I have tried to make JRobin-MRTG as clever as I could - if router gets reconfigured so that its interfaces change its corresponding interface numbers, JRobin-MRTG server application will notice this and update interface numbers on the fly.</p> <h2>How to create traffic graphs </h2> <ul> <li>Select network interface you want to create graph for. <li>Chose the desired graph type from the <em>Interface actions </em>menu. The following graphs can be created with a single click: daily, weekly, monthly, yearly, last 24 hours and custom-period graphs. The graph appears in the new frame. <li>Click on the <em>Save</em> button to the right of the graph to save it in a PNG file format.</li> </ul> <p><strong>Note: </strong></p> <ul> <li>Graphs starting in the past and ending in the future (graph for the current day, week, month and year, for example) are automatically refreshed each 5 minutes. You can watch the growth of your current daily graph - LIVE. <li>Graphs are created on the server side, not on the client side. Future versions of JRobin-MRTG might change this. But, at this moment, graphs are serialized on the server side and transmitted to the client via XML-RPC protocol. <li>You can open as many graph frames as you wish. All graphs will be updated simultaneously, if necessary. <li>Use custom graphs to create traffic graphs for arbitrary time intervals.</li> </ul> <p>Have fun! :)</p> --- NEW FILE: mrtg.png --- (This appears to be a binary file; contents omitted.) --- NEW FILE: link.png --- (This appears to be a binary file; contents omitted.) --- NEW FILE: router.png --- (This appears to be a binary file; contents omitted.) --- NEW FILE: router_inactive.png --- (This appears to be a binary file; contents omitted.) |
From: Sasa M. <sa...@us...> - 2004-06-09 10:23:25
|
Update of /cvsroot/jrobin/lib In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30937 Added Files: snmp-1.3.jar xmlrpc-1.2-b1.jar Log Message: External libraries --- NEW FILE: xmlrpc-1.2-b1.jar --- (This appears to be a binary file; contents omitted.) --- NEW FILE: snmp-1.3.jar --- (This appears to be a binary file; contents omitted.) |
From: Sasa M. <sa...@us...> - 2004-06-09 10:22:35
|
Update of /cvsroot/jrobin/ant In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30329 Added Files: build.xml Log Message: Ant build file --- NEW FILE: build.xml --- <!-- /* ============================================================ * JRobin : Pure java implementation of RRDTool's functionality * ============================================================ * * Project Info: http://www.jrobin.org * Project Lead: Sasa Markovic (sa...@jr...) * * Developers: Sasa Markovic (sa...@jr...) * Arne Vandamme (cob...@jr...) * * (C) Copyright 2003, by Sasa Markovic. * * This library is free software; you can redistribute it and/or modify it under the terms * of the GNU Lesser General Public License as published by the Free Software Foundation; * either version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License along with this * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, * Boston, MA 02111-1307, USA. */ --> <project name="JRobin" default="dist" basedir="."> <description>JRobin build file</description> <!-- VARIABLES --> <property name="version" value="1.4.0" /> <property name="who" value="Sasa Markovic <sa...@jr...>"/> <property name="cwd" location=".."/> <property name="classes" value="classes"/> <property name="doc" value="doc"/> <property name="javadoc" value="${doc}/javadoc"/> <property name="dist" value="dist"/> <property name="src" value="src"/> <property name="libs" value="lib" /> <property name="ant" value="ant" /> <property name="lib-snmp" value="snmp-1.3.jar"/> <property name="lib-xmlrpc" value="xmlrpc-1.2-b1.jar"/> <property name="lib-jrobin" value="JRobin-${version}.jar"/> <property name="lib-mrtg-client" value="mrtg-client-${version}.jar"/> <property name="lib-mrtg-server" value="mrtg-server-${version}.jar"/> <property name="lib-inspector" value="inspector-${version}.jar"/> <property name="lib-convertor" value="convertor-${version}.jar"/> <property name="res" value="res"/> <property name="res-mrtg" value="${res}/mrtg"/> <property name="classpath" value="${cwd}/${libs}/${lib-snmp}:${cwd}/${libs}/${lib-xmlrpc}"/> <property name="tarfile" value="JRobin-${version}.tar"/> <property name="tgzfile" value="JRobin-${version}.tar.gz"/> <!-- TARGETS --> <target name="init"> <tstamp/> </target> <target name="clean" depends="init"> <delete includeemptydirs="true"> <fileset dir="${cwd}" > <include name="${classes}/**/*"/> <include name="${dist}/JRobin*.tar.gz"/> <include name="${javadoc}/**/*"/> <include name="${libs}/${lib-jrobin}" /> <include name="${libs}/${lib-mrtg-client}" /> <include name="${libs}/${lib-mrtg-server}" /> <include name="${libs}/${lib-inspector}" /> <include name="${libs}/${lib-convertor}" /> </fileset> </delete> </target> <target name="compile" depends="init"> <mkdir dir="${cwd}/${classes}"/> <javac srcdir="${cwd}/${src}" destdir="${cwd}/${classes}" classpath="${classpath}" compiler="modern" source="1.4" /> </target> <target name="core-lib" depends="compile"> <delete file="${cwd}/${libs}/${lib-jrobin}" /> <jar jarfile="${cwd}/${libs}/${lib-jrobin}" basedir="${cwd}/${classes}"> <manifest> <attribute name="Main-Class" value="Demo"/> </manifest> <include name="org/jrobin/core/**/*.class"/> <include name="org/jrobin/graph/**/*.class"/> <include name="*.class"/> </jar> </target> <target name="mrtg-server-lib" depends="core-lib"> <delete file="${cwd}/${libs}/${lib-mrtg-server}" /> <jar jarfile="${cwd}/${libs}/${lib-mrtg-server}" basedir="${cwd}/${classes}"> <manifest> <attribute name="Main-Class" value="org.jrobin.mrtg.server.Server"/> <attribute name="Class-Path" value="${lib-xmlrpc} ${lib-snmp} ${lib-jrobin}"/> </manifest> <include name="org/jrobin/mrtg/*.class"/> <include name="org/jrobin/mrtg/server/*.class"/> </jar> </target> <target name="mrtg-client-lib" depends="mrtg-server-lib"> <delete file="${cwd}/${libs}/${lib-mrtg-client}" /> <jar jarfile="${cwd}/${libs}/${lib-mrtg-client}" basedir="${cwd}/${classes}"> <include name="org/jrobin/mrtg/*.class"/> <include name="org/jrobin/mrtg/client/*.class"/> </jar> <jar jarfile="${cwd}/${libs}/${lib-mrtg-client}" basedir="${cwd}" update="true" > <include name="${res-mrtg}/**/*"/> <manifest> <attribute name="Main-Class" value="org.jrobin.mrtg.client.Client"/> <attribute name="Class-Path" value="${lib-xmlrpc}"/> </manifest> </jar> </target> <target name="inspector-lib" depends="core-lib"> <delete file="${cwd}/${libs}/${lib-inspector}" /> <jar jarfile="${cwd}/${libs}/${lib-inspector}" basedir="${cwd}/${classes}"> <manifest> <attribute name="Main-Class" value="org.jrobin.inspector.RrdInspector"/> <attribute name="Class-Path" value="${lib-jrobin}"/> </manifest> <include name="org/jrobin/inspector/*.class"/> </jar> </target> <target name="convertor-lib" depends="core-lib"> <delete file="${cwd}/${libs}/${lib-convertor}" /> <jar jarfile="${cwd}/${libs}/${lib-convertor}" basedir="${cwd}/${classes}"> <manifest> <attribute name="Main-Class" value="org.jrobin.convertor.Convertor"/> <attribute name="Class-Path" value="${lib-jrobin}"/> </manifest> <include name="org/jrobin/convertor/*.class"/> </jar> </target> <target name="all-libs" depends="core-lib,mrtg-server-lib,mrtg-client-lib,inspector-lib,convertor-lib"/> <target name="javadoc" depends="compile"> <javadoc author="false" version="false" destdir="${cwd}/${javadoc}" packagenames="org.jrobin.core.*,org.jrobin.graph.*" source="1.4" sourcepath="${cwd}/${src}" classpath="${classpath}" access="protected" /> </target> <target name="dist" depends="all-libs,javadoc"> <mkdir dir="${cwd}/${dist}"/> <delete file="${cwd}/${dist}/${tarfile}>"/> <delete file="${cwd}/${dist}/${tgzfile}>"/> <property name="prefix" value="jrobin-${version}"/> <tar destfile="${cwd}/${dist}/${tarfile}"> <tarfileset dir="${cwd}/${doc}" prefix="${prefix}/${doc}"> <include name="**/*"/> </tarfileset> <tarfileset dir="${cwd}/${libs}" prefix="${prefix}/${libs}"> <include name="*.jar"/> </tarfileset> <tarfileset dir="${cwd}/${src}" prefix="${prefix}/${src}"> <exclude name="**/test/**/*"/> <include name="**/*.java"/> </tarfileset> <tarfileset dir="${cwd}/${res}" prefix="${prefix}/${res}"> <include name="**/*"/> </tarfileset> <tarfileset dir="${cwd}/${ant}" prefix="${prefix}/${ant}"> <include name="*.xml"/> </tarfileset> </tar> <gzip src="${cwd}/${dist}/${tarfile}" zipfile="${cwd}/${dist}/${tgzfile}"/> <delete file="${cwd}/${dist}/${tarfile}"/> </target> </project> |
From: Sasa M. <sa...@us...> - 2004-06-09 10:21:22
|
Update of /cvsroot/jrobin/res/mrtg In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv29194/mrtg Log Message: Directory /cvsroot/jrobin/res/mrtg added to the repository |
From: Sasa M. <sa...@us...> - 2004-06-09 09:44:57
|
Update of /cvsroot/jrobin/src/org/jrobin/core In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv1817/org/jrobin/core Modified Files: RrdNioBackendFactory.java Log Message: added javadoc Index: RrdNioBackendFactory.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/core/RrdNioBackendFactory.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** RrdNioBackendFactory.java 1 Jun 2004 14:41:01 -0000 1.6 --- RrdNioBackendFactory.java 9 Jun 2004 09:44:47 -0000 1.7 *************** *** 36,50 **** public static final String NAME = "NIO"; ! /** See {@link #setSyncMode(int) for explanation } */ public static final int SYNC_ONCLOSE = 0; // will sync() only on close() ! /** See {@link #setSyncMode(int) for explanation } */ public static final int SYNC_BEFOREUPDATE = 1; ! /** See {@link #setSyncMode(int) for explanation } */ public static final int SYNC_AFTERUPDATE = 2; ! /** See {@link #setSyncMode(int) for explanation } */ public static final int SYNC_BEFOREFETCH = 3; ! /** See {@link #setSyncMode(int) for explanation } */ public static final int SYNC_AFTERFETCH = 4; ! /** See {@link #setSyncMode(int) for explanation } */ public static final int SYNC_BACKGROUND = 5; /** --- 36,50 ---- public static final String NAME = "NIO"; ! /** See {@link #setSyncMode(int)} for explanation */ public static final int SYNC_ONCLOSE = 0; // will sync() only on close() ! /** See {@link #setSyncMode(int)} for explanation */ public static final int SYNC_BEFOREUPDATE = 1; ! /** See {@link #setSyncMode(int)} for explanation */ public static final int SYNC_AFTERUPDATE = 2; ! /** See {@link #setSyncMode(int)} for explanation */ public static final int SYNC_BEFOREFETCH = 3; ! /** See {@link #setSyncMode(int)} for explanation */ public static final int SYNC_AFTERFETCH = 4; ! /** See {@link #setSyncMode(int)} for explanation */ public static final int SYNC_BACKGROUND = 5; /** |