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: <sa...@us...> - 2003-10-21 13:52:07
|
Update of /cvsroot/jrobin/src/jrobin/core In directory sc8-pr-cvs1:/tmp/cvs-serv27580/jrobin/core Added Files: FetchData.java Log Message: FetchData class, use it to replace previous fetching mechanism... --- NEW FILE: FetchData.java --- /* ============================================================ * JRobin : Pure java implementation of RRDTool's functionality * ============================================================ * * Project Info: http://www.sourceforge.net/projects/jrobin * Project Lead: Sasa Markovic (sa...@eu...); * * (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 jrobin.core; import java.io.IOException; /** * Class used to represent data fetched from the RRD file. * Object of this class is created when the method * {@link jrobin.core.FetchRequest#fetchData() fetchData()} is * called on a {@link jrobin.core.FetchRequest FetchRequest} object.<p> * * Data returned from the RRD file is, simply, just one big table filled with * timestamps and corresponding datasource values. * Use {@link #getRowCount() getRowCount()} method to count the number * of returned timestamps (table rows).<p> * * The first table column is filled with timestamps. Time intervals * between consecutive timestamps are guaranteed to be equal. Use * {@link #getTimestamps() getTimestamps()} method to get an array of * timestamps returned.<p> * * Remaining columns are filled with datasource values for the whole timestamp range, * on a column-per-datasource basis. Use {@link #getColumnCount() getColumnCount()} to find * the number of datasources and {@link #getValues(int) getValues(i)} method to obtain * all values for the i-th datasource. Returned datasource values correspond to * the values returned with {@link #getTimestamps() getTimestamps()} method.<p> */ public class FetchData { private FetchRequest request; private Archive matchingArchive; private String[] dsNames; private long[] timestamps; private double[][] values; FetchData(Archive matchingArchive, FetchRequest request) throws IOException { this.matchingArchive = matchingArchive; this.dsNames = matchingArchive.getParentDb().getDsNames(); this.request = request; } void setTimestamps(long[] timestamps) { this.timestamps = timestamps; } void setValues(double[][] values) { this.values = values; } /** * Returns the number of rows fetched from the underlying RRD file. * Each row represents datasource values for the specific timestamp. * @return Number of rows. */ public int getRowCount() { return timestamps.length; } /** * Returns the number of columns fetched from the underlying RRD file. * This number is always equal to the number of datasources defined * in the RRD file. Each column represents values of a single datasource. * @return Number of columns (datasources). */ public int getColumnCount() { return dsNames.length; } /** * Returns the number of rows fetched from the underlying RRD file. * Each row represents datasource values for the specific timestamp. * @param rowIndex Row index. * @return FetchPoint object which represents datasource values for the * specific timestamp. */ public FetchPoint getRow(int rowIndex) { int numCols = getColumnCount(); FetchPoint point = new FetchPoint(timestamps[rowIndex], getColumnCount()); for(int dsIndex = 0; dsIndex < numCols; dsIndex++) { point.setValue(dsIndex, values[dsIndex][rowIndex]); } return point; } /** * Returns an array of timestamps covering the whole range specified in the * {@link FetchRequest FetchReguest} object. * @return Array of equidistant timestamps. */ public long[] getTimestamps() { return timestamps; } /** * Returns all archived values for a single datasource. * Returned values correspond to timestamps * returned with {@link #getTimestamps() getTimestamps()} method. * @param dsIndex Datasource index. * @return Array of single datasource values. */ public double[] getValues(int dsIndex) { return values[dsIndex]; } /** * Returns all archived values for a single datasource. * Returned values correspond to timestamps * returned with {@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 { for(int dsIndex = 0; dsIndex < getColumnCount(); dsIndex++) { if(dsName.equals(dsNames[dsIndex])) { return getValues(dsIndex); } } throw new RrdException("Datasource [" + dsName + "] not found"); } /** * Returns {@link FetchRequest FetchRequest} object used to create this FetchData object. * @return Fetch request object. */ public FetchRequest getRequest() { return request; } /** * Returns the first timestamp in this FetchData object. * @return The smallest timestamp. */ public long getFirstTimestamp() { return timestamps[0]; } /** * Returns the last timestamp in this FecthData object. * @return The biggest timestamp. */ public long getLastTimestamp() { return timestamps[timestamps.length - 1]; } /** * Returns Archive object which is determined to be the best match for the * timestamps specified in the fetch request. All datasource values are obtained * from round robin archives belonging to this archive. * @return Matching archive. */ public Archive getMatchingArchive() { return matchingArchive; } /** * Returns array of datasource names found in the underlying RRD file. * @return Array of datasource names. */ public String[] getDsNames() { return dsNames; } /** * Dumps the content of the whole FetchData object to stdout. Useful for debugging. */ public void dump() { for(int i = 0; i < getRowCount(); i++) { System.out.println(getRow(i).dump()); } } } |
|
From: <sa...@us...> - 2003-10-21 13:50:59
|
Update of /cvsroot/jrobin/src/jrobin/core
In directory sc8-pr-cvs1:/tmp/cvs-serv14516/jrobin/core
Modified Files:
Archive.java FetchPoint.java FetchRequest.java Robin.java
RrdDb.java
Log Message:
Two nice graphs...
Index: Archive.java
===================================================================
RCS file: /cvsroot/jrobin/src/jrobin/core/Archive.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** Archive.java 6 Oct 2003 10:45:04 -0000 1.5
--- Archive.java 21 Oct 2003 12:53:05 -0000 1.6
***************
*** 312,315 ****
--- 312,351 ----
}
+ FetchData fetchData(FetchRequest request) throws IOException, RrdException {
+ long arcStep = getArcStep();
+ long fetchStart = Util.normalize(request.getFetchStart(), arcStep);
+ long fetchEnd = Util.normalize(request.getFetchEnd(), arcStep);
+ if(fetchEnd < request.getFetchEnd()) {
+ fetchEnd += arcStep;
+ }
+ long startTime = getStartTime();
+ long endTime = getEndTime();
+ int dsCount = robins.length;
+ int ptsCount = (int) ((fetchEnd - fetchStart) / arcStep + 1);
+ long[] timestamps = new long[ptsCount];
+ double[][] values = new double[dsCount][ptsCount];
+ for(int ptIndex = 0; ptIndex < ptsCount; ptIndex++) {
+ long time = fetchStart + ptIndex * arcStep;
+ timestamps[ptIndex] = time;
+ if(time >= startTime && time <= endTime) {
+ // inbound time
+ int robinIndex = (int)((time - startTime) / arcStep);
+ for(int dsIndex = 0; dsIndex < dsCount; dsIndex++) {
+ values[dsIndex][ptIndex] = robins[dsIndex].getValue(robinIndex);
+ }
+ }
+ else {
+ // time out of bounds
+ for(int dsIndex = 0; dsIndex < dsCount; dsIndex++) {
+ values[dsIndex][ptIndex] = Double.NaN;
+ }
+ }
+ }
+ FetchData fetchData = new FetchData(this, request);
+ fetchData.setTimestamps(timestamps);
+ fetchData.setValues(values);
+ return fetchData;
+ }
+
void appendXml(XmlWriter writer) throws IOException {
writer.startTag("rra");
Index: FetchPoint.java
===================================================================
RCS file: /cvsroot/jrobin/src/jrobin/core/FetchPoint.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** FetchPoint.java 4 Sep 2003 13:26:41 -0000 1.1
--- FetchPoint.java 21 Oct 2003 12:53:05 -0000 1.2
***************
*** 74,90 ****
* @param i Data source index.
* @return Value of the i-th data source.
- * @throws RrdException
*/
! public double getValue(int i) throws RrdException {
! if(i >= values.length) {
! throw new RrdException("Index [" + i + "] out of bounds [" + values.length + "]");
! }
return values[i];
}
! void setValue(int index, double value) throws RrdException {
! if(index >= values.length) {
! throw new RrdException("Index [" + index + "] out of bounds [" + values.length + "]");
! }
values[index] = value;
}
--- 74,83 ----
* @param i Data source index.
* @return Value of the i-th data source.
*/
! public double getValue(int i) {
return values[i];
}
! void setValue(int index, double value) {
values[index] = value;
}
Index: FetchRequest.java
===================================================================
RCS file: /cvsroot/jrobin/src/jrobin/core/FetchRequest.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** FetchRequest.java 4 Sep 2003 13:26:41 -0000 1.1
--- FetchRequest.java 21 Oct 2003 12:53:05 -0000 1.2
***************
*** 119,124 ****
/**
! * Returns data from RRD file. Returned data consists of many fetch points (see
! * {@link jrobin.core.FetchPoint FetchPoint}), and each fetch point represents
* RRD datasource values for the specific timestamp. Timestamp difference between
* consecutive fecth points is guaranteed to be constant.
--- 119,124 ----
/**
! * Returns data from the underlying RRD file as an array of
! * {@link jrobin.core.FetchPoint FetchPoint} objects. Each fetch point object represents
* RRD datasource values for the specific timestamp. Timestamp difference between
* consecutive fecth points is guaranteed to be constant.
***************
*** 126,132 ****
--- 126,145 ----
* @throws RrdException Thrown in case of JRobin specific error.
* @throws IOException Thrown in case of I/O error.
+ * @deprecated As of version 1.2.0 replaced with {@link #fetchData() fetchData()}.
*/
public FetchPoint[] fetch() throws RrdException, IOException {
return parentDb.fetch(this);
+ }
+
+ /**
+ * Returns data from the underlying RRD file and puts it in a single
+ * {@link jrobin.core.FetchData FetchData} object. Use this method instead of
+ * deprecated {@link #fetch() fetch()} method.
+ * @return FetchPoint object filled with timestamps and datasource values.
+ * @throws RrdException Thrown in case of JRobin specific error.
+ * @throws IOException Thrown in case of I/O error.
+ */
+ public FetchData fetchData() throws RrdException, IOException {
+ return parentDb.fetchData(this);
}
Index: Robin.java
===================================================================
RCS file: /cvsroot/jrobin/src/jrobin/core/Robin.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** Robin.java 6 Oct 2003 10:45:04 -0000 1.3
--- Robin.java 21 Oct 2003 12:53:05 -0000 1.4
***************
*** 101,105 ****
*/
public double getValue(int index) throws IOException {
- assert(index < rows);
return values.get((pointer.get() + index) % rows);
}
--- 101,104 ----
Index: RrdDb.java
===================================================================
RCS file: /cvsroot/jrobin/src/jrobin/core/RrdDb.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -C2 -d -r1.8 -r1.9
*** RrdDb.java 17 Oct 2003 12:12:20 -0000 1.8
--- RrdDb.java 21 Oct 2003 12:53:05 -0000 1.9
***************
*** 24,27 ****
--- 24,28 ----
import java.io.*;
+ import java.util.GregorianCalendar;
/**
***************
*** 133,137 ****
* @throws RrdException Thrown in case of JRobin specific error.
*/
-
public RrdDb(String path) throws IOException, RrdException {
// opens existing RRD file - throw exception if the file does not exist...
--- 134,137 ----
***************
*** 185,189 ****
* @throws RrdException Thrown in case of JRobin specific error
*/
-
public RrdDb(String rrdPath, String xmlPath) throws IOException, RrdException {
initializeSetup(rrdPath);
--- 185,188 ----
***************
*** 228,232 ****
* @throws IOException Thrown in case of I/O related error.
*/
-
public synchronized void close() throws IOException {
if(file != null) {
--- 227,230 ----
***************
*** 243,247 ****
* @return Underlying RrdFile object
*/
-
public RrdFile getRrdFile() {
return file;
--- 241,244 ----
***************
*** 388,391 ****
--- 385,395 ----
}
+ synchronized FetchData fetchData(FetchRequest request) throws IOException, RrdException {
+ Archive archive = findMatchingArchive(request);
+ FetchData fetchData = archive.fetchData(request);
+ Util.debug(request.getRrdToolCommand());
+ return fetchData;
+ }
+
private Archive findMatchingArchive(FetchRequest request) throws IOException, RrdException {
String consolFun = request.getConsolFun();
***************
*** 640,643 ****
close();
}
-
}
--- 644,646 ----
|
|
From: <cob...@us...> - 2003-10-18 02:50:13
|
Update of /cvsroot/jrobin/src/jrobin/graph
In directory sc8-pr-cvs1:/tmp/cvs-serv19517/src/jrobin/graph
Modified Files:
RrdGraphDef.java Gprint.java
Log Message:
GRAPH LIB UPDATES
Add line width to horizontal rule
Fixed stack legend
Index: RrdGraphDef.java
===================================================================
RCS file: /cvsroot/jrobin/src/jrobin/graph/RrdGraphDef.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -C2 -d -r1.8 -r1.9
*** RrdGraphDef.java 15 Oct 2003 21:19:08 -0000 1.8
--- RrdGraphDef.java 17 Oct 2003 14:46:39 -0000 1.9
***************
*** 242,245 ****
--- 242,248 ----
void addPlot(Stack plotDef) throws RrdException {
plotDefs.add(plotDef);
+ // Add comment line for the legend
+ if ( plotDef.getLegend() != null )
+ addComment( new Legend(plotDef.getColor(), plotDef.getLegend()) );
OverlayGraph lastGraph = getLastGraph();
if(lastGraph != null) {
***************
*** 388,392 ****
public void stack(String sourceName, Color color, String legend) throws RrdException {
Source source = findSourceByName(sourceName);
! addPlot(new Stack(source, color, legend));
}
--- 391,395 ----
public void stack(String sourceName, Color color, String legend) throws RrdException {
Source source = findSourceByName(sourceName);
! addPlot( new Stack(source, color, legend) );
}
***************
*** 398,403 ****
* @throws RrdException Thrown in case of JRobin specific error.
*/
! public void rule(double value, Color color, String legend) throws RrdException {
addPlot( new Hrule(value, color, legend) );
}
--- 401,418 ----
* @throws RrdException Thrown in case of JRobin specific error.
*/
! public void hrule(double value, Color color, String legend) throws RrdException {
addPlot( new Hrule(value, color, legend) );
+ }
+
+ /**
+ * Adds horizontal rule to the graph definition.
+ * @param value Rule posiotion.
+ * @param color Rule color.
+ * @param legend Legend to be added to the graph.
+ * @param lineWidth Width of the hrule line in pixels.
+ * @throws RrdException Thrown in case of JRobin specific error.
+ */
+ public void hrule(double value, Color color, String legend, float lineWidth) throws RrdException {
+ addPlot( new Hrule(value, color, legend, lineWidth) );
}
Index: Gprint.java
===================================================================
RCS file: /cvsroot/jrobin/src/jrobin/graph/Gprint.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** Gprint.java 11 Oct 2003 20:32:35 -0000 1.3
--- Gprint.java 17 Oct 2003 14:46:39 -0000 1.4
***************
*** 1,139 ****
! /* ============================================================
! * JRobin : Pure java implementation of RRDTool's functionality
! * ============================================================
! *
! * Project Info: http://www.sourceforge.net/projects/jrobin
! * Project Lead: Sasa Markovic (sa...@eu...);
! *
! * (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 jrobin.graph;
!
! import jrobin.core.RrdException;
!
! import java.text.DecimalFormat;
! import java.util.regex.Matcher;
! import java.util.regex.Pattern;
!
! /**
! *
! */
! class Gprint extends Comment
! {
! private static final String SCALE_MARKER = "@s";
! private static final String UNIFORM_SCALE_MARKER = "@S";
! private static final String VALUE_MARKER = "@([0-9]*\\.[0-9]{1}|[0-9]{1}|\\.[0-9]{1})";
! private static final Pattern VALUE_PATTERN = Pattern.compile(VALUE_MARKER);
! private Source source;
! private String consolFun;
!
! Gprint(Source source, String consolFun, String comment) throws RrdException {
! super(comment);
! this.source = source;
! this.consolFun = consolFun;
! }
!
! String getMessage( double base ) throws RrdException
! {
! double value = source.getAggregate(consolFun);
! Matcher m = VALUE_PATTERN.matcher(comment);
! if ( m.find() )
! {
! String valueStr = "" + value;
! String prefixStr = " ";
! String uniformPrefixStr = " ";
!
! String[] group = m.group(1).split("\\.");
! int len = -1, numDec = 0;
!
! if ( group.length > 1 )
! {
! if ( group[0].length() > 0 ) {
! len = Integer.parseInt(group[0]);
! numDec = Integer.parseInt(group[1]);
! }
! else
! numDec = Integer.parseInt(group[1]);
! }
! else
! numDec = Integer.parseInt(group[0]);
!
! if( !Double.isNaN(value) )
! {
! DecimalFormat df = getDecimalFormat(numDec);
! // TO BE DONE
! // Treat special case here, if the value is something like 0.336985464
! // Look at the number of decimals we want, if we lose too much precision
! // use the scaler, otherwise just don't (it all depends also on the total
! // length we predefined)
! if(shouldScale() && !shouldUniformScale()) {
! ValueScaler scaler = new ValueScaler(value, base);
! valueStr = df.format(scaler.getScaledValue());
! prefixStr = scaler.getPrefix();
! scaleIndex = scaler.getScaleIndex();
! }
! else if(!shouldScale() && shouldUniformScale()) {
! ValueScaler scaler = new ValueScaler(value, scaleIndex, base);
! valueStr = df.format(scaler.getScaledValue());
! uniformPrefixStr = scaler.getPrefix();
! scaleIndex = scaler.getScaleIndex();
! }
! else if(!shouldScale() && !shouldUniformScale()) {
! valueStr = df.format(value);
! }
! else if(shouldScale() && shouldUniformScale()) {
! throw new RrdException("You cannot specify uniform and non-uniform value " +
! "scaling at the same time");
! }
! }
!
! int diff = len - valueStr.length();
!
! StringBuffer preSpace = new StringBuffer("");
! for (int i = 0; i < diff; i++)
! preSpace.append(' ');
! valueStr = preSpace.append(valueStr).toString();
!
! comment = comment.replaceFirst(VALUE_MARKER, valueStr);
! comment = comment.replaceFirst(SCALE_MARKER, prefixStr);
! comment = comment.replaceFirst(UNIFORM_SCALE_MARKER, uniformPrefixStr);
! }
! else {
! throw new RrdException("Could not find where to place value. No @ placeholder found");
! }
! return super.getMessage();
! }
!
! boolean shouldScale() {
! return comment.indexOf(SCALE_MARKER) >= 0;
! }
!
! boolean shouldUniformScale() {
! return comment.indexOf(UNIFORM_SCALE_MARKER) >= 0;
! }
!
! private DecimalFormat getDecimalFormat(int numDec) {
! String formatStr = "#,##0";
! for(int i = 0; i < numDec; i++) {
! if(i == 0) {
! formatStr += ".";
! }
! formatStr += "0";
! }
! return new DecimalFormat(formatStr);
! }
!
! }
--- 1,140 ----
! /* ============================================================
! * JRobin : Pure java implementation of RRDTool's functionality
! * ============================================================
! *
! * Project Info: http://www.sourceforge.net/projects/jrobin
! * Project Lead: Sasa Markovic (sa...@eu...);
! *
! * (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 jrobin.graph;
!
! import jrobin.core.RrdException;
!
! import java.text.DecimalFormat;
! import java.util.regex.Matcher;
! import java.util.regex.Pattern;
!
! /**
! *
! */
! class Gprint extends Comment
! {
! private static final String SCALE_MARKER = "@s";
! private static final String UNIFORM_SCALE_MARKER = "@S";
! private static final String VALUE_MARKER = "@([0-9]*\\.[0-9]{1}|[0-9]{1}|\\.[0-9]{1})";
! private static final Pattern VALUE_PATTERN = Pattern.compile(VALUE_MARKER);
! private Source source;
! private String consolFun;
!
! Gprint(Source source, String consolFun, String comment) throws RrdException {
! super(comment);
! this.source = source;
! this.consolFun = consolFun;
! }
!
! String getMessage( double base ) throws RrdException
! {
! double value = source.getAggregate(consolFun);
! Matcher m = VALUE_PATTERN.matcher(comment);
! if ( m.find() )
! {
! String valueStr = "" + value;
! String prefixStr = " ";
! String uniformPrefixStr = " ";
!
! String[] group = m.group(1).split("\\.");
! int len = -1, numDec = 0;
!
! if ( group.length > 1 )
! {
! if ( group[0].length() > 0 ) {
! len = Integer.parseInt(group[0]);
! numDec = Integer.parseInt(group[1]);
! }
! else
! numDec = Integer.parseInt(group[1]);
! }
! else
! numDec = Integer.parseInt(group[0]);
!
! if( !Double.isNaN(value) )
! {
! DecimalFormat df = getDecimalFormat(numDec);
! // TO BE DONE
! // Treat special case here, if the value is something like 0.336985464
! // Look at the number of decimals we want, if we lose too much precision
! // use the scaler, otherwise just don't (it all depends also on the total
! // length we predefined)
! if(shouldScale() && !shouldUniformScale()) {
! ValueScaler scaler = new ValueScaler(value, base);
! valueStr = df.format(scaler.getScaledValue());
! prefixStr = scaler.getPrefix();
! scaleIndex = scaler.getScaleIndex();
! }
! else if(!shouldScale() && shouldUniformScale()) {
!
! ValueScaler scaler = new ValueScaler(value, scaleIndex, base);
! valueStr = df.format(scaler.getScaledValue());
! uniformPrefixStr = scaler.getPrefix();
! scaleIndex = scaler.getScaleIndex();
! }
! else if(!shouldScale() && !shouldUniformScale()) {
! valueStr = df.format(value);
! }
! else if(shouldScale() && shouldUniformScale()) {
! throw new RrdException("You cannot specify uniform and non-uniform value " +
! "scaling at the same time");
! }
! }
!
! int diff = len - valueStr.length();
!
! StringBuffer preSpace = new StringBuffer("");
! for (int i = 0; i < diff; i++)
! preSpace.append(' ');
! valueStr = preSpace.append(valueStr).toString();
!
! comment = comment.replaceFirst(VALUE_MARKER, valueStr);
! comment = comment.replaceFirst(SCALE_MARKER, prefixStr);
! comment = comment.replaceFirst(UNIFORM_SCALE_MARKER, uniformPrefixStr);
! }
! else {
! throw new RrdException("Could not find where to place value. No @ placeholder found");
! }
! return super.getMessage();
! }
!
! boolean shouldScale() {
! return comment.indexOf(SCALE_MARKER) >= 0;
! }
!
! boolean shouldUniformScale() {
! return comment.indexOf(UNIFORM_SCALE_MARKER) >= 0;
! }
!
! private DecimalFormat getDecimalFormat(int numDec) {
! String formatStr = "#,##0";
! for(int i = 0; i < numDec; i++) {
! if(i == 0) {
! formatStr += ".";
! }
! formatStr += "0";
! }
! return new DecimalFormat(formatStr);
! }
!
! }
|
|
From: <cob...@us...> - 2003-10-18 02:18:49
|
Update of /cvsroot/jrobin/src/jrobin/demo
In directory sc8-pr-cvs1:/tmp/cvs-serv19517/src/jrobin/demo
Modified Files:
JRobinComplexGraph.java
Log Message:
GRAPH LIB UPDATES
Add line width to horizontal rule
Fixed stack legend
Index: JRobinComplexGraph.java
===================================================================
RCS file: /cvsroot/jrobin/src/jrobin/demo/JRobinComplexGraph.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -C2 -d -r1.8 -r1.9
*** JRobinComplexGraph.java 15 Oct 2003 21:19:08 -0000 1.8
--- JRobinComplexGraph.java 17 Oct 2003 14:46:39 -0000 1.9
***************
*** 67,75 ****
gDef.comment("CPU utilization (%)\n");
gDef.comment(" ");
gDef.area("load", new Color(0x66,0x99,0xcc), " 0 - 25%");
gDef.area("p25t50", new Color(0x00,0x66,0x99), "25 - 50%");
gDef.comment(" ");
gDef.gprint("busy", "MIN", "Minimum:@5.1@s%");
! gDef.gprint("busy", "MAX", "Maximum: @5.1@s%");
gDef.comment("\n");
gDef.comment(" ");
--- 67,76 ----
gDef.comment("CPU utilization (%)\n");
gDef.comment(" ");
+ gDef.hrule( 7.0, Color.YELLOW, null, 10f);
gDef.area("load", new Color(0x66,0x99,0xcc), " 0 - 25%");
gDef.area("p25t50", new Color(0x00,0x66,0x99), "25 - 50%");
gDef.comment(" ");
gDef.gprint("busy", "MIN", "Minimum:@5.1@s%");
! gDef.gprint("busy", "MAX", "Maximum: @5.1@S%");
gDef.comment("\n");
gDef.comment(" ");
***************
*** 86,90 ****
gDef.line("load", new Color(0x00,0x00,0x00), "Load average (5 min)" );
//gDef.area("load", Color.RED, " hmm \n");
! //gDef.stack("p75t90", Color.GREEN, " hmm \n");
gDef.comment(" ");
gDef.gprint("load", "MIN", " Minimum: @5.2@s");
--- 87,91 ----
gDef.line("load", new Color(0x00,0x00,0x00), "Load average (5 min)" );
//gDef.area("load", Color.RED, " hmm \n");
! //gDef.stack("p75t90", Color.GREEN, " hmm");
gDef.comment(" ");
gDef.gprint("load", "MIN", " Minimum: @5.2@s");
***************
*** 98,102 ****
gDef.comment("\n");
gDef.comment("-------------------------------------------------------------------------------@c");
! gDef.vrule( new GregorianCalendar(2003, 7, 24, 9, 00), Color.BLUE, "9am", 3f );
gDef.vrule( new GregorianCalendar(2003, 7, 24, 17, 00), Color.BLUE, "5pm", 3f );
gDef.comment("Generated: " + new Date() + "@r");
--- 99,103 ----
gDef.comment("\n");
gDef.comment("-------------------------------------------------------------------------------@c");
! gDef.vrule( new GregorianCalendar(2003, 7, 24, 9, 00), Color.BLUE, "9am", 2f );
gDef.vrule( new GregorianCalendar(2003, 7, 24, 17, 00), Color.BLUE, "5pm", 3f );
gDef.comment("Generated: " + new Date() + "@r");
***************
*** 115,119 ****
gDef.setAxisColor( Color.RED );
gDef.setArrowColor( Color.GREEN );
! gDef.setChartLeftPadding( 40 );
//gDef.setAntiAliasing(false);
//gDef.setTimeAxis( TimeAxisUnit.HOUR, 6, TimeAxisUnit.DAY, 1, "EEEEE dd MMM", true );
--- 116,120 ----
gDef.setAxisColor( Color.RED );
gDef.setArrowColor( Color.GREEN );
! //gDef.setChartLeftPadding( 40 );
//gDef.setAntiAliasing(false);
//gDef.setTimeAxis( TimeAxisUnit.HOUR, 6, TimeAxisUnit.DAY, 1, "EEEEE dd MMM", true );
***************
*** 137,140 ****
--- 138,143 ----
gd.area("in", Color.GREEN, null);
gd.line("out", Color.BLUE, null);
+ gd.gprint("out", "AVERAGE", " Minimum: @5.2@s");
+ gd.gprint("in", "AVERAGE", "Maximum: @6.2@s");
gd.setRigidGrid(true);
RrdGraph graph2 = new RrdGraph(gd);
|
|
From: <sa...@us...> - 2003-10-17 14:42:32
|
Update of /cvsroot/jrobin/src/jrobin/demo
In directory sc8-pr-cvs1:/tmp/cvs-serv18459/jrobin/demo
Added Files:
JRobinGallery.java
Log Message:
Two nice graphs...
--- NEW FILE: JRobinGallery.java ---
package jrobin.demo;
import jrobin.graph.RrdGraphDef;
import jrobin.graph.RrdGraph;
import jrobin.core.RrdException;
import java.util.GregorianCalendar;
import java.awt.*;
import java.io.IOException;
/**
* Created by IntelliJ IDEA.
* User: Administrator
* Date: Oct 16, 2003
* Time: 9:17:24 AM
* To change this template use Options | File Templates.
*/
public class JRobinGallery {
public static void graph7() throws RrdException, IOException {
RrdGraphDef def = new RrdGraphDef();
GregorianCalendar start = new GregorianCalendar(2003, 4, 1);
GregorianCalendar end = new GregorianCalendar(2003, 5, 1);
def.setTimePeriod(start, end);
long t0 = start.getTime().getTime() / 1000L;
long t1 = end.getTime().getTime() / 1000L;
def.datasource("sine", "TIME," + t0 + ",-," + (t1 - t0) +
",/,7,PI,*,*,SIN");
def.datasource("v2", "demo.rrd", "shade", "AVERAGE");
def.datasource("cosine", "TIME," + t0 + ",-," + (t1 - t0) +
",/,3,PI,*,*,COS");
def.datasource("line", "TIME," + t0 + ",-," + (t1 - t0) + ",/,1000,*");
def.datasource("v1", "sine,line,*,ABS");
int n = 40;
for(int i = 0; i < n; i++) {
long t = t0 + (t1 - t0) * i / n;
def.datasource("c" + i, "TIME," + t + ",GT,v2,UNKN,IF");
}
for(int i = 0; i < n; i++) {
if(i==0) {
def.area("c"+i, new Color(255-255*Math.abs(i-n/2)/(n/2),0,0), "Output by night");
}
else if(i==n/2) {
def.area("c"+i, new Color(255-255*Math.abs(i-n/2)/(n/2),0,0), "Output by day");
}
else {
def.area("c"+i, new Color(255-255*Math.abs(i-n/2)/(n/2),0,0), null);
}
}
def.line("v2", Color.YELLOW, null);
def.line("v1", Color.BLUE, "Input voltage", 3);
def.line("v1", Color.YELLOW, null, 1);
def.comment("fancy looking graphs@r");
def.setTitle("Voltage measurement");
def.setValueAxisLabel("[Volts]");
def.setValueStep(100);
RrdGraph graph = new RrdGraph(def);
graph.saveAsPNG("demo7.png", 400, 250);
}
public static void graph6() throws RrdException, IOException {
RrdGraphDef def = new RrdGraphDef();
GregorianCalendar start = new GregorianCalendar(2003, 4, 1);
GregorianCalendar end = new GregorianCalendar(2003, 4, 2);
def.setTimePeriod(start, end);
long t0 = start.getTime().getTime() / 1000L;
long t1 = end.getTime().getTime() / 1000L;
def.datasource("sine", "TIME," + t0 + ",-," + (t1 - t0) +
",/,7,PI,*,*,SIN");
def.datasource("cosine", "TIME," + t0 + ",-," + (t1 - t0) +
",/,3,PI,*,*,COS");
def.datasource("line", "TIME," + t0 + ",-," + (t1 - t0) + ",/,1000,*");
def.datasource("v1", "sine,line,*");
def.datasource("v2", "cosine,800,*");
def.datasource("diff", "v2,v1,-");
def.datasource("absdiff", "diff,ABS");
def.datasource("blank1", "v1,0,GT,v2,0,GT,AND,v1,v2,MIN,0,IF");
def.datasource("blank2", "v1,0,LT,v2,0,LT,AND,v1,v2,MAX,0,IF");
def.datasource("median", "v1,v2,+,2,/");
def.line("median", Color.YELLOW, "safe zone\n");
def.area("v1", Color.WHITE, null);
def.stack("diff", Color.YELLOW, "safe zone");
def.area("blank1", Color.WHITE, null);
def.area("blank2", Color.WHITE, null);
def.line("v1", Color.BLUE, null, 1);
def.line("v2", Color.BLUE, null, 1);
def.gprint("absdiff", "MAX", "max safe: @2V");
def.gprint("absdiff", "AVERAGE", "avg safe: @2V");
def.comment("fancy looking graphs@r");
def.setTitle("Voltage measurement");
def.setValueAxisLabel("[Volts]");
RrdGraph graph = new RrdGraph(def);
graph.saveAsPNG("demo6.png", 400, 250);
}
public static void main(String[] args) throws RrdException, IOException {
graph6();
graph7();
}
}
|
|
From: <sa...@us...> - 2003-10-17 12:12:26
|
Update of /cvsroot/jrobin/src/jrobin/graph
In directory sc8-pr-cvs1:/tmp/cvs-serv17241/jrobin/graph
Modified Files:
RpnCalculator.java
Log Message:
Added more appropriate exception when RrdDb tries to open non-existent RRD file. Added logical functions (AND, OR, XOR) to RpnCalculator.
Index: RpnCalculator.java
===================================================================
RCS file: /cvsroot/jrobin/src/jrobin/graph/RpnCalculator.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** RpnCalculator.java 4 Sep 2003 13:27:14 -0000 1.1
--- RpnCalculator.java 17 Oct 2003 12:12:20 -0000 1.2
***************
*** 169,172 ****
--- 169,185 ----
push(Math.E);
}
+ // logical operators
+ else if(token.equals("AND")) {
+ double x2 = pop(), x1 = pop();
+ push((x1 != 0 && x2 != 0)? 1: 0);
+ }
+ else if(token.equals("OR")) {
+ double x2 = pop(), x1 = pop();
+ push((x1 != 0 || x2 != 0)? 1: 0);
+ }
+ else if(token.equals("XOR")) {
+ double x2 = pop(), x1 = pop();
+ push(((x1 != 0 && x2 == 0) || (x1 == 0 && x2 != 0))? 1: 0);
+ }
else {
throw new RrdException("Unknown token enocuntered: " + token);
|
|
From: <sa...@us...> - 2003-10-17 12:12:26
|
Update of /cvsroot/jrobin/src/jrobin/core
In directory sc8-pr-cvs1:/tmp/cvs-serv17241/jrobin/core
Modified Files:
RrdDb.java
Log Message:
Added more appropriate exception when RrdDb tries to open non-existent RRD file. Added logical functions (AND, OR, XOR) to RpnCalculator.
Index: RrdDb.java
===================================================================
RCS file: /cvsroot/jrobin/src/jrobin/core/RrdDb.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -C2 -d -r1.7 -r1.8
*** RrdDb.java 6 Oct 2003 10:45:04 -0000 1.7
--- RrdDb.java 17 Oct 2003 12:12:20 -0000 1.8
***************
*** 135,138 ****
--- 135,143 ----
public RrdDb(String path) throws IOException, RrdException {
+ // opens existing RRD file - throw exception if the file does not exist...
+ File rrdFile = new File(path);
+ if(!rrdFile.exists()) {
+ throw new IOException("Could not open file " + path + " [non existent]");
+ }
try {
initializeSetup(path);
|
|
From: <sa...@us...> - 2003-10-16 09:27:21
|
Update of /cvsroot/jrobin/src/jrobin/core
In directory sc8-pr-cvs1:/tmp/cvs-serv9125/jrobin/core
Modified Files:
DsDef.java Sample.java Util.java XmlWriter.java
Log Message:
Consistent formatting of doubles for the entire core package
Index: DsDef.java
===================================================================
RCS file: /cvsroot/jrobin/src/jrobin/core/DsDef.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** DsDef.java 4 Sep 2003 13:26:41 -0000 1.1
--- DsDef.java 16 Oct 2003 09:26:30 -0000 1.2
***************
*** 150,155 ****
public String dump() {
return "DS:" + dsName + ":" + dsType + ":" + heartbeat +
! ":" + Util.formatDouble(minValue, true) +
! ":" + Util.formatDouble(maxValue, true);
}
--- 150,155 ----
public String dump() {
return "DS:" + dsName + ":" + dsType + ":" + heartbeat +
! ":" + Util.formatDouble(minValue, "U") +
! ":" + Util.formatDouble(maxValue, "U");
}
Index: Sample.java
===================================================================
RCS file: /cvsroot/jrobin/src/jrobin/core/Sample.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** Sample.java 9 Oct 2003 08:48:23 -0000 1.2
--- Sample.java 16 Oct 2003 09:26:30 -0000 1.3
***************
*** 227,231 ****
for(int i = 0; i < values.length; i++) {
buffer.append(":");
! buffer.append(Util.formatDouble(values[i], true));
}
return buffer.toString();
--- 227,231 ----
for(int i = 0; i < values.length; i++) {
buffer.append(":");
! buffer.append(Util.formatDouble(values[i], "U"));
}
return buffer.toString();
Index: Util.java
===================================================================
RCS file: /cvsroot/jrobin/src/jrobin/core/Util.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** Util.java 29 Sep 2003 11:25:05 -0000 1.4
--- Util.java 16 Oct 2003 09:26:30 -0000 1.5
***************
*** 24,28 ****
--- 24,30 ----
import java.text.DecimalFormat;
+ import java.text.NumberFormat;
import java.util.Date;
+ import java.util.Locale;
/**
***************
*** 32,39 ****
*/
public class Util {
! private static String DOUBLE_FORMAT = "0.0000000000E00";
! private static final DecimalFormat df = new DecimalFormat(DOUBLE_FORMAT);
!
! private Util() { };
/**
--- 34,44 ----
*/
public class Util {
! // pattern RRDTool uses to format doubles in XML files
! static final String PATTERN = "0.0000000000E00";
! static final DecimalFormat df;
! static {
! df = (DecimalFormat) NumberFormat.getNumberInstance(Locale.ENGLISH);
! df.applyPattern(PATTERN);
! }
/**
***************
*** 80,89 ****
}
! static String formatDouble(double x, boolean translateNans) {
if(Double.isNaN(x)) {
! return translateNans? "U": "" + Double.NaN;
! }
! if(x >= Long.MIN_VALUE && x <= Long.MAX_VALUE && Math.round(x) == x) {
! return "" + (long) x;
}
return df.format(x);
--- 85,91 ----
}
! static String formatDouble(double x, String nanString) {
if(Double.isNaN(x)) {
! return nanString;
}
return df.format(x);
***************
*** 91,95 ****
static String formatDouble(double x) {
! return formatDouble(x, false);
}
--- 93,97 ----
static String formatDouble(double x) {
! return formatDouble(x, "" + Double.NaN);
}
***************
*** 110,114 ****
}
! public static double parseDouble(String valueStr) {
double value;
try {
--- 112,116 ----
}
! static double parseDouble(String valueStr) {
double value;
try {
***************
*** 116,120 ****
}
catch(NumberFormatException nfe) {
- // Arne Vandamme fixed bug on UNKN value from Windows
value = Double.NaN;
}
--- 118,121 ----
Index: XmlWriter.java
===================================================================
RCS file: /cvsroot/jrobin/src/jrobin/core/XmlWriter.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** XmlWriter.java 15 Oct 2003 12:49:07 -0000 1.3
--- XmlWriter.java 16 Oct 2003 09:26:30 -0000 1.4
***************
*** 26,41 ****
import java.io.PrintWriter;
import java.util.Stack;
- import java.util.Locale;
- import java.text.DecimalFormat;
- import java.text.NumberFormat;
class XmlWriter {
static final String INDENT_STR = " ";
- static final String PATTERN = "0.0000000000E00";
- static final DecimalFormat df;
- static {
- df = (DecimalFormat) NumberFormat.getNumberInstance(Locale.ENGLISH);
- df.applyPattern(PATTERN);
- }
private PrintWriter writer;
--- 26,32 ----
***************
*** 72,85 ****
void writeTag(String tag, double value, String nanString) {
! if(Double.isNaN(value)) {
! writeTag(tag, nanString);
! }
! else {
! writeTag(tag, df.format(value));
! }
}
void writeTag(String tag, double value) {
! writeTag(tag, value, "" + Double.NaN);
}
--- 63,71 ----
void writeTag(String tag, double value, String nanString) {
! writeTag(tag, Util.formatDouble(value, nanString));
}
void writeTag(String tag, double value) {
! writeTag(tag, Util.formatDouble(value));
}
|
|
From: <cob...@us...> - 2003-10-15 21:19:13
|
Update of /cvsroot/jrobin/src/jrobin/graph In directory sc8-pr-cvs1:/tmp/cvs-serv16781/src/jrobin/graph Modified Files: RrdGraph.java RrdGraphDef.java Grapher.java PlotDef.java Added Files: Vrule.java VruleSource.java Log Message: GRAPH LIB UPDATES Add support for Vrule plotdef --- NEW FILE: Vrule.java --- /* ============================================================ * JRobin : Pure java implementation of RRDTool's functionality * ============================================================ * * Project Info: http://www.sourceforge.net/projects/jrobin * Project Lead: Sasa Markovic (sa...@eu...); * * (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 jrobin.graph; import java.awt.*; /** * @author cbld * * To change the template for this generated type comment go to * Window - Preferences - Java - Code Generation - Code and Comments */ public class Vrule extends PlotDef { Vrule( long timestamp, Color color, String legend) { super( new VruleSource(timestamp), color, legend ); plotType = PlotDef.PLOT_VRULE; } Vrule( long timestamp, Color color, String legend, float lineWidth) { super( new VruleSource(timestamp), color, legend ); super.setLineWidth(lineWidth); plotType = PlotDef.PLOT_VRULE; } } --- NEW FILE: VruleSource.java --- /* ============================================================ * JRobin : Pure java implementation of RRDTool's functionality * ============================================================ * * Project Info: http://www.sourceforge.net/projects/jrobin * Project Lead: Sasa Markovic (sa...@eu...); * * (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 jrobin.graph; /** * @author cbld * * To change the template for this generated type comment go to * Window - Preferences - Java - Code Generation - Code and Comments */ public class VruleSource extends Source { private long timestamp = 0; VruleSource(long timestamp) { this.timestamp = timestamp; } public long getTime() { return timestamp; } // Stub void setInterval(long start, long end) { } public double getValue(long timestamp, ValueCollection values) { return Double.NaN; } } Index: RrdGraph.java =================================================================== RCS file: /cvsroot/jrobin/src/jrobin/graph/RrdGraph.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** RrdGraph.java 14 Oct 2003 22:11:34 -0000 1.5 --- RrdGraph.java 15 Oct 2003 21:19:08 -0000 1.6 *************** *** 96,100 **** ImageIO.write( (RenderedImage) getBufferedImage(width, height), "png", new File(path) ); } ! /** * Saves graph in JPEG format --- 96,100 ---- ImageIO.write( (RenderedImage) getBufferedImage(width, height), "png", new File(path) ); } ! /** * Saves graph in JPEG format Index: RrdGraphDef.java =================================================================== RCS file: /cvsroot/jrobin/src/jrobin/graph/RrdGraphDef.java,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** RrdGraphDef.java 13 Oct 2003 22:53:33 -0000 1.7 --- RrdGraphDef.java 15 Oct 2003 21:19:08 -0000 1.8 *************** *** 249,252 **** --- 249,259 ---- throw new RrdException("You have to STACK graph onto something..."); } + + void addPlot(Vrule vruleDef) throws RrdException { + plotDefs.add(vruleDef); + sources.add( vruleDef.getSource() ); + if ( vruleDef.getLegend() != null ) + addComment( new Legend(vruleDef.getColor(), vruleDef.getLegend()) ); + } void addPlot(Hrule hruleDef) throws RrdException { *************** *** 392,396 **** */ public void rule(double value, Color color, String legend) throws RrdException { ! addPlot(new Hrule(value, color, legend)); } --- 399,424 ---- */ public void rule(double value, Color color, String legend) throws RrdException { ! addPlot( new Hrule(value, color, legend) ); ! } ! ! /** ! * Adds a vertical rule to the graph definition. ! * @param timestamp Rule position (specific moment in time) ! * @param color Rule color. ! * @param legend Legend to be added to the graph. ! */ ! public void vrule( GregorianCalendar timestamp, Color color, String legend ) throws RrdException { ! addPlot( new Vrule(timestamp.getTimeInMillis() / 1000, color, legend) ); ! } ! ! /** ! * Adds a vertical rule to the graph definition. ! * @param timestamp Rule position (specific moment in time) ! * @param color Rule color. ! * @param legend Legend to be added to the graph. ! * @param lineWidth Width of the vrule in pixels. ! */ ! public void vrule( GregorianCalendar timestamp, Color color, String legend, float lineWidth ) throws RrdException { ! addPlot( new Vrule(timestamp.getTimeInMillis() / 1000, color, legend, lineWidth) ); } Index: Grapher.java =================================================================== RCS file: /cvsroot/jrobin/src/jrobin/graph/Grapher.java,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** Grapher.java 14 Oct 2003 22:11:34 -0000 1.8 --- Grapher.java 15 Oct 2003 21:19:08 -0000 1.9 *************** *** 493,496 **** --- 493,502 ---- drawLine( g, parentSeries, source, true ); break; + case PlotDef.PLOT_VRULE: + int pos = g.getX( ((VruleSource) source).getTime() ); + graphics.setStroke( new BasicStroke(plotDefs[i].getLineWidth()) ); + g.drawLine( pos, 0 - chartHeight, pos, 0 + chartHeight ); + graphics.setStroke( new BasicStroke() ); + break; } } Index: PlotDef.java =================================================================== RCS file: /cvsroot/jrobin/src/jrobin/graph/PlotDef.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** PlotDef.java 25 Sep 2003 21:58:05 -0000 1.3 --- PlotDef.java 15 Oct 2003 21:19:08 -0000 1.4 *************** *** 34,37 **** --- 34,39 ---- static final int PLOT_AREA = 1; static final int PLOT_STACK = 2; + static final int PLOT_VRULE = 3; + int plotType = PLOT_LINE; |
|
From: <cob...@us...> - 2003-10-15 21:19:12
|
Update of /cvsroot/jrobin/src/jrobin/demo
In directory sc8-pr-cvs1:/tmp/cvs-serv16781/src/jrobin/demo
Modified Files:
JRobinComplexGraph.java
Log Message:
GRAPH LIB UPDATES
Add support for Vrule plotdef
Index: JRobinComplexGraph.java
===================================================================
RCS file: /cvsroot/jrobin/src/jrobin/demo/JRobinComplexGraph.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -C2 -d -r1.7 -r1.8
*** JRobinComplexGraph.java 14 Oct 2003 22:11:34 -0000 1.7
--- JRobinComplexGraph.java 15 Oct 2003 21:19:08 -0000 1.8
***************
*** 44,50 ****
public static void main(String[] args)
{
! GregorianCalendar start = new GregorianCalendar(2003, 7, 24, 0, 0);
! GregorianCalendar end = new GregorianCalendar(2003, 7, 25, 0, 0);
!
RrdGraphDef gDef = new RrdGraphDef();
--- 44,50 ----
public static void main(String[] args)
{
! GregorianCalendar start = new GregorianCalendar(2003, 7, 24, 00, 00);
! GregorianCalendar end = new GregorianCalendar(2003, 7, 25, 00, 00);
!
RrdGraphDef gDef = new RrdGraphDef();
***************
*** 98,101 ****
--- 98,103 ----
gDef.comment("\n");
gDef.comment("-------------------------------------------------------------------------------@c");
+ gDef.vrule( new GregorianCalendar(2003, 7, 24, 9, 00), Color.BLUE, "9am", 3f );
+ gDef.vrule( new GregorianCalendar(2003, 7, 24, 17, 00), Color.BLUE, "5pm", 3f );
gDef.comment("Generated: " + new Date() + "@r");
gDef.setBackColor( Color.DARK_GRAY );
***************
*** 120,124 ****
RrdGraph graph = new RrdGraph(gDef);
graph.saveAsPNG("/zzzzzz.png", 0, 0);
! //graph.saveAsJPEG("/zzzzzz.jpg", 0, 0, 1f);
//System.exit(0);
--- 122,126 ----
RrdGraph graph = new RrdGraph(gDef);
graph.saveAsPNG("/zzzzzz.png", 0, 0);
! graph.saveAsJPEG("/zzzzzz.jpg", 0, 0, 1f);
//System.exit(0);
|
|
From: <sa...@us...> - 2003-10-15 14:16:05
|
Update of /cvsroot/jrobin/src/jrobin/demo
In directory sc8-pr-cvs1:/tmp/cvs-serv372/jrobin/demo
Modified Files:
JRobinDemo.java
Log Message:
better looking colors
Index: JRobinDemo.java
===================================================================
RCS file: /cvsroot/jrobin/src/jrobin/demo/JRobinDemo.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -C2 -d -r1.7 -r1.8
*** JRobinDemo.java 15 Oct 2003 13:21:20 -0000 1.7
--- JRobinDemo.java 15 Oct 2003 14:16:00 -0000 1.8
***************
*** 190,210 ****
gDef.line("sun", Color.GREEN, "sun temp");
gDef.line("shade", Color.BLUE, "shade temp");
! gDef.line("median", Color.DARK_GRAY, "median value");
gDef.area("diff", Color.RED, "difference");
// gradient color areas
for(int i = GRADIENT_COLOR_STEPS - 1; i >= 1; i--) {
! gDef.area("diff" + i, new Color(255 * i / GRADIENT_COLOR_STEPS, 0, 0), null);
}
! gDef.line("sine", Color.CYAN, "sine function demo");
gDef.gprint("sun", "MAX", "\nmaxSun = @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");
RrdGraph graph = new RrdGraph(gDef);
println("==Graph created");
println("==Saving graph as PNG file " + pngPath);
! graph.saveAsPNG(pngPath, 600, 400);
println("==Saving graph as JPEG file " + jpegPath);
! graph.saveAsJPEG(jpegPath, 600, 400, 0.5F);
// demo ends
--- 190,212 ----
gDef.line("sun", Color.GREEN, "sun temp");
gDef.line("shade", Color.BLUE, "shade temp");
! gDef.line("median", Color.MAGENTA, "median value");
gDef.area("diff", Color.RED, "difference");
// gradient color areas
for(int i = GRADIENT_COLOR_STEPS - 1; i >= 1; i--) {
! gDef.area("diff" + i, new Color(255, 255 - 255 * i / GRADIENT_COLOR_STEPS, 0), null);
}
! gDef.line("sine", Color.CYAN, "sine");
gDef.gprint("sun", "MAX", "\nmaxSun = @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
+ // gDef.setValueRange(-1000, 1000);
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);
// demo ends
|
|
From: <sa...@us...> - 2003-10-15 13:21:41
|
Update of /cvsroot/jrobin/src/jrobin/demo
In directory sc8-pr-cvs1:/tmp/cvs-serv22984/jrobin/demo
Modified Files:
JRobinDemo.java
Log Message:
Fancy gradient graph added
Index: JRobinDemo.java
===================================================================
RCS file: /cvsroot/jrobin/src/jrobin/demo/JRobinDemo.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -d -r1.6 -r1.7
*** JRobinDemo.java 15 Oct 2003 12:49:07 -0000 1.6
--- JRobinDemo.java 15 Oct 2003 13:21:20 -0000 1.7
***************
*** 56,59 ****
--- 56,62 ----
static final int MAX_STEP = 240;
+ // increase this to get better flaming graph...
+ static final int GRADIENT_COLOR_STEPS = 20;
+
/**
* <p>Runs the demonstration.
***************
*** 178,187 ****
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.RED, "sun temp");
gDef.line("shade", Color.BLUE, "shade temp");
! gDef.line("median", Color.GREEN, "median value");
! gDef.area("diff", new Color(255, 0, 0), null);
gDef.line("sine", Color.CYAN, "sine function demo");
gDef.gprint("sun", "MAX", "\nmaxSun = @3@s");
--- 181,199 ----
gDef.datasource("median", "sun,shade,+,2,/");
gDef.datasource("diff", "sun,shade,-,ABS,-1,*");
+ // gradient color datasources
+ for(int i = 1; i < GRADIENT_COLOR_STEPS; i++) {
+ double factor = i / (double) GRADIENT_COLOR_STEPS;
+ gDef.datasource("diff" + i, "diff," + factor + ",*");
+ }
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.DARK_GRAY, "median value");
! gDef.area("diff", Color.RED, "difference");
! // gradient color areas
! for(int i = GRADIENT_COLOR_STEPS - 1; i >= 1; i--) {
! gDef.area("diff" + i, new Color(255 * i / GRADIENT_COLOR_STEPS, 0, 0), null);
! }
gDef.line("sine", Color.CYAN, "sine function demo");
gDef.gprint("sun", "MAX", "\nmaxSun = @3@s");
|
|
From: <sa...@us...> - 2003-10-15 12:49:14
|
Update of /cvsroot/jrobin/src/jrobin/demo
In directory sc8-pr-cvs1:/tmp/cvs-serv17744/jrobin/demo
Modified Files:
JRobinDemo.java
Log Message:
Fixed number formatting problem for XML export - previous version used default Locale which might produce strings that cannot be parsed with Double.parseDouble().
Index: JRobinDemo.java
===================================================================
RCS file: /cvsroot/jrobin/src/jrobin/demo/JRobinDemo.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** JRobinDemo.java 14 Oct 2003 22:11:34 -0000 1.5
--- JRobinDemo.java 15 Oct 2003 12:49:07 -0000 1.6
***************
*** 174,179 ****
gDef.setTitle("Temperatures in May 2003");
gDef.setValueAxisLabel("temperature");
! gDef.datasource("sun", rrdPath, "sun", "AVERAGE");
! gDef.datasource("shade", rrdPath, "shade", "AVERAGE");
gDef.datasource("median", "sun,shade,+,2,/");
gDef.datasource("diff", "sun,shade,-,ABS,-1,*");
--- 174,179 ----
gDef.setTitle("Temperatures in May 2003");
gDef.setValueAxisLabel("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,*");
***************
*** 183,187 ****
gDef.line("shade", Color.BLUE, "shade temp");
gDef.line("median", Color.GREEN, "median value");
! gDef.area("diff", Color.ORANGE, "difference");
gDef.line("sine", Color.CYAN, "sine function demo");
gDef.gprint("sun", "MAX", "\nmaxSun = @3@s");
--- 183,187 ----
gDef.line("shade", Color.BLUE, "shade temp");
gDef.line("median", Color.GREEN, "median value");
! gDef.area("diff", new Color(255, 0, 0), null);
gDef.line("sine", Color.CYAN, "sine function demo");
gDef.gprint("sun", "MAX", "\nmaxSun = @3@s");
|
|
From: <sa...@us...> - 2003-10-15 12:49:14
|
Update of /cvsroot/jrobin/src/jrobin/core
In directory sc8-pr-cvs1:/tmp/cvs-serv17744/jrobin/core
Modified Files:
XmlWriter.java
Log Message:
Fixed number formatting problem for XML export - previous version used default Locale which might produce strings that cannot be parsed with Double.parseDouble().
Index: XmlWriter.java
===================================================================
RCS file: /cvsroot/jrobin/src/jrobin/core/XmlWriter.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** XmlWriter.java 29 Sep 2003 11:25:05 -0000 1.2
--- XmlWriter.java 15 Oct 2003 12:49:07 -0000 1.3
***************
*** 26,34 ****
import java.io.PrintWriter;
import java.util.Stack;
import java.text.DecimalFormat;
class XmlWriter {
- static final DecimalFormat df = new DecimalFormat("0.0000000000E00");
static final String INDENT_STR = " ";
private PrintWriter writer;
--- 26,41 ----
import java.io.PrintWriter;
import java.util.Stack;
+ import java.util.Locale;
import java.text.DecimalFormat;
+ import java.text.NumberFormat;
class XmlWriter {
static final String INDENT_STR = " ";
+ static final String PATTERN = "0.0000000000E00";
+ static final DecimalFormat df;
+ static {
+ df = (DecimalFormat) NumberFormat.getNumberInstance(Locale.ENGLISH);
+ df.applyPattern(PATTERN);
+ }
private PrintWriter writer;
|
|
From: <cob...@us...> - 2003-10-14 22:11:39
|
Update of /cvsroot/jrobin/src/jrobin/graph In directory sc8-pr-cvs1:/tmp/cvs-serv10598/src/jrobin/graph Modified Files: RrdGraph.java ChartGraphics.java Grapher.java Log Message: GRAPH LIB UPDATES Repeatedly saving fixed (only with the same graph dimensions) Fixed graph generating for > 1000 pixel wide graphs Fixed graph generating for extremely small time ranges (smaller than or equal to step size) Index: RrdGraph.java =================================================================== RCS file: /cvsroot/jrobin/src/jrobin/graph/RrdGraph.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** RrdGraph.java 11 Oct 2003 20:32:35 -0000 1.4 --- RrdGraph.java 14 Oct 2003 22:11:34 -0000 1.5 *************** *** 1,230 **** ! /* ============================================================ ! * JRobin : Pure java implementation of RRDTool's functionality ! * ============================================================ ! * ! * Project Info: http://www.sourceforge.net/projects/jrobin ! * Project Lead: Sasa Markovic (sa...@eu...); ! * ! * (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 jrobin.graph; ! ! import jrobin.core.RrdException; ! ! import javax.imageio.*; ! import javax.imageio.stream.*; ! import java.awt.image.*; ! ! import java.util.*; ! import java.io.ByteArrayOutputStream; ! import java.io.File; ! import java.io.IOException; ! import java.io.Serializable; ! ! /** ! * <p>Class to represent JRobin graphs. This class is a light wrapper around ! * <a href="http://www.jfree.org/jfreechart/javadoc/org/jfree/chart/JFreeChart.html">JFreeChart ! * class</a>. ! * <a href="http://www.jfree.org/jfreechart/index.html">JFreeChart</a> ! * is an excellent free Java library for generating charts and graphs.</p> ! */ ! public class RrdGraph implements Serializable ! { ! private Grapher grapher; ! ! /** ! * Constructs new JRobin graph from the supplied definition. ! * @param graphDef Graph definition. ! * @throws IOException Thrown in case of I/O error. ! * @throws RrdException Thrown in case of JRobin specific error. ! */ ! public RrdGraph(RrdGraphDef graphDef) throws IOException, RrdException ! { ! grapher = new Grapher( graphDef ); ! } ! ! /** ! * Creates buffered image object from the graph. ! * @param width Image width. ! * @param height Image height. ! * @return Graph as a buffered image. ! */ ! public BufferedImage getBufferedImage(int width, int height) ! { ! try ! { ! return grapher.createImage( width, height ); ! } ! catch (RrdException e) { ! e.printStackTrace(); ! } ! ! return null; ! } ! ! /** ! * Saves graph in PNG format. ! * @param path Path to PNG file. ! * @param width Image width ! * @param height Image height ! * @throws IOException Thrown in case of I/O error. ! */ ! public void saveAsPNG(String path, int width, int height) throws IOException ! { ! try ! { ! BufferedImage gImage = grapher.createImage( width, height ); ! ImageIO.write( (RenderedImage) gImage, "png", new File(path) ); ! } ! catch ( RrdException e ) { ! e.printStackTrace(); ! } ! } ! ! /** ! * Saves graph in JPEG format ! * @param path Path to JPEG file. ! * @param width Image width. ! * @param height Image height. ! * @param quality JPEG qualitty (between 0 and 1). ! * @throws IOException Thrown in case of I/O error. ! */ ! public void saveAsJPEG(String path, int width, int height, float quality) throws IOException ! { ! // Based on http://javaalmanac.com/egs/javax.imageio/JpegWrite.html?l=rel ! try { ! // Retrieve jpg image to be compressed ! BufferedImage gImage = grapher.createImage( width, height ); ! RenderedImage rndImage = (RenderedImage) gImage; ! ! // Find a jpeg writer ! ImageWriter writer = null; ! Iterator iter = ImageIO.getImageWritersByFormatName("jpg"); ! if (iter.hasNext()) { ! writer = (ImageWriter)iter.next(); ! } ! ! // Prepare output file ! ImageOutputStream ios = ImageIO.createImageOutputStream(new File(path)); ! writer.setOutput(ios); ! ! // Set the compression quality ! ImageWriteParam iwparam = new JpegImageWriteParam(); ! iwparam.setCompressionMode(ImageWriteParam.MODE_EXPLICIT) ; ! iwparam.setCompressionQuality(quality); ! ! // Write the image ! writer.write(null, new IIOImage(rndImage, null, null), iwparam); ! ! // Cleanup ! ios.flush(); ! writer.dispose(); ! ios.close(); ! } ! catch (Exception e) { ! e.printStackTrace(); ! } ! ! } ! ! /** ! * Returns panel object so that graph can be easily embedded in swing applications. ! * @return Swing panel object with graph embedded in panel. ! */ ! public ChartPanel getChartPanel() ! { ! ChartPanel p = new ChartPanel(); ! try ! { ! p.setChart( grapher.createImage(0,0) ); ! } ! catch ( RrdException e ) { ! e.printStackTrace(); ! } ! ! return p; ! } ! ! /** ! * Returns graph as an array of PNG bytes ! * @param width Image width. ! * @param height Image height. ! * @return Array of PNG bytes. ! * @throws IOException Thrown in case of I/O error. ! */ ! public byte[] getPNGBytes(int width, int height) throws IOException ! { ! ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); ! try ! { ! BufferedImage gImage = grapher.createImage( width, height ); ! ! ImageIO.write( (RenderedImage) gImage, "png", outputStream ); ! } ! catch ( RrdException e ) { ! e.printStackTrace(); ! } ! ! return outputStream.toByteArray(); ! } ! ! /** ! * Returns graph as an array of JPEG bytes ! * @param width Image width. ! * @param height Image height. ! * @param quality JPEG quality between 0 and 1. ! * @return Array of PNG bytes. ! * @throws IOException Thrown in case of I/O error. ! */ ! public byte[] getJPEGBytes(int width, int height, float quality) throws IOException ! { ! ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); ! try { ! // Retrieve jpg image to be compressed ! BufferedImage gImage = grapher.createImage( width, height ); ! RenderedImage rndImage = (RenderedImage) gImage; ! ! // Find a jpeg writer ! ImageWriter writer = null; ! Iterator iter = ImageIO.getImageWritersByFormatName("jpg"); ! if (iter.hasNext()) { ! writer = (ImageWriter)iter.next(); ! } ! ! // Prepare output file ! ImageOutputStream ios = ImageIO.createImageOutputStream(outputStream); ! writer.setOutput(ios); ! ! // Set the compression quality ! ImageWriteParam iwparam = new JpegImageWriteParam(); ! iwparam.setCompressionMode(ImageWriteParam.MODE_EXPLICIT) ; ! iwparam.setCompressionQuality(quality); ! ! // Write the image ! writer.write(null, new IIOImage(rndImage, null, null), iwparam); ! ! // Cleanup ! ios.flush(); ! writer.dispose(); ! ios.close(); ! } ! catch (Exception e) { ! e.printStackTrace(); ! } ! return outputStream.toByteArray(); ! } ! ! } --- 1,219 ---- ! /* ============================================================ ! * JRobin : Pure java implementation of RRDTool's functionality ! * ============================================================ ! * ! * Project Info: http://www.sourceforge.net/projects/jrobin ! * Project Lead: Sasa Markovic (sa...@eu...); ! * ! * (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 jrobin.graph; ! ! import jrobin.core.RrdException; ! ! import javax.imageio.*; ! import javax.imageio.stream.*; ! import java.awt.image.*; ! ! import java.util.*; ! import java.io.ByteArrayOutputStream; ! import java.io.File; ! import java.io.IOException; ! import java.io.Serializable; ! ! /** ! * <p>Class to represent JRobin graphs. This class is a light wrapper around ! * <a href="http://www.jfree.org/jfreechart/javadoc/org/jfree/chart/JFreeChart.html">JFreeChart ! * class</a>. ! * <a href="http://www.jfree.org/jfreechart/index.html">JFreeChart</a> ! * is an excellent free Java library for generating charts and graphs.</p> ! */ ! public class RrdGraph implements Serializable ! { ! private Grapher grapher; ! private BufferedImage img = null; ! ! /** ! * Constructs new JRobin graph from the supplied definition. ! * @param graphDef Graph definition. ! * @throws IOException Thrown in case of I/O error. ! * @throws RrdException Thrown in case of JRobin specific error. ! */ ! public RrdGraph(RrdGraphDef graphDef) throws IOException, RrdException ! { ! grapher = new Grapher( graphDef ); ! } ! ! /** ! * Creates buffered image object from the graph. ! * @param width Image width. ! * @param height Image height. ! * @return Graph as a buffered image. ! */ ! // Check, if width/height has changed since last generation ! // Regenerate the graph ! public BufferedImage getBufferedImage(int width, int height) ! { ! try ! { ! if ( img != null ) ! return img; ! else ! { ! img = grapher.createImage( width, height ); ! return img; ! } ! } ! catch (RrdException e) { ! e.printStackTrace(); ! } ! ! return null; ! } ! ! /** ! * Saves graph in PNG format. ! * @param path Path to PNG file. ! * @param width Image width ! * @param height Image height ! * @throws IOException Thrown in case of I/O error. ! */ ! public void saveAsPNG(String path, int width, int height) throws IOException ! { ! ImageIO.write( (RenderedImage) getBufferedImage(width, height), "png", new File(path) ); ! } ! ! /** ! * Saves graph in JPEG format ! * @param path Path to JPEG file. ! * @param width Image width. ! * @param height Image height. ! * @param quality JPEG qualitty (between 0 and 1). ! * @throws IOException Thrown in case of I/O error. ! */ ! public void saveAsJPEG(String path, int width, int height, float quality) throws IOException ! { ! // Based on http://javaalmanac.com/egs/javax.imageio/JpegWrite.html?l=rel ! try { ! // Retrieve jpg image to be compressed ! BufferedImage gImage = getBufferedImage(width, height); ! RenderedImage rndImage = (RenderedImage) gImage; ! ! // Find a jpeg writer ! ImageWriter writer = null; ! Iterator iter = ImageIO.getImageWritersByFormatName("jpg"); ! if (iter.hasNext()) { ! writer = (ImageWriter)iter.next(); ! } ! ! // Prepare output file ! ImageOutputStream ios = ImageIO.createImageOutputStream(new File(path)); ! writer.setOutput(ios); ! ! // Set the compression quality ! ImageWriteParam iwparam = new JpegImageWriteParam(); ! iwparam.setCompressionMode(ImageWriteParam.MODE_EXPLICIT) ; ! iwparam.setCompressionQuality(quality); ! ! // Write the image ! writer.write(null, new IIOImage(rndImage, null, null), iwparam); ! ! // Cleanup ! ios.flush(); ! writer.dispose(); ! ios.close(); ! } ! catch (Exception e) { ! e.printStackTrace(); ! } ! ! } ! ! /** ! * Returns panel object so that graph can be easily embedded in swing applications. ! * @return Swing panel object with graph embedded in panel. ! */ ! public ChartPanel getChartPanel() ! { ! ChartPanel p = new ChartPanel(); ! p.setChart( getBufferedImage(0, 0) ); ! ! return p; ! } ! ! /** ! * Returns graph as an array of PNG bytes ! * @param width Image width. ! * @param height Image height. ! * @return Array of PNG bytes. ! * @throws IOException Thrown in case of I/O error. ! */ ! public byte[] getPNGBytes(int width, int height) throws IOException ! { ! ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); ! ! ImageIO.write( (RenderedImage) getBufferedImage(width, height), "png", outputStream ); ! ! return outputStream.toByteArray(); ! } ! ! /** ! * Returns graph as an array of JPEG bytes ! * @param width Image width. ! * @param height Image height. ! * @param quality JPEG quality between 0 and 1. ! * @return Array of PNG bytes. ! * @throws IOException Thrown in case of I/O error. ! */ ! public byte[] getJPEGBytes(int width, int height, float quality) throws IOException ! { ! ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); ! try { ! // Retrieve jpg image to be compressed ! BufferedImage gImage = getBufferedImage(width, height); ! RenderedImage rndImage = (RenderedImage) gImage; ! ! // Find a jpeg writer ! ImageWriter writer = null; ! Iterator iter = ImageIO.getImageWritersByFormatName("jpg"); ! if (iter.hasNext()) { ! writer = (ImageWriter)iter.next(); ! } ! ! // Prepare output file ! ImageOutputStream ios = ImageIO.createImageOutputStream(outputStream); ! writer.setOutput(ios); ! ! // Set the compression quality ! ImageWriteParam iwparam = new JpegImageWriteParam(); ! iwparam.setCompressionMode(ImageWriteParam.MODE_EXPLICIT) ; ! iwparam.setCompressionQuality(quality); ! ! // Write the image ! writer.write(null, new IIOImage(rndImage, null, null), iwparam); ! ! // Cleanup ! ios.flush(); ! writer.dispose(); ! ios.close(); ! } ! catch (Exception e) { ! e.printStackTrace(); ! } ! return outputStream.toByteArray(); ! } ! ! } Index: ChartGraphics.java =================================================================== RCS file: /cvsroot/jrobin/src/jrobin/graph/ChartGraphics.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** ChartGraphics.java 13 Oct 2003 22:53:33 -0000 1.4 --- ChartGraphics.java 14 Oct 2003 22:11:34 -0000 1.5 *************** *** 52,58 **** } void fillRect(int x1, int y1, int x2, int y2) { ! g.fillRect( x1, -y1, x2 - x1, y2 - y1 ); } --- 52,59 ---- } + // Contrary to Graphics2D fillRect, this method uses boundary points void fillRect(int x1, int y1, int x2, int y2) { ! g.fillRect( x1, -y2, x2 - x1, y2 - y1 ); } Index: Grapher.java =================================================================== RCS file: /cvsroot/jrobin/src/jrobin/graph/Grapher.java,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** Grapher.java 13 Oct 2003 22:53:33 -0000 1.7 --- Grapher.java 14 Oct 2003 22:11:34 -0000 1.8 *************** *** 517,521 **** RrdSecond[] times = (RrdSecond[]) s.getSeries().times.toArray( new RrdSecond[0] ); Double[] values = (Double[]) s.getSeries().values.toArray( new Double[0] ); ! for (int i = 0; i < times.length; i++) { --- 517,521 ---- RrdSecond[] times = (RrdSecond[]) s.getSeries().times.toArray( new RrdSecond[0] ); Double[] values = (Double[]) s.getSeries().values.toArray( new Double[0] ); ! for (int i = 0; i < times.length; i++) { *************** *** 525,529 **** ny += p[i]; ! if ( ax != 0 && ay != Integer.MIN_VALUE && ny != Integer.MIN_VALUE ) g.drawLine( ax, ay, nx, ny ); --- 525,529 ---- ny += p[i]; ! if ( nx != 0 && ay != Integer.MIN_VALUE && ny != Integer.MIN_VALUE ) g.drawLine( ax, ay, nx, ny ); *************** *** 547,551 **** RrdSecond[] times = (RrdSecond[]) s.getSeries().times.toArray( new RrdSecond[0] ); Double[] values = (Double[]) s.getSeries().values.toArray( new Double[0] ); ! for (int i = 0; i < times.length; i++) { --- 547,551 ---- RrdSecond[] times = (RrdSecond[]) s.getSeries().times.toArray( new RrdSecond[0] ); Double[] values = (Double[]) s.getSeries().values.toArray( new Double[0] ); ! for (int i = 0; i < times.length; i++) { *************** *** 560,566 **** } ! if ( ax != 0 && py != Integer.MIN_VALUE && ny != Integer.MIN_VALUE ) g.drawLine( nx, py, nx, ny ); ! p[i] = ny; ax = nx; --- 560,575 ---- } ! 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++) ! g.drawLine( j, py, j, ( co * (j - ax) + ay) ); ! } ! else if ( nx != 0 && py != Integer.MIN_VALUE && ny != Integer.MIN_VALUE ) g.drawLine( nx, py, nx, ny ); ! p[i] = ny; ax = nx; *************** *** 589,593 **** numPoints = (int)(endTime - startTime + 1); - /* // ------------------------------------------------------- // Experimental test code, faster fetching research --- 598,601 ---- *************** *** 632,642 **** } rrd.close(); - - - } // ------------------------------------------------------- - */ // ------------------------------------------------------- // Old fetching code --- 640,647 ---- } rrd.close(); } // ------------------------------------------------------- + /* // ------------------------------------------------------- // Old fetching code *************** *** 644,648 **** sources[i].setIntervalInternal(startTime, endTime); // ------------------------------------------------------- ! s3 = Calendar.getInstance().getTimeInMillis(); --- 649,653 ---- sources[i].setIntervalInternal(startTime, endTime); // ------------------------------------------------------- ! */ s3 = Calendar.getInstance().getTimeInMillis(); |
|
From: <cob...@us...> - 2003-10-14 22:11:39
|
Update of /cvsroot/jrobin/src/jrobin/demo
In directory sc8-pr-cvs1:/tmp/cvs-serv10598/src/jrobin/demo
Modified Files:
JRobinDemo.java JRobinComplexGraph.java
Log Message:
GRAPH LIB UPDATES
Repeatedly saving fixed (only with the same graph dimensions)
Fixed graph generating for > 1000 pixel wide graphs
Fixed graph generating for extremely small time ranges (smaller than or equal to step size)
Index: JRobinDemo.java
===================================================================
RCS file: /cvsroot/jrobin/src/jrobin/demo/JRobinDemo.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** JRobinDemo.java 13 Oct 2003 11:53:54 -0000 1.4
--- JRobinDemo.java 14 Oct 2003 22:11:34 -0000 1.5
***************
*** 174,179 ****
gDef.setTitle("Temperatures in May 2003");
gDef.setValueAxisLabel("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,*");
--- 174,179 ----
gDef.setTitle("Temperatures in May 2003");
gDef.setValueAxisLabel("temperature");
! gDef.datasource("sun", rrdPath, "sun", "AVERAGE");
! gDef.datasource("shade", rrdPath, "shade", "AVERAGE");
gDef.datasource("median", "sun,shade,+,2,/");
gDef.datasource("diff", "sun,shade,-,ABS,-1,*");
Index: JRobinComplexGraph.java
===================================================================
RCS file: /cvsroot/jrobin/src/jrobin/demo/JRobinComplexGraph.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -d -r1.6 -r1.7
*** JRobinComplexGraph.java 13 Oct 2003 22:53:33 -0000 1.6
--- JRobinComplexGraph.java 14 Oct 2003 22:11:34 -0000 1.7
***************
*** 44,48 ****
public static void main(String[] args)
{
! GregorianCalendar start = new GregorianCalendar(2003, 7, 23, 23, 55);
GregorianCalendar end = new GregorianCalendar(2003, 7, 25, 0, 0);
--- 44,48 ----
public static void main(String[] args)
{
! GregorianCalendar start = new GregorianCalendar(2003, 7, 24, 0, 0);
GregorianCalendar end = new GregorianCalendar(2003, 7, 25, 0, 0);
***************
*** 114,124 ****
gDef.setArrowColor( Color.GREEN );
gDef.setChartLeftPadding( 40 );
! gDef.setAntiAliasing(true);
! gDef.setTimeAxis( TimeAxisUnit.HOUR, 6, TimeAxisUnit.DAY, 1, "EEEEE dd MMM", true );
! gDef.setValueAxis( 2.5, 5 );
// Create actual graph
RrdGraph graph = new RrdGraph(gDef);
graph.saveAsPNG("/zzzzzz.png", 0, 0);
//graph.saveAsJPEG("/zzzzzz.jpg", 0, 0, 1f);
// -- New graph
--- 114,126 ----
gDef.setArrowColor( Color.GREEN );
gDef.setChartLeftPadding( 40 );
! //gDef.setAntiAliasing(false);
! //gDef.setTimeAxis( TimeAxisUnit.HOUR, 6, TimeAxisUnit.DAY, 1, "EEEEE dd MMM", true );
! //gDef.setValueAxis( 2.5, 5 );
// Create actual graph
RrdGraph graph = new RrdGraph(gDef);
graph.saveAsPNG("/zzzzzz.png", 0, 0);
//graph.saveAsJPEG("/zzzzzz.jpg", 0, 0, 1f);
+
+ //System.exit(0);
// -- New graph
|
|
From: <cob...@us...> - 2003-10-13 22:53:39
|
Update of /cvsroot/jrobin/src/jrobin/graph In directory sc8-pr-cvs1:/tmp/cvs-serv30840/src/jrobin/graph Modified Files: RrdGraphDef.java Def.java Source.java ChartGraphics.java Grapher.java Added Files: RrdFile.java Log Message: GRAPH LIB UPDATES Optimizing attempts: Experimental Code, use with extreme caution --- NEW FILE: RrdFile.java --- /* ============================================================ * JRobin : Pure java implementation of RRDTool's functionality * ============================================================ * * Project Info: http://www.sourceforge.net/projects/jrobin * Project Lead: Sasa Markovic (sa...@eu...); * * (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 jrobin.graph; import java.util.*; /** * @author cbld * * To change the template for this generated type comment go to * Window - Preferences - Java - Code Generation - Code and Comments */ public class RrdFile { private String fileName = ""; // Fill this one in later private int AVG = 0; private int MAX = 1; private int MIN = 2; public Vector[] cfDataSources = new Vector[3]; public RrdFile() { for (int i = 0; i < cfDataSources.length; i++) cfDataSources[i] = new Vector(); } public RrdFile( String consolFun, String dsName, String name ) { this(); if ( consolFun.equalsIgnoreCase("AVERAGE") ) cfDataSources[AVG].add( new String[] { dsName, name } ); else if ( consolFun.equalsIgnoreCase("MAX") ) cfDataSources[MAX].add( new String[] { dsName, name } ); else if ( consolFun.equalsIgnoreCase("MIN") ) cfDataSources[MIN].add( new String[] { dsName, name } ); } public void addSource( String consolFun, String dsName, String name ) { if ( consolFun.equalsIgnoreCase("AVERAGE") ) cfDataSources[AVG].add( new String[] { dsName, name } ); else if ( consolFun.equalsIgnoreCase("MAX") ) cfDataSources[MAX].add( new String[] { dsName, name } ); else if ( consolFun.equalsIgnoreCase("MIN") ) cfDataSources[MIN].add( new String[] { dsName, name } ); } } Index: RrdGraphDef.java =================================================================== RCS file: /cvsroot/jrobin/src/jrobin/graph/RrdGraphDef.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** RrdGraphDef.java 11 Oct 2003 20:32:35 -0000 1.6 --- RrdGraphDef.java 13 Oct 2003 22:53:33 -0000 1.7 *************** *** 1,914 **** ! /* ============================================================ ! * JRobin : Pure java implementation of RRDTool's functionality ! * ============================================================ ! * ! * Project Info: http://www.sourceforge.net/projects/jrobin ! * Project Lead: Sasa Markovic (sa...@eu...); ! * ! * (C) Copyright 2003, by Sasa Markovic. ! * ! * This library is free software; you can redistribute it and/or modify it under the terms [...1806 lines suppressed...] ! public void setBaseValue( double base ) { ! this.baseValue = base; ! } ! ! double getBaseValue() { ! return this.baseValue; ! } ! ! /** ! * ! * @param e ! */ ! public void setUnitsExponent( int e ) { ! this.scaleIndex = (6 - e / 3); // Index in the scale table ! } ! ! int getScaleIndex() { ! return this.scaleIndex; ! } ! } Index: Def.java =================================================================== RCS file: /cvsroot/jrobin/src/jrobin/graph/Def.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** Def.java 23 Sep 2003 13:39:21 -0000 1.2 --- Def.java 13 Oct 2003 22:53:33 -0000 1.3 *************** *** 23,26 **** --- 23,28 ---- package jrobin.graph; + import java.util.*; + import jrobin.core.FetchPoint; import jrobin.core.FetchRequest; *************** *** 46,51 **** --- 48,74 ---- this.consolFun = consolFun; } + + void setValues( FetchPoint[] fetchPoints, int index ) + { + try { + + int numPoints = fetchPoints.length; + DataPoint[] points = new DataPoint[numPoints]; + + for(int i = 0; i < numPoints; i++) { + long time = fetchPoints[i].getTime(); + double value = fetchPoints[i].getValue(index); + points[i] = new DataPoint(time, value); + } + + valueExtractor = new ValueExtractor(points); + + } catch(Exception e) { e.printStackTrace(); } + } void setInterval(long start, long end) throws RrdException, IOException { + + long s1 = Calendar.getInstance().getTimeInMillis(); + RrdDb rrd = new RrdDb(rrdPath); long rrdStep = rrd.getRrdDef().getStep(); *************** *** 55,65 **** DataPoint[] points = new DataPoint[numPoints]; int dsIndex = rrd.getDsIndex(dsName); for(int i = 0; i < numPoints; i++) { ! long time = fetchPoints[i].getTime(); ! double value = fetchPoints[i].getValue(dsIndex); ! points[i] = new DataPoint(time, value); } rrd.close(); valueExtractor = new ValueExtractor(points); } --- 78,93 ---- DataPoint[] points = new DataPoint[numPoints]; int dsIndex = rrd.getDsIndex(dsName); + for(int i = 0; i < numPoints; i++) { ! long time = fetchPoints[i].getTime(); ! double value = fetchPoints[i].getValue(dsIndex); ! points[i] = new DataPoint(time, value); } rrd.close(); valueExtractor = new ValueExtractor(points); + + long s2 = Calendar.getInstance().getTimeInMillis(); + + //System.err.println( "Fetched " + dsName + " in " + (s2 - s1) + " ms (source: " + rrdPath + ")" ); } Index: Source.java =================================================================== RCS file: /cvsroot/jrobin/src/jrobin/graph/Source.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** Source.java 23 Sep 2003 13:39:21 -0000 1.2 --- Source.java 13 Oct 2003 22:53:33 -0000 1.3 *************** *** 23,26 **** --- 23,27 ---- package jrobin.graph; + import jrobin.core.*; import jrobin.core.RrdException; import jrobin.core.Util; *************** *** 64,67 **** --- 65,74 ---- } + // Experimental, override in Def + void setValues( FetchPoint[] fetchPoints, int index ) + { + + } + void setIntervalInternal(long startTime, long endTime) throws RrdException, IOException { setInterval(startTime, endTime); Index: ChartGraphics.java =================================================================== RCS file: /cvsroot/jrobin/src/jrobin/graph/ChartGraphics.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** ChartGraphics.java 30 Sep 2003 21:45:21 -0000 1.3 --- ChartGraphics.java 13 Oct 2003 22:53:33 -0000 1.4 *************** *** 51,55 **** g.drawLine( x1, -y1, x2, -y2 ); } ! void setColor( Color c ) { --- 51,60 ---- g.drawLine( x1, -y1, x2, -y2 ); } ! ! void fillRect(int x1, int y1, int x2, int y2) ! { ! g.fillRect( x1, -y1, x2 - x1, y2 - y1 ); ! } ! void setColor( Color c ) { Index: Grapher.java =================================================================== RCS file: /cvsroot/jrobin/src/jrobin/graph/Grapher.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** Grapher.java 11 Oct 2003 20:32:35 -0000 1.6 --- Grapher.java 13 Oct 2003 22:53:33 -0000 1.7 *************** *** 1,973 **** ! /* ============================================================ ! * JRobin : Pure java implementation of RRDTool's functionality ! * ============================================================ ! * ! * Project Info: http://www.sourceforge.net/projects/jrobin ! * Project Lead: Sasa Markovic (sa...@eu...); ! * ! * (C) Copyright 2003, by Sasa Markovic. ! * ! * This library is free software; you can redistribute it and/or modify it under the terms [...1987 lines suppressed...] ! if ( !Double.isNaN(fixedGridStep) && !Double.isNaN(fixedLabelStep) ) ! v = new ValueAxisUnit( 1, fixedGridStep, 1, fixedLabelStep ); ! else ! { ! if ( shifted <= 3 ) ! v = new ValueAxisUnit( 1, 0.2*mod, 1, 1.0*mod ); ! else if ( shifted <= 5 ) ! v = new ValueAxisUnit( 1, 0.5*mod, 1, 1.0*mod ); ! else if ( shifted <= 9 ) ! v = new ValueAxisUnit( 1, 0.5*mod, 1, 2.0*mod ); ! else ! v = new ValueAxisUnit( 1, 1.0*mod, 1, 5.0*mod ); ! } ! ! if ( !upperFromRange ) upperValue = v.getNiceHigher( upperValue ); ! if ( !lowerFromRange ) lowerValue = v.getNiceLower( lowerValue ); ! ! return v.getValueMarkers( lowerValue, upperValue, graphDef.getBaseValue(), graphDef.getScaleIndex() ); ! } ! } |
|
From: <cob...@us...> - 2003-10-13 22:53:38
|
Update of /cvsroot/jrobin/src/jrobin/demo In directory sc8-pr-cvs1:/tmp/cvs-serv30840/src/jrobin/demo Modified Files: JRobinComplexGraph.java Log Message: GRAPH LIB UPDATES Optimizing attempts: Experimental Code, use with extreme caution Index: JRobinComplexGraph.java =================================================================== RCS file: /cvsroot/jrobin/src/jrobin/demo/JRobinComplexGraph.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** JRobinComplexGraph.java 11 Oct 2003 20:34:39 -0000 1.5 --- JRobinComplexGraph.java 13 Oct 2003 22:53:33 -0000 1.6 *************** *** 1,184 **** ! /* ============================================================ ! * JRobin : Pure java implementation of RRDTool's functionality ! * ============================================================ ! * ! * Project Info: http://www.sourceforge.net/projects/jrobin ! * Project Lead: Sasa Markovic (sa...@eu...); ! * ! * (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. ! */ ! /* ! * Created on 26-aug-2003 ! * ! * To change the template for this generated file go to ! * Window - Preferences - Java - Code Generation - Code and Comments ! */ ! package jrobin.demo; ! ! import java.util.*; ! import java.awt.*; ! import javax.swing.*; ! ! import jrobin.graph.*; ! ! /** ! * @author cbld ! * ! * To change the template for this generated type comment go to ! * Window - Preferences - Java - Code Generation - Code and Comments ! */ ! public class JRobinComplexGraph { ! ! public static void main(String[] args) ! { ! GregorianCalendar start = new GregorianCalendar(2003, 7, 23, 0, 0); ! GregorianCalendar end = new GregorianCalendar(2003, 7, 25, 0, 0); ! ! RrdGraphDef gDef = new RrdGraphDef(); ! ! try ! { ! gDef.setTimePeriod(start, end); ! gDef.setTitle("Server load baseline projection"); ! //gDef.setOverlay("/pkts.png"); ! gDef.datasource("load", "c:/test.rrd", "serverLoad", "AVERAGE"); ! gDef.datasource("user", "c:/test.rrd", "serverCPUUser", "AVERAGE"); ! gDef.datasource("nice", "c:/test.rrd", "serverCPUNice", "AVERAGE"); ! gDef.datasource("system", "c:/test.rrd", "serverCPUSystem", "AVERAGE"); ! gDef.datasource("idle", "c:/test.rrd", "serverCPUIdle", "AVERAGE"); ! gDef.datasource("total", "user,nice,+,system,+,idle,+"); ! gDef.datasource("busy", "user,nice,+,system,+,total,/,100,*"); ! gDef.datasource("p25t50", "busy,25,GT,busy,50,LE,load,0,IF,0,IF"); ! gDef.datasource("p50t75", "busy,50,GT,busy,75,LE,load,0,IF,0,IF"); ! gDef.datasource("p75t90", "busy,75,GT,busy,90,LE,load,0,IF,0,IF"); ! gDef.datasource("p90t100", "busy,90,GT,load,0,IF"); ! gDef.comment("CPU utilization (%)\n"); ! gDef.comment(" "); ! gDef.area("load", new Color(0x66,0x99,0xcc), " 0 - 25%"); ! gDef.area("p25t50", new Color(0x00,0x66,0x99), "25 - 50%"); ! gDef.comment(" "); ! gDef.gprint("busy", "MIN", "Minimum:@5.1@s%"); ! gDef.gprint("busy", "MAX", "Maximum: @5.1@s%"); ! gDef.comment("\n"); ! gDef.comment(" "); ! gDef.area("p50t75", new Color(0x66,0x66,0x00), "50 - 75%"); ! gDef.area("p75t90", new Color(0xff,0x66,0x00), "75 - 90%"); ! gDef.area("p90t100", new Color(0xcc,0x33,0x00), "90 - 100%"); ! //gDef.rule(10.0, Color.ORANGE, null); ! gDef.gprint("busy", "AVERAGE", " Average:@5.1@s%"); ! gDef.gprint("busy", "LAST", "Current: @5.1@s%"); ! gDef.comment("\n"); ! gDef.comment("\n"); ! gDef.comment("Server load\n"); ! gDef.comment(" "); ! gDef.line("load", new Color(0x00,0x00,0x00), "Load average (5 min)" ); ! //gDef.area("load", Color.RED, " hmm \n"); ! //gDef.stack("p75t90", Color.GREEN, " hmm \n"); ! gDef.comment(" "); ! gDef.gprint("load", "MIN", " Minimum: @5.2@s"); ! gDef.gprint("load", "MAX", "Maximum: @6.2@s"); ! gDef.comment("\n"); ! gDef.comment(" "); ! gDef.comment(" "); ! gDef.gprint("load", "AVERAGE", "Average: @5.2@s"); ! gDef.gprint("load", "LAST", "Current: @6.2@s"); ! gDef.comment("\n"); ! gDef.comment("\n"); ! gDef.comment("-------------------------------------------------------------------------------@c"); ! gDef.comment("Generated: " + new Date() + "@r"); ! gDef.setBackColor( Color.DARK_GRAY ); ! gDef.setCanvasColor( Color.LIGHT_GRAY ); ! gDef.setValueAxisLabel("server load"); ! gDef.setFontColor( Color.WHITE ); ! //gDef.setGridX( false ); ! //gDef.setGridY( false ); ! gDef.setImageBorder( Color.BLACK, 1 ); ! //gDef.setFrontGrid(false); ! gDef.setShowLegend(true); ! gDef.setMajorGridColor(Color.YELLOW); ! gDef.setMinorGridColor( new Color( 130, 30, 30) ); ! gDef.setFrameColor( Color.BLACK ); ! gDef.setAxisColor( Color.RED ); ! gDef.setArrowColor( Color.GREEN ); ! gDef.setChartLeftPadding( 40 ); ! gDef.setAntiAliasing(true); ! gDef.setTimeAxis( TimeAxisUnit.HOUR, 6, TimeAxisUnit.DAY, 1, "EEEEE dd MMM", true ); ! gDef.setValueAxis( 2.5, 5 ); ! // Create actual graph ! RrdGraph graph = new RrdGraph(gDef); ! graph.saveAsPNG("/zzzzzz.png", 0, 0); ! //graph.saveAsJPEG("/zzzzzz.jpg", 0, 0, 1f); ! ! // -- New graph ! RrdGraphDef gd = new RrdGraphDef(); ! //gd.setBackColor( Color.WHITE ); ! gd.setTimePeriod( start, end ); ! //gd.setBackground("/ftp.png"); ! gd.datasource("in2", "c:/test.rrd", "ifInOctets", "AVERAGE"); ! gd.datasource("out2", "c:/test.rrd", "ifOutOctets", "AVERAGE"); ! gd.datasource("in", "in2,8,*"); ! gd.datasource("out", "out2,8,*"); ! gd.area("in", Color.GREEN, null); ! gd.line("out", Color.BLUE, null); ! gd.setRigidGrid(true); ! RrdGraph graph2 = new RrdGraph(gd); ! graph2.saveAsPNG("/traff.png", 0, 0); ! ! ////////////////////////////// ! gd = new RrdGraphDef(); ! gd.setBackColor( Color.WHITE ); ! gd.setTimePeriod( start, end ); ! gd.datasource("in2", "c:/test.rrd", "ifInUcastPkts", "AVERAGE"); ! gd.datasource("out2", "c:/test.rrd", "ifOutUcastPkts", "AVERAGE"); ! gd.datasource("in", "in2,8,*"); ! gd.datasource("out", "out2,8,*"); ! gd.area("in", Color.GREEN, null); ! gd.line("out", Color.BLUE, null); ! //gd.setUnitsExponent(6); ! graph2 = new RrdGraph(gd); ! graph2.saveAsPNG("/pkts.png", 0, 0); ! ! gd = new RrdGraphDef(); ! gd.setBackColor( Color.WHITE ); ! gd.setTimePeriod( start, end ); ! gd.datasource("ftp", "c:/test.rrd", "ftpUsers", "AVERAGE"); ! gd.area("ftp", Color.BLUE, null); ! ! graph2 = new RrdGraph(gd); ! graph2.saveAsPNG("/ftp.png", 0, 0); ! ! /* ! try { ! JFrame frame = new JFrame("Simple chartpanel test"); ! ! frame.getContentPane().add(graph2.getChartPanel()); ! frame.pack(); ! frame.setVisible(true); ! } catch (Exception e) { ! e.printStackTrace(); ! } ! */ ! ! //graph.saveAsPNG("c:/demo.png", 495, 200); ! } ! catch (Exception e) { ! System.err.println( e.getMessage() ); ! System.exit(1); ! } ! ! System.out.println("Complex demo graph created."); ! } ! } ! --- 1,184 ---- ! /* ============================================================ ! * JRobin : Pure java implementation of RRDTool's functionality ! * ============================================================ ! * ! * Project Info: http://www.sourceforge.net/projects/jrobin ! * Project Lead: Sasa Markovic (sa...@eu...); ! * ! * (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. ! */ ! /* ! * Created on 26-aug-2003 ! * ! * To change the template for this generated file go to ! * Window - Preferences - Java - Code Generation - Code and Comments ! */ ! package jrobin.demo; ! ! import java.util.*; ! import java.awt.*; ! import javax.swing.*; ! ! import jrobin.graph.*; ! ! /** ! * @author cbld ! * ! * To change the template for this generated type comment go to ! * Window - Preferences - Java - Code Generation - Code and Comments ! */ ! public class JRobinComplexGraph { ! ! public static void main(String[] args) ! { ! GregorianCalendar start = new GregorianCalendar(2003, 7, 23, 23, 55); ! GregorianCalendar end = new GregorianCalendar(2003, 7, 25, 0, 0); ! ! RrdGraphDef gDef = new RrdGraphDef(); ! ! try ! { ! gDef.setTimePeriod(start, end); ! gDef.setTitle("Server load baseline projection"); ! //gDef.setOverlay("/pkts.png"); ! gDef.datasource("load", "c:/test.rrd", "serverLoad", "AVERAGE"); ! gDef.datasource("user", "c:/test.rrd", "serverCPUUser", "AVERAGE"); ! gDef.datasource("nice", "c:/test.rrd", "serverCPUNice", "AVERAGE"); ! gDef.datasource("system", "c:/test.rrd", "serverCPUSystem", "AVERAGE"); ! gDef.datasource("idle", "c:/test.rrd", "serverCPUIdle", "AVERAGE"); ! gDef.datasource("total", "user,nice,+,system,+,idle,+"); ! gDef.datasource("busy", "user,nice,+,system,+,total,/,100,*"); ! gDef.datasource("p25t50", "busy,25,GT,busy,50,LE,load,0,IF,0,IF"); ! gDef.datasource("p50t75", "busy,50,GT,busy,75,LE,load,0,IF,0,IF"); ! gDef.datasource("p75t90", "busy,75,GT,busy,90,LE,load,0,IF,0,IF"); ! gDef.datasource("p90t100", "busy,90,GT,load,0,IF"); ! gDef.comment("CPU utilization (%)\n"); ! gDef.comment(" "); ! gDef.area("load", new Color(0x66,0x99,0xcc), " 0 - 25%"); ! gDef.area("p25t50", new Color(0x00,0x66,0x99), "25 - 50%"); ! gDef.comment(" "); ! gDef.gprint("busy", "MIN", "Minimum:@5.1@s%"); ! gDef.gprint("busy", "MAX", "Maximum: @5.1@s%"); ! gDef.comment("\n"); ! gDef.comment(" "); ! gDef.area("p50t75", new Color(0x66,0x66,0x00), "50 - 75%"); ! gDef.area("p75t90", new Color(0xff,0x66,0x00), "75 - 90%"); ! gDef.area("p90t100", new Color(0xcc,0x33,0x00), "90 - 100%"); ! //gDef.rule(10.0, Color.ORANGE, null); ! gDef.gprint("busy", "AVERAGE", " Average:@5.1@s%"); ! gDef.gprint("busy", "LAST", "Current: @5.1@s%"); ! gDef.comment("\n"); ! gDef.comment("\n"); ! gDef.comment("Server load\n"); ! gDef.comment(" "); ! gDef.line("load", new Color(0x00,0x00,0x00), "Load average (5 min)" ); ! //gDef.area("load", Color.RED, " hmm \n"); ! //gDef.stack("p75t90", Color.GREEN, " hmm \n"); ! gDef.comment(" "); ! gDef.gprint("load", "MIN", " Minimum: @5.2@s"); ! gDef.gprint("load", "MAX", "Maximum: @6.2@s"); ! gDef.comment("\n"); ! gDef.comment(" "); ! gDef.comment(" "); ! gDef.gprint("load", "AVERAGE", "Average: @5.2@s"); ! gDef.gprint("load", "LAST", "Current: @6.2@s"); ! gDef.comment("\n"); ! gDef.comment("\n"); ! gDef.comment("-------------------------------------------------------------------------------@c"); ! gDef.comment("Generated: " + new Date() + "@r"); ! gDef.setBackColor( Color.DARK_GRAY ); ! gDef.setCanvasColor( Color.LIGHT_GRAY ); ! gDef.setValueAxisLabel("server load"); ! gDef.setFontColor( Color.WHITE ); ! //gDef.setGridX( false ); ! //gDef.setGridY( false ); ! gDef.setImageBorder( Color.BLACK, 1 ); ! //gDef.setFrontGrid(false); ! gDef.setShowLegend(true); ! gDef.setMajorGridColor(Color.YELLOW); ! gDef.setMinorGridColor( new Color( 130, 30, 30) ); ! gDef.setFrameColor( Color.BLACK ); ! gDef.setAxisColor( Color.RED ); ! gDef.setArrowColor( Color.GREEN ); ! gDef.setChartLeftPadding( 40 ); ! gDef.setAntiAliasing(true); ! gDef.setTimeAxis( TimeAxisUnit.HOUR, 6, TimeAxisUnit.DAY, 1, "EEEEE dd MMM", true ); ! gDef.setValueAxis( 2.5, 5 ); ! // Create actual graph ! RrdGraph graph = new RrdGraph(gDef); ! graph.saveAsPNG("/zzzzzz.png", 0, 0); ! //graph.saveAsJPEG("/zzzzzz.jpg", 0, 0, 1f); ! ! // -- New graph ! RrdGraphDef gd = new RrdGraphDef(); ! //gd.setBackColor( Color.WHITE ); ! gd.setTimePeriod( start, end ); ! //gd.setBackground("/ftp.png"); ! gd.datasource("in2", "c:/test.rrd", "ifInOctets", "AVERAGE"); ! gd.datasource("out2", "c:/test.rrd", "ifOutOctets", "AVERAGE"); ! gd.datasource("in", "in2,8,*"); ! gd.datasource("out", "out2,8,*"); ! gd.area("in", Color.GREEN, null); ! gd.line("out", Color.BLUE, null); ! gd.setRigidGrid(true); ! RrdGraph graph2 = new RrdGraph(gd); ! graph2.saveAsPNG("/traff.png", 0, 0); ! ! ////////////////////////////// ! gd = new RrdGraphDef(); ! gd.setBackColor( Color.WHITE ); ! gd.setTimePeriod( start, end ); ! gd.datasource("in2", "c:/test.rrd", "ifInUcastPkts", "AVERAGE"); ! gd.datasource("out2", "c:/test.rrd", "ifOutUcastPkts", "AVERAGE"); ! gd.datasource("in", "in2,8,*"); ! gd.datasource("out", "out2,8,*"); ! gd.area("in", Color.GREEN, null); ! gd.line("out", Color.BLUE, null); ! //gd.setUnitsExponent(6); ! graph2 = new RrdGraph(gd); ! graph2.saveAsPNG("/pkts.png", 0, 0); ! ! gd = new RrdGraphDef(); ! gd.setBackColor( Color.WHITE ); ! gd.setTimePeriod( start, end ); ! gd.datasource("ftp", "c:/test.rrd", "ftpUsers", "AVERAGE"); ! gd.area("ftp", Color.BLUE, null); ! ! graph2 = new RrdGraph(gd); ! graph2.saveAsPNG("/ftp.png", 0, 0); ! ! /* ! try { ! JFrame frame = new JFrame("Simple chartpanel test"); ! ! frame.getContentPane().add(graph2.getChartPanel()); ! frame.pack(); ! frame.setVisible(true); ! } catch (Exception e) { ! e.printStackTrace(); ! } ! */ ! ! //graph.saveAsPNG("c:/demo.png", 495, 200); ! } ! catch (Exception e) { ! System.err.println( e.getMessage() ); ! System.exit(1); ! } ! ! System.out.println("Complex demo graph created."); ! } ! } ! |
|
From: <sa...@us...> - 2003-10-13 11:53:58
|
Update of /cvsroot/jrobin/src/jrobin/demo In directory sc8-pr-cvs1:/tmp/cvs-serv27083/jrobin/demo Modified Files: JRobinDemo.java Log Message: Almost finished basic demo... Index: JRobinDemo.java =================================================================== RCS file: /cvsroot/jrobin/src/jrobin/demo/JRobinDemo.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** JRobinDemo.java 11 Oct 2003 20:34:39 -0000 1.3 --- JRobinDemo.java 13 Oct 2003 11:53:54 -0000 1.4 *************** *** 1,240 **** ! /* ============================================================ ! * JRobin : Pure java implementation of RRDTool's functionality ! * ============================================================ ! * ! * Project Info: http://www.sourceforge.net/projects/jrobin ! * Project Lead: Sasa Markovic (sa...@eu...); ! * ! * (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 jrobin.demo; ! ! import jrobin.core.*; ! import jrobin.graph.RrdGraph; ! import 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.GregorianCalendar; ! ! /** ! * <p>Class used to demonstrate almost all of JRobin capabilities. To run this ! * demonstration execute the following command:</p> ! * ! * <pre> ! * java -jar JRobin-{version}.jar ! * </pre> ! * ! * <p>The jar-file can be found in the <code>libs</code> directory of this distribution. ! * <b>On Linux platforms, graphs cannot be generated if your computer has no X-windows ! * server up and running</b> (you'll end up with a nasty looking exception).</p> ! * ! * @author <a href="mailto:sa...@eu...">Sasa Markovic</a> ! */ ! public class JRobinDemo { ! static final String HOME = System.getProperty("user.home"); ! static final String SEPARATOR = System.getProperty("file.separator"); ! static final String FILE = "demo"; ! static final GregorianCalendar START = new GregorianCalendar(2003, 4, 1); ! static final GregorianCalendar END = new GregorianCalendar(2003, 5, 1); ! static final int MAX_STEP = 240; ! ! /** ! * <p>Runs the demonstration. ! * Demonstration consists of the following steps: (all files will be ! * created in your HOME directory):</p> ! * ! * <ul> ! * <li>Sample RRD database 'demo.rrd' is created (uses two GAUGE data sources). ! * <li>RRD file is updated more than 20.000 times, simulating one month of updates with ! * time steps of max. 4 minutes. ! * <li>Last update time is printed. ! * <li>Sample fetch request is executed, fetching data from RRD file for the whole month. ! * <li>Fetched data is printed on the screen. ! * <li>RRD file is dumped to file 'demo.xml' (XML format). ! * <li>New RRD file 'demo_restored.rrd' is created from XML file. ! * <li>RRD graph for the whole month is created in memory. ! * <li>Graph is saved in PNG and JPEG format (files 'demo.png' and 'demo.jpeg'). ! * <li>All files are closed. ! * <li>Log file 'demo.log' is created. Log file consist of RRDTool commands - execute this file ! * as Linux shell script to compare RRDTool's and Jrobin's fetch results (should be exactly the ! * same). ! * </ul> ! * ! * <p>If everything goes well, no exceptions are thrown and your graphs should look like:</p> ! * <p align="center"><img src="../../../images/demo.png" border="1"></p> ! * <p>Red and blue lines are simple (DEF) graph sources. Green line (median value) ! * represents complex (CDEF) graph source which is defined by a RPN expression. Filled ! * area (orange color) represents the difference between data source values. Sine line is here ! * just to represent JRobin's advanced graphing capabilities.</p> ! * ! * @param args Empty. This demo does not accept command line parameters. ! * @throws RrdException Thrown in case of JRobin specific error. ! * @throws IOException Thrown in case of I/O related error. ! */ ! public static void main(String[] args) throws RrdException, IOException { ! // setup ! println("==Starting demo"); ! RrdDb.setLockMode(RrdDb.WAIT_IF_LOCKED); ! ! long startMillis = System.currentTimeMillis(); ! long start = START.getTime().getTime() / 1000L; ! long end = END.getTime().getTime() / 1000L; ! String rrdFile = getFullPath(FILE + ".rrd"); ! String xmlFile = getFullPath(FILE + ".xml"); ! String rrdFile2 = getFullPath(FILE + "_restored.rrd"); ! //String pngFile = getFullPath(FILE + ".png"); ! String pngFile = "/zzzzzz.png"; ! String jpegFile = getFullPath(FILE + ".jpeg"); ! String logFile = getFullPath(FILE + ".log"); ! PrintWriter pw = new PrintWriter( ! new BufferedOutputStream( ! new FileOutputStream(logFile, false)) ! ); ! ! // creation ! println("==Creating RRD file " + rrdFile); ! RrdDef rrdDef = new RrdDef(rrdFile, 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, 797); ! rrdDef.addArchive("AVERAGE", 0.5, 288, 775); ! rrdDef.addArchive("MAX", 0.5, 1, 600); ! rrdDef.addArchive("MAX", 0.5, 6, 700); ! rrdDef.addArchive("MAX", 0.5, 24, 797); ! rrdDef.addArchive("MAX", 0.5, 288, 775); ! println(rrdDef.dump()); ! pw.println(rrdDef.dump()); ! RrdDb rrdDb = new RrdDb(rrdDef); ! println("==RRD file created."); ! ! // 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; ! while(t <= end) { ! Sample sample = rrdDb.createSample(t); ! sample.setValue("sun", sunSource.getValue()); ! sample.setValue("shade", shadeSource.getValue()); ! pw.println(sample.dump()); ! sample.update(); ! t += Math.random() * 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()); ! pw.println(request.dump()); ! FetchPoint[] points = request.fetch(); ! println("==Data fetched. " + points.length + " points obtained"); ! for(int i = 0; i < points.length; i++) { ! println(points[i].dump()); ! } ! println("==Fetch completed"); ! println("==Dumping RRD file to XML file " + xmlFile + " (can be restored with RRDTool)"); ! //rrdDb.dumpXml(xmlFile); ! println("==Creating RRD file " + rrdFile2 + " from " + xmlFile); ! //RrdDb rrdDb2 = new RrdDb(rrdFile2, xmlFile); ! // close files ! println("==Closing both RRD files"); ! rrdDb.close(); ! //rrdDb2.close(); ! ! // creating graph ! println("==Creating graph from the second file"); ! RrdGraphDef gDef = new RrdGraphDef(); ! gDef.setTimePeriod(start, end); ! gDef.setTimeAxisLabel("day in month"); ! gDef.setTitle("Temperatures in May 2003"); ! gDef.setValueAxisLabel("temperature"); ! gDef.datasource("sun", rrdFile, "sun", "AVERAGE"); ! gDef.datasource("shade", rrdFile, "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.RED, "sun temp"); ! gDef.line("shade", Color.BLUE, "shade temp"); ! gDef.line("median", Color.GREEN, "median value"); ! gDef.area("diff", Color.ORANGE, "difference"); ! gDef.line("sine", Color.CYAN, "sine function demo"); ! gDef.gprint("sun", "MAX", "\nmaxSun = @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"); ! RrdGraph graph = new RrdGraph(gDef); ! println("==Graph created"); ! println("==Saving graph as PNG file " + pngFile); ! graph.saveAsPNG(pngFile, 600, 400); ! println("==Saving graph as JPEG file " + jpegFile); ! graph.saveAsJPEG(jpegFile, 600, 400, 0.8F); ! ! // demo ends ! pw.close(); ! println("Demo completed in " + ! ((System.currentTimeMillis() - startMillis) / 1000.0) + ! " sec"); ! } ! ! static void println(String msg) { ! System.out.println(msg); ! } ! ! static String getFullPath(String path) { ! return HOME + SEPARATOR + path; ! } ! } ! ! class GaugeSource { ! private double value; ! private double step; ! ! GaugeSource(double value, double step) { ! this.value = value; ! this.step = step; ! } ! ! double getValue() { ! double oldValue = value; ! double increment = Math.random() * step; ! if(Math.random() > 0.5) { ! increment *= -1; ! } ! value += increment; ! if(value <= 0) { ! value = 0; ! } ! return oldValue; ! } ! ! ! } ! ! --- 1,239 ---- ! /* ============================================================ ! * JRobin : Pure java implementation of RRDTool's functionality ! * ============================================================ ! * ! * Project Info: http://www.sourceforge.net/projects/jrobin ! * Project Lead: Sasa Markovic (sa...@eu...); ! * ! * (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 jrobin.demo; ! ! import jrobin.core.*; ! import jrobin.graph.RrdGraph; ! import 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.GregorianCalendar; ! ! /** ! * <p>Class used to demonstrate almost all of JRobin capabilities. To run this ! * demonstration execute the following command:</p> ! * ! * <pre> ! * java -jar JRobin-{version}.jar ! * </pre> ! * ! * <p>The jar-file can be found in the <code>libs</code> directory of this distribution. ! * <b>On Linux platforms, graphs cannot be generated if your computer has no X-windows ! * server up and running</b> (you'll end up with a nasty looking exception).</p> ! * ! * @author <a href="mailto:sa...@eu...">Sasa Markovic</a> ! */ ! public class JRobinDemo { ! static final String HOME = System.getProperty("user.home"); ! static final String SEPARATOR = System.getProperty("file.separator"); ! static final String FILE = "demo"; ! static final GregorianCalendar START = new GregorianCalendar(2003, 4, 1); ! static final GregorianCalendar END = new GregorianCalendar(2003, 5, 1); ! static final int MAX_STEP = 240; ! ! /** ! * <p>Runs the demonstration. ! * Demonstration consists of the following steps: (all files will be ! * created in your HOME directory):</p> ! * ! * <ul> ! * <li>Sample RRD database 'demo.rrd' is created (uses two GAUGE data sources). ! * <li>RRD file is updated more than 20.000 times, simulating one month of updates with ! * time steps of max. 4 minutes. ! * <li>Last update time is printed. ! * <li>Sample fetch request is executed, fetching data from RRD file for the whole month. ! * <li>Fetched data is printed on the screen. ! * <li>RRD file is dumped to file 'demo.xml' (XML format). ! * <li>New RRD file 'demo_restored.rrd' is created from XML file. ! * <li>RRD graph for the whole month is created in memory. ! * <li>Graph is saved in PNG and JPEG format (files 'demo.png' and 'demo.jpeg'). ! * <li>All files are closed. ! * <li>Log file 'demo.log' is created. Log file consist of RRDTool commands - execute this file ! * as Linux shell script to compare RRDTool's and Jrobin's fetch results (should be exactly the ! * same). ! * </ul> ! * ! * <p>If everything goes well, no exceptions are thrown and your graphs should look like:</p> ! * <p align="center"><img src="../../../images/demo.png" border="1"></p> ! * <p>Red and blue lines are simple (DEF) graph sources. Green line (median value) ! * represents complex (CDEF) graph source which is defined by a RPN expression. Filled ! * area (orange color) represents the difference between data source values. Sine line is here ! * just to represent JRobin's advanced graphing capabilities.</p> ! * ! * @param args Empty. This demo does not accept command line parameters. ! * @throws RrdException Thrown in case of JRobin specific error. ! * @throws IOException Thrown in case of I/O related error. ! */ ! 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.getTime().getTime() / 1000L; ! long end = END.getTime().getTime() / 1000L; ! String rrdPath = getFullPath(FILE + ".rrd"); ! String xmlPath = getFullPath(FILE + ".xml"); ! String rrdRestoredPath = getFullPath(FILE + "_restored.rrd"); ! String pngPath = getFullPath(FILE + ".png"); ! String jpegPath = getFullPath(FILE + ".jpeg"); ! String logPath = getFullPath(FILE + ".log"); ! PrintWriter pw = 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, 797); ! rrdDef.addArchive("AVERAGE", 0.5, 288, 775); ! rrdDef.addArchive("MAX", 0.5, 1, 600); ! rrdDef.addArchive("MAX", 0.5, 6, 700); ! rrdDef.addArchive("MAX", 0.5, 24, 797); ! rrdDef.addArchive("MAX", 0.5, 288, 775); ! println(rrdDef.dump()); ! pw.println(rrdDef.dump()); ! RrdDb rrdDb = new RrdDb(rrdDef); ! println("==RRD file created."); ! ! // 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; ! Sample sample = rrdDb.createSample(); ! while(t <= end) { ! sample.setTime(t); ! sample.setValue("sun", sunSource.getValue()); ! sample.setValue("shade", shadeSource.getValue()); ! pw.println(sample.dump()); ! sample.update(); ! t += Math.random() * 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()); ! pw.println(request.dump()); ! FetchPoint[] points = request.fetch(); ! println("==Data fetched. " + points.length + " points obtained"); ! for(int i = 0; i < points.length; i++) { ! println(points[i].dump()); ! } ! println("==Fetch completed"); ! println("==Dumping RRD file to XML file " + xmlPath + " (can be restored with RRDTool)"); ! rrdDb.dumpXml(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(); ! ! // creating graph ! println("==Creating graph from the second file"); ! RrdGraphDef gDef = new RrdGraphDef(); ! gDef.setTimePeriod(start, end); ! gDef.setTimeAxisLabel("day in month"); ! gDef.setTitle("Temperatures in May 2003"); ! gDef.setValueAxisLabel("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.RED, "sun temp"); ! gDef.line("shade", Color.BLUE, "shade temp"); ! gDef.line("median", Color.GREEN, "median value"); ! gDef.area("diff", Color.ORANGE, "difference"); ! gDef.line("sine", Color.CYAN, "sine function demo"); ! gDef.gprint("sun", "MAX", "\nmaxSun = @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"); ! RrdGraph graph = new RrdGraph(gDef); ! println("==Graph created"); ! println("==Saving graph as PNG file " + pngPath); ! graph.saveAsPNG(pngPath, 600, 400); ! println("==Saving graph as JPEG file " + jpegPath); ! graph.saveAsJPEG(jpegPath, 600, 400, 0.5F); ! ! // demo ends ! pw.close(); ! println("Demo completed in " + ! ((System.currentTimeMillis() - startMillis) / 1000.0) + ! " sec"); ! } ! ! static void println(String msg) { ! System.out.println(msg); ! } ! ! static String getFullPath(String path) { ! return HOME + SEPARATOR + path; ! } ! } ! ! class GaugeSource { ! private double value; ! private double step; ! ! GaugeSource(double value, double step) { ! this.value = value; ! this.step = step; ! } ! ! double getValue() { ! double oldValue = value; ! double increment = Math.random() * step; ! if(Math.random() > 0.5) { ! increment *= -1; ! } ! value += increment; ! if(value <= 0) { ! value = 0; ! } ! return oldValue; ! } ! ! ! } ! ! |
|
From: <sa...@us...> - 2003-10-13 09:36:43
|
Update of /cvsroot/jrobin/src/jrobin/demo In directory sc8-pr-cvs1:/tmp/cvs-serv4631/jrobin/demo Removed Files: JRobinMinMaxDemo.java Log Message: Removed this demo, put in on the site... Demo package should contain only two files: JRobinDemo and JRobinComplexDemo... --- JRobinMinMaxDemo.java DELETED --- |
|
From: <sa...@us...> - 2003-10-11 20:34:48
|
Update of /cvsroot/jrobin/src/jrobin/demo In directory sc8-pr-cvs1:/tmp/cvs-serv2803 Modified Files: JRobinComplexGraph.java JRobinDemo.java Log Message: Index: JRobinComplexGraph.java =================================================================== RCS file: /cvsroot/jrobin/src/jrobin/demo/JRobinComplexGraph.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** JRobinComplexGraph.java 3 Oct 2003 10:09:52 -0000 1.4 --- JRobinComplexGraph.java 11 Oct 2003 20:34:39 -0000 1.5 *************** *** 1,167 **** ! /* ============================================================ ! * JRobin : Pure java implementation of RRDTool's functionality ! * ============================================================ ! * ! * Project Info: http://www.sourceforge.net/projects/jrobin ! * Project Lead: Sasa Markovic (sa...@eu...); ! * ! * (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. ! */ ! /* ! * Created on 26-aug-2003 ! * ! * To change the template for this generated file go to ! * Window - Preferences - Java - Code Generation - Code and Comments ! */ ! package jrobin.demo; ! ! import java.util.*; ! import java.awt.*; ! ! import jrobin.graph.*; ! ! /** ! * @author cbld ! * ! * To change the template for this generated type comment go to ! * Window - Preferences - Java - Code Generation - Code and Comments ! */ ! public class JRobinComplexGraph { ! ! public static void main(String[] args) ! { ! GregorianCalendar start = new GregorianCalendar(2003, 7, 23, 0, 0); ! GregorianCalendar end = new GregorianCalendar(2003, 7, 24, 0, 0); ! ! RrdGraphDef gDef = new RrdGraphDef(); ! ! try ! { ! gDef.setTimePeriod(start, end); ! gDef.setTitle("Server load baseline projection"); ! gDef.datasource("load", "c:/test.rrd", "serverLoad", "AVERAGE"); ! gDef.datasource("user", "c:/test.rrd", "serverCPUUser", "AVERAGE"); ! gDef.datasource("nice", "c:/test.rrd", "serverCPUNice", "AVERAGE"); ! gDef.datasource("system", "c:/test.rrd", "serverCPUSystem", "AVERAGE"); ! gDef.datasource("idle", "c:/test.rrd", "serverCPUIdle", "AVERAGE"); ! gDef.datasource("total", "user,nice,+,system,+,idle,+"); ! gDef.datasource("busy", "user,nice,+,system,+,total,/,100,*"); ! gDef.datasource("p25t50", "busy,25,GT,busy,50,LE,load,0,IF,0,IF"); ! gDef.datasource("p50t75", "busy,50,GT,busy,75,LE,load,0,IF,0,IF"); ! gDef.datasource("p75t90", "busy,75,GT,busy,90,LE,load,0,IF,0,IF"); ! gDef.datasource("p90t100", "busy,90,GT,load,0,IF"); ! gDef.comment("CPU utilization (%)\n"); ! gDef.comment(" "); ! gDef.area("load", new Color(0x66,0x99,0xcc), " 0 - 25%"); ! gDef.area("p25t50", new Color(0x00,0x66,0x99), "25 - 50%"); ! gDef.comment(" "); ! gDef.gprint("busy", "MIN", "Minimum:@5.1@s%"); ! gDef.gprint("busy", "MAX", "Maximum: @5.1@s%"); ! gDef.comment("\n"); ! gDef.comment(" "); ! gDef.area("p50t75", new Color(0x66,0x66,0x00), "50 - 75%"); ! gDef.area("p75t90", new Color(0xff,0x66,0x00), "75 - 90%"); ! gDef.area("p90t100", new Color(0xcc,0x33,0x00), "90 - 100%"); ! //gDef.rule(10.0, Color.ORANGE, null); ! gDef.gprint("busy", "AVERAGE", " Average:@5.1@s%"); ! gDef.gprint("busy", "LAST", "Current: @5.1@s%"); ! gDef.comment("\n"); ! gDef.comment("\n"); ! gDef.comment("Server load\n"); ! gDef.comment(" "); ! gDef.line("load", new Color(0x00,0x00,0x00), "Load average (5 min)" ); ! //gDef.area("load", Color.RED, " hmm \n"); ! //gDef.stack("p75t90", Color.GREEN, " hmm \n"); ! gDef.comment(" "); ! gDef.gprint("load", "MIN", " Minimum: @5.2@s"); ! gDef.gprint("load", "MAX", "Maximum: @6.2@s"); ! gDef.comment("\n"); ! gDef.comment(" "); ! gDef.comment(" "); ! gDef.gprint("load", "AVERAGE", "Average: @5.2@s"); ! gDef.gprint("load", "LAST", "Current: @6.2@s"); ! gDef.comment("\n"); ! gDef.comment("\n"); ! gDef.comment("-------------------------------------------------------------------------------@c"); ! gDef.comment("Generated: " + new Date() + "@r"); ! gDef.setBackColor( Color.DARK_GRAY ); ! gDef.setCanvasColor( Color.LIGHT_GRAY ); ! gDef.setValueAxisLabel("server load"); ! gDef.setFontColor( Color.WHITE ); ! //gDef.setGridX( false ); ! //gDef.setGridY( false ); ! gDef.setImageBorder( Color.BLACK, 1 ); ! gDef.setFrontGrid(false); ! gDef.setShowLegend(true); ! gDef.setMajorGridColor(Color.BLACK); ! gDef.setMinorGridColor( new Color( 130, 30, 30) ); ! gDef.setFrameColor( Color.YELLOW ); ! gDef.setAxisColor( Color.RED ); ! gDef.setArrowColor( Color.GREEN ); ! gDef.setChartLeftPadding( 40 ); ! // Create actual graph ! RrdGraph graph = new RrdGraph(gDef); ! graph.saveAsPNG("/zzzzzz.png", 0, 0); ! ! ! // -- New graph ! RrdGraphDef gd = new RrdGraphDef(); ! //gd.setBackColor( Color.WHITE ); ! gd.setTimePeriod( start, end ); ! gd.datasource("in2", "c:/test.rrd", "ifInOctets", "AVERAGE"); ! gd.datasource("out2", "c:/test.rrd", "ifOutOctets", "AVERAGE"); ! gd.datasource("in", "in2,8,*"); ! gd.datasource("out", "out2,8,*"); ! gd.area("in", Color.GREEN, null); ! gd.line("out", Color.BLUE, null); ! gd.setRigidGrid(true); ! RrdGraph graph2 = new RrdGraph(gd); ! graph2.saveAsPNG("/traff.png", 0, 0); ! ! ////////////////////////////// ! gd = new RrdGraphDef(); ! //gd.setBackColor( Color.WHITE ); ! gd.setTimePeriod( start, end ); ! gd.datasource("in2", "c:/test.rrd", "ifInUcastPkts", "AVERAGE"); ! gd.datasource("out2", "c:/test.rrd", "ifOutUcastPkts", "AVERAGE"); ! gd.datasource("in", "in2,8,*"); ! gd.datasource("out", "out2,8,*"); ! gd.area("in", Color.GREEN, null); ! gd.line("out", Color.BLUE, null); ! ! graph2 = new RrdGraph(gd); ! graph2.saveAsPNG("/pkts.png", 0, 0); ! ! gd = new RrdGraphDef(); ! gd.setBackColor( Color.WHITE ); ! gd.setTimePeriod( start, end ); ! gd.datasource("ftp", "c:/test.rrd", "ftpUsers", "AVERAGE"); ! gd.area("ftp", Color.BLUE, null); ! ! graph2 = new RrdGraph(gd); ! graph2.saveAsPNG("/ftp.png", 0, 0); ! ! ! //graph.saveAsPNG("c:/demo.png", 495, 200); ! } ! catch (Exception e) { ! System.err.println( e.getMessage() ); ! System.exit(1); ! } ! ! System.out.println("Complex demo graph created."); ! } ! } ! --- 1,184 ---- ! /* ============================================================ ! * JRobin : Pure java implementation of RRDTool's functionality ! * ============================================================ ! * ! * Project Info: http://www.sourceforge.net/projects/jrobin ! * Project Lead: Sasa Markovic (sa...@eu...); ! * ! * (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. ! */ ! /* ! * Created on 26-aug-2003 ! * ! * To change the template for this generated file go to ! * Window - Preferences - Java - Code Generation - Code and Comments ! */ ! package jrobin.demo; ! ! import java.util.*; ! import java.awt.*; ! import javax.swing.*; ! ! import jrobin.graph.*; ! ! /** ! * @author cbld ! * ! * To change the template for this generated type comment go to ! * Window - Preferences - Java - Code Generation - Code and Comments ! */ ! public class JRobinComplexGraph { ! ! public static void main(String[] args) ! { ! GregorianCalendar start = new GregorianCalendar(2003, 7, 23, 0, 0); ! GregorianCalendar end = new GregorianCalendar(2003, 7, 25, 0, 0); ! ! RrdGraphDef gDef = new RrdGraphDef(); ! ! try ! { ! gDef.setTimePeriod(start, end); ! gDef.setTitle("Server load baseline projection"); ! //gDef.setOverlay("/pkts.png"); ! gDef.datasource("load", "c:/test.rrd", "serverLoad", "AVERAGE"); ! gDef.datasource("user", "c:/test.rrd", "serverCPUUser", "AVERAGE"); ! gDef.datasource("nice", "c:/test.rrd", "serverCPUNice", "AVERAGE"); ! gDef.datasource("system", "c:/test.rrd", "serverCPUSystem", "AVERAGE"); ! gDef.datasource("idle", "c:/test.rrd", "serverCPUIdle", "AVERAGE"); ! gDef.datasource("total", "user,nice,+,system,+,idle,+"); ! gDef.datasource("busy", "user,nice,+,system,+,total,/,100,*"); ! gDef.datasource("p25t50", "busy,25,GT,busy,50,LE,load,0,IF,0,IF"); ! gDef.datasource("p50t75", "busy,50,GT,busy,75,LE,load,0,IF,0,IF"); ! gDef.datasource("p75t90", "busy,75,GT,busy,90,LE,load,0,IF,0,IF"); ! gDef.datasource("p90t100", "busy,90,GT,load,0,IF"); ! gDef.comment("CPU utilization (%)\n"); ! gDef.comment(" "); ! gDef.area("load", new Color(0x66,0x99,0xcc), " 0 - 25%"); ! gDef.area("p25t50", new Color(0x00,0x66,0x99), "25 - 50%"); ! gDef.comment(" "); ! gDef.gprint("busy", "MIN", "Minimum:@5.1@s%"); ! gDef.gprint("busy", "MAX", "Maximum: @5.1@s%"); ! gDef.comment("\n"); ! gDef.comment(" "); ! gDef.area("p50t75", new Color(0x66,0x66,0x00), "50 - 75%"); ! gDef.area("p75t90", new Color(0xff,0x66,0x00), "75 - 90%"); ! gDef.area("p90t100", new Color(0xcc,0x33,0x00), "90 - 100%"); ! //gDef.rule(10.0, Color.ORANGE, null); ! gDef.gprint("busy", "AVERAGE", " Average:@5.1@s%"); ! gDef.gprint("busy", "LAST", "Current: @5.1@s%"); ! gDef.comment("\n"); ! gDef.comment("\n"); ! gDef.comment("Server load\n"); ! gDef.comment(" "); ! gDef.line("load", new Color(0x00,0x00,0x00), "Load average (5 min)" ); ! //gDef.area("load", Color.RED, " hmm \n"); ! //gDef.stack("p75t90", Color.GREEN, " hmm \n"); ! gDef.comment(" "); ! gDef.gprint("load", "MIN", " Minimum: @5.2@s"); ! gDef.gprint("load", "MAX", "Maximum: @6.2@s"); ! gDef.comment("\n"); ! gDef.comment(" "); ! gDef.comment(" "); ! gDef.gprint("load", "AVERAGE", "Average: @5.2@s"); ! gDef.gprint("load", "LAST", "Current: @6.2@s"); ! gDef.comment("\n"); ! gDef.comment("\n"); ! gDef.comment("-------------------------------------------------------------------------------@c"); ! gDef.comment("Generated: " + new Date() + "@r"); ! gDef.setBackColor( Color.DARK_GRAY ); ! gDef.setCanvasColor( Color.LIGHT_GRAY ); ! gDef.setValueAxisLabel("server load"); ! gDef.setFontColor( Color.WHITE ); ! //gDef.setGridX( false ); ! //gDef.setGridY( false ); ! gDef.setImageBorder( Color.BLACK, 1 ); ! //gDef.setFrontGrid(false); ! gDef.setShowLegend(true); ! gDef.setMajorGridColor(Color.YELLOW); ! gDef.setMinorGridColor( new Color( 130, 30, 30) ); ! gDef.setFrameColor( Color.BLACK ); ! gDef.setAxisColor( Color.RED ); ! gDef.setArrowColor( Color.GREEN ); ! gDef.setChartLeftPadding( 40 ); ! gDef.setAntiAliasing(true); ! gDef.setTimeAxis( TimeAxisUnit.HOUR, 6, TimeAxisUnit.DAY, 1, "EEEEE dd MMM", true ); ! gDef.setValueAxis( 2.5, 5 ); ! // Create actual graph ! RrdGraph graph = new RrdGraph(gDef); ! graph.saveAsPNG("/zzzzzz.png", 0, 0); ! //graph.saveAsJPEG("/zzzzzz.jpg", 0, 0, 1f); ! ! // -- New graph ! RrdGraphDef gd = new RrdGraphDef(); ! //gd.setBackColor( Color.WHITE ); ! gd.setTimePeriod( start, end ); ! //gd.setBackground("/ftp.png"); ! gd.datasource("in2", "c:/test.rrd", "ifInOctets", "AVERAGE"); ! gd.datasource("out2", "c:/test.rrd", "ifOutOctets", "AVERAGE"); ! gd.datasource("in", "in2,8,*"); ! gd.datasource("out", "out2,8,*"); ! gd.area("in", Color.GREEN, null); ! gd.line("out", Color.BLUE, null); ! gd.setRigidGrid(true); ! RrdGraph graph2 = new RrdGraph(gd); ! graph2.saveAsPNG("/traff.png", 0, 0); ! ! ////////////////////////////// ! gd = new RrdGraphDef(); ! gd.setBackColor( Color.WHITE ); ! gd.setTimePeriod( start, end ); ! gd.datasource("in2", "c:/test.rrd", "ifInUcastPkts", "AVERAGE"); ! gd.datasource("out2", "c:/test.rrd", "ifOutUcastPkts", "AVERAGE"); ! gd.datasource("in", "in2,8,*"); ! gd.datasource("out", "out2,8,*"); ! gd.area("in", Color.GREEN, null); ! gd.line("out", Color.BLUE, null); ! //gd.setUnitsExponent(6); ! graph2 = new RrdGraph(gd); ! graph2.saveAsPNG("/pkts.png", 0, 0); ! ! gd = new RrdGraphDef(); ! gd.setBackColor( Color.WHITE ); ! gd.setTimePeriod( start, end ); ! gd.datasource("ftp", "c:/test.rrd", "ftpUsers", "AVERAGE"); ! gd.area("ftp", Color.BLUE, null); ! ! graph2 = new RrdGraph(gd); ! graph2.saveAsPNG("/ftp.png", 0, 0); ! ! /* ! try { ! JFrame frame = new JFrame("Simple chartpanel test"); ! ! frame.getContentPane().add(graph2.getChartPanel()); ! frame.pack(); ! frame.setVisible(true); ! } catch (Exception e) { ! e.printStackTrace(); ! } ! */ ! ! //graph.saveAsPNG("c:/demo.png", 495, 200); ! } ! catch (Exception e) { ! System.err.println( e.getMessage() ); ! System.exit(1); ! } ! ! System.out.println("Complex demo graph created."); ! } ! } ! Index: JRobinDemo.java =================================================================== RCS file: /cvsroot/jrobin/src/jrobin/demo/JRobinDemo.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** JRobinDemo.java 22 Sep 2003 17:15:17 -0000 1.2 --- JRobinDemo.java 11 Oct 2003 20:34:39 -0000 1.3 *************** *** 1,240 **** ! /* ============================================================ ! * JRobin : Pure java implementation of RRDTool's functionality ! * ============================================================ ! * ! * Project Info: http://www.sourceforge.net/projects/jrobin ! * Project Lead: Sasa Markovic (sa...@eu...); ! * ! * (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 jrobin.demo; ! ! import jrobin.core.*; ! import jrobin.graph.RrdGraph; ! import 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.GregorianCalendar; ! ! /** ! * <p>Class used to demonstrate almost all of JRobin capabilities. To run this ! * demonstration execute the following command:</p> ! * ! * <pre> ! * java -jar JRobin-{version}.jar ! * </pre> ! * ! * <p>The jar-file can be found in the <code>libs</code> directory of this distribution. ! * <b>On Linux platforms, graphs cannot be generated if your computer has no X-windows ! * server up and running</b> (you'll end up with a nasty looking exception).</p> ! * ! * @author <a href="mailto:sa...@eu...">Sasa Markovic</a> ! */ ! public class JRobinDemo { ! static final String HOME = System.getProperty("user.home"); ! static final String SEPARATOR = System.getProperty("file.separator"); ! static final String FILE = "demo"; ! static final GregorianCalendar START = new GregorianCalendar(2003, 4, 1); ! static final GregorianCalendar END = new GregorianCalendar(2003, 5, 1); ! static final int MAX_STEP = 240; ! ! /** ! * <p>Runs the demonstration. ! * Demonstration consists of the following steps: (all files will be ! * created in your HOME directory):</p> ! * ! * <ul> ! * <li>Sample RRD database 'demo.rrd' is created (uses two GAUGE data sources). ! * <li>RRD file is updated more than 20.000 times, simulating one month of updates with ! * time steps of max. 4 minutes. ! * <li>Last update time is printed. ! * <li>Sample fetch request is executed, fetching data from RRD file for the whole month. ! * <li>Fetched data is printed on the screen. ! * <li>RRD file is dumped to file 'demo.xml' (XML format). ! * <li>New RRD file 'demo_restored.rrd' is created from XML file. ! * <li>RRD graph for the whole month is created in memory. ! * <li>Graph is saved in PNG and JPEG format (files 'demo.png' and 'demo.jpeg'). ! * <li>All files are closed. ! * <li>Log file 'demo.log' is created. Log file consist of RRDTool commands - execute this file ! * as Linux shell script to compare RRDTool's and Jrobin's fetch results (should be exactly the ! * same). ! * </ul> ! * ! * <p>If everything goes well, no exceptions are thrown and your graphs should look like:</p> ! * <p align="center"><img src="../../../images/demo.png" border="1"></p> ! * <p>Red and blue lines are simple (DEF) graph sources. Green line (median value) ! * represents complex (CDEF) graph source which is defined by a RPN expression. Filled ! * area (orange color) represents the difference between data source values. Sine line is here ! * just to represent JRobin's advanced graphing capabilities.</p> ! * ! * @param args Empty. This demo does not accept command line parameters. ! * @throws RrdException Thrown in case of JRobin specific error. ! * @throws IOException Thrown in case of I/O related error. ! */ ! public static void main(String[] args) throws RrdException, IOException { ! // setup ! println("==Starting demo"); ! RrdDb.setLockMode(RrdDb.WAIT_IF_LOCKED); ! ! long startMillis = System.currentTimeMillis(); ! long start = START.getTime().getTime() / 1000L; ! long end = END.getTime().getTime() / 1000L; ! String rrdFile = getFullPath(FILE + ".rrd"); ! String xmlFile = getFullPath(FILE + ".xml"); ! String rrdFile2 = getFullPath(FILE + "_restored.rrd"); ! //String pngFile = getFullPath(FILE + ".png"); ! String pngFile = "/zzzzzz.png"; ! String jpegFile = getFullPath(FILE + ".jpeg"); ! String logFile = getFullPath(FILE + ".log"); ! PrintWriter pw = new PrintWriter( ! new BufferedOutputStream( ! new FileOutputStream(logFile, false)) ! ); ! ! // creation ! println("==Creating RRD file " + rrdFile); ! RrdDef rrdDef = new RrdDef(rrdFile, 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, 797); ! rrdDef.addArchive("AVERAGE", 0.5, 288, 775); ! rrdDef.addArchive("MAX", 0.5, 1, 600); ! rrdDef.addArchive("MAX", 0.5, 6, 700); ! rrdDef.addArchive("MAX", 0.5, 24, 797); ! rrdDef.addArchive("MAX", 0.5, 288, 775); ! println(rrdDef.dump()); ! pw.println(rrdDef.dump()); ! RrdDb rrdDb = new RrdDb(rrdDef); ! println("==RRD file created."); ! ! // 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; ! while(t <= end) { ! Sample sample = rrdDb.createSample(t); ! sample.setValue("sun", sunSource.getValue()); ! sample.setValue("shade", shadeSource.getValue()); ! pw.println(sample.dump()); ! sample.update(); ! t += Math.random() * 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()); ! pw.println(request.dump()); ! FetchPoint[] points = request.fetch(); ! println("==Data fetched. " + points.length + " points obtained"); ! for(int i = 0; i < points.length; i++) { ! println(points[i].dump()); ! } ! println("==Fetch completed"); ! println("==Dumping RRD file to XML file " + xmlFile + " (can be restored with RRDTool)"); ! //rrdDb.dumpXml(xmlFile); ! println("==Creating RRD file " + rrdFile2 + " from " + xmlFile); ! //RrdDb rrdDb2 = new RrdDb(rrdFile2, xmlFile); ! // close files ! println("==Closing both RRD files"); ! rrdDb.close(); ! //rrdDb2.close(); ! ! // creating graph ! println("==Creating graph from the second file"); ! RrdGraphDef gDef = new RrdGraphDef(); ! gDef.setTimePeriod(start, end); ! gDef.setTimeAxisLabel("day in month"); ! gDef.setTitle("Temperatures in May 2003"); ! gDef.setValueAxisLabel("temperature"); ! gDef.datasource("sun", rrdFile, "sun", "AVERAGE"); ! gDef.datasource("shade", rrdFile, "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.RED, "sun temp"); ! gDef.line("shade", Color.BLUE, "shade temp"); ! gDef.line("median", Color.GREEN, "median value"); ! gDef.area("diff", Color.ORANGE, "difference"); ! gDef.line("sine", Color.CYAN, "sine function demo"); ! gDef.gprint("sun", "MAX", "\nmaxSun = @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"); ! RrdGraph graph = new RrdGraph(gDef); ! println("==Graph created"); ! println("==Saving graph as PNG file " + pngFile); ! graph.saveAsPNG(pngFile, 600, 400); ! println("==Saving graph as JPEG file " + jpegFile); ! graph.saveAsJPEG(jpegFile, 600, 400, 0.8F); ! ! // demo ends ! pw.close(); ! println("Demo completed in " + ! ((System.currentTimeMillis() - startMillis) / 1000.0) + ! " sec"); ! } ! ! static void println(String msg) { ! System.out.println(msg); ! } ! ! static String getFullPath(String path) { ! return HOME + SEPARATOR + path; ! } ! } ! ! class GaugeSource { ! private double value; ! private double step; ! ! GaugeSource(double value, double step) { ! this.value = value; ! this.step = step; ! } ! ! double getValue() { ! double oldValue = value; ! double increment = Math.random() * step; ! if(Math.random() > 0.5) { ! increment *= -1; ! } ! value += increment; ! if(value <= 0) { ! value = 0; ! } ! return oldValue; ! } ! ! ! } ! ! --- 1,240 ---- ! /* ============================================================ ! * JRobin : Pure java implementation of RRDTool's functionality ! * ============================================================ ! * ! * Project Info: http://www.sourceforge.net/projects/jrobin ! * Project Lead: Sasa Markovic (sa...@eu...); ! * ! * (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 jrobin.demo; ! ! import jrobin.core.*; ! import jrobin.graph.RrdGraph; ! import 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.GregorianCalendar; ! ! /** ! * <p>Class used to demonstrate almost all of JRobin capabilities. To run this ! * demonstration execute the following command:</p> ! * ! * <pre> ! * java -jar JRobin-{version}.jar ! * </pre> ! * ! * <p>The jar-file can be found in the <code>libs</code> directory of this distribution. ! * <b>On Linux platforms, graphs cannot be generated if your computer has no X-windows ! * server up and running</b> (you'll end up with a nasty looking exception).</p> ! * ! * @author <a href="mailto:sa...@eu...">Sasa Markovic</a> ! */ ! public class JRobinDemo { ! static final String HOME = System.getProperty("user.home"); ! static final String SEPARATOR = System.getProperty("file.separator"); ! static final String FILE = "demo"; ! static final GregorianCalendar START = new GregorianCalendar(2003, 4, 1); ! static final GregorianCalendar END = new GregorianCalendar(2003, 5, 1); ! static final int MAX_STEP = 240; ! ! /** ! * <p>Runs the demonstration. ! * Demonstration consists of the following steps: (all files will be ! * created in your HOME directory):</p> ! * ! * <ul> ! * <li>Sample RRD database 'demo.rrd' is created (uses two GAUGE data sources). ! * <li>RRD file is updated more than 20.000 times, simulating one month of updates with ! * time steps of max. 4 minutes. ! * <li>Last update time is printed. ! * <li>Sample fetch request is executed, fetching data from RRD file for the whole month. ! * <li>Fetched data is printed on the screen. ! * <li>RRD file is dumped to file 'demo.xml' (XML format). ! * <li>New RRD file 'demo_restored.rrd' is created from XML file. ! * <li>RRD graph for the whole month is created in memory. ! * <li>Graph is saved in PNG and JPEG format (files 'demo.png' and 'demo.jpeg'). ! * <li>All files are closed. ! * <li>Log file 'demo.log' is created. Log file consist of RRDTool commands - execute this file ! * as Linux shell script to compare RRDTool's and Jrobin's fetch results (should be exactly the ! * same). ! * </ul> ! * ! * <p>If everything goes well, no exceptions are thrown and your graphs should look like:</p> ! * <p align="center"><img src="../../../images/demo.png" border="1"></p> ! * <p>Red and blue lines are simple (DEF) graph sources. Green line (median value) ! * represents complex (CDEF) graph source which is defined by a RPN expression. Filled ! * area (orange color) represents the difference between data source values. Sine line is here ! * just to represent JRobin's advanced graphing capabilities.</p> ! * ! * @param args Empty. This demo does not accept command line parameters. ! * @throws RrdException Thrown in case of JRobin specific error. ! * @throws IOException Thrown in case of I/O related error. ! */ ! public static void main(String[] args) throws RrdException, IOException { ! // setup ! println("==Starting demo"); ! RrdDb.setLockMode(RrdDb.WAIT_IF_LOCKED); ! ! long startMillis = System.currentTimeMillis(); ! long start = START.getTime().getTime() / 1000L; ! long end = END.getTime().getTime() / 1000L; ! String rrdFile = getFullPath(FILE + ".rrd"); ! String xmlFile = getFullPath(FILE + ".xml"); ! String rrdFile2 = getFullPath(FILE + "_restored.rrd"); ! //String pngFile = getFullPath(FILE + ".png"); ! String pngFile = "/zzzzzz.png"; ! String jpegFile = getFullPath(FILE + ".jpeg"); ! String logFile = getFullPath(FILE + ".log"); ! PrintWriter pw = new PrintWriter( ! new BufferedOutputStream( ! new FileOutputStream(logFile, false)) ! ); ! ! // creation ! println("==Creating RRD file " + rrdFile); ! RrdDef rrdDef = new RrdDef(rrdFile, 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, 797); ! rrdDef.addArchive("AVERAGE", 0.5, 288, 775); ! rrdDef.addArchive("MAX", 0.5, 1, 600); ! rrdDef.addArchive("MAX", 0.5, 6, 700); ! rrdDef.addArchive("MAX", 0.5, 24, 797); ! rrdDef.addArchive("MAX", 0.5, 288, 775); ! println(rrdDef.dump()); ! pw.println(rrdDef.dump()); ! RrdDb rrdDb = new RrdDb(rrdDef); ! println("==RRD file created."); ! ! // 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; ! while(t <= end) { ! Sample sample = rrdDb.createSample(t); ! sample.setValue("sun", sunSource.getValue()); ! sample.setValue("shade", shadeSource.getValue()); ! pw.println(sample.dump()); ! sample.update(); ! t += Math.random() * 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()); ! pw.println(request.dump()); ! FetchPoint[] points = request.fetch(); ! println("==Data fetched. " + points.length + " points obtained"); ! for(int i = 0; i < points.length; i++) { ! println(points[i].dump()); ! } ! println("==Fetch completed"); ! println("==Dumping RRD file to XML file " + xmlFile + " (can be restored with RRDTool)"); ! //rrdDb.dumpXml(xmlFile); ! println("==Creating RRD file " + rrdFile2 + " from " + xmlFile); ! //RrdDb rrdDb2 = new RrdDb(rrdFile2, xmlFile); ! // close files ! println("==Closing both RRD files"); ! rrdDb.close(); ! //rrdDb2.close(); ! ! // creating graph ! println("==Creating graph from the second file"); ! RrdGraphDef gDef = new RrdGraphDef(); ! gDef.setTimePeriod(start, end); ! gDef.setTimeAxisLabel("day in month"); ! gDef.setTitle("Temperatures in May 2003"); ! gDef.setValueAxisLabel("temperature"); ! gDef.datasource("sun", rrdFile, "sun", "AVERAGE"); ! gDef.datasource("shade", rrdFile, "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.RED, "sun temp"); ! gDef.line("shade", Color.BLUE, "shade temp"); ! gDef.line("median", Color.GREEN, "median value"); ! gDef.area("diff", Color.ORANGE, "difference"); ! gDef.line("sine", Color.CYAN, "sine function demo"); ! gDef.gprint("sun", "MAX", "\nmaxSun = @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"); ! RrdGraph graph = new RrdGraph(gDef); ! println("==Graph created"); ! println("==Saving graph as PNG file " + pngFile); ! graph.saveAsPNG(pngFile, 600, 400); ! println("==Saving graph as JPEG file " + jpegFile); ! graph.saveAsJPEG(jpegFile, 600, 400, 0.8F); ! ! // demo ends ! pw.close(); ! println("Demo completed in " + ! ((System.currentTimeMillis() - startMillis) / 1000.0) + ! " sec"); ! } ! ! static void println(String msg) { ! System.out.println(msg); ! } ! ! static String getFullPath(String path) { ! return HOME + SEPARATOR + path; ! } ! } ! ! class GaugeSource { ! private double value; ! private double step; ! ! GaugeSource(double value, double step) { ! this.value = value; ! this.step = step; ! } ! ! double getValue() { ! double oldValue = value; ! double increment = Math.random() * step; ! if(Math.random() > 0.5) { ! increment *= -1; ! } ! value += increment; ! if(value <= 0) { ! value = 0; ! } ! return oldValue; ! } ! ! ! } ! ! |
|
From: <sa...@us...> - 2003-10-09 08:48:28
|
Update of /cvsroot/jrobin/src/jrobin/core
In directory sc8-pr-cvs1:/tmp/cvs-serv866/jrobin/core
Modified Files:
Sample.java
Log Message:
Minor changes... added some shortcut methods
Index: Sample.java
===================================================================
RCS file: /cvsroot/jrobin/src/jrobin/core/Sample.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** Sample.java 4 Sep 2003 13:26:41 -0000 1.1
--- Sample.java 9 Oct 2003 08:48:23 -0000 1.2
***************
*** 24,27 ****
--- 24,28 ----
import java.io.IOException;
+ import java.util.StringTokenizer;
/**
***************
*** 57,63 ****
this.time = time;
this.dsNames = parentDb.getDsNames();
! int n = dsNames.length;
! values = new double[n];
! for(int i = 0; i < n; i++) {
values[i] = Double.NaN;
}
--- 58,67 ----
this.time = time;
this.dsNames = parentDb.getDsNames();
! values = new double[dsNames.length];
! clearCurrentValues();
! }
!
! private void clearCurrentValues() {
! for(int i = 0; i < values.length; i++) {
values[i] = Double.NaN;
}
***************
*** 71,75 ****
*/
public void setValue(String dsName, double value) throws RrdException {
! for(int i = 0; i < dsNames.length; i++) {
if(dsNames[i].equals(dsName)) {
values[i] = value;
--- 75,79 ----
*/
public void setValue(String dsName, double value) throws RrdException {
! for(int i = 0; i < values.length; i++) {
if(dsNames[i].equals(dsName)) {
values[i] = value;
***************
*** 88,92 ****
*/
public void setValue(int i, double value) throws RrdException {
! if(i < dsNames.length) {
values[i] = value;
return;
--- 92,96 ----
*/
public void setValue(int i, double value) throws RrdException {
! if(i < values.length) {
values[i] = value;
return;
***************
*** 96,116 ****
/**
! * Sets all data source values. You must supply values for all data sources defined in
! * a RRD file.
* @param values Data source values.
! * @throws RrdException Thrown if number of supplied values is different from number of
! * data sources defined in a RRD file.
*/
public void setValues(double[] values) throws RrdException {
! if(values.length == dsNames.length) {
! this.values = values;
! return;
}
- throw new RrdException("Invalid number of values specified (found " + values.length +
- ", exactly " + dsNames.length + " needed");
}
/**
! * Returns all data source values in the sample.
* @return Data source values.
*/
--- 100,124 ----
/**
! * Sets some (possibly all) data source values in bulk. Data source values are
! * assigned in the order of their definition inside the RRD file.
! *
* @param values Data source values.
! * @throws RrdException Thrown if the number of supplied values is zero or greater
! * than the number of data sources defined in the RRD file.
*/
public void setValues(double[] values) throws RrdException {
! if(values.length <= this.values.length) {
! for(int i = 0; i < values.length; i++) {
! this.values[i] = values[i];
! }
! }
! else {
! throw new RrdException("Invalid number of values specified (found " +
! values.length + ", only " + dsNames.length + " allowed)");
}
}
/**
! * Returns all current data source values in the sample.
* @return Data source values.
*/
***************
*** 145,149 ****
/**
! * Stores sample in the corresponding RRD file.
* @throws IOException Thrown in case of I/O error.
* @throws RrdException Thrown in case of JRobin related error.
--- 153,193 ----
/**
! * <p>Sets sample timestamp and data source values in a fashion similar to RRDTool.
! * Argument string should be composed in the following way:
! * <code>timestamp:value1:value2:...:valueN</code>.</p>
! *
! * <p>You don't have to supply all datasource values. Unspecified values will be treated
! * as unknowns. To specify unknown value in the argument string, use letter 'U'
! *
! * @param timeAndValues String made by concatenating sample timestamp with corresponding
! * data source values delmited with colons. For example:
! * <code>1005234132:12.2:35.6:U:24.5</code>
! * @throws RrdException Thrown if too many datasource values are supplied
! */
! public void set(String timeAndValues) throws RrdException {
! StringTokenizer st = new StringTokenizer(timeAndValues, ":", false);
! int numTokens = st.countTokens();
! String[] tokens = new String[numTokens];
! for(int i = 0; i < numTokens; i++) {
! tokens[i] = st.nextToken();
! }
! long time = Long.parseLong(tokens[0]);
! double[] values = new double[numTokens - 1];
! for(int i = 0; i < numTokens - 1; i++) {
! try {
! values[i] = Double.parseDouble(tokens[i + 1]);
! }
! catch(NumberFormatException nfe) {
! values[i] = Double.NaN;
! }
! }
! setTime(time);
! setValues(values);
! }
!
! /**
! * Stores sample in the corresponding RRD file. If the update operation succeedes,
! * all datasource values in the sample will be set to Double.NaN (unknown) values.
! *
* @throws IOException Thrown in case of I/O error.
* @throws RrdException Thrown in case of JRobin related error.
***************
*** 151,154 ****
--- 195,219 ----
public void update() throws IOException, RrdException {
parentDb.store(this);
+ clearCurrentValues();
+ }
+
+ /**
+ * <p>Creates sample with the timestamp and data source values supplied
+ * in the argument string and stores sample in the corresponding RRD file.
+ * This method is just a shortcut for:</p>
+ * <pre>
+ * set(timeAndValues);
+ * update();
+ * </pre>
+ * @param timeAndValues String made by concatenating sample timestamp with corresponding
+ * data source values delmited with colons. For example:
+ * <code>1005234132:12.2:35.6:U:24.5</code>
+ *
+ * @throws IOException Thrown in case of I/O error.
+ * @throws RrdException Thrown in case of JRobin related error.
+ */
+ public void setAndUpdate(String timeAndValues) throws IOException, RrdException {
+ set(timeAndValues);
+ update();
}
|
|
From: <sa...@us...> - 2003-10-06 10:45:19
|
Update of /cvsroot/jrobin/src/jrobin/core
In directory sc8-pr-cvs1:/tmp/cvs-serv6772/jrobin/core
Modified Files:
ArcState.java Archive.java Datasource.java Header.java
Robin.java RrdDb.java
Log Message:
Javadoc added for classes and methods made public
Index: ArcState.java
===================================================================
RCS file: /cvsroot/jrobin/src/jrobin/core/ArcState.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** ArcState.java 6 Oct 2003 08:50:59 -0000 1.3
--- ArcState.java 6 Oct 2003 10:45:04 -0000 1.4
***************
*** 25,29 ****
import java.io.IOException;
! // TODO: Fix javadoc, class made public
public class ArcState implements RrdUpdater {
private Archive parentArc;
--- 25,35 ----
import java.io.IOException;
! /**
! * Class to represent internal RRD archive state for a single datasource. Objects of this
! * class are never manipulated directly, it's up to JRobin framework to manage
! * internal arcihve states.<p>
! *
! * @author <a href="mailto:sa...@eu...">Sasa Markovic</a>
! */
public class ArcState implements RrdUpdater {
private Archive parentArc;
***************
*** 50,53 ****
--- 56,63 ----
}
+ /**
+ * Returns the underlying RrdFile object.
+ * @return Underlying RrdFile object.
+ */
public RrdFile getRrdFile() {
return parentArc.getParentDb().getRrdFile();
***************
*** 62,65 ****
--- 72,81 ----
}
+ /**
+ * Returns the number of currently accumulated NaN steps.
+ *
+ * @return Number of currently accumulated NaN steps.
+ * @throws IOException Thrown in case of IO specific error
+ */
public long getNanSteps() throws IOException {
return nanSteps.get();
***************
*** 70,75 ****
--- 86,106 ----
}
+ /**
+ * Returns the value accumulated so far.
+ *
+ * @return Accumulated value
+ * @throws IOException Thrown in case of IO specific error
+ */
public double getAccumValue() throws IOException {
return accumValue.get();
+ }
+
+ /**
+ * Returns the Archive object to which this ArcState object belongs.
+ *
+ * @return Parent Archive object.
+ */
+ public Archive getParent() {
+ return parentArc;
}
Index: Archive.java
===================================================================
RCS file: /cvsroot/jrobin/src/jrobin/core/Archive.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** Archive.java 6 Oct 2003 08:50:59 -0000 1.4
--- Archive.java 6 Oct 2003 10:45:04 -0000 1.5
***************
*** 25,29 ****
import java.io.IOException;
! // TODO: FIX JAVADOC, CLASS MADE PUBLIC
public class Archive implements RrdUpdater {
private RrdDb parentDb;
--- 25,39 ----
import java.io.IOException;
! /**
! * Class to represent single RRD archive in a RRD file with its internal state.
! * Normally, you don't need methods to manipulate archive objects directly
! * because JRobin framework does it automatically for you.<p>
! *
! * Each archive object consists of three parts: archive definition, archive state objects
! * (one state object for each datasource) and round robin archives (one round robin for
! * each datasource). API (read-only) is provided to access each of theese parts.<p>
! *
! * @author <a href="mailto:sa...@eu...">Sasa Markovic</a>
! */
public class Archive implements RrdUpdater {
private RrdDb parentDb;
***************
*** 90,93 ****
--- 100,110 ----
}
+ /**
+ * Returns archive time step in seconds. Archive step is equal to RRD file step
+ * multiplied with the number of archive steps.
+ *
+ * @return Archive time step in seconds
+ * @throws IOException Thrown in case of IO error
+ */
public long getArcStep() throws IOException {
long step = parentDb.getHeader().getStep();
***************
*** 111,114 ****
--- 128,135 ----
}
+ /**
+ * Returns the underlying RrdFile object.
+ * @return Underlying RrdFile object
+ */
public RrdFile getRrdFile() {
return parentDb.getRrdFile();
***************
*** 185,204 ****
--- 206,250 ----
}
+ /**
+ * Returns archive consolidation function (AVERAGE, MIN, MAX or LAST).
+ * @return Archive consolidation function.
+ * @throws IOException Thrown in case of IO related error
+ */
public String getConsolFun() throws IOException {
return consolFun.get();
}
+ /**
+ * Returns archive X-files factor.
+ * @return Archive X-files factor (between 0 and 1).
+ * @throws IOException Thrown in case of IO related error
+ */
public double getXff() throws IOException {
return xff.get();
}
+ /**
+ * Returns the number of archive steps.
+ * @return Number of archive steps.
+ * @throws IOException Thrown in case of IO related error
+ */
public int getSteps() throws IOException {
return steps.get();
}
+ /**
+ * Returns the number of archive rows.
+ * @return Number of archive rows.
+ * @throws IOException Thrown in case of IO related error
+ */
public int getRows() throws IOException{
return rows.get();
}
+ /**
+ * Returns current starting timestamp. This value is not constant.
+ * @return Timestamp corresponding to the first archive row
+ * @throws IOException Thrown in case of IO related error
+ */
public long getStartTime() throws IOException {
long endTime = getEndTime();
***************
*** 208,211 ****
--- 254,262 ----
}
+ /**
+ * Returns current ending timestamp. This value is not constant.
+ * @return Timestamp corresponding to the last archive row
+ * @throws IOException Thrown in case of IO related error
+ */
public long getEndTime() throws IOException {
long arcStep = getArcStep();
***************
*** 214,221 ****
--- 265,285 ----
}
+ /**
+ * Returns the underlying archive state object. Each datasource has its
+ * corresponding ArcState object (archive states are managed independently
+ * for each RRD datasource).
+ * @param dsIndex Datasource index
+ * @return Underlying archive state object
+ */
public ArcState getArcState(int dsIndex) {
return states[dsIndex];
}
+ /**
+ * Returns the underlying round robin archive. Robins are used to store actual
+ * archive values on a per-datasource basis.
+ * @param dsIndex Index of the datasource in the RRD file.
+ * @return Underlying round robin archive for the given datasource.
+ */
public Robin getRobin(int dsIndex) {
return robins[dsIndex];
Index: Datasource.java
===================================================================
RCS file: /cvsroot/jrobin/src/jrobin/core/Datasource.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** Datasource.java 6 Oct 2003 08:50:59 -0000 1.4
--- Datasource.java 6 Oct 2003 10:45:04 -0000 1.5
***************
*** 26,30 ****
--- 26,37 ----
/**
+ * Class to represent single datasource within RRD file. Each datasource object holds the
+ * following information: datasource definition (once set, never changed) and
+ * datasource state variables (changed whenever RRD file gets updated).<p>
+ *
+ * Normally, you don't need to manipluate Datasource objects directly, it's up to
+ * JRobin framework to do it for you.
*
+ * @author <a href="mailto:sa...@eu...">Sasa Markovic</a>
*/
public class Datasource implements RrdUpdater {
***************
*** 85,120 ****
--- 92,178 ----
}
+ /**
+ * Returns the underlying RrdFile object.
+ * @return Underlying RrdFile object.
+ */
public RrdFile getRrdFile() {
return parentDb.getRrdFile();
}
+ /**
+ * Returns datasource name.
+ * @return Datasource name
+ * @throws IOException Thrown in case of IO related error
+ */
public String getDsName() throws IOException {
return dsName.get();
}
+ /**
+ * Returns datasource type (GAUGE, COUNTER, DERIVE, ABSOLUTE).
+ *
+ * @return Datasource type.
+ * @throws IOException Thrown in case of IO related error
+ */
public String getDsType() throws IOException {
return dsType.get();
}
+ /**
+ * Returns datasource heartbeat
+ *
+ * @return Datasource heartbeat
+ * @throws IOException Thrown in case of IO related error
+ */
public long getHeartbeat() throws IOException {
return heartbeat.get();
}
+ /**
+ * Returns mimimal allowed value of the datasource.
+ *
+ * @return Minimal value allowed.
+ * @throws IOException Thrown in case of IO related error
+ */
public double getMinValue() throws IOException {
return minValue.get();
}
+ /**
+ * Returns maximal allowed value of the datasource.
+ *
+ * @return Maximal value allowed.
+ * @throws IOException Thrown in case of IO related error
+ */
public double getMaxValue() throws IOException {
return maxValue.get();
}
+ /**
+ * Returns last known value of the datasource.
+ *
+ * @return Last datasource value.
+ * @throws IOException Thrown in case of IO related error
+ */
public double getLastValue() throws IOException {
return lastValue.get();
}
+ /**
+ * Returns value this datasource accumulated so far.
+ *
+ * @return Accumulated datasource value.
+ * @throws IOException Thrown in case of IO related error
+ */
public double getAccumValue() throws IOException {
return accumValue.get();
}
+ /**
+ * Returns the number of accumulated NaN seconds.
+ *
+ * @return Accumulated NaN seconds.
+ * @throws IOException Thrown in case of IO related error
+ */
public long getNanSeconds() throws IOException {
return nanSeconds.get();
Index: Header.java
===================================================================
RCS file: /cvsroot/jrobin/src/jrobin/core/Header.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** Header.java 6 Oct 2003 08:50:59 -0000 1.3
--- Header.java 6 Oct 2003 10:45:04 -0000 1.4
***************
*** 25,32 ****
import java.io.IOException;
- // TODO: Fix javadoc, class made public!
-
/**
*
*/
public class Header implements RrdUpdater {
--- 25,37 ----
import java.io.IOException;
/**
+ * Class to represent RRD file header. Header information is mainly static (once set, it
+ * cannot be changed), with the exception of last update time (this value is changed whenever
+ * RRD file gets updated).<p>
+ *
+ * Normally, you don't need to manipulate the Header object directly - JRobin framework
+ * does it for you.<p>
*
+ * @author <a href="mailto:sa...@eu...">Sasa Markovic</a>*
*/
public class Header implements RrdUpdater {
***************
*** 75,94 ****
--- 80,131 ----
}
+ /**
+ * Returns RRD file signature. The returned string will be always
+ * of the form <b><i>JRobin, version x.x</i></b>. Note: RRD file format did not
+ * change since Jrobin 1.0.0 release (and probably never will).
+ *
+ * @return RRD file signature
+ * @throws IOException Thrown in case of IO specific error
+ */
public String getSignature() throws IOException {
return signature.get();
}
+ /**
+ * Returns the last update time of the RRD file.
+ *
+ * @return Timestamp (Unix epoch, no milliseconds) corresponding to the last update time.
+ * @throws IOException Thrown in case of IO specific error
+ */
public long getLastUpdateTime() throws IOException {
return lastUpdateTime.get();
}
+ /**
+ * Returns primary RRD file time step.
+ *
+ * @return Primary time step in seconds
+ * @throws IOException Thrown in case of IO specific error
+ */
public long getStep() throws IOException {
return step.get();
}
+ /**
+ * Returns the number of datasources defined in the RRD file.
+ *
+ * @return Number of datasources defined
+ * @throws IOException Thrown in case of IO specific error
+ */
public int getDsCount() throws IOException {
return dsCount.get();
}
+ /**
+ * Returns the number of archives defined in the RRD file.
+ *
+ * @return Number of archives defined
+ * @throws IOException Thrown in case of IO specific error
+ */
public int getArcCount() throws IOException {
return arcCount.get();
***************
*** 108,111 ****
--- 145,153 ----
}
+ /**
+ * Returns the underlying RrdFile object.
+ *
+ * @return Underlying RrdFile object.
+ */
public RrdFile getRrdFile() {
return parentDb.getRrdFile();
Index: Robin.java
===================================================================
RCS file: /cvsroot/jrobin/src/jrobin/core/Robin.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** Robin.java 6 Oct 2003 08:50:59 -0000 1.2
--- Robin.java 6 Oct 2003 10:45:04 -0000 1.3
***************
*** 25,36 ****
import java.io.IOException;
! // TODO: Fix javadoc, class made public
public class Robin implements RrdUpdater {
-
private Archive parentArc;
-
private RrdInt pointer;
private RrdDouble values;
-
private int rows;
--- 25,44 ----
import java.io.IOException;
! /**
! * Class to represent archive values for a single datasource. Robin class is the heart of
! * the so-called "round robin database" concept. Basically, each Robin object is a
! * fixed length array of double values. Each double value reperesents consolidated archive
! * value for the specific timestamp. When the underlying array of double values gets completely
! * filled, new values will replace the oldest entries.<p>
! *
! * Robin object does not hold values in memory - such object could be quite large.
! * Instead of it, Robin stores all values on the disk and reads them only when necessary.
! *
! * @author <a href="mailto:sa...@eu...">Sasa Markovic</a>
! */
public class Robin implements RrdUpdater {
private Archive parentArc;
private RrdInt pointer;
private RrdDouble values;
private int rows;
***************
*** 48,51 ****
--- 56,65 ----
}
+ /**
+ * Fetches all Robin archive values from the disk.
+ *
+ * @return Array of double archive values, starting from the oldest one.
+ * @throws IOException Thrown in case of IO specific error.
+ */
public double[] getValues() throws IOException {
double[] result = new double[rows];
***************
*** 63,66 ****
--- 77,84 ----
}
+ /**
+ * Returns the underlying RrdFile object.
+ * @return Underlying RrdFile object
+ */
public RrdFile getRrdFile() {
return parentArc.getRrdFile();
***************
*** 77,83 ****
}
! double getValue(int index) throws IOException {
assert(index < rows);
return values.get((pointer.get() + index) % rows);
}
--- 95,124 ----
}
! /**
! * Returns the i-th value from the Robin archive.
! * @param index Value index
! * @return Value stored in the i-th position (the oldest value has zero index)
! */
! public double getValue(int index) throws IOException {
assert(index < rows);
return values.get((pointer.get() + index) % rows);
+ }
+
+ /**
+ * Returns the Archive object to which this Robin object belongs.
+ *
+ * @return Parent Archive object
+ */
+ public Archive getParent() {
+ return parentArc;
+ }
+
+ /**
+ * Returns the size of the underlying array of archive values.
+ *
+ * @return Number of stored values
+ */
+ public int getSize() {
+ return rows;
}
Index: RrdDb.java
===================================================================
RCS file: /cvsroot/jrobin/src/jrobin/core/RrdDb.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -d -r1.6 -r1.7
*** RrdDb.java 6 Oct 2003 08:50:59 -0000 1.6
--- RrdDb.java 6 Oct 2003 10:45:04 -0000 1.7
***************
*** 243,255 ****
}
! // TODO: ADD JAVADOC for methods made public!
public Header getHeader() {
return header;
}
public Datasource getDatasource(int dsIndex) {
return datasources[dsIndex];
}
public Archive getArchive(int arcIndex) {
return archives[arcIndex];
--- 243,268 ----
}
! /**
! * Returns RRD file header.
! * @return Header object
! */
public Header getHeader() {
return header;
}
+ /**
+ * Returns Datasource object for the given datasource index.
+ * @param dsIndex Datasource index (zero based)
+ * @return Datasource object
+ */
public Datasource getDatasource(int dsIndex) {
return datasources[dsIndex];
}
+ /**
+ * Returns Archive object for the given archive index.
+ * @param arcIndex Archive index (zero based)
+ * @return Archive object
+ */
public Archive getArchive(int arcIndex) {
return archives[arcIndex];
|
|
From: <sa...@us...> - 2003-10-06 08:58:17
|
Update of /cvsroot/jrobin/src/jrobin/inspector In directory sc8-pr-cvs1:/tmp/cvs-serv24601/jrobin/inspector Added Files: ArchiveTableModel.java DataTableModel.java DatasourceTableModel.java HeaderTableModel.java InspectorModel.java MainTreeModel.java RrdInspector.java RrdNode.java Log Message: RRD Inspector - initial release. Swing application used to debug JRobin rrd files. Just run RrdInspector to see what happens --- NEW FILE: ArchiveTableModel.java --- /* ============================================================ * JRobin : Pure java implementation of RRDTool's functionality * ============================================================ * * Project Info: http://www.sourceforge.net/projects/jrobin * Project Lead: Sasa Markovic (sa...@eu...); * * (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 jrobin.inspector; import jrobin.core.*; import javax.swing.table.AbstractTableModel; import java.io.File; import java.io.IOException; import java.util.Date; class ArchiveTableModel extends AbstractTableModel { private static final Object[] DESCRIPTIONS = { "consolidation", "xff", "steps", "rows", "accum. value", "NaN steps", "start", "end" }; private static final String[] COLUMN_NAMES = {"description", "value"}; private File file; private Object[] values; private int dsIndex = -1, arcIndex = -1; public int getRowCount() { return DESCRIPTIONS.length; } public int getColumnCount() { return COLUMN_NAMES.length; } public Object getValueAt(int rowIndex, int columnIndex) { if (columnIndex == 0) { return DESCRIPTIONS[rowIndex]; } else if (columnIndex == 1) { if (values != null) { return values[rowIndex]; } else { return "--"; } } return null; } public String getColumnName(int column) { return COLUMN_NAMES[column]; } void setFile(File newFile) { if (file == null || !file.getAbsolutePath().equals(newFile.getAbsolutePath())) { file = newFile; setIndex(-1, -1); } } void setIndex(int newDsIndex, int newArcIndex) { if (dsIndex != newDsIndex || arcIndex != newArcIndex) { dsIndex = newDsIndex; arcIndex = newArcIndex; values = null; if(dsIndex >= 0 && arcIndex >= 0) { try { RrdDb rrd = new RrdDb(file.getAbsolutePath()); Archive arc = rrd.getArchive(arcIndex); ArcState state = arc.getArcState(dsIndex); values = new Object[]{ arc.getConsolFun(), "" + arc.getXff(), "" + arc.getSteps(), "" + arc.getRows(), InspectorModel.formatDouble(state.getAccumValue()), "" + state.getNanSteps(), "" + arc.getStartTime() + " [" + new Date(arc.getStartTime() * 1000L) + "]", "" + arc.getEndTime() + " [" + new Date(arc.getEndTime() * 1000L) + "]" }; rrd.close(); } catch (IOException e) { } catch (RrdException e) { } } fireTableDataChanged(); } } } --- NEW FILE: DataTableModel.java --- /* ============================================================ * JRobin : Pure java implementation of RRDTool's functionality * ============================================================ * * Project Info: http://www.sourceforge.net/projects/jrobin * Project Lead: Sasa Markovic (sa...@eu...); * * (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 jrobin.inspector; import jrobin.core.*; import javax.swing.table.AbstractTableModel; import java.io.File; import java.io.IOException; import java.util.Date; class DataTableModel extends AbstractTableModel { private static final String[] COLUMN_NAMES = {"timestamp", "date", "value"}; private File file; private Object[][] values; private int dsIndex = -1, arcIndex = -1; public int getRowCount() { if(values == null) { return 0; } else { return values.length; } } public int getColumnCount() { return COLUMN_NAMES.length; } public Object getValueAt(int rowIndex, int columnIndex) { if(values == null) { return "--"; } return values[rowIndex][columnIndex]; } public String getColumnName(int column) { return COLUMN_NAMES[column]; } void setFile(File newFile) { if (file == null || !file.getAbsolutePath().equals(newFile.getAbsolutePath())) { file = newFile; setIndex(-1, -1); } } void setIndex(int newDsIndex, int newArcIndex) { if (dsIndex != newDsIndex || arcIndex != newArcIndex) { dsIndex = newDsIndex; arcIndex = newArcIndex; values = null; if(dsIndex >= 0 && arcIndex >= 0) { try { RrdDb rrd = new RrdDb(file.getAbsolutePath()); Archive arc = rrd.getArchive(arcIndex); Robin robin = arc.getRobin(dsIndex); long start = arc.getStartTime(); long step = arc.getArcStep(); double robinValues[] = robin.getValues(); values = new Object[robinValues.length][]; for(int i = 0; i < robinValues.length; i++) { long timestamp = start + i * step; String date = new Date(timestamp * 1000L).toString(); String value = InspectorModel.formatDouble(robinValues[i]); values[i] = new Object[] { "" + timestamp, date, value }; } rrd.close(); } catch (IOException e) { } catch (RrdException e) { } } fireTableDataChanged(); } } } --- NEW FILE: DatasourceTableModel.java --- /* ============================================================ * JRobin : Pure java implementation of RRDTool's functionality * ============================================================ * * Project Info: http://www.sourceforge.net/projects/jrobin * Project Lead: Sasa Markovic (sa...@eu...); * * (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 jrobin.inspector; import jrobin.core.RrdDb; import jrobin.core.Datasource; import jrobin.core.RrdException; import javax.swing.table.AbstractTableModel; import java.io.IOException; import java.io.File; class DatasourceTableModel extends AbstractTableModel { private static final Object[] DESCRIPTIONS = {"name", "type", "heartbeat", "min value", "max value", "last value", "accum. value", "NaN seconds"}; private static final String[] COLUMN_NAMES = {"description", "value"}; private File file; private Object[] values; private int dsIndex = -1; public int getRowCount() { return DESCRIPTIONS.length; } public int getColumnCount() { return COLUMN_NAMES.length; } public Object getValueAt(int rowIndex, int columnIndex) { if (columnIndex == 0) { return DESCRIPTIONS[rowIndex]; } else if (columnIndex == 1) { if (values != null) { return values[rowIndex]; } else { return "--"; } } return null; } public String getColumnName(int column) { return COLUMN_NAMES[column]; } void setFile(File newFile) { if (file == null || !file.getAbsolutePath().equals(newFile.getAbsolutePath())) { file = newFile; setIndex(-1); } } void setIndex(int newDsIndex) { if (dsIndex != newDsIndex) { dsIndex = newDsIndex; values = null; if(dsIndex >= 0) { try { RrdDb rrd = new RrdDb(file.getAbsolutePath()); Datasource ds = rrd.getDatasource(dsIndex); values = new Object[]{ ds.getDsName(), ds.getDsType(), "" + ds.getHeartbeat(), InspectorModel.formatDouble(ds.getMinValue()), InspectorModel.formatDouble(ds.getMaxValue()), InspectorModel.formatDouble(ds.getLastValue()), InspectorModel.formatDouble(ds.getAccumValue()), "" + ds.getNanSeconds() }; rrd.close(); } catch (IOException e) { } catch (RrdException e) { } } fireTableDataChanged(); } } } --- NEW FILE: HeaderTableModel.java --- /* ============================================================ * JRobin : Pure java implementation of RRDTool's functionality * ============================================================ * * Project Info: http://www.sourceforge.net/projects/jrobin * Project Lead: Sasa Markovic (sa...@eu...); * * (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 jrobin.inspector; import jrobin.core.RrdDb; import jrobin.core.Header; import jrobin.core.RrdException; import javax.swing.table.AbstractTableModel; import java.util.Date; import java.io.IOException; import java.io.File; class HeaderTableModel extends AbstractTableModel { private static final Object[] DESCRIPTIONS = {"path", "signature", "step", "last timestamp", "datasources", "archives"}; private static final String[] COLUMN_NAMES = {"description", "value"}; private File file; private Object[] values; public int getRowCount() { return DESCRIPTIONS.length; } public int getColumnCount() { return COLUMN_NAMES.length; } public Object getValueAt(int rowIndex, int columnIndex) { if(columnIndex == 0) { return DESCRIPTIONS[rowIndex]; } else if(columnIndex == 1) { if(values != null) { return values[rowIndex]; } else { return "--"; } } return null; } public String getColumnName(int column) { return COLUMN_NAMES[column]; } void setFile(File newFile) { if(file == null || !file.getAbsolutePath().equals(newFile.getAbsolutePath())) { try { file = newFile; values = null; String path = file.getAbsolutePath(); RrdDb rrd = new RrdDb(path); Header header = rrd.getHeader(); String signature = header.getSignature(); String step = "" + header.getStep(); String lastTimestamp = header.getLastUpdateTime() + " [" + new Date(header.getLastUpdateTime() * 1000L) + "]"; String datasources = "" + header.getDsCount(); String archives = "" + header.getArcCount(); rrd.close(); values = new Object[] { path, signature, step, lastTimestamp, datasources, archives }; fireTableDataChanged(); } catch (IOException e) { } catch (RrdException e) { } } } } --- NEW FILE: InspectorModel.java --- /* ============================================================ * JRobin : Pure java implementation of RRDTool's functionality * ============================================================ * * Project Info: http://www.sourceforge.net/projects/jrobin * Project Lead: Sasa Markovic (sa...@eu...); * * (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 jrobin.inspector; import java.io.File; import java.text.DecimalFormat; /** * Created by saxon * User: stalker * Date: Oct 5, 2003 * Time: 11:26:05 AM */ class InspectorModel { private MainTreeModel mainTreeModel = new MainTreeModel(); private HeaderTableModel generalTableModel = new HeaderTableModel(); private DatasourceTableModel datasourceTableModel = new DatasourceTableModel(); private ArchiveTableModel archiveTableModel = new ArchiveTableModel(); private DataTableModel dataTableModel = new DataTableModel(); MainTreeModel getMainTreeModel() { return mainTreeModel; } HeaderTableModel getGeneralTableModel() { return generalTableModel; } DatasourceTableModel getDatasourceTableModel() { return datasourceTableModel; } DataTableModel getDataTableModel() { return dataTableModel; } ArchiveTableModel getArchiveTableModel() { return archiveTableModel; } void setFile(File file) { mainTreeModel.setFile(file); generalTableModel.setFile(file); datasourceTableModel.setFile(file); archiveTableModel.setFile(file); dataTableModel.setFile(file); } void selectModel(int dsIndex, int arcIndex) { datasourceTableModel.setIndex(dsIndex); archiveTableModel.setIndex(dsIndex, arcIndex); dataTableModel.setIndex(dsIndex, arcIndex); } private static String DOUBLE_FORMAT = "0.0000000000E00"; private static final DecimalFormat df = new DecimalFormat(DOUBLE_FORMAT); static String formatDouble(double x, String nanString) { if(Double.isNaN(x)) { return nanString; } return df.format(x); } static String formatDouble(double x) { return formatDouble(x, "" + Double.NaN); } } --- NEW FILE: MainTreeModel.java --- /* ============================================================ * JRobin : Pure java implementation of RRDTool's functionality * ============================================================ * * Project Info: http://www.sourceforge.net/projects/jrobin * Project Lead: Sasa Markovic (sa...@eu...); * * (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 jrobin.inspector; import jrobin.core.RrdDb; import jrobin.core.RrdException; import javax.swing.tree.DefaultTreeModel; import javax.swing.tree.DefaultMutableTreeNode; import java.io.IOException; import java.io.File; class MainTreeModel extends DefaultTreeModel { private static final DefaultMutableTreeNode INVALID_NODE = new DefaultMutableTreeNode("No valid RRD file specified"); private File file; MainTreeModel() { super(INVALID_NODE); } void setFile(File newFile) { if (file == null || !file.getAbsolutePath().equals(newFile.getAbsolutePath())) { try { file = newFile; RrdDb rrd = new RrdDb(file.getAbsolutePath()); DefaultMutableTreeNode root = new DefaultMutableTreeNode(new RrdNode(rrd)); int dsCount = rrd.getRrdDef().getDsCount(); int arcCount = rrd.getRrdDef().getArcCount(); for (int dsIndex = 0; dsIndex < dsCount; dsIndex++) { DefaultMutableTreeNode dsNode = new DefaultMutableTreeNode(new RrdNode(rrd, dsIndex)); for (int arcIndex = 0; arcIndex < arcCount; arcIndex++) { DefaultMutableTreeNode arcNode = new DefaultMutableTreeNode(new RrdNode(rrd, dsIndex, arcIndex)); dsNode.add(arcNode); } root.add(dsNode); } rrd.close(); setRoot(root); } catch (IOException e) { setRoot(INVALID_NODE); } catch (RrdException e) { setRoot(INVALID_NODE); } } } } --- NEW FILE: RrdInspector.java --- /* ============================================================ * JRobin : Pure java implementation of RRDTool's functionality * ============================================================ * * Project Info: http://www.sourceforge.net/projects/jrobin * Project Lead: Sasa Markovic (sa...@eu...); * * (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 jrobin.inspector; import javax.swing.*; import javax.swing.filechooser.FileFilter; import javax.swing.event.TreeSelectionListener; import javax.swing.event.TreeSelectionEvent; import javax.swing.tree.TreeSelectionModel; import javax.swing.tree.DefaultMutableTreeNode; import javax.swing.tree.TreePath; import java.awt.*; import java.awt.event.*; import java.io.File; class RrdInspector extends JFrame { static final String TITLE = "RRD File Inspector"; static Dimension MAIN_TREE_SIZE = new Dimension(250, 400); static Dimension INFO_PANE_SIZE = new Dimension(450, 400); JTabbedPane tabbedPane = new JTabbedPane(); private JTree mainTree = new JTree(); private JTable generalTable = new JTable(); private JTable datasourceTable = new JTable(); private JTable archiveTable = new JTable(); private JTable dataTable = new JTable(); private InspectorModel inspectorModel = new InspectorModel(); RrdInspector() { super(TITLE); constructUI(); showCentered(); selectFile(); } private void showCentered() { pack(); Toolkit t = Toolkit.getDefaultToolkit(); Dimension screenSize = t.getScreenSize(), frameSize = getPreferredSize(); double x = (screenSize.getWidth() - frameSize.getWidth()) / 2; double y = (screenSize.getHeight() - frameSize.getHeight()) / 2; setLocation((int) x, (int) y); setVisible(true); } private void constructUI() { JPanel content = (JPanel) getContentPane(); content.setLayout(new BorderLayout()); // WEST, tree pane JPanel leftPanel = new JPanel(); leftPanel.setLayout(new BorderLayout()); JScrollPane treePane = new JScrollPane(mainTree); leftPanel.add(treePane); leftPanel.setPreferredSize(MAIN_TREE_SIZE); content.add(leftPanel, BorderLayout.WEST); mainTree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION); mainTree.addTreeSelectionListener(new TreeSelectionListener() { public void valueChanged(TreeSelectionEvent e) { nodeChangedAction(); } }); mainTree.setModel(inspectorModel.getMainTreeModel()); // EAST, tabbed pane // GENERAL TAB JScrollPane spGeneral = new JScrollPane(generalTable); spGeneral.setPreferredSize(INFO_PANE_SIZE); tabbedPane.add("General info", spGeneral); generalTable.setModel(inspectorModel.getGeneralTableModel()); generalTable.getColumnModel().getColumn(0).setPreferredWidth(150); generalTable.getColumnModel().getColumn(0).setMaxWidth(150); //generalTable.getColumnModel().getColumn(0).setMinWidth(150); // DATASOURCE TAB JScrollPane spDatasource = new JScrollPane(datasourceTable); spDatasource.setPreferredSize(INFO_PANE_SIZE); tabbedPane.add("Datasource info", spDatasource); datasourceTable.setModel(inspectorModel.getDatasourceTableModel()); datasourceTable.getColumnModel().getColumn(0).setPreferredWidth(150); datasourceTable.getColumnModel().getColumn(0).setMaxWidth(150); //datasourceTable.getColumnModel().getColumn(0).setMinWidth(150); // ARCHIVE TAB JScrollPane spArchive = new JScrollPane(archiveTable); archiveTable.setModel(inspectorModel.getArchiveTableModel()); archiveTable.getColumnModel().getColumn(0).setPreferredWidth(150); archiveTable.getColumnModel().getColumn(0).setMaxWidth(150); //archiveTable.getColumnModel().getColumn(0).setMinWidth(150); spArchive.setPreferredSize(INFO_PANE_SIZE); tabbedPane.add("Archive info", spArchive); // DATA TAB JScrollPane spData = new JScrollPane(dataTable); dataTable.setModel(inspectorModel.getDataTableModel()); dataTable.getColumnModel().getColumn(0).setPreferredWidth(100); dataTable.getColumnModel().getColumn(0).setMaxWidth(100); dataTable.getColumnModel().getColumn(1).setPreferredWidth(150); spData.setPreferredSize(INFO_PANE_SIZE); tabbedPane.add("Archive data", spData); content.add(tabbedPane, BorderLayout.CENTER); // MENU JMenuBar menuBar = new JMenuBar(); JMenu fileMenu = new JMenu("File"); fileMenu.setMnemonic(KeyEvent.VK_F); JMenuItem fileMenuItem = new JMenuItem("Open RRD file...", KeyEvent.VK_O); fileMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { selectFile(); } }); fileMenu.add(fileMenuItem); JMenuItem exitMenuItem = new JMenuItem("Exit", KeyEvent.VK_X); exitMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { System.exit(0); } }); fileMenu.addSeparator(); fileMenu.add(exitMenuItem); menuBar.add(fileMenu); setJMenuBar(menuBar); // finalize UI addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }); } private void nodeChangedAction() { TreePath path = mainTree.getSelectionPath(); if(path != null) { DefaultMutableTreeNode node = (DefaultMutableTreeNode) path.getLastPathComponent(); Object obj = node.getUserObject(); if(obj instanceof RrdNode) { RrdNode rrdNode = (RrdNode) obj; inspectorModel.selectModel(rrdNode.getDsIndex(), rrdNode.getArcIndex()); if(rrdNode.getDsIndex() >= 0 && rrdNode.getArcIndex() >= 0) { // archive node if(tabbedPane.getSelectedIndex() < 2) { tabbedPane.setSelectedIndex(2); } } else if(rrdNode.getDsIndex() >= 0) { tabbedPane.setSelectedIndex(1); } else { tabbedPane.setSelectedIndex(0); } } } } private void selectFile() { JFileChooser chooser = new JFileChooser(); FileFilter filter = new FileFilter() { public boolean accept(File f) { return f.isDirectory()? true: f.getAbsolutePath().toLowerCase().endsWith(".rrd"); } public String getDescription() { return "JRobin RRD files"; } }; chooser.setFileFilter(filter); int returnVal = chooser.showOpenDialog(this); if(returnVal == JFileChooser.APPROVE_OPTION) { File file = chooser.getSelectedFile(); inspectorModel.setFile(file); tabbedPane.setSelectedIndex(0); } } public static void main(String[] args) { new RrdInspector(); } } --- NEW FILE: RrdNode.java --- /* ============================================================ * JRobin : Pure java implementation of RRDTool's functionality * ============================================================ * * Project Info: http://www.sourceforge.net/projects/jrobin * Project Lead: Sasa Markovic (sa...@eu...); * * (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 jrobin.inspector; import jrobin.core.*; import java.io.File; import java.io.IOException; class RrdNode { private int dsIndex = -1, arcIndex = -1; private String label; RrdNode(RrdDb rrd) { // header node String path = rrd.getRrdFile().getFilePath(); label = new File(path).getName(); } RrdNode(RrdDb rrd, int dsIndex) throws IOException, RrdException { // datasource node this.dsIndex = dsIndex; RrdDef def = rrd.getRrdDef(); DsDef[] dsDefs = def.getDsDefs(); label = dsDefs[dsIndex].dump(); } RrdNode(RrdDb rrd, int dsIndex, int arcIndex) throws IOException, RrdException { // archive node this.dsIndex = dsIndex; this.arcIndex = arcIndex; ArcDef[] arcDefs = rrd.getRrdDef().getArcDefs(); label = arcDefs[arcIndex].dump(); } int getDsIndex() { return dsIndex; } int getArcIndex() { return arcIndex; } public String toString() { return label; } } |
|
From: <sa...@us...> - 2003-10-06 08:51:45
|
Update of /cvsroot/jrobin/src/jrobin/inspector In directory sc8-pr-cvs1:/tmp/cvs-serv23625/inspector Log Message: Directory /cvsroot/jrobin/src/jrobin/inspector added to the repository |