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: Sasa M. <sa...@us...> - 2004-07-22 09:34:21
|
Update of /cvsroot/jrobin/src/org/jrobin/core/jrrd In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9612/org/jrobin/core/jrrd Added Files: Archive.java CDPStatusBlock.java ConsolidationFunctionType.java Constants.java DataChunk.java DataSource.java DataSourceType.java Header.java Main.java PDPStatusBlock.java RRDException.java RRDFile.java RRDatabase.java Log Message: Added support for direct RRDTool file format reading --- NEW FILE: DataSourceType.java --- /* * Copyright (C) 2001 Ciaran Treanor <ci...@co...> * * Distributable under GPL license. * See terms of license at gnu.org. * * $Id: DataSourceType.java,v 1.1 2004/07/22 09:34:10 saxon64 Exp $ */ package org.jrobin.core.jrrd; /** * Class DataSourceType * * @author <a href="mailto:ci...@co...">Ciaran Treanor</a> * @version $Revision: 1.1 $ */ public class DataSourceType { private static final int _COUNTER = 0; private static final String STR_COUNTER = "COUNTER"; /** * Field COUNTER */ public static final DataSourceType COUNTER = new DataSourceType(_COUNTER); private static final int _ABSOLUTE = 1; private static final String STR_ABSOLUTE = "ABSOLUTE"; /** * Field ABSOLUTE */ public static final DataSourceType ABSOLUTE = new DataSourceType(_ABSOLUTE); private static final int _GAUGE = 2; private static final String STR_GAUGE = "GAUGE"; /** * Field GAUGE */ public static final DataSourceType GAUGE = new DataSourceType(_GAUGE); private static final int _DERIVE = 3; private static final String STR_DERIVE = "DERIVE"; /** * Field DERIVE */ public static final DataSourceType DERIVE = new DataSourceType(_DERIVE); private int type; private DataSourceType(int type) { this.type = type; } /** * Returns a <code>DataSourceType</code> with the given name. * * @param s name of the <code>DataSourceType</code> required. * @return a <code>DataSourceType</code> with the given name. */ public static DataSourceType get(String s) { if (s.equalsIgnoreCase(STR_COUNTER)) { return COUNTER; } else if (s.equalsIgnoreCase(STR_ABSOLUTE)) { return ABSOLUTE; } else if (s.equalsIgnoreCase(STR_GAUGE)) { return GAUGE; } else if (s.equalsIgnoreCase(STR_DERIVE)) { return DERIVE; } else { throw new IllegalArgumentException("Invalid DataSourceType"); } } /** * Compares this object against the specified object. * * @return <code>true</code> if the objects are the same, * <code>false</code> otherwise. */ public boolean equals(Object obj) { if (!(obj instanceof DataSourceType)) { throw new IllegalArgumentException("Not a DataSourceType"); } return (((DataSourceType) obj).type == type) ? true : false; } /** * Returns a string representation of this object. * * @return a string representation of this object. */ public String toString() { String strType; switch (type) { case _COUNTER: strType = STR_COUNTER; break; case _ABSOLUTE: strType = STR_ABSOLUTE; break; case _GAUGE: strType = STR_GAUGE; break; case _DERIVE: strType = STR_DERIVE; break; default : // Don't you just hate it when you see a line like this? throw new RuntimeException("This should never happen"); } return strType; } } --- NEW FILE: ConsolidationFunctionType.java --- /* * Copyright (C) 2001 Ciaran Treanor <ci...@co...> * * Distributable under GPL license. * See terms of license at gnu.org. * * $Id: ConsolidationFunctionType.java,v 1.1 2004/07/22 09:34:10 saxon64 Exp $ */ package org.jrobin.core.jrrd; /** * Class ConsolidationFunctionType * * @author <a href="mailto:ci...@co...">Ciaran Treanor</a> * @version $Revision: 1.1 $ */ public class ConsolidationFunctionType { private static final int _AVERAGE = 0; private static final String STR_AVERAGE = "AVERAGE"; /** * Field AVERAGE */ public static final ConsolidationFunctionType AVERAGE = new ConsolidationFunctionType(_AVERAGE); private static final int _MIN = 1; private static final String STR_MIN = "MIN"; /** * Field MIN */ public static final ConsolidationFunctionType MIN = new ConsolidationFunctionType(_MIN); private static final int _MAX = 2; private static final String STR_MAX = "MAX"; /** * Field MAX */ public static final ConsolidationFunctionType MAX = new ConsolidationFunctionType(_MAX); private static final int _LAST = 3; private static final String STR_LAST = "LAST"; /** * Field LAST */ public static final ConsolidationFunctionType LAST = new ConsolidationFunctionType(_LAST); private int type; private ConsolidationFunctionType(int type) { this.type = type; } /** * Returns a <code>ConsolidationFunctionType</code> with the given name. * * @param s name of the <code>ConsolidationFunctionType</code> required. * @return a <code>ConsolidationFunctionType</code> with the given name. */ public static ConsolidationFunctionType get(String s) { if (s.equalsIgnoreCase(STR_AVERAGE)) { return AVERAGE; } else if (s.equalsIgnoreCase(STR_MIN)) { return MIN; } else if (s.equalsIgnoreCase(STR_MAX)) { return MAX; } else if (s.equalsIgnoreCase(STR_LAST)) { return LAST; } else { throw new IllegalArgumentException("Invalid ConsolidationFunctionType"); } } /** * Compares this object against the specified object. * * @return <code>true</code> if the objects are the same, * <code>false</code> otherwise. */ public boolean equals(Object o) { if (!(o instanceof ConsolidationFunctionType)) { throw new IllegalArgumentException("Not a ConsolidationFunctionType"); } return (((ConsolidationFunctionType) o).type == type) ? true : false; } /** * Returns a string representation of this object. * * @return a string representation of this object. */ public String toString() { String strType; switch (type) { case _AVERAGE: strType = STR_AVERAGE; break; case _MIN: strType = STR_MIN; break; case _MAX: strType = STR_MAX; break; case _LAST: strType = STR_LAST; break; default : throw new RuntimeException("This should never happen"); } return strType; } } --- NEW FILE: PDPStatusBlock.java --- /* * Copyright (C) 2001 Ciaran Treanor <ci...@co...> * * Distributable under GPL license. * See terms of license at gnu.org. * * $Id: PDPStatusBlock.java,v 1.1 2004/07/22 09:34:10 saxon64 Exp $ */ package org.jrobin.core.jrrd; import java.io.IOException; /** * Instances of this class model the primary data point status from an RRD file. * * @author <a href="mailto:ci...@co...">Ciaran Treanor</a> * @version $Revision: 1.1 $ */ public class PDPStatusBlock { long offset; long size; String lastReading; int unknownSeconds; double value; PDPStatusBlock(RRDFile file) throws IOException { offset = file.getFilePointer(); lastReading = file.readString(Constants.LAST_DS_LEN); file.align(4); unknownSeconds = file.readInt(); file.skipBytes(4); value = file.readDouble(); // Skip rest of pdp_prep_t.par[] file.skipBytes(64); size = file.getFilePointer() - offset; } /** * Returns the last reading from the data source. * * @return the last reading from the data source. */ public String getLastReading() { return lastReading; } /** * Returns the current value of the primary data point. * * @return the current value of the primary data point. */ public double getValue() { return value; } /** * Returns the number of seconds of the current primary data point is * unknown data. * * @return the number of seconds of the current primary data point is unknown data. */ public int getUnknownSeconds() { return unknownSeconds; } /** * Returns a summary the contents of this PDP status block. * * @return a summary of the information contained in this PDP status block. */ public String toString() { StringBuffer sb = new StringBuffer("[PDPStatus: OFFSET=0x"); sb.append(Long.toHexString(offset)); sb.append(", SIZE=0x"); sb.append(Long.toHexString(size)); sb.append(", lastReading="); sb.append(lastReading); sb.append(", unknownSeconds="); sb.append(unknownSeconds); sb.append(", value="); sb.append(value); sb.append("]"); return sb.toString(); } } --- NEW FILE: Header.java --- /* * Copyright (C) 2001 Ciaran Treanor <ci...@co...> * * Distributable under GPL license. * See terms of license at gnu.org. * * $Id: Header.java,v 1.1 2004/07/22 09:34:10 saxon64 Exp $ */ package org.jrobin.core.jrrd; import java.io.*; /** * Instances of this class model the header section of an RRD file. * * @author <a href="mailto:ci...@co...">Ciaran Treanor</a> * @version $Revision: 1.1 $ */ public class Header implements Constants { static final long offset = 0; long size; String version; int dsCount; int rraCount; int pdpStep; Header(RRDFile file) throws IOException { if (!file.readString(4).equals(COOKIE)) { throw new IOException("Invalid COOKIE"); } if (!(version = file.readString(5)).equals(VERSION)) { throw new IOException("Unsupported RRD version (" + version + ")"); } file.align(); // Consume the FLOAT_COOKIE file.readDouble(); dsCount = file.readInt(); rraCount = file.readInt(); pdpStep = file.readInt(); // Skip rest of stat_head_t.par file.align(); file.skipBytes(80); size = file.getFilePointer() - offset; } /** * Returns the version of the database. * * @return the version of the database. */ public String getVersion() { return version; } /** * Returns the number of <code>DataSource</code>s in the database. * * @return the number of <code>DataSource</code>s in the database. */ public int getDSCount() { return dsCount; } /** * Returns the number of <code>Archive</code>s in the database. * * @return the number of <code>Archive</code>s in the database. */ public int getRRACount() { return rraCount; } /** * Returns the primary data point interval in seconds. * * @return the primary data point interval in seconds. */ public int getPDPStep() { return pdpStep; } /** * Returns a summary the contents of this header. * * @return a summary of the information contained in this header. */ public String toString() { StringBuffer sb = new StringBuffer("[Header: OFFSET=0x00, SIZE=0x"); sb.append(Long.toHexString(size)); sb.append(", version="); sb.append(version); sb.append(", dsCount="); sb.append(dsCount); sb.append(", rraCount="); sb.append(rraCount); sb.append(", pdpStep="); sb.append(pdpStep); sb.append("]"); return sb.toString(); } } --- NEW FILE: Archive.java --- /* * Copyright (C) 2001 Ciaran Treanor <ci...@co...> * * Distributable under GPL license. * See terms of license at gnu.org. * * $Id: Archive.java,v 1.1 2004/07/22 09:34:10 saxon64 Exp $ */ package org.jrobin.core.jrrd; import java.io.IOException; import java.io.PrintStream; import java.text.*; import java.util.*; /** * Instances of this class model an archive section of an RRD file. * * @author <a href="mailto:ci...@co...">Ciaran Treanor</a> * @version $Revision: 1.1 $ */ public class Archive { RRDatabase db; long offset; long dataOffset; long size; ConsolidationFunctionType type; int rowCount; int pdpCount; double xff; ArrayList cdpStatusBlocks; int currentRow; private double[][] values; Archive(RRDatabase db) throws IOException { this.db = db; RRDFile file = db.rrdFile; offset = file.getFilePointer(); type = ConsolidationFunctionType.get(file.readString(Constants.CF_NAM_SIZE)); rowCount = file.readInt(); pdpCount = file.readInt(); file.align(); xff = file.readDouble(); // Skip rest of rra_def_t.par[] file.align(); file.skipBytes(72); size = file.getFilePointer() - offset; } /** * Returns the type of function used to calculate the consolidated data point. * * @return the type of function used to calculate the consolidated data point. */ public ConsolidationFunctionType getType() { return type; } void loadCDPStatusBlocks(RRDFile file, int numBlocks) throws IOException { cdpStatusBlocks = new ArrayList(); for (int i = 0; i < numBlocks; i++) { cdpStatusBlocks.add(new CDPStatusBlock(file)); } } /** * Returns the <code>CDPStatusBlock</code> at the specified position in this archive. * * @param index index of <code>CDPStatusBlock</code> to return. * @return the <code>CDPStatusBlock</code> at the specified position in this archive. */ public CDPStatusBlock getCDPStatusBlock(int index) { return (CDPStatusBlock) cdpStatusBlocks.get(index); } /** * Returns an iterator over the CDP status blocks in this archive in proper sequence. * * @return an iterator over the CDP status blocks in this archive in proper sequence. * @see CDPStatusBlock */ public Iterator getCDPStatusBlocks() { return cdpStatusBlocks.iterator(); } void loadCurrentRow(RRDFile file) throws IOException { currentRow = file.readInt(); } void loadData(RRDFile file, int dsCount) throws IOException { dataOffset = file.getFilePointer(); // Skip over the data to position ourselves at the start of the next archive file.skipBytes(8 * rowCount * dsCount); } DataChunk loadData(DataChunk chunk) throws IOException { Calendar end = Calendar.getInstance(); Calendar start = (Calendar) end.clone(); start.add(Calendar.DATE, -1); loadData(chunk, start.getTime().getTime() / 1000, end.getTime().getTime() / 1000); return chunk; } void loadData(DataChunk chunk, long startTime, long endTime) throws IOException { long pointer; if (chunk.start < 0) { pointer = currentRow + 1; } else { pointer = currentRow + chunk.start + 1; } db.rrdFile.ras.seek(dataOffset + (pointer * 8)); //cat.debug("Archive Base: " + dataOffset + " Archive Pointer: " + pointer); //cat.debug("Start Offset: " + chunk.start + " End Offset: " // + (rowCount - chunk.end)); double[][] data = chunk.data; /* * This is also terrible - cleanup - CT */ int row = 0; for (int i = chunk.start; i < rowCount - chunk.end; i++, row++) { if (i < 0) { // no valid data yet for (int ii = 0; ii < chunk.dsCount; ii++) { data[row][ii] = Double.NaN; } } else if (i >= rowCount) { // past valid data area for (int ii = 0; ii < chunk.dsCount; ii++) { data[row][ii] = Double.NaN; } } else { // inside the valid are but the pointer has to be wrapped if (pointer >= rowCount) { pointer -= rowCount; db.rrdFile.ras.seek(dataOffset + (pointer * 8)); } for (int ii = 0; ii < chunk.dsCount; ii++) { data[row][ii] = db.rrdFile.readDouble(); } pointer++; } } } void printInfo(PrintStream s, NumberFormat numberFormat, int index) { StringBuffer sb = new StringBuffer("rra["); sb.append(index); s.print(sb); s.print("].cf = \""); s.print(type); s.println("\""); s.print(sb); s.print("].rows = "); s.println(rowCount); s.print(sb); s.print("].pdp_per_row = "); s.println(pdpCount); s.print(sb); s.print("].xff = "); s.println(xff); sb.append("].cdp_prep["); int cdpIndex = 0; for (Iterator i = cdpStatusBlocks.iterator(); i.hasNext();) { CDPStatusBlock cdp = (CDPStatusBlock) i.next(); s.print(sb); s.print(cdpIndex); s.print("].value = "); double value = cdp.value; s.println(Double.isNaN(value) ? "NaN" : numberFormat.format(value)); s.print(sb); s.print(cdpIndex++); s.print("].unknown_datapoints = "); s.println(cdp.unknownDatapoints); } } void toXml(PrintStream s) { try { s.println("\t<rra>"); s.print("\t\t<cf> "); s.print(type); s.println(" </cf>"); s.print("\t\t<pdp_per_row> "); s.print(pdpCount); s.print(" </pdp_per_row> <!-- "); s.print(db.header.pdpStep * pdpCount); s.println(" seconds -->"); s.print("\t\t<xff> "); s.print(xff); s.println(" </xff>"); s.println(); s.println("\t\t<cdp_prep>"); for (int i = 0; i < cdpStatusBlocks.size(); i++) { ((CDPStatusBlock) cdpStatusBlocks.get(i)).toXml(s); } s.println("\t\t</cdp_prep>"); s.println("\t\t<database>"); long timer = -(rowCount - 1); int counter = 0; int row = currentRow; db.rrdFile.ras.seek(dataOffset + (row + 1) * 16); long lastUpdate = db.lastUpdate.getTime() / 1000; int pdpStep = db.header.pdpStep; NumberFormat numberFormat = new DecimalFormat("0.0000000000E0"); SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss z"); while (counter++ < rowCount) { row++; if (row == rowCount) { row = 0; db.rrdFile.ras.seek(dataOffset); } long now = (lastUpdate - lastUpdate % (pdpCount * pdpStep)) + (timer * pdpCount * pdpStep); timer++; s.print("\t\t\t<!-- "); s.print(dateFormat.format(new Date(now * 1000))); s.print(" / "); s.print(now); s.print(" --> "); for (int col = 0; col < db.header.dsCount; col++) { s.print("<v> "); double value = db.rrdFile.readDouble(); // NumberFormat doesn't know how to handle NaN if (Double.isNaN(value)) { s.print("NaN"); } else { s.print(numberFormat.format(value)); } s.print(" </v>"); } s.println("</row>"); } s.println("\t\t</database>"); s.println("\t</rra>"); } catch (IOException e) { // Is the best thing to do here? throw new RuntimeException(e.getMessage()); } } public double[][] getValues() throws IOException { if (values != null) { return values; } values = new double[db.header.dsCount][rowCount]; int row = currentRow; db.rrdFile.ras.seek(dataOffset + (row + 1) * 16); for (int counter = 0; counter < rowCount; counter++) { row++; if (row == rowCount) { row = 0; db.rrdFile.ras.seek(dataOffset); } for (int col = 0; col < db.header.dsCount; col++) { double value = db.rrdFile.readDouble(); values[col][counter] = value; } } return values; } /** * Returns the number of primary data points required for a consolidated * data point in this archive. * * @return the number of primary data points required for a consolidated * data point in this archive. */ public int getPdpCount() { return pdpCount; } /** * Returns the number of entries in this archive. * * @return the number of entries in this archive. */ public int getRowCount() { return rowCount; } /** * Returns the X-Files Factor for this archive. * * @return the X-Files Factor for this archive. */ public double getXff() { return xff; } /** * Returns a summary the contents of this archive. * * @return a summary of the information contained in this archive. */ public String toString() { StringBuffer sb = new StringBuffer("[Archive: OFFSET=0x"); sb.append(Long.toHexString(offset)); sb.append(", SIZE=0x"); sb.append(Long.toHexString(size)); sb.append(", type="); sb.append(type); sb.append(", rowCount="); sb.append(rowCount); sb.append(", pdpCount="); sb.append(pdpCount); sb.append(", xff="); sb.append(xff); sb.append(", currentRow="); sb.append(currentRow); sb.append("]"); for (Iterator i = cdpStatusBlocks.iterator(); i.hasNext();) { CDPStatusBlock cdp = (CDPStatusBlock) i.next(); sb.append("\n\t\t"); sb.append(cdp.toString()); } return sb.toString(); } } --- NEW FILE: RRDFile.java --- /* * Copyright (C) 2001 Ciaran Treanor <ci...@co...> * * Distributable under GPL license. * See terms of license at gnu.org. * * $Id: RRDFile.java,v 1.1 2004/07/22 09:34:10 saxon64 Exp $ */ package org.jrobin.core.jrrd; import java.io.*; /** * This class is a quick hack to read information from an RRD file. Writing * to RRD files is not currently supported. As I said, this is a quick hack. * Some thought should be put into the overall design of the file IO. * <p/> * Currently this can read RRD files that were generated on Solaris (Sparc) * and Linux (x86). * * @author <a href="mailto:ci...@co...">Ciaran Treanor</a> * @version $Revision: 1.1 $ */ public class RRDFile implements Constants { boolean bigEndian; int alignment; RandomAccessFile ras; byte[] buffer; RRDFile(String name) throws IOException { this(new File(name)); } RRDFile(File file) throws IOException { ras = new RandomAccessFile(file, "r"); buffer = new byte[128]; initDataLayout(file); } private void initDataLayout(File file) throws IOException { if (file.exists()) { // Load the data formats from the file ras.read(buffer, 0, 24); int index; if ((index = indexOf(FLOAT_COOKIE_BIG_ENDIAN, buffer)) != -1) { bigEndian = true; } else if ((index = indexOf(FLOAT_COOKIE_LITTLE_ENDIAN, buffer)) != -1) { bigEndian = false; } else { throw new IOException("Invalid RRD file"); } switch (index) { case 12: alignment = 4; break; case 16: alignment = 8; break; default : throw new RuntimeException("Unsupported architecture"); } } else { // Default to data formats for this hardware architecture } ras.seek(0); // Reset file pointer to start of file } private int indexOf(byte[] pattern, byte[] array) { return (new String(array)).indexOf(new String(pattern)); } boolean isBigEndian() { return bigEndian; } int getAlignment() { return alignment; } double readDouble() throws IOException { //double value; byte[] tx = new byte[8]; ras.read(buffer, 0, 8); if (bigEndian) { tx = buffer; } else { for (int i = 0; i < 8; i++) { tx[7 - i] = buffer[i]; } } DataInputStream reverseDis = new DataInputStream(new ByteArrayInputStream(tx)); return reverseDis.readDouble(); } int readInt() throws IOException { return readInt(false); } int readInt(boolean dump) throws IOException { ras.read(buffer, 0, 4); int value; if (bigEndian) { value = (0xFF & buffer[3]) | ((0xFF & buffer[2]) << 8) | ((0xFF & buffer[1]) << 16) | ((0xFF & buffer[0]) << 24); } else { value = (0xFF & buffer[0]) | ((0xFF & buffer[1]) << 8) | ((0xFF & buffer[2]) << 16) | ((0xFF & buffer[3]) << 24); } return value; } String readString(int maxLength) throws IOException { ras.read(buffer, 0, maxLength); return new String(buffer, 0, maxLength).trim(); } void skipBytes(int n) throws IOException { ras.skipBytes(n); } int align(int boundary) throws IOException { int skip = (int) (boundary - (ras.getFilePointer() % boundary)) % boundary; if (skip != 0) { ras.skipBytes(skip); } return skip; } int align() throws IOException { return align(alignment); } long info() throws IOException { return ras.getFilePointer(); } long getFilePointer() throws IOException { return ras.getFilePointer(); } void close() throws IOException { ras.close(); } } --- NEW FILE: Constants.java --- /* * Copyright (C) 2001 Ciaran Treanor <ci...@co...> * * Distributable under GPL license. * See terms of license at gnu.org. * * $Id: Constants.java,v 1.1 2004/07/22 09:34:10 saxon64 Exp $ */ package org.jrobin.core.jrrd; interface Constants { int DS_NAM_SIZE = 20; int DST_SIZE = 20; int CF_NAM_SIZE = 20; int LAST_DS_LEN = 30; static String COOKIE = "RRD"; static String VERSION = "0001"; double FLOAT_COOKIE = 8.642135E130; static byte[] FLOAT_COOKIE_BIG_ENDIAN = {0x5B, 0x1F, 0x2B, 0x43, (byte) 0xC7, (byte) 0xC0, 0x25, 0x2F}; static byte[] FLOAT_COOKIE_LITTLE_ENDIAN = {0x2F, 0x25, (byte) 0xC0, (byte) 0xC7, 0x43, 0x2B, 0x1F, 0x5B}; } --- NEW FILE: CDPStatusBlock.java --- /* * Copyright (C) 2001 Ciaran Treanor <ci...@co...> * * Distributable under GPL license. * See terms of license at gnu.org. * * $Id: CDPStatusBlock.java,v 1.1 2004/07/22 09:34:10 saxon64 Exp $ */ package org.jrobin.core.jrrd; import java.io.IOException; import java.io.PrintStream; /** * Instances of this class model the consolidation data point status from an RRD file. * * @author <a href="mailto:ci...@co...">Ciaran Treanor</a> * @version $Revision: 1.1 $ */ public class CDPStatusBlock { long offset; long size; int unknownDatapoints; double value; CDPStatusBlock(RRDFile file) throws IOException { offset = file.getFilePointer(); value = file.readDouble(); unknownDatapoints = file.readInt(); // Skip rest of cdp_prep_t.scratch file.skipBytes(68); size = file.getFilePointer() - offset; } /** * Returns the number of unknown primary data points that were integrated. * * @return the number of unknown primary data points that were integrated. */ public int getUnknownDatapoints() { return unknownDatapoints; } /** * Returns the value of this consolidated data point. * * @return the value of this consolidated data point. */ public double getValue() { return value; } void toXml(PrintStream s) { s.print("\t\t\t<ds><value> "); s.print(value); s.print(" </value> <unknown_datapoints> "); s.print(unknownDatapoints); s.println(" </unknown_datapoints></ds>"); } /** * Returns a summary the contents of this CDP status block. * * @return a summary of the information contained in the CDP status block. */ public String toString() { StringBuffer sb = new StringBuffer("[CDPStatusBlock: OFFSET=0x"); sb.append(Long.toHexString(offset)); sb.append(", SIZE=0x"); sb.append(Long.toHexString(size)); sb.append(", unknownDatapoints="); sb.append(unknownDatapoints); sb.append(", value="); sb.append(value); sb.append("]"); return sb.toString(); } } --- NEW FILE: RRDatabase.java --- /* * Copyright (C) 2001 Ciaran Treanor <ci...@co...> * * Distributable under GPL license. * See terms of license at gnu.org. * * $Id: RRDatabase.java,v 1.1 2004/07/22 09:34:10 saxon64 Exp $ */ package org.jrobin.core.jrrd; import java.io.*; import java.util.*; import java.text.NumberFormat; import java.text.DecimalFormat; /** * Instances of this class model * <a href="http://people.ee.ethz.ch/~oetiker/webtools/rrdtool/">Round Robin Database</a> * (RRD) files. * * @author <a href="mailto:ci...@co...">Ciaran Treanor</a> * @version $Revision: 1.1 $ */ public class RRDatabase { RRDFile rrdFile; // RRD file name private String name; Header header; ArrayList dataSources; ArrayList archives; Date lastUpdate; /** * Creates a database to read from. * * @param name the filename of the file to read from. * @throws IOException if an I/O error occurs. */ public RRDatabase(String name) throws IOException { this(new File(name)); } /** * Creates a database to read from. * * @param file the file to read from. * @throws IOException if an I/O error occurs. */ public RRDatabase(File file) throws IOException { name = file.getName(); rrdFile = new RRDFile(file); header = new Header(rrdFile); // Load the data sources dataSources = new ArrayList(); for (int i = 0; i < header.dsCount; i++) { DataSource ds = new DataSource(rrdFile); dataSources.add(ds); } // Load the archives archives = new ArrayList(); for (int i = 0; i < header.rraCount; i++) { Archive archive = new Archive(this); archives.add(archive); } rrdFile.align(); lastUpdate = new Date((long) (rrdFile.readInt()) * 1000); // Load PDPStatus(s) for (int i = 0; i < header.dsCount; i++) { DataSource ds = (DataSource) dataSources.get(i); ds.loadPDPStatusBlock(rrdFile); } // Load CDPStatus(s) for (int i = 0; i < header.rraCount; i++) { Archive archive = (Archive) archives.get(i); archive.loadCDPStatusBlocks(rrdFile, header.dsCount); } // Load current row information for each archive for (int i = 0; i < header.rraCount; i++) { Archive archive = (Archive) archives.get(i); archive.loadCurrentRow(rrdFile); } // Now load the data for (int i = 0; i < header.rraCount; i++) { Archive archive = (Archive) archives.get(i); archive.loadData(rrdFile, header.dsCount); } } /** * Returns the <code>Header</code> for this database. * * @return the <code>Header</code> for this database. */ public Header getHeader() { return header; } /** * Returns the date this database was last updated. To convert this date to * the form returned by <code>rrdtool last</code> call Date.getTime() and * divide the result by 1000. * * @return the date this database was last updated. */ public Date getLastUpdate() { return lastUpdate; } /** * Returns the <code>DataSource</code> at the specified position in this database. * * @param index index of <code>DataSource</code> to return. * @return the <code>DataSource</code> at the specified position in this database */ public DataSource getDataSource(int index) { return (DataSource) dataSources.get(index); } /** * Returns an iterator over the data sources in this database in proper sequence. * * @return an iterator over the data sources in this database in proper sequence. */ public Iterator getDataSources() { return dataSources.iterator(); } /** * Returns the <code>Archive</code> at the specified position in this database. * * @param index index of <code>Archive</code> to return. * @return the <code>Archive</code> at the specified position in this database. */ public Archive getArchive(int index) { return (Archive) archives.get(index); } /** * Returns an iterator over the archives in this database in proper sequence. * * @return an iterator over the archives in this database in proper sequence. */ public Iterator getArchives() { return archives.iterator(); } /** * Returns the number of archives in this database. * * @return the number of archives in this database. */ public int getNumArchives() { return header.rraCount; } /** * Returns an iterator over the archives in this database of the given type * in proper sequence. * * @param type the consolidation function that should have been applied to * the data. * @return an iterator over the archives in this database of the given type * in proper sequence. */ public Iterator getArchives(ConsolidationFunctionType type) { return getArchiveList(type).iterator(); } ArrayList getArchiveList(ConsolidationFunctionType type) { ArrayList subset = new ArrayList(); for (int i = 0; i < archives.size(); i++) { Archive archive = (Archive) archives.get(i); if (archive.getType().equals(type)) { subset.add(archive); } } return subset; } /** * Closes this database stream and releases any associated system resources. * * @throws IOException if an I/O error occurs. */ public void close() throws IOException { rrdFile.close(); } /** * Outputs the header information of the database to the given print stream * using the default number format. The default format for <code>double</code> * is 0.0000000000E0. * * @param s the PrintStream to print the header information to. */ public void printInfo(PrintStream s) { NumberFormat numberFormat = new DecimalFormat("0.0000000000E0"); printInfo(s, numberFormat); } /** * Returns data from the database corresponding to the given consolidation * function and a step size of 1. * * @param type the consolidation function that should have been applied to * the data. * @return the raw data. * @throws RRDException if there was a problem locating a data archive with * the requested consolidation function. * @throws IOException if there was a problem reading data from the database. */ public DataChunk getData(ConsolidationFunctionType type) throws RRDException, IOException { return getData(type, 1L); } /** * Returns data from the database corresponding to the given consolidation * function. * * @param type the consolidation function that should have been applied to * the data. * @param step the step size to use. * @return the raw data. * @throws RRDException if there was a problem locating a data archive with * the requested consolidation function. * @throws IOException if there was a problem reading data from the database. */ public DataChunk getData(ConsolidationFunctionType type, long step) throws RRDException, IOException { ArrayList possibleArchives = getArchiveList(type); if (possibleArchives.size() == 0) { throw new RRDException("Database does not contain an Archive of consolidation function type " + type); } Calendar endCal = Calendar.getInstance(); endCal.set(Calendar.MILLISECOND, 0); Calendar startCal = (Calendar) endCal.clone(); startCal.add(Calendar.DATE, -1); long end = endCal.getTime().getTime() / 1000; long start = startCal.getTime().getTime() / 1000; Archive archive = findBestArchive(start, end, step, possibleArchives); // Tune the parameters step = header.pdpStep * archive.pdpCount; start -= start % step; if (end % step != 0) { end += step - end % step; } int rows = (int) ((end - start) / step + 1); //cat.debug("start " + start + " end " + end + " step " + step + " rows " // + rows); // Find start and end offsets // todo: This is terrible - some of this should be encapsulated in Archive - CT. long lastUpdateLong = lastUpdate.getTime() / 1000; long archiveEndTime = lastUpdateLong - (lastUpdateLong % step); long archiveStartTime = archiveEndTime - (step * (archive.rowCount - 1)); int startOffset = (int) ((start - archiveStartTime) / step); int endOffset = (int) ((archiveEndTime - end) / step); //cat.debug("start " + archiveStartTime + " end " + archiveEndTime // + " startOffset " + startOffset + " endOffset " // + (archive.rowCount - endOffset)); DataChunk chunk = new DataChunk(start, startOffset, endOffset, step, header.dsCount, rows); archive.loadData(chunk); return chunk; } /* * This is almost a verbatim copy of the original C code by Tobias Oetiker. * I need to put more of a Java style on it - CT */ private Archive findBestArchive(long start, long end, long step, ArrayList archives) { Archive archive = null; Archive bestFullArchive = null; Archive bestPartialArchive = null; long lastUpdateLong = lastUpdate.getTime() / 1000; int firstPart = 1; int firstFull = 1; long bestMatch = 0; long bestPartRRA = 0; long bestStepDiff = 0; long tmpStepDiff = 0; for (int i = 0; i < archives.size(); i++) { archive = (Archive) archives.get(i); long calEnd = lastUpdateLong - (lastUpdateLong % (archive.pdpCount * header.pdpStep)); long calStart = calEnd - (archive.pdpCount * archive.rowCount * header.pdpStep); long fullMatch = end - start; if ((calEnd >= end) && (calStart < start)) { // Best full match tmpStepDiff = Math.abs(step - (header.pdpStep * archive.pdpCount)); if ((firstFull != 0) || (tmpStepDiff < bestStepDiff)) { firstFull = 0; bestStepDiff = tmpStepDiff; bestFullArchive = archive; } } else { // Best partial match long tmpMatch = fullMatch; if (calStart > start) { tmpMatch -= calStart - start; } if (calEnd < end) { tmpMatch -= end - calEnd; } if ((firstPart != 0) || (bestMatch < tmpMatch)) { firstPart = 0; bestMatch = tmpMatch; bestPartialArchive = archive; } } } // See how the matching went // todo: optimise this if (firstFull == 0) { archive = bestFullArchive; } else if (firstPart == 0) { archive = bestPartialArchive; } return archive; } /** * Outputs the header information of the database to the given print stream * using the given number format. The format is almost identical to that * produced by * <a href="http://people.ee.ethz.ch/~oetiker/webtools/rrdtool/manual/rrdinfo.html">rrdtool info</a> * * @param s the PrintStream to print the header information to. * @param numberFormat the format to print <code>double</code>s as. */ public void printInfo(PrintStream s, NumberFormat numberFormat) { s.print("filename = \""); s.print(name); s.println("\""); s.print("rrd_version = \""); s.print(header.version); s.println("\""); s.print("step = "); s.println(header.pdpStep); s.print("last_update = "); s.println(lastUpdate.getTime() / 1000); for (Iterator i = dataSources.iterator(); i.hasNext();) { DataSource ds = (DataSource) i.next(); ds.printInfo(s, numberFormat); } int index = 0; for (Iterator i = archives.iterator(); i.hasNext();) { Archive archive = (Archive) i.next(); archive.printInfo(s, numberFormat, index++); } } /** * Outputs the content of the database to the given print stream * as a stream of XML. The XML format is almost identical to that produced by * <a href="http://people.ee.ethz.ch/~oetiker/webtools/rrdtool/manual/rrddump.html">rrdtool dump</a> * * @param s the PrintStream to send the XML to. */ public void toXml(PrintStream s) { s.println("<!--"); s.println(" -- Round Robin RRDatabase Dump "); s.println(" -- Generated by jRRD <ci...@co...>"); s.println(" -->"); s.println("<rrd>"); s.print("\t<version> "); s.print(header.version); s.println(" </version>"); s.print("\t<step> "); s.print(header.pdpStep); s.println(" </step> <!-- Seconds -->"); s.print("\t<lastupdate> "); s.print(lastUpdate.getTime() / 1000); s.print(" </lastupdate> <!-- "); s.print(lastUpdate.toString()); s.println(" -->"); s.println(); for (int i = 0; i < header.dsCount; i++) { DataSource ds = (DataSource) dataSources.get(i); ds.toXml(s); } s.println("<!-- Round Robin Archives -->"); for (int i = 0; i < header.rraCount; i++) { Archive archive = (Archive) archives.get(i); archive.toXml(s); } s.println("</rrd>"); } /** * Returns a summary the contents of this database. * * @return a summary of the information contained in this database. */ public String toString() { StringBuffer sb = new StringBuffer("\n"); sb.append(header.toString()); for (Iterator i = dataSources.iterator(); i.hasNext();) { DataSource ds = (DataSource) i.next(); sb.append("\n\t"); sb.append(ds.toString()); } for (Iterator i = archives.iterator(); i.hasNext();) { Archive archive = (Archive) i.next(); sb.append("\n\t"); sb.append(archive.toString()); } return sb.toString(); } } --- NEW FILE: Main.java --- /* * Copyright (C) 2001 Ciaran Treanor <ci...@co...> * * Distributable under GPL license. * See terms of license at gnu.org. * * $Id: Main.java,v 1.1 2004/07/22 09:34:10 saxon64 Exp $ */ package org.jrobin.core.jrrd; import java.io.IOException; /** * Show some of the things jRRD can do. * * @author <a href="mailto:ci...@co...">Ciaran Treanor</a> * @version $Revision: 1.1 $ */ public class Main { public Main(String rrdFile) { RRDatabase rrd = null; DataChunk chunk = null; try { rrd = new RRDatabase(rrdFile); chunk = rrd.getData(ConsolidationFunctionType.AVERAGE); } catch (Exception e) { e.printStackTrace(); return; } rrd.toXml(System.out); // Dump the database as XML. rrd.printInfo(System.out); // Dump the database header information. System.out.println(rrd); // Dump a summary of the contents of the database. System.out.println(chunk); // Dump the chunk. try { rrd.close(); } catch (IOException e) { e.printStackTrace(); } } static void usage(int status) { System.err.println("Usage: " + Main.class.getName() + " rrdfile"); System.exit(status); } public static void main(String[] args) { if (args.length != 1) { usage(1); } new Main(args[0]); } } --- NEW FILE: DataSource.java --- /* * Copyright (C) 2001 Ciaran Treanor <ci...@co...> * * Distributable under GPL license. * See terms of license at gnu.org. * * $Id: DataSource.java,v 1.1 2004/07/22 09:34:10 saxon64 Exp $ */ package org.jrobin.core.jrrd; import java.io.*; import java.text.NumberFormat; /** * Instances of this class model a data source in an RRD file. * * @author <a href="mailto:ci...@co...">Ciaran Treanor</a> * @version $Revision: 1.1 $ */ public class DataSource { long offset; long size; String name; DataSourceType type; int minimumHeartbeat; double minimum; double maximum; PDPStatusBlock pdpStatusBlock; DataSource(RRDFile file) throws IOException { offset = file.getFilePointer(); name = file.readString(Constants.DS_NAM_SIZE); type = DataSourceType.get(file.readString(Constants.DST_SIZE)); file.align(8); minimumHeartbeat = file.readInt(true); file.align(8); minimum = file.readDouble(); maximum = file.readDouble(); // Skip rest of ds_def_t.par[] file.align(); file.skipBytes(56); size = file.getFilePointer() - offset; } void loadPDPStatusBlock(RRDFile file) throws IOException { pdpStatusBlock = new PDPStatusBlock(file); } /** * Returns the primary data point status block for this data source. * * @return the primary data point status block for this data source. */ public PDPStatusBlock getPDPStatusBlock() { return pdpStatusBlock; } /** * Returns the minimum required heartbeat for this data source. * * @return the minimum required heartbeat for this data source. */ public int getMinimumHeartbeat() { return minimumHeartbeat; } /** * Returns the minimum value input to this data source can have. * * @return the minimum value input to this data source can have. */ public double getMinimum() { return minimum; } /** * Returns the type this data source is. * * @return the type this data source is. * @see DataSourceType */ public DataSourceType getType() { return type; } /** * Returns the maximum value input to this data source can have. * * @return the maximum value input to this data source can have. */ public double getMaximum() { return maximum; } /** * Returns the name of this data source. * * @return the name of this data source. */ public String getName() { return name; } void printInfo(PrintStream s, NumberFormat numberFormat) { StringBuffer sb = new StringBuffer("ds["); sb.append(name); s.print(sb); s.print("].type = \""); s.print(type); s.println("\""); s.print(sb); s.print("].minimal_heartbeat = "); s.println(minimumHeartbeat); s.print(sb); s.print("].min = "); s.println(Double.isNaN(minimum) ? "NaN" : numberFormat.format(minimum)); s.print(sb); s.print("].max = "); s.println(Double.isNaN(maximum) ? "NaN" : numberFormat.format(maximum)); s.print(sb); s.print("].last_ds = "); s.println(pdpStatusBlock.lastReading); s.print(sb); s.print("].value = "); double value = pdpStatusBlock.value; s.println(Double.isNaN(value) ? "NaN" : numberFormat.format(value)); s.print(sb); s.print("].unknown_sec = "); s.println(pdpStatusBlock.unknownSeconds); } void toXml(PrintStream s) { s.println("\t<ds>"); s.print("\t\t<name> "); s.print(name); s.println(" </name>"); s.print("\t\t<type> "); s.print(type); s.println(" </type>"); s.print("\t\t<minimal_heartbeat> "); s.print(minimumHeartbeat); s.println(" </minimal_heartbeat>"); s.print("\t\t<min> "); s.print(minimum); s.println(" </min>"); s.print("\t\t<max> "); s.print(maximum); s.println(" </max>"); s.println(); s.println("\t\t<!-- PDP Status -->"); s.print("\t\t<last_ds> "); s.print(pdpStatusBlock.lastReading); s.println(" </last_ds>"); s.print("\t\t<value> "); s.print(pdpStatusBlock.value); s.println(" </value>"); s.print("\t\t<unknown_sec> "); s.print(pdpStatusBlock.unknownSeconds); s.println(" </unknown_sec>"); s.println("\t</ds>"); s.println(); } /** * Returns a summary the contents of this data source. * * @return a summary of the information contained in this data source. */ public String toString() { StringBuffer sb = new StringBuffer("[DataSource: OFFSET=0x"); sb.append(Long.toHexString(offset)); sb.append(", SIZE=0x"); sb.append(Long.toHexString(size)); sb.append(", name="); sb.append(name); sb.append(", type="); sb.append(type.toString()); sb.append(", minHeartbeat="); sb.append(minimumHeartbeat); sb.append(", min="); sb.append(minimum); sb.append(", max="); sb.append(maximum); sb.append("]"); sb.append("\n\t\t"); sb.append(pdpStatusBlock.toString()); return sb.toString(); } } --- NEW FILE: RRDException.java --- /* * Copyright (C) 2001 Ciaran Treanor <ci...@co...> * * Distributable under GPL license. * See terms of license at gnu.org. * * $Id: RRDException.java,v 1.1 2004/07/22 09:34:10 saxon64 Exp $ */ package org.jrobin.core.jrrd; /** * This exception may be throw if an error occurs while operating * on an RRD object. * * @author <a href="mailto:ci...@co...">Ciaran Treanor</a> * @version $Revision: 1.1 $ */ public class RRDException extends Exception { /** * Constructs an RRDException with no detail message. */ public RRDException() { super(); } /** * Constructs an RRDException with the specified detail message. */ public RRDException(String message) { super(message); } } --- NEW FILE: DataChunk.java --- /* * Copyright (C) 2001 Ciaran Treanor <ci...@co...> * * Distributable under GPL license. * See terms of license at gnu.org. * * $Id: DataChunk.java,v 1.1 2004/07/22 09:34:10 saxon64 Exp $ */ package org.jrobin.core.jrrd; /** * Models a chunk of result data from an RRDatabase. * * @author <a href="mailto:ci...@co...">Ciaran Treanor</a> * @version $Revision: 1.1 $ */ public class DataChunk { private static final String NEWLINE = System.getProperty("line.separator"); long startTime; int start; int end; long step; int dsCount; double[][] data; int rows; DataChunk(long startTime, int start, int end, long step, int dsCount, int rows) { this.startTime = startTime; this.start = start; this.end = end; this.step = step; this.dsCount = dsCount; this.rows = rows; data = new double[rows][dsCount]; } /** * Returns a summary of the contents of this data chunk. The first column is * the time (RRD format) and the following columns are the data source * values. * * @return a summary of the contents of this data chunk. */ public String toString() { StringBuffer sb = new StringBuffer(); long time = startTime; for (int row = 0; row < rows; row++, time += step) { sb.append(time); sb.append(": "); for (int ds = 0; ds < dsCount; ds++) { sb.append(data[row][ds]); sb.append(" "); } sb.append(NEWLINE); } return sb.toString(); } } |
From: Sasa M. <sa...@us...> - 2004-07-22 09:34:19
|
Update of /cvsroot/jrobin/src/org/jrobin/core In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9612/org/jrobin/core Modified Files: Archive.java DataImporter.java Datasource.java Header.java RrdDb.java Added Files: RrdToolReader.java Log Message: Added support for direct RRDTool file format reading Index: Datasource.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/core/Datasource.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** Datasource.java 20 May 2004 10:29:32 -0000 1.6 --- Datasource.java 22 Jul 2004 09:34:10 -0000 1.7 *************** *** 75,79 **** } ! Datasource(RrdDb parentDb, XmlReader reader, int dsIndex) throws IOException, RrdException { this(parentDb, null); dsName.set(reader.getDsName(dsIndex)); --- 75,79 ---- } ! Datasource(RrdDb parentDb, DataImporter reader, int dsIndex) throws IOException, RrdException { this(parentDb, null); dsName.set(reader.getDsName(dsIndex)); Index: DataImporter.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/core/DataImporter.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** DataImporter.java 22 Jul 2004 07:23:46 -0000 1.1 --- DataImporter.java 22 Jul 2004 09:34:10 -0000 1.2 *************** *** 70,72 **** --- 70,76 ---- } + void release() throws RrdException, IOException { + // NOP + } + } \ No newline at end of file Index: Header.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/core/Header.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** Header.java 20 May 2004 10:29:32 -0000 1.6 --- Header.java 22 Jul 2004 09:34:10 -0000 1.7 *************** *** 66,70 **** } ! Header(RrdDb parentDb, XmlReader reader) throws IOException, RrdException { this(parentDb, (RrdDef) null); String version = reader.getVersion(); --- 66,70 ---- } ! Header(RrdDb parentDb, DataImporter reader) throws IOException, RrdException { this(parentDb, (RrdDef) null); String version = reader.getVersion(); --- NEW FILE: RrdToolReader.java --- /* ============================================================ * JRobin : Pure java implementation of RRDTool's functionality * ============================================================ * * Project Info: http://www.jrobin.org * Project Lead: Sasa Markovic (sa...@jr...); * * (C) Copyright 2003, by Sasa Markovic. * * Developers: Sasa Markovic (sa...@jr...) * Arne Vandamme (cob...@jr...) * * This library is free software; you can redistribute it and/or modify it under the terms * of the GNU Lesser General Public License as published by the Free Software Foundation; * either version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License along with this * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, * Boston, MA 02111-1307, USA. */ package org.jrobin.core; import org.jrobin.core.jrrd.RRDatabase; import java.io.IOException; class RrdToolReader extends DataImporter { private RRDatabase rrd; RrdToolReader(String rrdPath) throws IOException { rrd = new RRDatabase(rrdPath); } String getVersion() { return rrd.getHeader().getVersion(); } long getLastUpdateTime() { return Util.getTimestamp(rrd.getLastUpdate()); } long getStep() { return rrd.getHeader().getPDPStep(); } int getDsCount() { return rrd.getHeader().getDSCount(); } int getArcCount() throws RrdException, IOException { return rrd.getNumArchives(); } String getDsName(int dsIndex) { return rrd.getDataSource(dsIndex).getName(); } String getDsType(int dsIndex) { return rrd.getDataSource(dsIndex).getType().toString(); } long getHeartbeat(int dsIndex) { return rrd.getDataSource(dsIndex).getMinimumHeartbeat(); } double getMinValue(int dsIndex) { return rrd.getDataSource(dsIndex).getMinimum(); } double getMaxValue(int dsIndex) { return rrd.getDataSource(dsIndex).getMaximum(); } double getLastValue(int dsIndex) { String valueStr = rrd.getDataSource(dsIndex).getPDPStatusBlock().getLastReading(); return Util.parseDouble(valueStr); } double getAccumValue(int dsIndex) { return rrd.getDataSource(dsIndex).getPDPStatusBlock().getValue(); } long getNanSeconds(int dsIndex) { return rrd.getDataSource(dsIndex).getPDPStatusBlock().getUnknownSeconds(); } String getConsolFun(int arcIndex) { return rrd.getArchive(arcIndex).getType().toString(); } double getXff(int arcIndex) { return rrd.getArchive(arcIndex).getXff(); } int getSteps(int arcIndex) { return rrd.getArchive(arcIndex).getPdpCount(); } int getRows(int arcIndex) throws RrdException, IOException { return rrd.getArchive(arcIndex).getRowCount(); } double getStateAccumValue(int arcIndex, int dsIndex) throws RrdException, IOException { return rrd.getArchive(arcIndex).getCDPStatusBlock(dsIndex).getValue(); } int getStateNanSteps(int arcIndex, int dsIndex) throws RrdException, IOException { return rrd.getArchive(arcIndex).getCDPStatusBlock(dsIndex).getUnknownDatapoints(); } double[] getValues(int arcIndex, int dsIndex) throws RrdException, IOException { return rrd.getArchive(arcIndex).getValues()[dsIndex]; } void release() throws IOException { if(rrd != null) { rrd.close(); rrd = null; } } protected void finalize() throws Throwable { release(); } } Index: Archive.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/core/Archive.java,v retrieving revision 1.15 retrieving revision 1.16 diff -C2 -d -r1.15 -r1.16 *** Archive.java 20 May 2004 10:29:32 -0000 1.15 --- Archive.java 22 Jul 2004 09:34:10 -0000 1.16 *************** *** 72,76 **** // read from XML ! Archive(RrdDb parentDb, XmlReader reader, int arcIndex) throws IOException, RrdException { this(parentDb, new ArcDef( reader.getConsolFun(arcIndex), reader.getXff(arcIndex), --- 72,76 ---- // read from XML ! Archive(RrdDb parentDb, DataImporter reader, int arcIndex) throws IOException, RrdException { this(parentDb, new ArcDef( reader.getConsolFun(arcIndex), reader.getXff(arcIndex), Index: RrdDb.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/core/RrdDb.java,v retrieving revision 1.25 retrieving revision 1.26 diff -C2 -d -r1.25 -r1.26 *** RrdDb.java 21 Jul 2004 08:27:40 -0000 1.25 --- RrdDb.java 22 Jul 2004 09:34:10 -0000 1.26 *************** *** 306,310 **** throws IOException, RrdException { backend = factory.open(rrdPath, false, lockMode); ! XmlReader reader = new XmlReader(xmlPath); backend.setLength(reader.getEstimatedSize()); // create header --- 306,321 ---- throws IOException, RrdException { backend = factory.open(rrdPath, false, lockMode); ! DataImporter reader; ! if(xmlPath.startsWith("rrdtool:/")) { ! String rrdToolPath = xmlPath.substring("rrdtool:/".length()); ! reader = new RrdToolReader(rrdToolPath); ! } ! else if(xmlPath.startsWith("xml:/")) { ! xmlPath = xmlPath.substring("xml:/".length()); ! reader = new XmlReader(xmlPath); ! } ! else { ! reader = new XmlReader(xmlPath); ! } backend.setLength(reader.getEstimatedSize()); // create header *************** *** 320,323 **** --- 331,335 ---- archives[i] = new Archive(this, reader, i); } + reader.release(); // XMLReader is a rather huge DOM tree, release memory ASAP reader = null; |
From: Sasa M. <sa...@us...> - 2004-07-22 09:33:19
|
Update of /cvsroot/jrobin/src/org/jrobin/core/jrrd In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9487/jrrd Log Message: Directory /cvsroot/jrobin/src/org/jrobin/core/jrrd added to the repository |
From: Sasa M. <sa...@us...> - 2004-07-22 08:10:28
|
Update of /cvsroot/jrobin/src/org/jrobin/core In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv29692/org/jrobin/core Modified Files: Util.java Log Message: javadoc added Index: Util.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/core/Util.java,v retrieving revision 1.21 retrieving revision 1.22 diff -C2 -d -r1.21 -r1.22 *** Util.java 21 Jul 2004 07:10:26 -0000 1.21 --- Util.java 22 Jul 2004 08:10:19 -0000 1.22 *************** *** 215,218 **** --- 215,224 ---- } + /** + * Parses input string as a double value. If the value cannot be parsed, Double.NaN + * is returned (NumberFormatException is never thrown). + * @param valueStr String representing double value + * @return a double corresponding to the input string + */ public static double parseDouble(String valueStr) { double value; *************** *** 226,229 **** --- 232,241 ---- } + /** + * Parses input string as a boolean value. The parser is case insensitive. + * @param valueStr String representing boolean value + * @return <code>true</code>, if valueStr equals to 'true', 'on', 'yes', 'y' or '1'; + * <code>false</code> in all other cases. + */ public static boolean parseBoolean(String valueStr) { return valueStr.equalsIgnoreCase("true") || |
From: Sasa M. <sa...@us...> - 2004-07-22 07:23:56
|
Update of /cvsroot/jrobin/src/org/jrobin/core In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv23408/org/jrobin/core Modified Files: XmlReader.java Added Files: DataImporter.java Log Message: Added interface for all clases which import data to RrdDb - not necessary now, but might be useful later (jrrd) --- NEW FILE: DataImporter.java --- /* ============================================================ * JRobin : Pure java implementation of RRDTool's functionality * ============================================================ * * Project Info: http://www.jrobin.org * Project Lead: Sasa Markovic (sa...@jr...); * * (C) Copyright 2003, by Sasa Markovic. * * Developers: Sasa Markovic (sa...@jr...) * Arne Vandamme (cob...@jr...) * * This library is free software; you can redistribute it and/or modify it under the terms * of the GNU Lesser General Public License as published by the Free Software Foundation; * either version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License along with this * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, * Boston, MA 02111-1307, USA. */ package org.jrobin.core; import java.io.IOException; abstract class DataImporter { // header abstract String getVersion() throws RrdException, IOException; abstract long getLastUpdateTime() throws RrdException, IOException; abstract long getStep() throws RrdException, IOException; abstract int getDsCount() throws RrdException, IOException; abstract int getArcCount() throws RrdException, IOException; // datasource abstract String getDsName(int dsIndex) throws RrdException, IOException; abstract String getDsType(int dsIndex) throws RrdException, IOException; abstract long getHeartbeat(int dsIndex) throws RrdException, IOException; abstract double getMinValue(int dsIndex) throws RrdException, IOException; abstract double getMaxValue(int dsIndex) throws RrdException, IOException; // datasource state abstract double getLastValue(int dsIndex) throws RrdException, IOException; abstract double getAccumValue(int dsIndex) throws RrdException, IOException; abstract long getNanSeconds(int dsIndex) throws RrdException, IOException; // archive abstract String getConsolFun(int arcIndex) throws RrdException, IOException; abstract double getXff(int arcIndex) throws RrdException, IOException; abstract int getSteps(int arcIndex) throws RrdException, IOException; abstract int getRows(int arcIndex) throws RrdException, IOException; // archive state abstract double getStateAccumValue(int arcIndex, int dsIndex) throws RrdException, IOException; abstract int getStateNanSteps(int arcIndex, int dsIndex) throws RrdException, IOException; abstract double[] getValues(int arcIndex, int dsIndex) throws RrdException, IOException; long getEstimatedSize() throws RrdException, IOException { int dsCount = getDsCount(); int arcCount = getArcCount(); int rowCount = 0; for(int i = 0; i < arcCount; i++) { rowCount += getRows(i); } return RrdDef.calculateSize(dsCount, arcCount, rowCount); } } Index: XmlReader.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/core/XmlReader.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** XmlReader.java 20 May 2004 10:29:33 -0000 1.5 --- XmlReader.java 22 Jul 2004 07:23:46 -0000 1.6 *************** *** 31,35 **** import java.io.File; ! class XmlReader { private Element root; --- 31,35 ---- import java.io.File; ! class XmlReader extends DataImporter { private Element root; *************** *** 135,148 **** return values; } - - long getEstimatedSize() throws RrdException { - int dsCount = getDsCount(); - int arcCount = getArcCount(); - int rowCount = 0; - for(int i = 0; i < arcCount; i++) { - rowCount += getRows(i); - } - return RrdDef.calculateSize(dsCount, arcCount, rowCount); - } - } \ No newline at end of file --- 135,137 ---- |
From: Sasa M. <sa...@us...> - 2004-07-21 08:27:49
|
Update of /cvsroot/jrobin/src/org/jrobin/core In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv11525/org/jrobin/core Modified Files: FetchRequest.java RrdDb.java RrdDbPool.java RrdDef.java Sample.java Log Message: Minor changes Index: RrdDbPool.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/core/RrdDbPool.java,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** RrdDbPool.java 21 Jul 2004 07:10:25 -0000 1.9 --- RrdDbPool.java 21 Jul 2004 08:27:40 -0000 1.10 *************** *** 31,37 **** * Class to represent the pool of open RRD files.<p> * - * <b>WARNING:</b> The pool cannot be used to manipulate RrdDb objects - * with {@link RrdBackend backends} different from default. - * * To open already existing RRD file with JRobin, you have to create a * {@link org.jrobin.core.RrdDb RrdDb} object by specifying RRD file path --- 31,34 ---- *************** *** 98,101 **** --- 95,101 ---- * * The pool is thread-safe.<p> + * + * <b>WARNING:</b> The pool cannot be used to manipulate RrdDb objects + * with {@link RrdBackend backends} different from default.<p> */ public class RrdDbPool implements Runnable { *************** *** 303,307 **** try { ! debug("GC: sleeping (" + rrdMap.size() + "/" + rrdGcList.size() + ")"); wait(); debug("GC: running"); --- 303,312 ---- try { ! debug("GC: waiting: " + ! rrdMap.size() + " open, " + ! rrdGcList.size() + " released, " + ! "capacity = " + capacity + ", " + ! "hits = " + poolHitsCount + ", " + ! "requests = " + poolRequestsCount); wait(); debug("GC: running"); *************** *** 376,379 **** --- 381,385 ---- public synchronized void setCapacity(int capacity) { this.capacity = capacity; + debug("Capacity set to: " + capacity); } Index: RrdDef.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/core/RrdDef.java,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** RrdDef.java 20 Jul 2004 08:21:02 -0000 1.13 --- RrdDef.java 21 Jul 2004 08:27:40 -0000 1.14 *************** *** 425,430 **** */ public String dump() { ! StringBuffer buffer = new StringBuffer(RrdDb.RRDTOOL); ! buffer.append(" create " + path); buffer.append(" --start " + getStartTime()); buffer.append(" --step " + getStep() + " "); --- 425,430 ---- */ public String dump() { ! StringBuffer buffer = new StringBuffer("create \""); ! buffer.append(path + "\""); buffer.append(" --start " + getStartTime()); buffer.append(" --step " + getStep() + " "); Index: FetchRequest.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/core/FetchRequest.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** FetchRequest.java 28 May 2004 10:22:47 -0000 1.6 --- FetchRequest.java 21 Jul 2004 08:27:40 -0000 1.7 *************** *** 148,153 **** */ public String dump() { ! return RrdDb.RRDTOOL + " fetch " + parentDb.getRrdBackend().getPath() + ! " " + consolFun + " --start " + fetchStart + " --end " + fetchEnd + (resolution > 1? " --resolution " + resolution: ""); } --- 148,153 ---- */ public String dump() { ! return "fetch \"" + parentDb.getRrdBackend().getPath() + ! "\" " + consolFun + " --start " + fetchStart + " --end " + fetchEnd + (resolution > 1? " --resolution " + resolution: ""); } Index: RrdDb.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/core/RrdDb.java,v retrieving revision 1.24 retrieving revision 1.25 diff -C2 -d -r1.24 -r1.25 *** RrdDb.java 14 Jul 2004 12:52:34 -0000 1.24 --- RrdDb.java 21 Jul 2004 08:27:40 -0000 1.25 *************** *** 74,78 **** public static final int EXCEPTION_IF_LOCKED = 2; ! static final String RRDTOOL = "rrdtool"; static final int XML_INITIAL_BUFFER_CAPACITY = 100000; // bytes private static int lockMode = NO_LOCKS; --- 74,78 ---- public static final int EXCEPTION_IF_LOCKED = 2; ! // static final String RRDTOOL = "rrdtool"; static final int XML_INITIAL_BUFFER_CAPACITY = 100000; // bytes private static int lockMode = NO_LOCKS; Index: Sample.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/core/Sample.java,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** Sample.java 2 Jun 2004 08:55:48 -0000 1.9 --- Sample.java 21 Jul 2004 08:27:40 -0000 1.10 *************** *** 241,246 **** */ public String dump() { ! StringBuffer buffer = new StringBuffer(RrdDb.RRDTOOL); ! buffer.append(" update " + parentDb.getRrdBackend().getPath() + " " + time); for(int i = 0; i < values.length; i++) { buffer.append(":"); --- 241,246 ---- */ public String dump() { ! StringBuffer buffer = new StringBuffer("update \""); ! buffer.append(parentDb.getRrdBackend().getPath() + "\" " + time); for(int i = 0; i < values.length; i++) { buffer.append(":"); |
From: Sasa M. <sa...@us...> - 2004-07-21 07:10:41
|
Update of /cvsroot/jrobin/src/org/jrobin/mrtg/client In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31656/org/jrobin/mrtg/client Modified Files: MrtgData.java ServerInfo.java Log Message: Minor changes Index: MrtgData.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/mrtg/client/MrtgData.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** MrtgData.java 10 Nov 2003 08:52:29 -0000 1.2 --- MrtgData.java 21 Jul 2004 07:10:26 -0000 1.3 *************** *** 220,223 **** --- 220,224 ---- info.setSavesCount(Integer.parseInt(serverInfo.get("savesCount").toString())); info.setSampleCount(Integer.parseInt(serverInfo.get("sampleCount").toString())); + info.setPoolEfficency(Double.parseDouble(serverInfo.get("poolEfficency").toString())); info.setStartDate((Date)serverInfo.get("startDate")); return info; Index: ServerInfo.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/mrtg/client/ServerInfo.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** ServerInfo.java 10 Nov 2003 08:52:29 -0000 1.2 --- ServerInfo.java 21 Jul 2004 07:10:26 -0000 1.3 *************** *** 30,33 **** --- 30,34 ---- private String serverHost; private int sampleCount, savesCount, goodSavesCount, badSavesCount; + private double poolEfficency; private Date startDate; *************** *** 92,95 **** --- 93,97 ---- buffer.append("Samples stored OK: " + getGoodSavesCount() + "\n"); buffer.append("Samples not stored: " + getBadSavesCount() + "\n"); + buffer.append("Pool efficency: " + getPoolEfficency() + "\n"); return buffer.toString(); } *************** *** 99,101 **** --- 101,111 ---- } + double getPoolEfficency() { + return poolEfficency; + } + + void setPoolEfficency(double poolEfficency) { + this.poolEfficency = poolEfficency; + } + } |
From: Sasa M. <sa...@us...> - 2004-07-21 07:10:36
|
Update of /cvsroot/jrobin/src/org/jrobin/core In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31656/org/jrobin/core Modified Files: RrdDbPool.java Util.java Log Message: Minor changes Index: RrdDbPool.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/core/RrdDbPool.java,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** RrdDbPool.java 28 May 2004 10:22:47 -0000 1.8 --- RrdDbPool.java 21 Jul 2004 07:10:25 -0000 1.9 *************** *** 85,89 **** * becomes eligible for closing so that the oldest RRD file gets closed first.<p> * ! * Initial RrdDbPool capacity is set to 50. Use {@link #setCapacity(int)} method to * change it at any time.<p> * --- 85,89 ---- * becomes eligible for closing so that the oldest RRD file gets closed first.<p> * ! * Initial RrdDbPool capacity is set to {@link #INITIAL_CAPACITY}. Use {@link #setCapacity(int)} method to * change it at any time.<p> * *************** *** 105,111 **** /** * Constant to represent the maximum number of internally open RRD files ! * which still does not force garbage collector to run. */ ! public static final int INITIAL_CAPACITY = 50; private int capacity = INITIAL_CAPACITY; --- 105,111 ---- /** * Constant to represent the maximum number of internally open RRD files ! * which still does not force garbage collector (the process which closes RRD files) to run. */ ! public static final int INITIAL_CAPACITY = 100; private int capacity = INITIAL_CAPACITY; *************** *** 113,116 **** --- 113,117 ---- private List rrdGcList = new LinkedList(); private RrdBackendFactory factory; + private int poolHitsCount, poolRequestsCount; /** *************** *** 147,150 **** --- 148,152 ---- public synchronized RrdDb requestRrdDb(String path) throws IOException, RrdException { String keypath = getCanonicalPath(path); + RrdDb rrdDbRequested; if (rrdMap.containsKey(keypath)) { // already open *************** *** 152,162 **** reportUsage(rrdEntry); debug("EXISTING: " + rrdEntry.dump()); ! return rrdEntry.getRrdDb(); } else { // not found, open it RrdDb rrdDb = new RrdDb(path, getFactory()); addRrdEntry(keypath, rrdDb); ! return rrdDb; } } --- 154,167 ---- reportUsage(rrdEntry); debug("EXISTING: " + rrdEntry.dump()); ! rrdDbRequested = rrdEntry.getRrdDb(); ! poolHitsCount++; } else { // not found, open it RrdDb rrdDb = new RrdDb(path, getFactory()); addRrdEntry(keypath, rrdDb); ! rrdDbRequested = rrdDb; } + poolRequestsCount++; + return rrdDbRequested; } *************** *** 177,180 **** --- 182,186 ---- RrdDb rrdDb = new RrdDb(path, xmlPath, getFactory()); addRrdEntry(keypath, rrdDb); + poolRequestsCount++; return rrdDb; } *************** *** 194,197 **** --- 200,204 ---- RrdDb rrdDb = new RrdDb(rrdDef, getFactory()); addRrdEntry(keypath, rrdDb); + poolRequestsCount++; return rrdDb; } *************** *** 418,421 **** --- 425,460 ---- } } + + /** + * Calculates pool's efficency ratio. The ratio is obtained by dividing the number of + * RrdDb requests served from the internal pool of open RRD files + * with the number of total RrdDb requests. + * @return Pool's efficiency ratio as a double between 1 (best) and 0 (worst). If no RrdDb reference + * was ever requested, 1 would be returned. + */ + public synchronized double getPoolEfficency() { + if(poolRequestsCount == 0) { + return 1.0; + } + double ratio = (double) poolHitsCount / (double) poolRequestsCount; + // round to 3 decimal digits + return Math.round(ratio * 1000.0) / 1000.0; + } + + /** + * Returns the number of RRD requests served from the internal pool of open RRD files + * @return The number of pool "hits". + */ + public synchronized int getPoolHitsCount() { + return poolHitsCount; + } + + /** + * Returns the total number of RRD requests successfully served by this pool. + * @return Total number of RRD requests + */ + public synchronized int getPoolRequestsCount() { + return poolRequestsCount; + } } Index: Util.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/core/Util.java,v retrieving revision 1.20 retrieving revision 1.21 diff -C2 -d -r1.20 -r1.21 *** Util.java 20 Jul 2004 08:21:02 -0000 1.20 --- Util.java 21 Jul 2004 07:10:26 -0000 1.21 *************** *** 85,90 **** /** ! * Rounds the given timestamp to the nearest whole "step" by evaluating ! * the following expression:<p> * <code>timestamp - timestamp % step;</code> * @param timestamp Timestamp in seconds --- 85,90 ---- /** ! * Rounds the given timestamp to the nearest whole "e;step"e;. Rounded value is obtained ! * from the following expression:<p> * <code>timestamp - timestamp % step;</code> * @param timestamp Timestamp in seconds |
From: Sasa M. <sa...@us...> - 2004-07-21 07:10:36
|
Update of /cvsroot/jrobin/src/org/jrobin/mrtg/server In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31656/org/jrobin/mrtg/server Modified Files: Listener.java Server.java Log Message: Minor changes Index: Listener.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/mrtg/server/Listener.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** Listener.java 31 Mar 2004 12:02:00 -0000 1.4 --- Listener.java 21 Jul 2004 07:10:27 -0000 1.5 *************** *** 37,41 **** private WebServer webServer; ! Listener(String[] clients) throws MrtgException { webServer = new WebServer(SERVER_PORT); webServer.addHandler("mrtg", new EventHandler()); --- 37,41 ---- private WebServer webServer; ! Listener(String[] clients) { webServer = new WebServer(SERVER_PORT); webServer.addHandler("mrtg", new EventHandler()); Index: Server.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/mrtg/server/Server.java,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** Server.java 31 May 2004 09:04:54 -0000 1.13 --- Server.java 21 Jul 2004 07:10:27 -0000 1.14 *************** *** 292,295 **** --- 292,296 ---- hash.put("badSavesCount", new Integer(rrdWriter.getBadSavesCount())); hash.put("startDate", startDate); + hash.put("poolEfficency", new Double(RrdDbPool.getInstance().getPoolEfficency())); return hash; } |
From: Sasa M. <sa...@us...> - 2004-07-21 07:10:36
|
Update of /cvsroot/jrobin/src/org/jrobin/mrtg In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31656/org/jrobin/mrtg Modified Files: MrtgConstants.java Log Message: Minor changes Index: MrtgConstants.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/mrtg/MrtgConstants.java,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** MrtgConstants.java 31 May 2004 09:04:51 -0000 1.9 --- MrtgConstants.java 21 Jul 2004 07:10:26 -0000 1.10 *************** *** 46,50 **** // number of open RRD files held in the pool ! int POOL_CAPACITY = 50; // graph dimensions --- 46,50 ---- // number of open RRD files held in the pool ! int POOL_CAPACITY = 100; // graph dimensions |
From: Arne V. <cob...@us...> - 2004-07-20 17:01:49
|
Update of /cvsroot/jrobin/src/org/jrobin/graph In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv8819/org/jrobin/graph Modified Files: ValueGrid.java Log Message: JRobin 1.4.1 - Altered ValueGrid to throw Exception in rare case Index: ValueGrid.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/graph/ValueGrid.java,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** ValueGrid.java 20 Jul 2004 16:51:27 -0000 1.11 --- ValueGrid.java 20 Jul 2004 17:01:41 -0000 1.12 *************** *** 77,85 **** this.upper = up; this.vAxis = vAxis; ! baseValue = base; ! // Fill in the scale values if ( base != baseValue ) { double tmp = 1; for (int i = 1; i < 7; i++) { --- 77,86 ---- this.upper = up; this.vAxis = vAxis; ! // Fill in the scale values if ( base != baseValue ) { + baseValue = base; + double tmp = 1; for (int i = 1; i < 7; i++) { |
From: Arne V. <cob...@us...> - 2004-07-20 16:51:42
|
Update of /cvsroot/jrobin/src/org/jrobin/graph In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv7020/org/jrobin/graph Modified Files: RrdGraphDefTemplate.java ValueGrid.java Log Message: JRobin 1.4.1 - Altered ValueGrid to throw Exception in rare case Index: ValueGrid.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/graph/ValueGrid.java,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** ValueGrid.java 10 Jul 2004 00:07:03 -0000 1.10 --- ValueGrid.java 20 Jul 2004 16:51:27 -0000 1.11 *************** *** 25,28 **** --- 25,30 ---- package org.jrobin.graph; + import org.jrobin.core.RrdException; + /** * <p>Holds specific information about the Value axis grid of the chart.</p> *************** *** 60,64 **** * ValueAxisUnit is null, one will be automatically determined. */ ! ValueGrid( GridRange gr, double low, double up, ValueAxisUnit vAxis, double base ) { double grLower = Double.MAX_VALUE; --- 62,66 ---- * ValueAxisUnit is null, one will be automatically determined. */ ! ValueGrid( GridRange gr, double low, double up, ValueAxisUnit vAxis, double base ) throws RrdException { double grLower = Double.MAX_VALUE; *************** *** 78,92 **** // Fill in the scale values ! double tmp = 1; ! for (int i = 1; i < 7; i++) { ! tmp *= baseValue; ! scaleValues[6 - i] = tmp; ! } ! tmp = 1; ! for (int i = 7; i < scaleValues.length; i++) { ! tmp *= baseValue; ! scaleValues[i] = ( 1 / tmp ); } ! // Set an appropriate value axis it not given yet setValueAxis(); --- 80,97 ---- // Fill in the scale values ! if ( base != baseValue ) ! { ! double tmp = 1; ! for (int i = 1; i < 7; i++) { ! tmp *= baseValue; ! scaleValues[6 - i] = tmp; ! } ! tmp = 1; ! for (int i = 7; i < scaleValues.length; i++) { ! tmp *= baseValue; ! scaleValues[i] = ( 1 / tmp ); ! } } ! // Set an appropriate value axis it not given yet setValueAxis(); *************** *** 122,126 **** * A decent grid is selected based on the value range being used in the chart. */ ! private void setValueAxis() { if ( vAxis != null ) --- 127,131 ---- * A decent grid is selected based on the value range being used in the chart. */ ! private void setValueAxis() throws RrdException { if ( vAxis != null ) *************** *** 131,135 **** if ( Double.isNaN(lower) || lower == Double.MAX_VALUE || lower == Double.MIN_VALUE ) lower = 0; ! if ( !rigid && upper == 0 && upper == lower ) upper = 0.9; --- 136,140 ---- if ( Double.isNaN(lower) || lower == Double.MAX_VALUE || lower == Double.MIN_VALUE ) lower = 0; ! if ( !rigid && upper == 0 && upper == lower ) upper = 0.9; *************** *** 143,151 **** double mod = 1.0; int scaleIndex = scaleValues.length - 1; ! while ( scaleIndex >= 0 && scaleValues[scaleIndex] < shifted ) scaleIndex--; // Keep the rest of division ! shifted = shifted / scaleValues[++scaleIndex]; // While rest > 10, divide by 10 --- 148,161 ---- double mod = 1.0; int scaleIndex = scaleValues.length - 1; ! while ( scaleIndex >= 0 && scaleValues[scaleIndex] < shifted ) scaleIndex--; // Keep the rest of division ! if ( scaleValues[++scaleIndex] != 0 ) // Don't divide by zero, it is silly ! shifted = shifted / scaleValues[scaleIndex]; ! ! // Safety check to avoid infinite loop ! if ( Double.isInfinite(shifted) ) ! throw new RrdException( "ValueGrid failure: u=" + upper + " l=" + lower + " sv=" + scaleValues[scaleIndex] ); // While rest > 10, divide by 10 *************** *** 154,158 **** mod *= 10; } ! while ( shifted < 1.0 ) { shifted *= 10; --- 164,168 ---- mod *= 10; } ! while ( shifted < 1.0 ) { shifted *= 10; Index: RrdGraphDefTemplate.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/graph/RrdGraphDefTemplate.java,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** RrdGraphDefTemplate.java 13 Jul 2004 12:13:13 -0000 1.9 --- RrdGraphDefTemplate.java 20 Jul 2004 16:51:27 -0000 1.10 *************** *** 383,389 **** String format = getChildValue(childs[i], "format", false ); String pattern = getChildValue(childs[i], "pattern"); - String timestamp = getChildValue(childs[i], "value"); ! rrdGraphDef.time( format, pattern, Util.getGregorianCalendar(timestamp) ); } else if(nodeName.equals("hrule")) { --- 383,394 ---- String format = getChildValue(childs[i], "format", false ); String pattern = getChildValue(childs[i], "pattern"); ! if ( Util.Xml.hasChildNode( childs[i], "value" ) ) ! { ! String timestamp = getChildValue(childs[i], "value"); ! rrdGraphDef.time( format, pattern, Util.getGregorianCalendar(timestamp) ); ! } ! else ! rrdGraphDef.time( format, pattern ); } else if(nodeName.equals("hrule")) { *************** *** 563,567 **** "overlay", "show_legend", "show_signature", "time_axis", "time_axis_label", "title", "title_font", "title_font_color", "units_exponent", "value_axis", ! "vertical_label", "strict_export", "resolution" }); Node[] optionNodes = getChildNodes(rootOptionNode); --- 568,572 ---- "overlay", "show_legend", "show_signature", "time_axis", "time_axis_label", "title", "title_font", "title_font_color", "units_exponent", "value_axis", ! "vertical_label", "strict_export", "resolution", "lower_limit" }); Node[] optionNodes = getChildNodes(rootOptionNode); *************** *** 637,640 **** --- 642,650 ---- rrdGraphDef.setGridRange(lower, upper, rigid); } + // LOWER LIMIT + else if(option.equals("lower_limit")) { + double lower = getValueAsDouble(optionNode); + rrdGraphDef.setLowerLimit( lower ); + } // GRID X? else if(option.equals("grid_x")) { |
From: Sasa M. <sa...@us...> - 2004-07-20 09:08:14
|
Update of /cvsroot/jrobin/src/org/jrobin/demo In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv27765/org/jrobin/demo Modified Files: Demo.java Log Message: Minor code change Index: Demo.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/demo/Demo.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** Demo.java 9 Jun 2004 12:09:23 -0000 1.1 --- Demo.java 20 Jul 2004 09:08:03 -0000 1.2 *************** *** 85,88 **** --- 85,95 ---- RrdDb rrdDb = new RrdDb(rrdDef); println("== RRD file created."); + if(rrdDb.getRrdDef().equals(rrdDef)) { + println("Checking RRD file structure... OK"); + } + else { + println("Invalid RRD file created. This is a serious bug, bailing out"); + return; + } rrdDb.close(); println("== RRD file closed."); |
From: Sasa M. <sa...@us...> - 2004-07-20 09:07:02
|
Update of /cvsroot/jrobin/src/org/jrobin/cmd In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv27522/org/jrobin/cmd Added Files: Epoch.java Log Message: Added small swing utility for converting readable dates to timestamps and vice versa --- NEW FILE: Epoch.java --- package org.jrobin.cmd; import org.jrobin.core.RrdException; import org.jrobin.core.Util; // import org.jrobin.cmd.TimeParser; import javax.swing.*; import java.util.Date; import java.awt.*; import java.awt.event.ActionListener; import java.awt.event.ActionEvent; import java.text.SimpleDateFormat; import java.text.ParseException; class Epoch extends JFrame implements Runnable { private static final String[] formats = { "MM/dd/yy HH:mm:ss", "dd.MM.yy HH:mm:ss", "yy-MM-dd HH:mm:ss", "MM/dd/yy HH:mm", "dd.MM.yy HH:mm", "yy-MM-dd HH:mm", "MM/dd/yy", "dd.MM.yy", "yy-MM-dd", "HH:mm MM/dd/yy", "HH:mm dd.MM.yy", "HH:mm yy-MM-dd", "HH:mm:ss MM/dd/yy", "HH:mm:ss dd.MM.yy", "HH:mm:ss yy-MM-dd" }; private static final SimpleDateFormat[] parsers = new SimpleDateFormat[formats.length]; private static final String helpText; static { for(int i = 0; i < parsers.length; i++) { parsers[i] = new SimpleDateFormat(formats[i]); parsers[i].setLenient(true); } StringBuffer tooltipBuff = new StringBuffer("<html><b>Supported input formats:</b><br>"); for(int i = 0; i < formats.length; i++) { tooltipBuff.append(formats[i] + "<br>"); } tooltipBuff.append("<b>RRDTool time format</b><br>"); tooltipBuff.append("... including timestamps</html>"); helpText = tooltipBuff.toString(); } private JLabel topLabel = new JLabel("Enter timestamp or readable date:"); private JTextField inputField = new JTextField(25); private JButton button = new JButton("Convert"); //private JLabel helpLabel = new JLabel(helpText); private static final SimpleDateFormat OUTPUT_DATE_FORMAT = new SimpleDateFormat("MM/dd/yy HH:mm:ss EEE"); Epoch() { super("Epoch"); constructUI(); setVisible(true); new Thread(this).start(); } private void constructUI() { JPanel c = (JPanel) getContentPane(); c.setLayout(new BorderLayout()); c.add(topLabel, BorderLayout.NORTH); c.add(inputField, BorderLayout.CENTER); c.add(button, BorderLayout.EAST); // c.add(helpLabel, BorderLayout.WEST); button.setToolTipText(helpText); button.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { convert(); } }); inputField.requestFocus(); getRootPane().setDefaultButton(button); setResizable(false); setDefaultCloseOperation(EXIT_ON_CLOSE); pack(); centerOnScreen(); } void centerOnScreen() { Toolkit t = Toolkit.getDefaultToolkit(); Dimension screenSize = t.getScreenSize(); Dimension frameSize = getPreferredSize(); double x = (screenSize.getWidth() - frameSize.getWidth()) / 2; double y = (screenSize.getHeight() - frameSize.getHeight()) / 2; setLocation((int) x, (int) y); } private void convert() { String time = inputField.getText().trim(); if(time.length() > 0) { // try simple timestamp try { long timestamp = Long.parseLong(time); Date date = new Date(timestamp * 1000L); formatDate(date); } catch(NumberFormatException nfe) { // failed, try as a date try { inputField.setText("" + parseDate(time)); } catch (RrdException e) { inputField.setText("Could not convert, sorry"); } } } } public void run() { for(;;) { Date now = new Date(); long timestamp = now.getTime() / 1000L; setTitle(timestamp + " seconds since epoch"); try { Thread.sleep(1000L); } catch (InterruptedException e) { } } } void formatDate(Date date) { inputField.setText(OUTPUT_DATE_FORMAT.format(date)); } private long parseDate(String time) throws RrdException { for(int i = 0; i < parsers.length; i++) { try { return Util.getTimestamp(parsers[i].parse(time)); } catch (ParseException e) { } } return new TimeParser(time).parse().getTimestamp(); } public static void main(String[] args) { new Epoch(); } } |
From: Sasa M. <sa...@us...> - 2004-07-20 08:21:10
|
Update of /cvsroot/jrobin/src/org/jrobin/core In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21840/org/jrobin/core Modified Files: ArcDef.java DsDef.java RrdDef.java Util.java Log Message: implemented equals() for RrdDef class Index: DsDef.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/core/DsDef.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** DsDef.java 20 May 2004 10:29:32 -0000 1.5 --- DsDef.java 20 Jul 2004 08:21:02 -0000 1.6 *************** *** 173,175 **** --- 173,180 ---- } + boolean exactlyEqual(DsDef def) { + return dsName.equals(def.dsName) && dsType.equals(def.dsType) && + heartbeat == def.heartbeat && Util.equal(minValue, def.minValue) && + Util.equal(maxValue, def.maxValue); + } } Index: RrdDef.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/core/RrdDef.java,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** RrdDef.java 20 May 2004 10:29:33 -0000 1.12 --- RrdDef.java 20 Jul 2004 08:21:02 -0000 1.13 *************** *** 549,551 **** --- 549,612 ---- 20L * dsCount * arcCount + 8L * dsCount * rowsCount; } + + /** + * Compares the current RrdDef with another. RrdDefs are considered equal if:<p> + *<ul> + * <li>RRD steps match + * <li>all datasources have exactly the same definition in both RrdDef objects (datasource names, + * types, heartbeat, min and max values must match) + * <li>all archives have exactly the same definition in both RrdDef objects (archive consolidation + * functions, X-file factors, step and row counts must match) + * </ul> + * @param obj The second RrdDef object + * @return true if RrdDefs match exactly, false otherwise + */ + public boolean equals(Object obj) { + if(obj == null || !(obj instanceof RrdDef)) { + return false; + } + RrdDef rrdDef2 = (RrdDef) obj; + // check primary RRD step + if(step != rrdDef2.step) { + return false; + } + // check datasources + DsDef[] dsDefs = getDsDefs(), dsDefs2 = rrdDef2.getDsDefs(); + if(dsDefs.length != dsDefs2.length) { + return false; + } + for(int i = 0; i < dsDefs.length; i++) { + boolean matched = false; + for(int j = 0; j < dsDefs2.length; j++) { + if(dsDefs[i].exactlyEqual(dsDefs2[j])) { + matched = true; + break; + } + } + // this datasource could not be matched + if(!matched) { + return false; + } + } + // check archives + ArcDef[] arcDefs = getArcDefs(), arcDefs2 = rrdDef2.getArcDefs(); + if(arcDefs.length != arcDefs2.length) { + return false; + } + for(int i = 0; i < arcDefs.length; i++) { + boolean matched = false; + for(int j = 0; j < arcDefs2.length; j++) { + if(arcDefs[i].exactlyEqual(arcDefs2[j])) { + matched = true; + break; + } + } + // this archive could not be matched + if(!matched) { + return false; + } + } + // everything matches + return true; + } } Index: Util.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/core/Util.java,v retrieving revision 1.19 retrieving revision 1.20 diff -C2 -d -r1.19 -r1.20 *** Util.java 14 Jul 2004 12:52:34 -0000 1.19 --- Util.java 20 Jul 2004 08:21:02 -0000 1.20 *************** *** 534,536 **** --- 534,551 ---- } + /** + * Compares two doubles, but returns true if x = y = Double.NaN + * @param x First double + * @param y Second double + * @return true, if doubles are equal, false otherwise. + */ + public static boolean equal(double x, double y) { + if(Double.isNaN(x) && Double.isNaN(y)) { + return true; + } + else { + return x == y; + } + } + } \ No newline at end of file Index: ArcDef.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/core/ArcDef.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** ArcDef.java 20 May 2004 10:29:32 -0000 1.6 --- ArcDef.java 20 Jul 2004 08:21:01 -0000 1.7 *************** *** 162,164 **** --- 162,168 ---- } + boolean exactlyEqual(ArcDef def) { + return consolFun.equals(def.consolFun) && xff == def.xff && + steps == def.steps && rows == def.rows; + } } |
From: Arne V. <cob...@us...> - 2004-07-19 21:12:38
|
Update of /cvsroot/jrobin/src/org/jrobin/graph In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv23152/org/jrobin/graph Modified Files: Grapher.java RrdExporter.java Log Message: JRobin 1.4.1 - Fixed RrdOpener bug Index: Grapher.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/graph/Grapher.java,v retrieving revision 1.18 retrieving revision 1.19 diff -C2 -d -r1.18 -r1.19 *** Grapher.java 13 Jul 2004 16:20:07 -0000 1.18 --- Grapher.java 19 Jul 2004 21:12:27 -0000 1.19 *************** *** 286,289 **** --- 286,290 ---- { FetchSourceList fetchSources = graphDef.getFetchSources(); + fetchSources.setRrdOpener( getRrdOpener() ); fetchSources.openAll(); Index: RrdExporter.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/graph/RrdExporter.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** RrdExporter.java 13 Jul 2004 16:20:07 -0000 1.4 --- RrdExporter.java 19 Jul 2004 21:12:27 -0000 1.5 *************** *** 518,520 **** --- 518,528 ---- return createExportData(); } + + public RrdExportDef getExportDef() { + return def; + } + + public RrdOpener getRrdOpener() { + return rrdOpener; + } } |
From: Sasa M. <sa...@us...> - 2004-07-19 15:00:13
|
Update of /cvsroot/jrobin/src/org/jrobin/cmd In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv13171/org/jrobin/cmd Modified Files: RrdXportCmd.java TimeParser.java TimeSpec.java Log Message: Added javadoc Index: TimeSpec.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/cmd/TimeSpec.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** TimeSpec.java 12 Jul 2004 13:35:17 -0000 1.1 --- TimeSpec.java 19 Jul 2004 15:00:03 -0000 1.2 *************** *** 33,40 **** import java.util.Calendar; ! class TimeSpec { ! public static final int TYPE_ABSOLUTE = 0; ! public static final int TYPE_START = 1; ! public static final int TYPE_END = 2; int type = TYPE_ABSOLUTE; --- 33,44 ---- import java.util.Calendar; ! /** ! * Simple class to represent time obtained by parsing at-style date specification (described ! * in detail on the rrdfetch man page. See javadoc {@link TimeParser} for more information. ! */ ! public class TimeSpec { ! static final int TYPE_ABSOLUTE = 0; ! static final int TYPE_START = 1; ! static final int TYPE_END = 2; int type = TYPE_ABSOLUTE; *************** *** 47,51 **** TimeSpec context; ! public TimeSpec(String dateString) { this.dateString = dateString; } --- 51,55 ---- TimeSpec context; ! TimeSpec(String dateString) { this.dateString = dateString; } *************** *** 87,91 **** } ! long getTimestamp() throws RrdException { return Util.getTimestamp(getTime()); } --- 91,105 ---- } ! /** ! * Returns the corresponding timestamp (seconds since Epoch). Example:<p> ! * <pre> ! * TimeParser p = new TimeParser("now-1day"); ! * TimeSpec ts = p.parse(); ! * System.out.println("Timestamp was: " + ts.getTimestamp(); ! * </pre> ! * @return Timestamp (in seconds, no milliseconds) ! * @throws RrdException Thrown if this TimeSpec object does not represent absolute time. ! */ ! public long getTimestamp() throws RrdException { return Util.getTimestamp(getTime()); } *************** *** 99,103 **** } ! static GregorianCalendar[] getTimes(TimeSpec spec1, TimeSpec spec2) throws RrdException { if(spec1.type == TYPE_START || spec2.type == TYPE_END) { throw new RrdException("Recursive time specifications not allowed"); --- 113,132 ---- } ! /** ! * Use this static method to resolve relative time references and obtain the corresponding ! * GregorianCalendar objects. Example:<p> ! * <pre> ! * TimeParser pStart = new TimeParser("now-1month"); // starting time ! * TimeParser pEnd = new TimeParser("start+1week"); // ending time ! * TimeSpec specStart = pStart.parse(); ! * TimeSpec specEnd = pEnd.parse(); ! * GregorianCalendar[] gc = TimeSpec.getTimes(specStart, specEnd); ! * </pre> ! * @param spec1 Starting time specification ! * @param spec2 Ending time specification ! * @return ! * @throws RrdException Thrown if relative time references cannot be resolved ! */ ! public static GregorianCalendar[] getTimes(TimeSpec spec1, TimeSpec spec2) throws RrdException { if(spec1.type == TYPE_START || spec2.type == TYPE_END) { throw new RrdException("Recursive time specifications not allowed"); *************** *** 111,115 **** } ! static long[] getTimestamps(TimeSpec spec1, TimeSpec spec2) throws RrdException { GregorianCalendar[] gcs = getTimes(spec1, spec2); return new long[] { --- 140,159 ---- } ! /** ! * Use this static method to resolve relative time references and obtain the corresponding ! * timestamps (seconds since epoch). Example:<p> ! * <pre> ! * TimeParser pStart = new TimeParser("now-1month"); // starting time ! * TimeParser pEnd = new TimeParser("start+1week"); // ending time ! * TimeSpec specStart = pStart.parse(); ! * TimeSpec specEnd = pEnd.parse(); ! * long[] ts = TimeSpec.getTimestamps(specStart, specEnd); ! * </pre> ! * @param spec1 Starting time specification ! * @param spec2 Ending time specification ! * @return ! * @throws RrdException Thrown if relative time references cannot be resolved ! */ ! public static long[] getTimestamps(TimeSpec spec1, TimeSpec spec2) throws RrdException { GregorianCalendar[] gcs = getTimes(spec1, spec2); return new long[] { Index: RrdXportCmd.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/cmd/RrdXportCmd.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** RrdXportCmd.java 16 Jul 2004 07:40:48 -0000 1.2 --- RrdXportCmd.java 19 Jul 2004 15:00:03 -0000 1.3 *************** *** 80,84 **** ExportData data = export.fetch(maxRows); ! System.out.println(data.exportXml()); return data; --- 80,84 ---- ExportData data = export.fetch(maxRows); ! println(data.exportXml()); return data; *************** *** 133,136 **** --- 133,137 ---- def.export(tokens[1], tokens[2]); } + /* public static void main(String[] args) throws Exception { Index: TimeParser.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/cmd/TimeParser.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** TimeParser.java 12 Jul 2004 13:35:17 -0000 1.1 --- TimeParser.java 19 Jul 2004 15:00:03 -0000 1.2 *************** *** 36,41 **** import java.io.IOException; ! class TimeParser { ! public static final int PREVIOUS_OP = -1; TimeToken token; --- 36,46 ---- import java.io.IOException; ! /** ! * Class which parses at-style time specification (describided in detail on the rrdfetch man page), ! * used in all RRDTool commands. This code is in most parts just a java port of Tobi's parsetime.c ! * code. ! */ ! public class TimeParser { ! private static final int PREVIOUS_OP = -1; TimeToken token; *************** *** 46,49 **** --- 51,59 ---- int prev_multiplier = -1; + /** + * Constructs TimeParser instance from the given input string. + * @param dateString at-style time specification (read rrdfetch man page + * for the complete explanation) + */ public TimeParser(String dateString) { scanner = new TimeScanner(dateString); *************** *** 295,299 **** } ! TimeSpec parse() throws RrdException { long now = Util.getTime(); int hr = 0; --- 305,314 ---- } ! /** ! * Parses the input string specified in the constructor. ! * @return Object representing parsed date/time. ! * @throws RrdException Thrown if the date string cannot be parsed. ! */ ! public TimeSpec parse() throws RrdException { long now = Util.getTime(); int hr = 0; *************** *** 403,406 **** --- 418,422 ---- } + /* public static void main(String[] args) throws IOException { BufferedReader r = new BufferedReader(new InputStreamReader(System.in)); *************** *** 417,419 **** --- 433,436 ---- } } + */ } \ No newline at end of file |
From: Sasa M. <sa...@us...> - 2004-07-16 14:16:48
|
Update of /cvsroot/jrobin/src/org/jrobin/core In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv20180/org/jrobin/core Modified Files: RrdNioBackend.java Log Message: Workaround for strange NIO exceptions (finally). Index: RrdNioBackend.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/core/RrdNioBackend.java,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** RrdNioBackend.java 16 Jul 2004 08:01:14 -0000 1.14 --- RrdNioBackend.java 16 Jul 2004 14:16:38 -0000 1.15 *************** *** 33,49 **** /** ! * JRobin backend which is used to store RRD data to ordinary files on the disk ! * by using java.nio.* package. This is the default backend engine since JRobin 1.4.0. */ public class RrdNioBackend extends RrdFileBackend { /** ! * Defines if the <code>System.gc()</code> method should be executed when necessary. ! * NIO backend uses large in-memory buffer to cache file data. The buffer remains 'active' ! * (by prohibiting file re-creation, for example) as long as it is not garbage collected. ! * By forcing <code>gc()</code> where appropriate, memory gets freed sooner and file ! * re-creation won't fail.<p> * ! * The constant is set to true initially and currently there is no API to change it ! * during runtime.<p> */ public static final boolean SHOULD_GC = true; --- 33,53 ---- /** ! * JRobin backend which is used to store RRD data to ordinary disk files ! * by using fast java.nio.* package. This is the default backend engine since JRobin 1.4.0. */ public class RrdNioBackend extends RrdFileBackend { /** ! * Defines <code>System.gc()</code> usage policy for this backend.<p> * ! * NIO backend uses potentially large in-memory buffer to cache file data. ! * The buffer remains 'active' (by prohibiting file re-creation with the smaller file size) ! * as long as it is not garbage-collected. By forcing <code>System.gc()</code> call where ! * appropriate, this backend will free in-memory buffers sooner and file re-creation won't fail.<p> ! * ! * The constant is set to <b><code>true</code></b> initially and currently there is no ! * API to change it during runtime. ! * ! * Garbage collection will be forced only in some special circumstances. ! * It should not affect the speed of your application significantly.<p> */ public static final boolean SHOULD_GC = true; *************** *** 51,57 **** static { if(SHOULD_GC) { ! Runtime.getRuntime().addShutdownHook(new Thread() { public void run() { ! System.gc(); } }); --- 55,63 ---- static { if(SHOULD_GC) { ! final Runtime runtime = Runtime.getRuntime(); ! runtime.addShutdownHook(new Thread() { public void run() { ! runtime.runFinalization(); ! runtime.gc(); } }); *************** *** 68,72 **** throws IOException { super(path, readOnly, lockMode); ! map(false, readOnly); this.syncMode = syncMode; if(syncMode == RrdNioBackendFactory.SYNC_BACKGROUND && !readOnly) { --- 74,78 ---- throws IOException { super(path, readOnly, lockMode); ! map(readOnly); this.syncMode = syncMode; if(syncMode == RrdNioBackendFactory.SYNC_BACKGROUND && !readOnly) { *************** *** 75,90 **** } ! private void map(boolean isShorter, boolean readOnly) throws IOException { ! if(isShorter) { ! byteBuffer = null; ! if(SHOULD_GC) { ! System.gc(); ! } ! } ! long newLength = getLength(); ! if(newLength > 0) { FileChannel.MapMode mapMode = readOnly? FileChannel.MapMode.READ_ONLY: FileChannel.MapMode.READ_WRITE; ! byteBuffer = channel.map(mapMode, 0, newLength); } } --- 81,93 ---- } ! private void map(boolean readOnly) throws IOException { ! long length = getLength(); ! if(length > 0) { FileChannel.MapMode mapMode = readOnly? FileChannel.MapMode.READ_ONLY: FileChannel.MapMode.READ_WRITE; ! byteBuffer = channel.map(mapMode, 0, length); ! } ! else { ! byteBuffer = null; } } *************** *** 106,112 **** */ protected void setLength(long newLength) throws IOException { ! boolean isShorter = newLength < getLength(); super.setLength(newLength); ! map(isShorter, false); } --- 109,121 ---- */ protected void setLength(long newLength) throws IOException { ! if(newLength < getLength()) { ! // the file will be truncated ! if(SHOULD_GC) { ! byteBuffer = null; ! System.gc(); ! } ! } super.setLength(newLength); ! map(false); } |
From: Sasa M. <sa...@us...> - 2004-07-16 08:01:27
|
Update of /cvsroot/jrobin/src/org/jrobin/cmd In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv22984/org/jrobin/cmd Modified Files: RrdCommander.java RrdToolCmd.java Log Message: XPORT command added (not tested yet) Index: RrdToolCmd.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/cmd/RrdToolCmd.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** RrdToolCmd.java 16 Jul 2004 07:40:48 -0000 1.4 --- RrdToolCmd.java 16 Jul 2004 08:01:13 -0000 1.5 *************** *** 40,45 **** abstract Object execute() throws RrdException, IOException; ! void setCommand(String command) throws RrdException { cmdScanner = new RrdCmdScanner(command); } --- 40,46 ---- abstract Object execute() throws RrdException, IOException; ! Object executeCommand(String command) throws RrdException, IOException { cmdScanner = new RrdCmdScanner(command); + return execute(); } Index: RrdCommander.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/cmd/RrdCommander.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** RrdCommander.java 16 Jul 2004 07:40:48 -0000 1.6 --- RrdCommander.java 16 Jul 2004 08:01:09 -0000 1.7 *************** *** 44,49 **** new RrdFetchCmd(), new RrdDumpCmd(), ! new RrdRestoreCmd() ! }; --- 44,49 ---- new RrdFetchCmd(), new RrdDumpCmd(), ! new RrdRestoreCmd(), ! new RrdXportCmd() }; *************** *** 120,125 **** for(int i = 0; i < rrdCommands.length; i++) { if(cmd.startsWith(rrdCommands[i].getCmdType())) { ! rrdCommands[i].setCommand(cmd); ! return rrdCommands[i].execute(); } } --- 120,124 ---- for(int i = 0; i < rrdCommands.length; i++) { if(cmd.startsWith(rrdCommands[i].getCmdType())) { ! return rrdCommands[i].executeCommand(cmd); } } |
From: Sasa M. <sa...@us...> - 2004-07-16 08:01:27
|
Update of /cvsroot/jrobin/src/org/jrobin/core In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv22984/org/jrobin/core Modified Files: RrdNioBackend.java Log Message: XPORT command added (not tested yet) Index: RrdNioBackend.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/core/RrdNioBackend.java,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** RrdNioBackend.java 16 Jul 2004 07:40:49 -0000 1.13 --- RrdNioBackend.java 16 Jul 2004 08:01:14 -0000 1.14 *************** *** 44,48 **** * re-creation won't fail.<p> * ! * The constant is set to false initially and currently there is no API to change it * during runtime.<p> */ --- 44,48 ---- * re-creation won't fail.<p> * ! * The constant is set to true initially and currently there is no API to change it * during runtime.<p> */ |
From: Sasa M. <sa...@us...> - 2004-07-16 07:40:58
|
Update of /cvsroot/jrobin/src/org/jrobin/cmd In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv20380/org/jrobin/cmd Modified Files: RrdCommander.java RrdDumpCmd.java RrdFetchCmd.java RrdLastCmd.java RrdRestoreCmd.java RrdToolCmd.java RrdXportCmd.java Added Files: RrdUpdateCmd.java Removed Files: RrdUpdateCommand.java Log Message: Completely redesigned and simplified RRDTool commander... --- NEW FILE: RrdUpdateCmd.java --- /* ============================================================ * JRobin : Pure java implementation of RRDTool's functionality * ============================================================ * * Project Info: http://www.jrobin.org * Project Lead: Sasa Markovic (sa...@jr...); * * (C) Copyright 2003, by Sasa Markovic. * * Developers: Sasa Markovic (sa...@jr...) * Arne Vandamme (cob...@jr...) * * This library is free software; you can redistribute it and/or modify it under the terms * of the GNU Lesser General Public License as published by the Free Software Foundation; * either version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License along with this * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, * Boston, MA 02111-1307, USA. */ package org.jrobin.cmd; import org.jrobin.core.*; import java.io.IOException; class RrdUpdateCmd extends RrdToolCmd { private String[] dsNames; String getCmdType() { return "update"; } Object execute() throws RrdException, IOException { String template = getOptionValue("t", "template"); if (template != null) { dsNames = template.split(":"); } String[] words = getRemainingWords(); if (words.length < 3) { throw new RrdException("Insufficent number of parameters for rrdupdate"); } String path = words[1]; RrdDb rrdDb = getRrdDbReference(path); try { if (dsNames != null) { // template specified, check datasource names for (int i = 0; i < dsNames.length; i++) { rrdDb.getDsIndex(dsNames[i]); // will throw exception if not found } } // parse update strings long timestamp = -1; for (int i = 2; i < words.length; i++) { String[] tokens = words[i].split(":"); if (dsNames != null && dsNames.length + 1 != tokens.length) { throw new RrdException("Template required " + dsNames.length + " values, " + (tokens.length - 1) + " value(s) found in: " + words[i]); } int dsCount = rrdDb.getHeader().getDsCount(); if (dsNames == null && dsCount + 1 != tokens.length) { throw new RrdException("Expected " + dsCount + " values, " + (tokens.length - 1) + " value(s) found in: " + words[i]); } TimeSpec spec = new TimeParser(tokens[0]).parse(); timestamp = spec.getTimestamp(); Sample sample = rrdDb.createSample(timestamp); for (int j = 1; j < tokens.length; j++) { if (dsNames == null) { sample.setValue(j - 1, parseDouble(tokens[j])); } else { sample.setValue(dsNames[j - 1], parseDouble(tokens[j])); } } sample.update(); } return new Long(timestamp); } finally { releaseRrdDbReference(rrdDb); } } } Index: RrdLastCmd.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/cmd/RrdLastCmd.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** RrdLastCmd.java 12 Jul 2004 13:35:17 -0000 1.1 --- RrdLastCmd.java 16 Jul 2004 07:40:48 -0000 1.2 *************** *** 32,38 **** class RrdLastCmd extends RrdToolCmd { - RrdLastCmd(RrdCmdScanner cmdScanner) { - super(cmdScanner); - } String getCmdType() { --- 32,35 ---- *************** *** 41,45 **** Object execute() throws RrdException, IOException { ! String[] words = cmdScanner.getRemainingWords(); if(words.length != 2) { throw new RrdException("Invalid rrdlast syntax"); --- 38,42 ---- Object execute() throws RrdException, IOException { ! String[] words = getRemainingWords(); if(words.length != 2) { throw new RrdException("Invalid rrdlast syntax"); Index: RrdCommander.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/cmd/RrdCommander.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** RrdCommander.java 15 Jul 2004 14:23:53 -0000 1.5 --- RrdCommander.java 16 Jul 2004 07:40:48 -0000 1.6 *************** *** 31,34 **** --- 31,35 ---- import java.io.BufferedReader; import java.io.InputStreamReader; + import java.io.File; /** *************** *** 39,43 **** private static final RrdToolCmd[] rrdCommands = { new RrdCreateCmd(), ! new RrdUpdateCommand() }; --- 40,49 ---- private static final RrdToolCmd[] rrdCommands = { new RrdCreateCmd(), ! new RrdUpdateCmd(), ! new RrdLastCmd(), ! new RrdFetchCmd(), ! new RrdDumpCmd(), ! new RrdRestoreCmd() ! }; *************** *** 121,129 **** } ! public static void main(String[] args) { System.out.println("== JRobin's RRDTool commander =="); System.out.println("Type a RRDTool command after the dollar sign and press Enter."); System.out.println("Start your RRDTool command with 'create', 'update', 'fetch' etc."); System.out.println("Use any word starting with a dot '.' to bail out"); System.out.println("================================"); RrdToolCmd.setRrdDbPoolUsed(false); --- 127,136 ---- } ! public static void main(String[] args) throws IOException { System.out.println("== JRobin's RRDTool commander =="); System.out.println("Type a RRDTool command after the dollar sign and press Enter."); System.out.println("Start your RRDTool command with 'create', 'update', 'fetch' etc."); System.out.println("Use any word starting with a dot '.' to bail out"); + System.out.println("Current directory is: " + new File(".").getCanonicalPath()); System.out.println("================================"); RrdToolCmd.setRrdDbPoolUsed(false); *************** *** 134,138 **** String s = r.readLine(); if(s.startsWith(".")) { ! System.exit(0); } execute(s); --- 141,145 ---- String s = r.readLine(); if(s.startsWith(".")) { ! return; } execute(s); Index: RrdToolCmd.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/cmd/RrdToolCmd.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** RrdToolCmd.java 15 Jul 2004 14:23:53 -0000 1.3 --- RrdToolCmd.java 16 Jul 2004 07:40:48 -0000 1.4 *************** *** 40,44 **** abstract Object execute() throws RrdException, IOException; ! public void setCommand(String command) throws RrdException { cmdScanner = new RrdCmdScanner(command); } --- 40,44 ---- abstract Object execute() throws RrdException, IOException; ! void setCommand(String command) throws RrdException { cmdScanner = new RrdCmdScanner(command); } Index: RrdFetchCmd.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/cmd/RrdFetchCmd.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** RrdFetchCmd.java 12 Jul 2004 13:37:50 -0000 1.2 --- RrdFetchCmd.java 16 Jul 2004 07:40:48 -0000 1.3 *************** *** 37,44 **** static final String DEFAULT_END = "now"; - public RrdFetchCmd(RrdCmdScanner cmdScanner) { - super(cmdScanner); - } - String getCmdType() { return "fetch"; --- 37,40 ---- *************** *** 47,69 **** Object execute() throws RrdException, IOException { // --start ! String startStr = cmdScanner.getOptionValue("s", "start", DEFAULT_START); TimeSpec spec1 = new TimeParser(startStr).parse(); // --end ! String endStr = cmdScanner.getOptionValue("e", "end", DEFAULT_END); TimeSpec spec2 = new TimeParser(endStr).parse(); long[] timestamps = TimeSpec.getTimestamps(spec1, spec2); // --resolution ! String resolutionStr = cmdScanner.getOptionValue("r", "resolution"); ! long resolution = 1; ! if(resolutionStr != null) { ! resolution = parseLong(resolutionStr); ! } // other words ! String[] tokens = cmdScanner.getRemainingWords(); ! if(tokens.length != 3) { throw new RrdException("Invalid rrdfetch syntax"); } ! String path = tokens[1]; ! String consolFun = tokens[2]; RrdDb rrdDb = getRrdDbReference(path); try { --- 43,62 ---- Object execute() throws RrdException, IOException { // --start ! String startStr = getOptionValue("s", "start", DEFAULT_START); TimeSpec spec1 = new TimeParser(startStr).parse(); // --end ! String endStr = getOptionValue("e", "end", DEFAULT_END); TimeSpec spec2 = new TimeParser(endStr).parse(); long[] timestamps = TimeSpec.getTimestamps(spec1, spec2); // --resolution ! String resolutionStr = getOptionValue("r", "resolution", "1"); ! long resolution = parseLong(resolutionStr); // other words ! String[] words = getRemainingWords(); ! if(words.length != 3) { throw new RrdException("Invalid rrdfetch syntax"); } ! String path = words[1]; ! String consolFun = words[2]; RrdDb rrdDb = getRrdDbReference(path); try { Index: RrdRestoreCmd.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/cmd/RrdRestoreCmd.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** RrdRestoreCmd.java 13 Jul 2004 11:45:39 -0000 1.1 --- RrdRestoreCmd.java 16 Jul 2004 07:40:48 -0000 1.2 *************** *** 8,14 **** class RrdRestoreCmd extends RrdToolCmd { - public RrdRestoreCmd(RrdCmdScanner cmdScanner) { - super(cmdScanner); - } String getCmdType() { --- 8,11 ---- *************** *** 17,22 **** Object execute() throws RrdException, IOException { ! boolean check = cmdScanner.getBooleanOption("r", "range-check"); ! String[] words = cmdScanner.getRemainingWords(); if(words.length != 3) { throw new RrdException("Invalid rrdrestore syntax"); --- 14,19 ---- Object execute() throws RrdException, IOException { ! boolean check = getBooleanOption("r", "range-check"); ! String[] words = getRemainingWords(); if(words.length != 3) { throw new RrdException("Invalid rrdrestore syntax"); Index: RrdDumpCmd.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/cmd/RrdDumpCmd.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** RrdDumpCmd.java 12 Jul 2004 13:35:17 -0000 1.1 --- RrdDumpCmd.java 16 Jul 2004 07:40:48 -0000 1.2 *************** *** 32,39 **** class RrdDumpCmd extends RrdToolCmd { - RrdDumpCmd(RrdCmdScanner cmdScanner) { - super(cmdScanner); - } - String getCmdType() { return "dump"; --- 32,35 ---- *************** *** 41,45 **** Object execute() throws RrdException, IOException { ! String[] words = cmdScanner.getRemainingWords(); if(words.length != 2) { throw new RrdException("Invalid rrddump syntax"); --- 37,41 ---- Object execute() throws RrdException, IOException { ! String[] words = getRemainingWords(); if(words.length != 2) { throw new RrdException("Invalid rrddump syntax"); --- RrdUpdateCommand.java DELETED --- Index: RrdXportCmd.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/cmd/RrdXportCmd.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** RrdXportCmd.java 13 Jul 2004 20:57:47 -0000 1.1 --- RrdXportCmd.java 16 Jul 2004 07:40:48 -0000 1.2 *************** *** 32,53 **** import java.io.IOException; ! /** ! * <p>Description</p> ! * ! * @author Arne Vandamme (cob...@jr...) ! */ ! public class RrdXportCmd extends RrdToolCmd ! { ! static final String DEFAULT_START = "end-1day"; ! static final String DEFAULT_END = "now"; ! ! static ! { ! keywords = new String[] { "DEF", "CDEF", "XPORT" }; ! } ! ! public RrdXportCmd( RrdCmdScanner cmdScanner ) { ! super(cmdScanner); ! } String getCmdType() { --- 32,38 ---- import java.io.IOException; ! class RrdXportCmd extends RrdToolCmd { ! static final String DEFAULT_START = "end-1day"; ! static final String DEFAULT_END = "now"; String getCmdType() { *************** *** 55,98 **** } ! Object execute() throws RrdException, IOException ! { // --start ! String startStr = cmdScanner.getOptionValue( "s", "start", DEFAULT_START ); ! TimeSpec spec1 = new TimeParser(startStr).parse(); // --end ! String endStr = cmdScanner.getOptionValue( "e", "end", DEFAULT_END ); ! TimeSpec spec2 = new TimeParser(endStr).parse(); ! long[] timestamps = TimeSpec.getTimestamps(spec1, spec2); // --step ! String resolutionStr = cmdScanner.getOptionValue( "step", null, "1" ); // Smallest step possible is default ! long resolution = parseLong( resolutionStr ); // --maxrows ! String maxrowsStr = cmdScanner.getOptionValue( "m", "maxrows", "400" ); ! int maxRows = parseInt( maxrowsStr ); ! RrdExportDef exportDef = new RrdExportDef( timestamps[0], timestamps[1] ); ! exportDef.setResolution( resolution ); ! exportDef.setStrictExport( true ); // Always use strict export in case of RrdTool command ! String[] words = cmdScanner.getRemainingWords(); ! for ( int i = 0; i < words.length; i++ ) ! { ! if ( words[i].startsWith("DEF:") ) ! parseDef( words[i], exportDef ); ! else if ( words[i].startsWith("CDEF:") ) ! parseCdef( words[i], exportDef ); ! else if ( words[i].startsWith("XPORT:") ) ! parseXport( words[i], exportDef ); } // Now create the export data ! RrdExport export = new RrdExport( exportDef ); ! ExportData data = export.fetch( maxRows ); ! System.out.println( data.exportXml() ); return data; --- 40,84 ---- } ! Object execute() throws RrdException, IOException { // --start ! String startStr = getOptionValue("s", "start", DEFAULT_START); ! TimeSpec spec1 = new TimeParser(startStr).parse(); // --end ! String endStr = getOptionValue("e", "end", DEFAULT_END); ! TimeSpec spec2 = new TimeParser(endStr).parse(); ! long[] timestamps = TimeSpec.getTimestamps(spec1, spec2); // --step ! String resolutionStr = getOptionValue("step", null, "1"); // Smallest step possible is default ! long resolution = parseLong(resolutionStr); // --maxrows ! String maxrowsStr = getOptionValue("m", "maxrows", "400"); ! int maxRows = parseInt(maxrowsStr); ! RrdExportDef exportDef = new RrdExportDef(timestamps[0], timestamps[1]); ! exportDef.setResolution(resolution); ! exportDef.setStrictExport(true); // Always use strict export in case of RrdTool command ! String[] words = getRemainingWords(); ! for (int i = 0; i < words.length; i++) { ! if (words[i].startsWith("DEF:")) ! parseDef(words[i], exportDef); ! else if (words[i].startsWith("CDEF:")) ! parseCdef(words[i], exportDef); ! else if (words[i].startsWith("XPORT:")) ! parseXport(words[i], exportDef); ! else { ! throw new RrdException("Invalid xport syntax: " + words[i]); ! } } // Now create the export data ! RrdExport export = new RrdExport(exportDef); ! ExportData data = export.fetch(maxRows); ! System.out.println(data.exportXml()); return data; *************** *** 102,118 **** * DEF:vname=rrd:ds-name:CF */ ! private void parseDef( String word, RrdExportDef def ) throws RrdException ! { String[] tokens = word.split(":"); ! if ( tokens.length != 4 ) ! throw new RrdException( "Invalid DEF command: " + word ); ! String[] token1 = tokens[1].split("="); ! if ( token1.length != 2 ) ! throw new RrdException( "Invalid DEF command: " + word ); ! def.datasource( token1[0], token1[1], tokens[2], tokens[3] ); } --- 88,103 ---- * DEF:vname=rrd:ds-name:CF */ ! private void parseDef(String word, RrdExportDef def) throws RrdException { String[] tokens = word.split(":"); ! if (tokens.length != 4) ! throw new RrdException("Invalid DEF command: " + word); ! String[] token1 = tokens[1].split("="); ! if (token1.length != 2) ! throw new RrdException("Invalid DEF command: " + word); ! def.datasource(token1[0], token1[1], tokens[2], tokens[3]); } *************** *** 120,136 **** * CDEF:vname=rpn-expression */ ! private void parseCdef( String word, RrdExportDef def ) throws RrdException ! { String[] tokens = word.split(":"); ! if ( tokens.length != 2 ) ! throw new RrdException( "Invalid CDEF command: " + word ); ! String[] token1 = tokens[1].split("="); ! if ( token1.length != 2 ) ! throw new RrdException( "Invalid CDEF command: " + word ); ! def.datasource( token1[0], token1[1] ); } --- 105,120 ---- * CDEF:vname=rpn-expression */ ! private void parseCdef(String word, RrdExportDef def) throws RrdException { String[] tokens = word.split(":"); ! if (tokens.length != 2) ! throw new RrdException("Invalid CDEF command: " + word); ! String[] token1 = tokens[1].split("="); ! if (token1.length != 2) ! throw new RrdException("Invalid CDEF command: " + word); ! def.datasource(token1[0], token1[1]); } *************** *** 138,162 **** * XPORT:vname:legend */ ! private void parseXport( String word, RrdExportDef def ) throws RrdException ! { String[] tokens = word.split(":"); ! if ( tokens.length < 2 || tokens.length > 3 ) ! throw new RrdException( "Invalid XPORT command: " + word ); ! if ( tokens.length == 2 ) ! def.export( tokens[1] ); else ! def.export( tokens[1], tokens[2] ); } ! ! public static void main( String[] args ) throws Exception ! { String cmd = "xport --start now-1h --end now DEF:xx=host-inout.lo.rrd:output:AVERAGE DEF:yy=host-inout.lo.rrd:input:AVERAGE CDEF:aa=xx,yy,+,8,* " ! + "XPORT:xx:\"out bytes\" XPORT:aa:\"in and out bits\""; cmd = "xport --start now-1h --end now -m 10 DEF:xx=/code/idea-projects/jrobin/res/demo/eth0.rrd:ifOutOctets:AVERAGE XPORT:xx:outgoing traffic"; ! RrdCommander.execute( cmd ); } } --- 122,145 ---- * XPORT:vname:legend */ ! private void parseXport(String word, RrdExportDef def) throws RrdException { String[] tokens = word.split(":"); ! if (tokens.length < 2 || tokens.length > 3) ! throw new RrdException("Invalid XPORT command: " + word); ! if (tokens.length == 2) ! def.export(tokens[1]); else ! def.export(tokens[1], tokens[2]); } ! /* ! public static void main(String[] args) throws Exception { String cmd = "xport --start now-1h --end now DEF:xx=host-inout.lo.rrd:output:AVERAGE DEF:yy=host-inout.lo.rrd:input:AVERAGE CDEF:aa=xx,yy,+,8,* " ! + "XPORT:xx:\"out bytes\" XPORT:aa:\"in and out bits\""; cmd = "xport --start now-1h --end now -m 10 DEF:xx=/code/idea-projects/jrobin/res/demo/eth0.rrd:ifOutOctets:AVERAGE XPORT:xx:outgoing traffic"; ! RrdCommander.execute(cmd); } + */ } |
From: Sasa M. <sa...@us...> - 2004-07-16 07:40:58
|
Update of /cvsroot/jrobin/src/org/jrobin/core In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv20380/org/jrobin/core Modified Files: RrdNioBackend.java Log Message: Completely redesigned and simplified RRDTool commander... Index: RrdNioBackend.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/core/RrdNioBackend.java,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** RrdNioBackend.java 15 Jul 2004 14:22:12 -0000 1.12 --- RrdNioBackend.java 16 Jul 2004 07:40:49 -0000 1.13 *************** *** 37,40 **** --- 37,62 ---- */ public class RrdNioBackend extends RrdFileBackend { + /** + * Defines if the <code>System.gc()</code> method should be executed when necessary. + * NIO backend uses large in-memory buffer to cache file data. The buffer remains 'active' + * (by prohibiting file re-creation, for example) as long as it is not garbage collected. + * By forcing <code>gc()</code> where appropriate, memory gets freed sooner and file + * re-creation won't fail.<p> + * + * The constant is set to false initially and currently there is no API to change it + * during runtime.<p> + */ + public static final boolean SHOULD_GC = true; + + static { + if(SHOULD_GC) { + Runtime.getRuntime().addShutdownHook(new Thread() { + public void run() { + System.gc(); + } + }); + } + } + private static final Timer syncTimer = new Timer(true); *************** *** 46,53 **** throws IOException { super(path, readOnly, lockMode); this.syncMode = syncMode; - FileChannel.MapMode mapMode = - readOnly? FileChannel.MapMode.READ_ONLY: FileChannel.MapMode.READ_WRITE; - this.byteBuffer = channel.map(mapMode, 0, getLength()); if(syncMode == RrdNioBackendFactory.SYNC_BACKGROUND && !readOnly) { createSyncTask(syncPeriod); --- 68,73 ---- throws IOException { super(path, readOnly, lockMode); + map(false, readOnly); this.syncMode = syncMode; if(syncMode == RrdNioBackendFactory.SYNC_BACKGROUND && !readOnly) { createSyncTask(syncPeriod); *************** *** 55,58 **** --- 75,93 ---- } + private void map(boolean isShorter, boolean readOnly) throws IOException { + if(isShorter) { + byteBuffer = null; + if(SHOULD_GC) { + System.gc(); + } + } + long newLength = getLength(); + if(newLength > 0) { + FileChannel.MapMode mapMode = + readOnly? FileChannel.MapMode.READ_ONLY: FileChannel.MapMode.READ_WRITE; + byteBuffer = channel.map(mapMode, 0, newLength); + } + } + private void createSyncTask(int syncPeriod) { syncTask = new TimerTask() { *************** *** 67,76 **** * Sets length of the underlying RRD file. This method is called only once, immediately * after a new RRD file gets created. ! * @param length Length of the RRD file * @throws IOException Thrown in case of I/O error. */ ! protected void setLength(long length) throws IOException { ! super.setLength(length); ! byteBuffer = channel.map(FileChannel.MapMode.READ_WRITE, 0, length); } --- 102,112 ---- * Sets length of the underlying RRD file. This method is called only once, immediately * after a new RRD file gets created. ! * @param newLength Length of the RRD file * @throws IOException Thrown in case of I/O error. */ ! protected void setLength(long newLength) throws IOException { ! boolean isShorter = newLength < getLength(); ! super.setLength(newLength); ! map(isShorter, false); } *************** *** 120,126 **** */ public void sync() { ! synchronized(byteBuffer) { ! // System.out.println("** SYNC **"); ! byteBuffer.force(); } } --- 156,164 ---- */ public void sync() { ! if(byteBuffer != null) { ! synchronized(byteBuffer) { ! // System.out.println("** SYNC **"); ! byteBuffer.force(); ! } } } |
From: Sasa M. <sa...@us...> - 2004-07-15 14:24:11
|
Update of /cvsroot/jrobin/src/org/jrobin/cmd In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv11635/org/jrobin/cmd Modified Files: RrdCmdScanner.java RrdCommander.java RrdCreateCmd.java RrdToolCmd.java RrdUpdateCommand.java Log Message: Major changes and simplifications... Index: RrdCmdScanner.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/cmd/RrdCmdScanner.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** RrdCmdScanner.java 13 Jul 2004 20:57:44 -0000 1.2 --- RrdCmdScanner.java 15 Jul 2004 14:23:53 -0000 1.3 *************** *** 29,179 **** import java.util.LinkedList; ! import java.util.regex.Pattern; ! import java.util.regex.Matcher; class RrdCmdScanner { ! //private static final Pattern PATTERN = Pattern.compile("([^\"\\s]*\"[^\"]*\")|([^\"\\s]+)"); ! ! private String cmdType; ! private String command; ! ! private LinkedList options = new LinkedList(); ! private LinkedList words = new LinkedList(); ! RrdCmdScanner(String[] cmdWords) { ! for(int i = 0; i < cmdWords.length; i++) { ! words.add(cmdWords[i]); ! if(words.size() == 1) { ! cmdType = cmdWords[i]; } } } ! RrdCmdScanner( String command ) ! { ! // Set the command type only ! String cmd = command.trim(); ! int typePos = command.indexOf( ' ' ); ! cmdType = cmd.substring( 0, typePos ); ! ! this.command = cmd.substring( typePos ).trim(); ! ! //parseWords(command); ! } ! ! protected void parse( String[] keywords ) ! { ! StringBuffer sbuf = new StringBuffer( "( -)"); ! ! for ( int i = 0; i < keywords.length; i++ ) ! sbuf.append( "|( " + keywords[i] + ":)" ); ! ! Pattern pattern = Pattern.compile( sbuf.toString() ); ! ! parseWords( command, pattern ); } ! private void parseWords( String command, Pattern pattern ) ! { ! int start = 0, stop = 0; ! ! Matcher m = pattern.matcher(command); ! ! while ( m.find() ) ! { ! if ( start == 0 ) ! start = m.start(); ! else ! { ! stop = m.start(); ! ! // Put this 'word' away ! storeWord( command.substring( start, stop ).trim() ); ! ! // This is a new start ! start = stop; ! stop = 0; ! } } ! ! // Ok, see if we have to put the last word away ! if ( start > 0 && stop == 0 ) ! storeWord( command.substring( start ).trim() ); } ! private void storeWord( String word ) ! { ! if ( word.charAt(0) == '-' ) // This is an option ! options.add( word ); ! else // This is a general 'word' ! { ! // TODO: Remove \ characters or other 'in between' characters that are used in scripting ! // TODO: Remove leading single and double quotes in text, make sure all special characters are detected and treated okay ! // TODO: Best way to try this probably to put the code from: http://www.jrobin.org/phpBB2/viewtopic.php?t=39 in a file ! // TODO: read that file in, and then see if the resulting string parses correctly ! words.add( word ); } } ! /* ! private void parseWords2(String command) { ! // Make this a bit more complex, read until ' -', or keyword ! Matcher m = PATTERN.matcher(command); ! while(m.find()) { ! String word = m.group(); ! word = word.replaceAll("\"", ""); ! // System.out.println("Adding: [" + word + "]"); ! words.add(word); ! if(words.size() == 1) { ! cmdType = word; ! } } } - */ ! String getCmdType() { ! return cmdType; } ! String getOptionValue( String shortFormWord, String longFormWord ) throws RrdException ! { ! String shortForm = "-" + shortFormWord; ! String longForm = "--" + longFormWord; ! ! for ( int i = 0; i < options.size(); i++ ) ! { ! String value = null; ! String option = (String) options.get( i ); ! ! if ( shortForm != null && option.startsWith( shortForm ) ) ! value = option.substring( shortForm.length() ).trim(); ! else if ( longForm != null && option.startsWith( longForm ) ) ! { ! // Next character might be = ! value = option.substring( longForm.length() ).trim(); ! if ( value.length() > 1 && value.charAt(0) == '=' ) ! value = value.substring( 1 ); ! } ! ! if ( value != null ) ! { ! options.remove( i ); ! ! return value; } } ! // Option not found ! return null; } ! /* ! String getOptionValue(String shortForm, String longForm) throws RrdException { for(int i = 0; i < words.size(); i++) { String word = (String) words.get(i); ! if((shortForm != null && word.equals("-" + shortForm)) || ! (longForm != null && word.equals("--" + longForm))) { ! // match found ! if(i < words.size() - 1) { ! // value available String value = (String) words.get(i + 1); words.remove(i + 1); --- 29,139 ---- import java.util.LinkedList; ! import java.io.BufferedReader; ! import java.io.InputStreamReader; ! import java.io.IOException; class RrdCmdScanner { ! private LinkedList words = new LinkedList(); ! private StringBuffer buff; ! RrdCmdScanner(String command) throws RrdException { ! String cmd = command.trim(); ! // parse words ! char activeQuote = 0; ! for(int i = 0; i < cmd.length(); i++) { ! char c = cmd.charAt(i); ! if((c == '"' || c == '\'') && activeQuote == 0) { ! // opening double or single quote ! initWord(); ! activeQuote = c; ! continue; ! } ! if(c == activeQuote) { ! // closing quote ! activeQuote = 0; ! continue; ! } ! if(c == ' ' && activeQuote == 0) { ! // separator encountered ! finishWord(); ! continue; } + if(c == '\\' && activeQuote == '"' && i + 1 < cmd.length()) { + // check for \" and \\ inside double quotes + char c2 = cmd.charAt(i + 1); + if(c2 == '\\' || c2 == '"') { + appendWord(c2); + i++; + continue; + } + } + // ordinary character + appendWord(c); } + if(activeQuote != 0) { + throw new RrdException("End of command reached but " + activeQuote + " expected"); + } + finishWord(); } ! String getCmdType() { ! if(words.size() > 0) { ! return (String) words.get(0); ! } ! else { ! return null; ! } } ! private void appendWord(char c) { ! if(buff == null) { ! buff = new StringBuffer(""); } ! buff.append(c); } ! private void finishWord() { ! if(buff != null) { ! words.add(buff.toString()); ! buff = null; } } ! private void initWord() { ! if(buff == null) { ! buff = new StringBuffer(""); } } ! void dump() { ! for(int i = 0; i < words.size(); i++) { ! System.out.println(words.get(i)); ! } } ! String getOptionValue(String shortForm, String longForm, String defaultValue) ! throws RrdException { ! String value = getOptionValue("-" + shortForm); ! if(value == null) { ! value = getOptionValue("--" + longForm); ! if(value == null) { ! value = defaultValue; } } + return value; + } ! String getOptionValue(String shortForm, String longForm) ! throws RrdException { ! return getOptionValue(shortForm, longForm, null); } ! ! private String getOptionValue(String fullForm) throws RrdException { for(int i = 0; i < words.size(); i++) { String word = (String) words.get(i); ! if(word.equals(fullForm)) { ! // full match ! // the value is in the next word ! if(i + 1 < words.size()) { String value = (String) words.get(i + 1); words.remove(i + 1); *************** *** 182,209 **** } else { ! throw new RrdException("Option found but value is not available"); } } } return null; } - */ ! String getOptionValue(String shortForm, String longForm, String defaultValue) throws RrdException { ! String value = getOptionValue(shortForm, longForm); ! return value != null? value: defaultValue; ! } ! ! boolean getBooleanOption(String shortForm, String longForm) throws RrdException { ! return (getOptionValue( shortForm, longForm ) != null); ! } ! ! /* ! boolean getBooleanOption2(String shortForm, String longForm) throws RrdException { for(int i = 0; i < words.size(); i++) { String word = (String) words.get(i); ! if((shortForm != null && word.equals("-" + shortForm)) || ! (longForm != null && word.equals("--" + longForm))) { ! // match found words.remove(i); return true; --- 142,165 ---- } else { ! throw new RrdException("Value for option " + fullForm + " expected but not found"); } } + if(word.startsWith(fullForm)) { + int pos = fullForm.length(); + if(word.charAt(pos) == '=') { + // skip '=' if present + pos++; + } + words.remove(i); + return word.substring(pos); + } } return null; } ! boolean getBooleanOption(String shortForm, String longForm) { for(int i = 0; i < words.size(); i++) { String word = (String) words.get(i); ! if(word.equals("-" + shortForm) || word.equals("--" + longForm)) { words.remove(i); return true; *************** *** 212,219 **** return false; } - */ String[] getRemainingWords() { return (String[]) words.toArray(new String[0]); } } --- 168,190 ---- return false; } String[] getRemainingWords() { return (String[]) words.toArray(new String[0]); } + + public static void main(String[] args) { + BufferedReader r = new BufferedReader(new InputStreamReader(System.in)); + while (true) { + try { + System.out.print("$ "); + String s = r.readLine(); + RrdCmdScanner sc = new RrdCmdScanner(s); + System.out.println("Value for option x is: [" + sc.getOptionValue("x", "xx") + "]"); + } catch (IOException e) { + System.err.println(e); + } catch (RrdException e) { + System.err.println(e); + } + } + } } Index: RrdToolCmd.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/cmd/RrdToolCmd.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** RrdToolCmd.java 13 Jul 2004 20:57:47 -0000 1.2 --- RrdToolCmd.java 15 Jul 2004 14:23:53 -0000 1.3 *************** *** 35,40 **** abstract class RrdToolCmd { ! // Holds the list of keywords ! static String[] keywords = new String[0]; static boolean rrdDbPoolUsed = true; --- 35,62 ---- abstract class RrdToolCmd { ! private RrdCmdScanner cmdScanner; ! ! abstract String getCmdType(); ! abstract Object execute() throws RrdException, IOException; ! ! public void setCommand(String command) throws RrdException { ! cmdScanner = new RrdCmdScanner(command); ! } ! ! String getOptionValue(String shortForm, String longForm) throws RrdException { ! return cmdScanner.getOptionValue(shortForm, longForm); ! } ! ! String getOptionValue(String shortForm, String longForm, String defaultValue) throws RrdException { ! return cmdScanner.getOptionValue(shortForm, longForm, defaultValue); ! } ! ! boolean getBooleanOption(String shortForm, String longForm) { ! return cmdScanner.getBooleanOption(shortForm, longForm); ! } ! ! String[] getRemainingWords() { ! return cmdScanner.getRemainingWords(); ! } static boolean rrdDbPoolUsed = true; *************** *** 57,83 **** } - - RrdCmdScanner cmdScanner; - - RrdToolCmd(RrdCmdScanner cmdScanner) { - this.cmdScanner = cmdScanner; - } - - abstract String getCmdType(); - - Object go() throws IOException, RrdException - { - if(!getCmdType().equals(cmdScanner.getCmdType())) { - return null; - } - - // Parse the command based on the keywords - cmdScanner.parse( keywords ); - - return execute(); - } - - abstract Object execute() throws RrdException, IOException; - static long parseLong(String value) throws RrdException { try { --- 79,82 ---- Index: RrdCreateCmd.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/cmd/RrdCreateCmd.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** RrdCreateCmd.java 12 Jul 2004 13:35:17 -0000 1.1 --- RrdCreateCmd.java 15 Jul 2004 14:23:53 -0000 1.2 *************** *** 38,45 **** private RrdDef rrdDef; - public RrdCreateCmd(RrdCmdScanner cmdScanner) { - super(cmdScanner); - } - String getCmdType() { return "create"; --- 38,41 ---- *************** *** 47,56 **** Object execute() throws RrdException, IOException { ! String startStr = cmdScanner.getOptionValue("b", "start", DEFAULT_START); TimeSpec spec = new TimeParser(startStr).parse(); long start = spec.getTimestamp(); ! String stepStr = cmdScanner.getOptionValue("s", "step", DEFAULT_STEP); long step = parseLong(stepStr); ! String[] words = cmdScanner.getRemainingWords(); if(words.length < 2) { throw new RrdException("RRD file path not specified"); --- 43,52 ---- Object execute() throws RrdException, IOException { ! String startStr = getOptionValue("b", "start", DEFAULT_START); TimeSpec spec = new TimeParser(startStr).parse(); long start = spec.getTimestamp(); ! String stepStr = getOptionValue("s", "step", DEFAULT_STEP); long step = parseLong(stepStr); ! String[] words = getRemainingWords(); if(words.length < 2) { throw new RrdException("RRD file path not specified"); *************** *** 66,70 **** } else { ! throw new RrdException("Invalid word in the rrdcreate syntax: " + words[i]); } } --- 62,66 ---- } else { ! throw new RrdException("Invalid rrdcreate syntax: " + words[i]); } } Index: RrdUpdateCommand.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/cmd/RrdUpdateCommand.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** RrdUpdateCommand.java 12 Jul 2004 13:35:17 -0000 1.1 --- RrdUpdateCommand.java 15 Jul 2004 14:23:53 -0000 1.2 *************** *** 32,39 **** private String[] dsNames; - RrdUpdateCommand(RrdCmdScanner cmdScanner) { - super(cmdScanner); - } - String getCmdType() { return "update"; --- 32,35 ---- *************** *** 41,49 **** Object execute() throws RrdException, IOException { ! String template = cmdScanner.getOptionValue("t", "template"); if (template != null) { dsNames = template.split(":"); } ! String[] words = cmdScanner.getRemainingWords(); if (words.length < 3) { throw new RrdException("Insufficent number of parameters for rrdupdate"); --- 37,45 ---- Object execute() throws RrdException, IOException { ! String template = getOptionValue("t", "template"); if (template != null) { dsNames = template.split(":"); } ! String[] words = getRemainingWords(); if (words.length < 3) { throw new RrdException("Insufficent number of parameters for rrdupdate"); Index: RrdCommander.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/cmd/RrdCommander.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** RrdCommander.java 13 Jul 2004 20:57:47 -0000 1.4 --- RrdCommander.java 15 Jul 2004 14:23:53 -0000 1.5 *************** *** 36,39 **** --- 36,45 ---- */ public class RrdCommander { + // just add all new commands here + private static final RrdToolCmd[] rrdCommands = { + new RrdCreateCmd(), + new RrdUpdateCommand() + }; + /** * Checks if the output from any RRDTool command will be visible on the standard output device *************** *** 105,143 **** public static synchronized Object execute(String command) throws IOException, RrdException { ! RrdCmdScanner cmdScanner = new RrdCmdScanner(command); ! RrdToolCmd[] commanders = { ! new RrdCreateCmd(cmdScanner), ! new RrdLastCmd(cmdScanner), ! new RrdUpdateCommand(cmdScanner), ! new RrdDumpCmd(cmdScanner), ! new RrdFetchCmd(cmdScanner), ! new RrdRestoreCmd(cmdScanner) ! }; ! for(int i = 0; i < commanders.length; i++) { ! Object result = commanders[i].go(); ! if(result != null) { ! return result; } } throw new RrdException("Unknown RRDTool command: " + command); } - /*public static synchronized Object execute(String command) throws IOException, RrdException { - RrdCmdScanner cmdScanner = new RrdCmdScanner(command); - RrdToolCmd[] commanders = { - new RrdCreateCmd(cmdScanner), - new RrdLastCmd(cmdScanner), - new RrdUpdateCommand(cmdScanner), - new RrdDumpCmd(cmdScanner), - new RrdFetchCmd(cmdScanner), - new RrdXportCmd(cmdScanner) - }; - for(int i = 0; i < commanders.length; i++) { - Object result = commanders[i].go(); - if(result != null) { - return result; - } - } - throw new RrdException("Unknown RRDTool command: " + command); - }*/ public static void main(String[] args) { --- 111,123 ---- public static synchronized Object execute(String command) throws IOException, RrdException { ! String cmd = command.trim(); ! for(int i = 0; i < rrdCommands.length; i++) { ! if(cmd.startsWith(rrdCommands[i].getCmdType())) { ! rrdCommands[i].setCommand(cmd); ! return rrdCommands[i].execute(); } } throw new RrdException("Unknown RRDTool command: " + command); } public static void main(String[] args) { *************** *** 147,150 **** --- 127,131 ---- System.out.println("Use any word starting with a dot '.' to bail out"); System.out.println("================================"); + RrdToolCmd.setRrdDbPoolUsed(false); BufferedReader r = new BufferedReader(new InputStreamReader(System.in)); while (true) { *************** *** 157,163 **** execute(s); } catch (IOException e) { ! System.err.println(e); } catch (RrdException e) { ! System.err.println(e); } } --- 138,144 ---- execute(s); } catch (IOException e) { ! e.printStackTrace(); } catch (RrdException e) { ! e.printStackTrace(); } } |
From: Sasa M. <sa...@us...> - 2004-07-15 14:22:27
|
Update of /cvsroot/jrobin/src/org/jrobin/core In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv11359/org/jrobin/core Modified Files: RrdNioBackend.java Log Message: Minor changes Index: RrdNioBackend.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/core/RrdNioBackend.java,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** RrdNioBackend.java 14 Jul 2004 08:59:55 -0000 1.11 --- RrdNioBackend.java 15 Jul 2004 14:22:12 -0000 1.12 *************** *** 37,52 **** */ public class RrdNioBackend extends RrdFileBackend { - /** - * Defines if the <code>System.gc()</code> method should be executed when the backend is closed. - * NIO backend uses large in-memory buffer to cache file data. The buffer remains 'active' - * (by prohibiting file re-creation, for example) as long as it is not garbage collected. - * By forcing <code>gc()</code> after the file is closed memory gets freed sooner and file - * re-creation won't fail.<p> - * - * The constant is set to false initially and currently there is no API to change it - * during runtime.<p> - */ - public static final boolean SHOULD_GC_AFTER_CLOSE = false; - private static final Timer syncTimer = new Timer(true); --- 37,40 ---- *************** *** 123,130 **** // release the buffer, make it eligible for GC as soon as possible byteBuffer = null; - if(SHOULD_GC_AFTER_CLOSE) { - // I am not happy with this, but it might be necessary in the future - System.gc(); - } } --- 111,114 ---- |
From: Sasa M. <sa...@us...> - 2004-07-15 07:49:25
|
Update of /cvsroot/jrobin/src/org/jrobin/demo/graph In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10276/org/jrobin/demo/graph Modified Files: SwingDemo.java SwingDemoPanel.java Log Message: Graph gets resized when frame gets resized. Index: SwingDemo.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/demo/graph/SwingDemo.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** SwingDemo.java 11 Jul 2004 22:06:55 -0000 1.1 --- SwingDemo.java 15 Jul 2004 07:49:10 -0000 1.2 *************** *** 32,35 **** --- 32,37 ---- import java.io.IOException; import java.awt.*; + import java.awt.event.ComponentAdapter; + import java.awt.event.ComponentEvent; import java.util.Date; *************** *** 41,48 **** public class SwingDemo { ! static JFrame frame = null; ! static JPanel demoPanel = null; ! static RrdGraph graph = null; ! static RrdGraphDef gDef = null; static final String rrd = "SwingDemo.rrd"; --- 43,50 ---- public class SwingDemo { ! static JFrame frame = null; ! static SwingDemoPanel demoPanel = null; ! static RrdGraph graph = null; ! static RrdGraphDef gDef = null; static final String rrd = "SwingDemo.rrd"; *************** *** 80,84 **** gDef.time( "@l@lTime period: @t", "MMM dd, yyyy HH:mm:ss", START ); gDef.time( "to @t@l", "HH:mm:ss", end ); ! gDef.time("@l@lGenerated: @t@c", "HH:mm:ss" ); // create graph finally --- 82,86 ---- gDef.time( "@l@lTime period: @t", "MMM dd, yyyy HH:mm:ss", START ); gDef.time( "to @t@l", "HH:mm:ss", end ); ! gDef.time("@lGenerated: @t@c", "HH:mm:ss" ); // create graph finally *************** *** 93,96 **** --- 95,105 ---- frame.pack(); + + frame.addComponentListener(new ComponentAdapter() { + public void componentResized(ComponentEvent e) { + Dimension d = frame.getContentPane().getSize(); + demoPanel.setGraphDimension(d); + } + }); frame.setBounds( 10, 10, 504, 303 ); frame.show(); Index: SwingDemoPanel.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/demo/graph/SwingDemoPanel.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** SwingDemoPanel.java 11 Jul 2004 22:06:55 -0000 1.1 --- SwingDemoPanel.java 15 Jul 2004 07:49:10 -0000 1.2 *************** *** 38,41 **** --- 38,42 ---- { private RrdGraph graph; + private int width, height; SwingDemoPanel( RrdGraph graph ) *************** *** 50,54 **** // Render the image directly on the Graphics object of the JPanel // Width and height of 0 means autoscale the graph ! graph.renderImage( (Graphics2D) g, 0, 0 ); } catch ( Exception e ) { --- 51,57 ---- // Render the image directly on the Graphics object of the JPanel // Width and height of 0 means autoscale the graph ! graph.specifyImageSize(true); ! graph.renderImage( (Graphics2D) g, width, height ); ! } catch ( Exception e ) { *************** *** 56,58 **** --- 59,67 ---- } } + + void setGraphDimension(Dimension d) { + width = d.width; + height = d.height; + repaint(); + } } |