You can subscribe to this list here.
2003 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
(11) |
Oct
(60) |
Nov
(68) |
Dec
(10) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2004 |
Jan
(10) |
Feb
(15) |
Mar
(30) |
Apr
(20) |
May
(32) |
Jun
(30) |
Jul
(61) |
Aug
(13) |
Sep
(14) |
Oct
(13) |
Nov
(28) |
Dec
(10) |
2005 |
Jan
(7) |
Feb
(5) |
Mar
|
Apr
(2) |
May
|
Jun
|
Jul
|
Aug
|
Sep
(4) |
Oct
|
Nov
|
Dec
|
2006 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
(15) |
2007 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
(20) |
Aug
(35) |
Sep
(3) |
Oct
(2) |
Nov
|
Dec
|
2008 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
(14) |
Sep
(2) |
Oct
|
Nov
|
Dec
|
2010 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
(3) |
2011 |
Jan
|
Feb
|
Mar
|
Apr
(5) |
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
From: Arne V. <cob...@us...> - 2004-04-21 09:50:20
|
Update of /cvsroot/jrobin/src/org/jrobin/graph In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21125/src/org/jrobin/graph Modified Files: RrdGraph.java RrdGraphDef.java TimeGrid.java Grapher.java TimeAxisUnit.java ValueGrid.java Log Message: JRobin 1.3.1 DEBUG UPDATE - testing purposes - Improved Value Grid calculation - Added setFirstDayOfWeek option to RrdGraphDef Index: Grapher.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/graph/Grapher.java,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** Grapher.java 19 Apr 2004 22:35:00 -0000 1.9 --- Grapher.java 21 Apr 2004 09:49:01 -0000 1.10 *************** *** 304,310 **** { // Get the rrdDb ! src = (FetchSource) fetchSources.next(); ! String rrdFile = src.getRrdFile(); ! rrd = rrdGraph.getRrd( rrdFile ); // If the endtime is 0, use the last time a database was updated --- 304,310 ---- { // Get the rrdDb ! src = (FetchSource) fetchSources.next(); ! String rrdFile = src.getRrdFile(); ! rrd = rrdGraph.getRrd( rrdFile ); // If the endtime is 0, use the last time a database was updated *************** *** 520,524 **** vGrid = new ValueGrid( range, lowerValue, upperValue, graphDef.getValueAxis(), graphDef.getBaseValue() ); ! tGrid = new TimeGrid( graphDef.getStartTime(), ( graphDef.getEndTime() != 0 ? graphDef.getEndTime() : calculatedEndTime ), graphDef.getTimeAxis() ); lowerValue = vGrid.getLowerValue(); --- 520,524 ---- vGrid = new ValueGrid( range, lowerValue, upperValue, graphDef.getValueAxis(), graphDef.getBaseValue() ); ! tGrid = new TimeGrid( graphDef.getStartTime(), ( graphDef.getEndTime() != 0 ? graphDef.getEndTime() : calculatedEndTime ), graphDef.getTimeAxis(), graphDef.getFirstDayOfWeek() ); lowerValue = vGrid.getLowerValue(); Index: ValueGrid.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/graph/ValueGrid.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** ValueGrid.java 19 Apr 2004 22:35:00 -0000 1.5 --- ValueGrid.java 21 Apr 2004 09:49:01 -0000 1.6 *************** *** 149,153 **** double left = shifted % scaleValues[scaleIndex + 1]; shifted = shifted / scaleValues[++scaleIndex]; ! // While rest > 10, divide by 10 while ( shifted > 10.0 ) { --- 149,153 ---- double left = shifted % scaleValues[scaleIndex + 1]; shifted = shifted / scaleValues[++scaleIndex]; ! // While rest > 10, divide by 10 while ( shifted > 10.0 ) { *************** *** 162,170 **** left = left / scaleValues[scaleIndex]; ! if ( left > 0.9 || left == 0.00 ) { scaleIndex--; mod = 1.0; } // Create nice grid based on 'fixed' ranges if ( shifted <= 1.5 ) --- 162,173 ---- left = left / scaleValues[scaleIndex]; ! ! ! if ( left == 0.00 ) { scaleIndex--; mod = 1.0; } + // Create nice grid based on 'fixed' ranges if ( shifted <= 1.5 ) Index: RrdGraph.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/graph/RrdGraph.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** RrdGraph.java 30 Mar 2004 22:57:45 -0000 1.6 --- RrdGraph.java 21 Apr 2004 09:48:54 -0000 1.7 *************** *** 369,386 **** RrdDb getRrd( String rrdFile ) throws IOException, RrdException { ! if ( pool != null ) { return pool.requestRrdDb( rrdFile ); - } else ! return new RrdDb( rrdFile ); } ! void releaseRrd(RrdDb rrdDb) throws RrdException, IOException { ! if(pool != null) { pool.release(rrdDb); ! } ! else { rrdDb.close(); - } } --- 369,384 ---- RrdDb getRrd( String rrdFile ) throws IOException, RrdException { ! if ( pool != null ) return pool.requestRrdDb( rrdFile ); else ! return new RrdDb( rrdFile, true ); } ! void releaseRrd(RrdDb rrdDb) throws RrdException, IOException ! { ! if ( pool != null ) pool.release(rrdDb); ! else rrdDb.close(); } Index: TimeAxisUnit.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/graph/TimeAxisUnit.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** TimeAxisUnit.java 19 Apr 2004 22:35:00 -0000 1.5 --- TimeAxisUnit.java 21 Apr 2004 09:49:01 -0000 1.6 *************** *** 49,66 **** // Indices in the calendarUnit table ! /** constant for seconds */ ! public static final int SECOND = 0; ! /** constant for minutes */ ! public static final int MINUTE = 1; ! /** constant for hours */ ! public static final int HOUR = 2; ! /** constant for days */ ! public static final int DAY = 3; ! /** constant for weeks */ ! public static final int WEEK = 4; ! /** constant for months */ ! public static final int MONTH = 5; ! /** constant for years */ ! public static final int YEAR = 6; private static final String[] UNIT_NAMES = { --- 49,68 ---- // Indices in the calendarUnit table ! public static final int SECOND = 0; /** constant for seconds */ ! public static final int MINUTE = 1; /** constant for minutes */ ! public static final int HOUR = 2; /** constant for hours */ ! public static final int DAY = 3; /** constant for days */ ! public static final int WEEK = 4; /** constant for weeks */ ! public static final int MONTH = 5; /** constant for months */ ! public static final int YEAR = 6; /** constant for years */ ! ! // Days of the week ! public static final int MONDAY = Calendar.MONDAY; ! public static final int TUESDAY = Calendar.TUESDAY; ! public static final int WEDNESDAY = Calendar.WEDNESDAY; ! public static final int THURSDAY = Calendar.THURSDAY; ! public static final int FRIDAY = Calendar.FRIDAY; ! public static final int SATURDAY = Calendar.SATURDAY; ! public static final int SUNDAY = Calendar.SUNDAY; private static final String[] UNIT_NAMES = { *************** *** 75,78 **** --- 77,82 ---- private boolean centerLabels = false; private SimpleDateFormat dateFormat = new SimpleDateFormat("HH:mm", Locale.ENGLISH ); + + private int firstDayOfWeek = MONDAY; // first day of a week *************** *** 95,102 **** * @param dateFormat Format to use to convert the specific time into a label string. * @param centerLabels True if labels (major grid) should be centered between two major grid lines. */ TimeAxisUnit( int minGridTimeUnit, int minGridUnitSteps, int majGridTimeUnit, int majGridUnitSteps, ! SimpleDateFormat dateFormat, boolean centerLabels ) { this.minGridTimeUnit = minGridTimeUnit; --- 99,107 ---- * @param dateFormat Format to use to convert the specific time into a label string. * @param centerLabels True if labels (major grid) should be centered between two major grid lines. + * @param firstDayOfWeek First day of a calendar week. */ TimeAxisUnit( int minGridTimeUnit, int minGridUnitSteps, int majGridTimeUnit, int majGridUnitSteps, ! SimpleDateFormat dateFormat, boolean centerLabels, int firstDayOfWeek ) { this.minGridTimeUnit = minGridTimeUnit; *************** *** 106,109 **** --- 111,115 ---- this.dateFormat = new SimpleDateFormat( dateFormat.toPattern(), Locale.ENGLISH ); this.centerLabels = centerLabels; + this.firstDayOfWeek = firstDayOfWeek; } *************** *** 240,245 **** { t.setTimeInMillis( exactStart ); - t.setFirstDayOfWeek(Calendar.MONDAY); for (int i = 0; i < HOUR && i <= unit; i++) t.set( calendarUnit[i], 0 ); --- 246,251 ---- { t.setTimeInMillis( exactStart ); + t.setFirstDayOfWeek( firstDayOfWeek ); for (int i = 0; i < HOUR && i <= unit; i++) t.set( calendarUnit[i], 0 ); Index: RrdGraphDef.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/graph/RrdGraphDef.java,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** RrdGraphDef.java 1 Mar 2004 08:50:25 -0000 1.8 --- RrdGraphDef.java 21 Apr 2004 09:48:58 -0000 1.9 *************** *** 102,105 **** --- 102,107 ---- private int chart_lpadding = Grapher.CHART_LPADDING; // padding space on the left of the chart area + private int firstDayOfWeek = TimeAxisUnit.MONDAY; // first day of a calendar week, default: monday + private double baseValue = ValueFormatter.DEFAULT_BASE; // unit base value to use (default: 1000) private int scaleIndex = ValueFormatter.NO_SCALE; // fixed units exponent value to use *************** *** 599,605 **** majGridUnitSteps, new SimpleDateFormat( dateFormat ), ! centerLabels ); } /** --- 601,618 ---- majGridUnitSteps, new SimpleDateFormat( dateFormat ), ! centerLabels , ! firstDayOfWeek ); } + + /** + * Sets the first day of a calendar week, defaults to monday if not set. + * + * @param day Weekday, 0 for sunday, 6 for saturday. + */ + public void setFirstDayOfWeek( int day ) + { + firstDayOfWeek = day; + } /** *************** *** 1192,1195 **** --- 1205,1212 ---- } + protected int getFirstDayOfWeek() { + return firstDayOfWeek; + } + protected PlotDef[] getPlotDefs() { Index: TimeGrid.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/graph/TimeGrid.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** TimeGrid.java 1 Mar 2004 08:50:25 -0000 1.2 --- TimeGrid.java 21 Apr 2004 09:49:01 -0000 1.3 *************** *** 53,58 **** * @param tAxis TimeAxisUnit specified to determine the grid lines, if the given * TimeAxisUnit is null, one will be automatically determined. */ ! TimeGrid( long startTime, long endTime, TimeAxisUnit tAxis ) { this.startTime = startTime; --- 53,59 ---- * @param tAxis TimeAxisUnit specified to determine the grid lines, if the given * TimeAxisUnit is null, one will be automatically determined. + * @param firstDayOfWeek First day of a calendar week. */ ! TimeGrid( long startTime, long endTime, TimeAxisUnit tAxis, int firstDayOfWeek ) { this.startTime = startTime; *************** *** 61,65 **** // Set an appropriate time axis it not given yet ! setTimeAxis(); } --- 62,66 ---- // Set an appropriate time axis it not given yet ! setTimeAxis( firstDayOfWeek ); } *************** *** 95,100 **** * Determines a good TimeAxisUnit to use for grid calculation. * A decent grid is selected based on the timespan being used in the chart. */ ! private void setTimeAxis() { if ( tAxis != null ) --- 96,103 ---- * Determines a good TimeAxisUnit to use for grid calculation. * A decent grid is selected based on the timespan being used in the chart. + * + * @param firstDayOfWeek First day of a calendar week. */ ! private void setTimeAxis( int firstDayOfWeek ) { if ( tAxis != null ) *************** *** 104,150 **** if ( days <= 0.75 / 24.0 ) { ! tAxis = new TimeAxisUnit( TimeAxisUnit.MINUTE, 1, TimeAxisUnit.MINUTE, 5, new SimpleDateFormat("HH:mm"), false ); } else if ( days <= 2.0 / 24.0 ) { ! tAxis = new TimeAxisUnit( TimeAxisUnit.MINUTE, 5, TimeAxisUnit.MINUTE, 10, new SimpleDateFormat("HH:mm"), false ); } else if ( days <= 3.0 / 24.0 ) { ! tAxis = new TimeAxisUnit( TimeAxisUnit.MINUTE, 5, TimeAxisUnit.MINUTE, 20, new SimpleDateFormat("HH:mm"), false ); } else if ( days <= 5.0 / 24.0 ) { ! tAxis = new TimeAxisUnit( TimeAxisUnit.MINUTE, 10, TimeAxisUnit.MINUTE, 30, new SimpleDateFormat("HH:mm"), false ); } else if ( days <= 10.0 / 24.0 ) { ! tAxis = new TimeAxisUnit( TimeAxisUnit.MINUTE, 15, TimeAxisUnit.HOUR, 1, new SimpleDateFormat("HH:mm"), false ); } else if ( days <= 15.0 / 24.0 ) { ! tAxis = new TimeAxisUnit( TimeAxisUnit.MINUTE, 30, TimeAxisUnit.HOUR, 2, new SimpleDateFormat("HH:mm"), false ); } else if ( days <= 20.0 / 24.0 ) { ! tAxis = new TimeAxisUnit( TimeAxisUnit.HOUR, 1, TimeAxisUnit.HOUR, 1, new SimpleDateFormat("HH"), true ); } else if ( days <= 36.0 / 24.0 ) { ! tAxis = new TimeAxisUnit( TimeAxisUnit.HOUR, 1, TimeAxisUnit.HOUR, 4, new SimpleDateFormat("HH:mm"), false ); } else if ( days <= 2 ) { ! tAxis = new TimeAxisUnit( TimeAxisUnit.HOUR, 2, TimeAxisUnit.HOUR, 6, new SimpleDateFormat("HH:mm"), false ); } else if ( days <= 3 ) { ! tAxis = new TimeAxisUnit( TimeAxisUnit.HOUR, 3, TimeAxisUnit.HOUR, 12, new SimpleDateFormat("HH:mm"), false ); } else if ( days < 8 ) { ! tAxis = new TimeAxisUnit( TimeAxisUnit.HOUR, 6, TimeAxisUnit.DAY, 1, new SimpleDateFormat("EEE dd"), true); } else if ( days <= 14 ) { ! tAxis = new TimeAxisUnit( TimeAxisUnit.HOUR, 12, TimeAxisUnit.DAY, 1, new SimpleDateFormat("dd"), true ); } else if ( days <= 43 ) { ! tAxis = new TimeAxisUnit( TimeAxisUnit.DAY, 1, TimeAxisUnit.WEEK, 1, new SimpleDateFormat("'week' ww"), true ); } else if ( days <= 157 ) { ! tAxis = new TimeAxisUnit( TimeAxisUnit.WEEK, 1, TimeAxisUnit.WEEK, 1, new SimpleDateFormat("ww"), true ); } else { ! tAxis = new TimeAxisUnit( TimeAxisUnit.MONTH, 1, TimeAxisUnit.MONTH, 1, new SimpleDateFormat("MMM"), true ); } } --- 107,153 ---- if ( days <= 0.75 / 24.0 ) { ! tAxis = new TimeAxisUnit( TimeAxisUnit.MINUTE, 1, TimeAxisUnit.MINUTE, 5, new SimpleDateFormat("HH:mm"), false, firstDayOfWeek ); } else if ( days <= 2.0 / 24.0 ) { ! tAxis = new TimeAxisUnit( TimeAxisUnit.MINUTE, 5, TimeAxisUnit.MINUTE, 10, new SimpleDateFormat("HH:mm"), false, firstDayOfWeek ); } else if ( days <= 3.0 / 24.0 ) { ! tAxis = new TimeAxisUnit( TimeAxisUnit.MINUTE, 5, TimeAxisUnit.MINUTE, 20, new SimpleDateFormat("HH:mm"), false, firstDayOfWeek ); } else if ( days <= 5.0 / 24.0 ) { ! tAxis = new TimeAxisUnit( TimeAxisUnit.MINUTE, 10, TimeAxisUnit.MINUTE, 30, new SimpleDateFormat("HH:mm"), false, firstDayOfWeek ); } else if ( days <= 10.0 / 24.0 ) { ! tAxis = new TimeAxisUnit( TimeAxisUnit.MINUTE, 15, TimeAxisUnit.HOUR, 1, new SimpleDateFormat("HH:mm"), false, firstDayOfWeek ); } else if ( days <= 15.0 / 24.0 ) { ! tAxis = new TimeAxisUnit( TimeAxisUnit.MINUTE, 30, TimeAxisUnit.HOUR, 2, new SimpleDateFormat("HH:mm"), false, firstDayOfWeek ); } else if ( days <= 20.0 / 24.0 ) { ! tAxis = new TimeAxisUnit( TimeAxisUnit.HOUR, 1, TimeAxisUnit.HOUR, 1, new SimpleDateFormat("HH"), true, firstDayOfWeek ); } else if ( days <= 36.0 / 24.0 ) { ! tAxis = new TimeAxisUnit( TimeAxisUnit.HOUR, 1, TimeAxisUnit.HOUR, 4, new SimpleDateFormat("HH:mm"), false, firstDayOfWeek ); } else if ( days <= 2 ) { ! tAxis = new TimeAxisUnit( TimeAxisUnit.HOUR, 2, TimeAxisUnit.HOUR, 6, new SimpleDateFormat("HH:mm"), false, firstDayOfWeek ); } else if ( days <= 3 ) { ! tAxis = new TimeAxisUnit( TimeAxisUnit.HOUR, 3, TimeAxisUnit.HOUR, 12, new SimpleDateFormat("HH:mm"), false, firstDayOfWeek ); } else if ( days < 8 ) { ! tAxis = new TimeAxisUnit( TimeAxisUnit.HOUR, 6, TimeAxisUnit.DAY, 1, new SimpleDateFormat("EEE dd"), true, firstDayOfWeek ); } else if ( days <= 14 ) { ! tAxis = new TimeAxisUnit( TimeAxisUnit.HOUR, 12, TimeAxisUnit.DAY, 1, new SimpleDateFormat("dd"), true, firstDayOfWeek ); } else if ( days <= 43 ) { ! tAxis = new TimeAxisUnit( TimeAxisUnit.DAY, 1, TimeAxisUnit.WEEK, 1, new SimpleDateFormat("'week' ww"), true, firstDayOfWeek ); } else if ( days <= 157 ) { ! tAxis = new TimeAxisUnit( TimeAxisUnit.WEEK, 1, TimeAxisUnit.WEEK, 1, new SimpleDateFormat("ww"), true, firstDayOfWeek ); } else { ! tAxis = new TimeAxisUnit( TimeAxisUnit.MONTH, 1, TimeAxisUnit.MONTH, 1, new SimpleDateFormat("MMM"), true, firstDayOfWeek ); } } |
From: Sasa M. <sa...@us...> - 2004-04-20 10:22:14
|
Update of /cvsroot/jrobin/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24439 Modified Files: Demo.java Log Message: Slightly modified to test read-only access to a RRD file Index: Demo.java =================================================================== RCS file: /cvsroot/jrobin/src/Demo.java,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** Demo.java 22 Mar 2004 09:27:13 -0000 1.13 --- Demo.java 20 Apr 2004 10:22:03 -0000 1.14 *************** *** 99,103 **** log.println(sample.dump()); sample.update(); - t += RANDOM.nextDouble() * MAX_STEP + 1; if(((++n) % 1000) == 0) { --- 99,102 ---- *************** *** 108,111 **** --- 107,115 ---- println("== Finished. RRD file updated " + n + " times"); println("== Last update time was: " + rrdDb.getLastUpdateTime()); + rrdDb.close(); + + // test read-only access! + rrdDb = new RrdDb(rrdPath, true); + println("File reopen in read-only mode"); // fetch data |
Update of /cvsroot/jrobin/src/org/jrobin/core In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv3307/org/jrobin/core Modified Files: ArcState.java Robin.java RrdDb.java RrdDouble.java RrdFile.java RrdInt.java RrdLong.java RrdString.java Log Message: Added option to open RRD files in READ-ONLY mode. Index: RrdString.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/core/RrdString.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** RrdString.java 29 Mar 2004 14:38:28 -0000 1.5 --- RrdString.java 20 Apr 2004 08:20:29 -0000 1.6 *************** *** 40,44 **** void loadCache() throws IOException { RrdFile rrdFile = getRrdFile(); ! if(rrdFile.getMode() == RrdFile.MODE_RESTORE) { rrdFile.seek(getPointer()); char[] c = new char[SIZE]; --- 40,44 ---- void loadCache() throws IOException { RrdFile rrdFile = getRrdFile(); ! if(rrdFile.getRrdMode() == RrdFile.MODE_RESTORE) { rrdFile.seek(getPointer()); char[] c = new char[SIZE]; Index: RrdLong.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/core/RrdLong.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** RrdLong.java 29 Mar 2004 14:38:28 -0000 1.5 --- RrdLong.java 20 Apr 2004 08:20:29 -0000 1.6 *************** *** 40,44 **** void loadCache() throws IOException { RrdFile rrdFile = getRrdFile(); ! if(rrdFile.getMode() == RrdFile.MODE_RESTORE) { rrdFile.seek(getPointer()); cache = rrdFile.readLong(); --- 40,44 ---- void loadCache() throws IOException { RrdFile rrdFile = getRrdFile(); ! if(rrdFile.getRrdMode() == RrdFile.MODE_RESTORE) { rrdFile.seek(getPointer()); cache = rrdFile.readLong(); Index: ArcState.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/core/ArcState.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** ArcState.java 2 Dec 2003 10:18:17 -0000 1.6 --- ArcState.java 20 Apr 2004 08:20:29 -0000 1.7 *************** *** 43,47 **** ArcState(Archive parentArc) throws IOException { this.parentArc = parentArc; ! if(getRrdFile().getMode() == RrdFile.MODE_CREATE) { // should initialize Header header = parentArc.getParentDb().getHeader(); --- 43,47 ---- ArcState(Archive parentArc) throws IOException { this.parentArc = parentArc; ! if(getRrdFile().getRrdMode() == RrdFile.MODE_CREATE) { // should initialize Header header = parentArc.getParentDb().getHeader(); Index: Robin.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/core/Robin.java,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** Robin.java 30 Mar 2004 09:55:22 -0000 1.10 --- Robin.java 20 Apr 2004 08:20:29 -0000 1.11 *************** *** 49,53 **** this.parentArc = parentArc; this.rows = rows; ! if(getRrdFile().getMode() == RrdFile.MODE_CREATE) { pointer = new RrdInt(0, this); values = new RrdDoubleArray(this, rows, Double.NaN); --- 49,53 ---- this.parentArc = parentArc; this.rows = rows; ! if(getRrdFile().getRrdMode() == RrdFile.MODE_CREATE) { pointer = new RrdInt(0, this); values = new RrdDoubleArray(this, rows, Double.NaN); Index: RrdFile.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/core/RrdFile.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** RrdFile.java 26 Mar 2004 08:47:05 -0000 1.6 --- RrdFile.java 20 Apr 2004 08:20:29 -0000 1.7 *************** *** 46,51 **** static final int MODE_CREATE = 2; ! static final long LOCK_DELAY = 500; // 0.5sec ! static final String FLAGS = "rw"; // R/W access static int lockMode = RrdDb.NO_LOCKS; --- 46,55 ---- static final int MODE_CREATE = 2; ! static final long LOCK_DELAY = 100; // 0.1sec ! ! // access mode ! static final String ACCESS_READ_WRITE = "rw"; ! static final String ACCESS_READ_ONLY = "r"; ! static int lockMode = RrdDb.NO_LOCKS; *************** *** 53,62 **** private FileLock fileLock; private List primitives = new LinkedList(); ! private int mode; ! RrdFile(String filePath, int mode) throws IOException { ! super(filePath, FLAGS); this.filePath = filePath; ! this.mode = mode; lockFile(); } --- 57,66 ---- private FileLock fileLock; private List primitives = new LinkedList(); ! private int rrdMode; ! RrdFile(String filePath, int rrdMode, boolean readOnly) throws IOException { ! super(filePath, readOnly? ACCESS_READ_ONLY: ACCESS_READ_WRITE); this.filePath = filePath; ! this.rrdMode = rrdMode; lockFile(); } *************** *** 170,179 **** } ! int getMode() { ! return mode; } ! void setMode(int mode) { ! this.mode = mode; } --- 174,183 ---- } ! int getRrdMode() { ! return rrdMode; } ! void setRrdMode(int rrdMode) { ! this.rrdMode = rrdMode; } Index: RrdInt.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/core/RrdInt.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** RrdInt.java 29 Mar 2004 14:38:28 -0000 1.5 --- RrdInt.java 20 Apr 2004 08:20:29 -0000 1.6 *************** *** 40,44 **** void loadCache() throws IOException { RrdFile rrdFile = getRrdFile(); ! if(rrdFile.getMode() == RrdFile.MODE_RESTORE) { rrdFile.seek(getPointer()); cache = rrdFile.readInt(); --- 40,44 ---- void loadCache() throws IOException { RrdFile rrdFile = getRrdFile(); ! if(rrdFile.getRrdMode() == RrdFile.MODE_RESTORE) { rrdFile.seek(getPointer()); cache = rrdFile.readInt(); Index: RrdDouble.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/core/RrdDouble.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** RrdDouble.java 29 Mar 2004 14:38:28 -0000 1.5 --- RrdDouble.java 20 Apr 2004 08:20:29 -0000 1.6 *************** *** 40,44 **** void loadCache() throws IOException { RrdFile rrdFile = getRrdFile(); ! if(rrdFile.getMode() == RrdFile.MODE_RESTORE) { rrdFile.seek(getPointer()); cache = rrdFile.readDouble(); --- 40,44 ---- void loadCache() throws IOException { RrdFile rrdFile = getRrdFile(); ! if(rrdFile.getRrdMode() == RrdFile.MODE_RESTORE) { rrdFile.seek(getPointer()); cache = rrdFile.readDouble(); Index: RrdDb.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/core/RrdDb.java,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** RrdDb.java 11 Mar 2004 13:54:25 -0000 1.13 --- RrdDb.java 20 Apr 2004 08:20:29 -0000 1.14 *************** *** 108,112 **** public RrdDb(RrdDef rrdDef) throws IOException, RrdException { rrdDef.validate(); ! initializeSetup(rrdDef.getPath(), RrdFile.MODE_CREATE); // create header header = new Header(this, rrdDef); --- 108,112 ---- public RrdDb(RrdDef rrdDef) throws IOException, RrdException { rrdDef.validate(); ! initializeSetup(rrdDef.getPath(), RrdFile.MODE_CREATE, false); // create header header = new Header(this, rrdDef); *************** *** 130,141 **** /** * <p>Constructor used to open already existing RRD file. ! * Obtains read/write access to RRD file so that future ! * fetch and update operations are possible.</p> * * @param path Path to existing RRD file. * @throws IOException Thrown in case of I/O error. * @throws RrdException Thrown in case of JRobin specific error. */ ! public RrdDb(String path) throws IOException, RrdException { // opens existing RRD file - throw exception if the file does not exist... File rrdFile = new File(path); --- 130,145 ---- /** * <p>Constructor used to open already existing RRD file. ! * Obtains read or read/write access to RRD file.</p> * * @param path Path to existing RRD file. + * @param readOnly Should be set to <code>false</code> if you want to update + * the underlying RRD file. If you want just to fetch data from the RRD file + * (read-only access), specify <code>true</code>. If you try to update RRD file + * open in read-only mode (<code>readOnly</code> set to <code>true</code>), + * <code>IOException</code> will be thrown. * @throws IOException Thrown in case of I/O error. * @throws RrdException Thrown in case of JRobin specific error. */ ! public RrdDb(String path, boolean readOnly) throws IOException, RrdException { // opens existing RRD file - throw exception if the file does not exist... File rrdFile = new File(path); *************** *** 144,148 **** } try { ! initializeSetup(path, RrdFile.MODE_RESTORE); // restore header header = new Header(this); --- 148,152 ---- } try { ! initializeSetup(path, RrdFile.MODE_RESTORE, readOnly); // restore header header = new Header(this); *************** *** 167,170 **** --- 171,187 ---- /** + * <p>Constructor used to open already existing RRD file. + * Obtains <b>full</b> (read/write) access to the underlying RRD file + * so that future RRD updates are possible.</p> + * + * @param path Path to existing RRD file. + * @throws IOException Thrown in case of I/O error. + * @throws RrdException Thrown in case of JRobin specific error. + */ + public RrdDb(String path) throws IOException, RrdException { + this(path, false); + } + + /** * <p>Constructor used to create new RRD file from XML dump. JRobin and RRDTool * use the same format for XML dump and this constructor should be used to *************** *** 189,193 **** */ public RrdDb(String rrdPath, String xmlPath) throws IOException, RrdException { ! initializeSetup(rrdPath, RrdFile.MODE_CREATE); XmlReader reader = new XmlReader(xmlPath); // create header --- 206,210 ---- */ public RrdDb(String rrdPath, String xmlPath) throws IOException, RrdException { ! initializeSetup(rrdPath, RrdFile.MODE_CREATE, false); XmlReader reader = new XmlReader(xmlPath); // create header *************** *** 210,219 **** ! private void initializeSetup(String path, int mode) throws IOException { ! file = new RrdFile(path, mode); } private void finalizeSetup() throws IOException { ! int mode = file.getMode(); if(mode == RrdFile.MODE_CREATE) { file.truncateFile(); --- 227,236 ---- ! private void initializeSetup(String path, int mode, boolean readOnly) throws IOException { ! file = new RrdFile(path, mode, readOnly); } private void finalizeSetup() throws IOException { ! int mode = file.getRrdMode(); if(mode == RrdFile.MODE_CREATE) { file.truncateFile(); *************** *** 224,228 **** } } ! file.setMode(RrdFile.MODE_NORMAL); canonicalPath = file.getCanonicalFilePath(); } --- 241,245 ---- } } ! file.setRrdMode(RrdFile.MODE_NORMAL); canonicalPath = file.getCanonicalFilePath(); } |
From: Arne V. <cob...@us...> - 2004-04-19 22:35:10
|
Update of /cvsroot/jrobin/src/org/jrobin/graph In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30568/src/org/jrobin/graph Modified Files: Gprint.java Grapher.java ChartGraphics.java TimeAxisUnit.java ValueGrid.java ValueAxisUnit.java Source.java Log Message: JRobin 1.3.1 DEBUG UPDATE - testing purposes - Bug fixes for bugs #0000032 and #0000033 - Improved Value Grid calculation - Improved Time Grid calculation for monthly gridlines - Fixed possible Trime Grid shift between minor and major lines - Modified right aligned title padding (signature overlap) Index: Grapher.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/graph/Grapher.java,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** Grapher.java 30 Mar 2004 22:57:45 -0000 1.8 --- Grapher.java 19 Apr 2004 22:35:00 -0000 1.9 *************** *** 194,200 **** plotOverlay( graphics ); // draw a possible image overlay - - plotSignature( graphics ); // draw the JRobin signature // Dispose graphics context --- 194,199 ---- plotOverlay( graphics ); // draw a possible image overlay + plotSignature( graphics ); // draw the JRobin signature // Dispose graphics context *************** *** 254,260 **** plotOverlay( graphics ); // draw a possible image overlay - - plotSignature( graphics ); // draw the JRobin signature // Dispose graphics context --- 253,258 ---- plotOverlay( graphics ); // draw a possible image overlay + plotSignature( graphics ); // draw the JRobin signature // Dispose graphics context *************** *** 333,337 **** veList[ vePos++ ] = ve; } ! // Add all Pdefs to the source table for ( int i = 0; i < pdefList.length; i++ ) --- 331,335 ---- veList[ vePos++ ] = ve; } ! // Add all Pdefs to the source table for ( int i = 0; i < pdefList.length; i++ ) *************** *** 482,486 **** double min = src.getAggregate( Source.AGG_MINIMUM ); double max = src.getAggregate( Source.AGG_MAXIMUM ); ! // If the plotdef is a stack, evaluate ALL previous values to find a possible max if ( plotDefs[i].plotType == PlotDef.PLOT_STACK && i >= 1 ) --- 480,484 ---- double min = src.getAggregate( Source.AGG_MINIMUM ); double max = src.getAggregate( Source.AGG_MAXIMUM ); ! // If the plotdef is a stack, evaluate ALL previous values to find a possible max if ( plotDefs[i].plotType == PlotDef.PLOT_STACK && i >= 1 ) *************** *** 526,530 **** lowerValue = vGrid.getLowerValue(); upperValue = vGrid.getUpperValue(); ! // Use a special graph 'object' that takes care of resizing and reversing y coordinates ChartGraphics g = new ChartGraphics( graphics ); --- 524,528 ---- lowerValue = vGrid.getLowerValue(); upperValue = vGrid.getUpperValue(); ! // Use a special graph 'object' that takes care of resizing and reversing y coordinates ChartGraphics g = new ChartGraphics( graphics ); *************** *** 901,905 **** else if ( tkn == Comment.TKN_ARF ) { newLine = true; ! posx = imgWidth - RBORDER_SPACE - (tmpStr.length() * tfont_width); } else if ( tkn == Comment.TKN_ACF ) { --- 899,903 ---- else if ( tkn == Comment.TKN_ARF ) { newLine = true; ! posx = imgWidth - RBORDER_SPACE - (tmpStr.length() * tfont_width) - tfont_width; } else if ( tkn == Comment.TKN_ACF ) { *************** *** 910,914 **** posx = LBORDER_SPACE; else if ( tkn == Comment.TKN_AR ) ! posx = imgWidth - RBORDER_SPACE - (tmpStr.length() * tfont_width); else if ( tkn == Comment.TKN_AC ) posx = imgWidth / 2 - (tmpStr.length() * tfont_width) / 2; --- 908,912 ---- posx = LBORDER_SPACE; else if ( tkn == Comment.TKN_AR ) ! posx = imgWidth - RBORDER_SPACE - (tmpStr.length() * tfont_width) - tfont_width; else if ( tkn == Comment.TKN_AC ) posx = imgWidth / 2 - (tmpStr.length() * tfont_width) / 2; Index: ValueAxisUnit.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/graph/ValueAxisUnit.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** ValueAxisUnit.java 30 Mar 2004 22:57:45 -0000 1.4 --- ValueAxisUnit.java 19 Apr 2004 22:35:00 -0000 1.5 *************** *** 226,233 **** double value = ovalue * gridFactor; ! int valueInt = new Double(value).intValue(); ! int roundStep = new Double(gridStep).intValue(); if ( roundStep == 0 ) roundStep = 1; ! int num = valueInt / roundStep; // int mod = valueInt % roundStep; double gridValue = (roundStep * (num + 1)) * 1.0d; --- 226,233 ---- double value = ovalue * gridFactor; ! long valueInt = new Double(value).longValue(); ! long roundStep = new Double(gridStep).longValue(); if ( roundStep == 0 ) roundStep = 1; ! long num = valueInt / roundStep; // int mod = valueInt % roundStep; double gridValue = (roundStep * (num + 1)) * 1.0d; *************** *** 236,240 **** value = ovalue * mGridFactor; ! roundStep = new Double(mGridStep).intValue(); if ( roundStep == 0 ) roundStep = 1; num = valueInt / roundStep; --- 236,240 ---- value = ovalue * mGridFactor; ! roundStep = new Double(mGridStep).longValue(); if ( roundStep == 0 ) roundStep = 1; num = valueInt / roundStep; Index: ValueGrid.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/graph/ValueGrid.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** ValueGrid.java 30 Mar 2004 22:57:45 -0000 1.4 --- ValueGrid.java 19 Apr 2004 22:35:00 -0000 1.5 *************** *** 174,181 **** else if ( shifted <= 5 ) vAxis = new ValueAxisUnit( 0.5 * mod * scaleValues[scaleIndex], 1.0 * mod * scaleValues[scaleIndex] ); - else if ( shifted <= 9 ) - vAxis = new ValueAxisUnit( 0.5 * mod * scaleValues[scaleIndex], 2.0 * mod * scaleValues[scaleIndex] ); else ! vAxis = new ValueAxisUnit( 0.1 * mod * scaleValues[scaleIndex], 0.5 * mod * scaleValues[scaleIndex] ); } } --- 174,179 ---- else if ( shifted <= 5 ) vAxis = new ValueAxisUnit( 0.5 * mod * scaleValues[scaleIndex], 1.0 * mod * scaleValues[scaleIndex] ); else ! vAxis = new ValueAxisUnit( 0.5 * mod * scaleValues[scaleIndex], 2.0 * mod * scaleValues[scaleIndex] ); } } Index: ChartGraphics.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/graph/ChartGraphics.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** ChartGraphics.java 7 Nov 2003 08:23:19 -0000 1.1 --- ChartGraphics.java 19 Apr 2004 22:35:00 -0000 1.2 *************** *** 141,145 **** yStart = lower; yEnd = upper; ! if ( yEnd != yStart ) heightDelta = height * 1.0d / (( yEnd - yStart) * 1.0d); --- 141,145 ---- yStart = lower; yEnd = upper; ! if ( yEnd != yStart ) heightDelta = height * 1.0d / (( yEnd - yStart) * 1.0d); *************** *** 168,173 **** int tmp = new Double( (value - ( yStart < 0 ? 0 : Math.abs(yStart) ) ) * heightDelta).intValue(); ! ! return ( tmp > value * heightDelta ? tmp - 1 : tmp ); } --- 168,173 ---- int tmp = new Double( (value - ( yStart < 0 ? 0 : Math.abs(yStart) ) ) * heightDelta).intValue(); ! ! return ( tmp > value * heightDelta ? tmp - 1 : tmp ); } Index: Source.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/graph/Source.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** Source.java 30 Mar 2004 22:57:45 -0000 1.5 --- Source.java 19 Apr 2004 22:35:00 -0000 1.6 *************** *** 42,47 **** protected static final int AGG_FIRST = 3; protected static final int AGG_LAST = 4; ! protected static final String[] aggregates = { "MINIMUM", "MAXIMUM", "AVERAGE", "FIRST", "LAST" }; private String name; protected double[] values; --- 42,48 ---- protected static final int AGG_FIRST = 3; protected static final int AGG_LAST = 4; + protected static final int AGG_TOTAL = 5; ! protected static final String[] aggregates = { "MINIMUM", "MAXIMUM", "AVERAGE", "FIRST", "LAST", "TOTAL" }; private String name; protected double[] values; *************** *** 54,58 **** private long lastTime = 0; private long totalTime = 0; ! // ================================================================ --- 55,59 ---- private long lastTime = 0; private long totalTime = 0; ! double testval = 0; // ================================================================ *************** *** 97,101 **** * Gets a specific aggregate of this datasource. * Requested aggregate can be one of the following: ! * <code>AGG_MINIMUM, AGG_MAXIMUM, AGG_AVERAGE, AGG_FIRST</code> * and <code>AGG_LAST</code>. * @param aggType Type of the aggregate requested. --- 98,102 ---- * Gets a specific aggregate of this datasource. * Requested aggregate can be one of the following: ! * <code>AGG_MINIMUM, AGG_MAXIMUM, AGG_AVERAGE, AGG_FIRST, AGG_TOTAL</code> * and <code>AGG_LAST</code>. * @param aggType Type of the aggregate requested. *************** *** 125,129 **** if ( values != null && values.length > 0) return values[values.length - 1]; ! break; } --- 126,133 ---- if ( values != null && values.length > 0) return values[values.length - 1]; ! break; ! ! case AGG_TOTAL: ! return testval; } *************** *** 160,163 **** --- 164,168 ---- { long timeDelta = time - lastTime; + testval += value; totalValue += timeDelta * ( value + lastValue ) / 2.0; totalTime += timeDelta; Index: TimeAxisUnit.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/graph/TimeAxisUnit.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** TimeAxisUnit.java 1 Mar 2004 08:50:25 -0000 1.4 --- TimeAxisUnit.java 19 Apr 2004 22:35:00 -0000 1.5 *************** *** 47,60 **** Calendar.YEAR }; - private static final int[] nullValue = - { - 0, - 0, - 0, - 1, - 1, - 0, - 1970 // Should never be used, but put there to avoid index out of bounds - }; // Indices in the calendarUnit table --- 47,50 ---- *************** *** 79,88 **** private int minGridTimeUnit = HOUR; // minor grid ! private int minGridUnitSteps = 1; private int majGridTimeUnit = HOUR; // major grid ! private int majGridUnitSteps = 6; ! private boolean centerLabels = false; ! private SimpleDateFormat dateFormat = new SimpleDateFormat("HH:mm", Locale.ENGLISH ); --- 69,78 ---- private int minGridTimeUnit = HOUR; // minor grid ! private int minGridUnitSteps = 1; private int majGridTimeUnit = HOUR; // major grid ! private int majGridUnitSteps = 6; ! private boolean centerLabels = false; ! private SimpleDateFormat dateFormat = new SimpleDateFormat("HH:mm", Locale.ENGLISH ); *************** *** 250,257 **** { t.setTimeInMillis( exactStart ); ! for (int i = 0; i < calendarUnit.length && i <= unit; i++) ! t.set( calendarUnit[i], nullValue[i] ); if ( unit == WEEK ) t.set( Calendar.DAY_OF_WEEK, t.getFirstDayOfWeek() ); } --- 240,260 ---- { t.setTimeInMillis( exactStart ); ! ! t.setFirstDayOfWeek(Calendar.MONDAY); ! for (int i = 0; i < HOUR && i <= unit; i++) ! t.set( calendarUnit[i], 0 ); ! ! if ( unit >= HOUR ) ! t.set( Calendar.HOUR_OF_DAY, 0 ); ! if ( unit == WEEK ) t.set( Calendar.DAY_OF_WEEK, t.getFirstDayOfWeek() ); + else if ( unit == MONTH ) + t.set( Calendar.DAY_OF_MONTH, 1 ); + else if ( unit == YEAR ) + { + t.set( Calendar.DATE, 1 ); + t.set( Calendar.MONTH, 0 ); + } } *************** *** 266,269 **** --- 269,273 ---- { t.add( calendarUnit[unit], unitSteps ); + return t.getTimeInMillis(); } Index: Gprint.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/graph/Gprint.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** Gprint.java 1 Mar 2004 08:50:25 -0000 1.3 --- Gprint.java 19 Apr 2004 22:35:00 -0000 1.4 *************** *** 88,91 **** --- 88,93 ---- else if ( consolFunc.equalsIgnoreCase("FIRST") ) aggregate = Source.AGG_FIRST; + else if ( consolFunc.equalsIgnoreCase("TOTAL") ) + aggregate = Source.AGG_TOTAL; else throw new RrdException( "Invalid consolidation function specified." ); |
From: Sasa M. <sa...@us...> - 2004-04-19 13:45:49
|
Update of /cvsroot/jrobin/src/org/jrobin/mrtg/server In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv13941/org/jrobin/mrtg/server Modified Files: Config.java Poller.java RawSample.java RrdWriter.java Log Message: Index: Config.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/mrtg/server/Config.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** Config.java 8 Mar 2004 13:14:39 -0000 1.3 --- Config.java 19 Apr 2004 13:45:39 -0000 1.4 *************** *** 62,70 **** } ! public static String getRrdTemplateFile() { return RRD_DEF_TEMPLATE_FILE; } ! public static String getGraphTemplateFile() { return RRD_GRAPH_DEF_TEMPLATE_FILE; } --- 62,70 ---- } ! static String getRrdTemplateFile() { return RRD_DEF_TEMPLATE_FILE; } ! static String getGraphTemplateFile() { return RRD_GRAPH_DEF_TEMPLATE_FILE; } Index: Poller.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/mrtg/server/Poller.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** Poller.java 8 Apr 2004 12:00:01 -0000 1.3 --- Poller.java 19 Apr 2004 13:45:39 -0000 1.4 *************** *** 55,59 **** private SNMPv1CommunicationInterface comm; ! public Poller(String host, String community) throws IOException { // check for port information --- 55,59 ---- private SNMPv1CommunicationInterface comm; ! Poller(String host, String community) throws IOException { // check for port information *************** *** 72,76 **** } ! public String getNumericOid(String oid) { int n = OIDS.length; for(int i = 0; i < n; i++) { --- 72,76 ---- } ! String getNumericOid(String oid) { int n = OIDS.length; for(int i = 0; i < n; i++) { *************** *** 84,88 **** } ! public String get(String oid) throws IOException { String numericOid = getNumericOid(oid); try { --- 84,88 ---- } ! String get(String oid) throws IOException { String numericOid = getNumericOid(oid); try { *************** *** 100,108 **** } ! public String get(String oid, int index) throws IOException { return get(oid + "." + index); } ! public String[] get(String[] oids) throws IOException { int count = oids.length; String[] result = new String[count]; --- 100,108 ---- } ! String get(String oid, int index) throws IOException { return get(oid + "." + index); } ! String[] get(String[] oids) throws IOException { int count = oids.length; String[] result = new String[count]; *************** *** 113,117 **** } ! public SortedMap walk(String base) throws IOException { SortedMap map = new TreeMap(); String baseOid = getNumericOid(base); --- 113,117 ---- } ! SortedMap walk(String base) throws IOException { SortedMap map = new TreeMap(); String baseOid = getNumericOid(base); *************** *** 141,145 **** } ! public SortedMap walkIfDescr() throws IOException { SortedMap rawInterfacesMap = walk("ifDescr"); SortedMap enumeratedInterfacesMap = new TreeMap(); --- 141,145 ---- } ! SortedMap walkIfDescr() throws IOException { SortedMap rawInterfacesMap = walk("ifDescr"); SortedMap enumeratedInterfacesMap = new TreeMap(); *************** *** 163,167 **** } ! public int getIfIndexByIfDescr(String ifDescr) throws IOException { SortedMap map = walkIfDescr(); Iterator it = map.keySet().iterator(); --- 163,167 ---- } ! int getIfIndexByIfDescr(String ifDescr) throws IOException { SortedMap map = walkIfDescr(); Iterator it = map.keySet().iterator(); *************** *** 176,180 **** } ! public void close() { if(comm != null) { try { --- 176,180 ---- } ! void close() { if(comm != null) { try { Index: RawSample.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/mrtg/server/RawSample.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** RawSample.java 10 Nov 2003 08:52:29 -0000 1.2 --- RawSample.java 19 Apr 2004 13:45:39 -0000 1.3 *************** *** 37,101 **** private int ifOperStatus; ! public String getHost() { return host; } ! public void setHost(String host) { this.host = host; } ! public String getIfDescr() { return ifDescr; } ! public void setIfDescr(String ifDescr) { this.ifDescr = ifDescr; } ! public boolean isValid() { return valid; } ! public void setValid(boolean valid) { this.valid = valid; } ! public long getTimestamp() { return timestamp; } ! public void setTimestamp(long timestamp) { this.timestamp = timestamp; } ! public long getIfInOctets() { return ifInOctets; } ! public void setIfInOctets(long ifInOctets) { this.ifInOctets = ifInOctets; } ! public long getIfOutOctets() { return ifOutOctets; } ! public void setIfOutOctets(long ifOutOctets) { this.ifOutOctets = ifOutOctets; } ! public long getSysUpTime() { return sysUpTime; } ! public void setSysUpTime(long sysUpTime) { this.sysUpTime = sysUpTime; } ! public int getIfOperStatus() { return ifOperStatus; } ! public void setIfOperStatus(int ifOperStatus) { this.ifOperStatus = ifOperStatus; } --- 37,101 ---- private int ifOperStatus; ! String getHost() { return host; } ! void setHost(String host) { this.host = host; } ! String getIfDescr() { return ifDescr; } ! void setIfDescr(String ifDescr) { this.ifDescr = ifDescr; } ! boolean isValid() { return valid; } ! void setValid(boolean valid) { this.valid = valid; } ! long getTimestamp() { return timestamp; } ! void setTimestamp(long timestamp) { this.timestamp = timestamp; } ! long getIfInOctets() { return ifInOctets; } ! void setIfInOctets(long ifInOctets) { this.ifInOctets = ifInOctets; } ! long getIfOutOctets() { return ifOutOctets; } ! void setIfOutOctets(long ifOutOctets) { this.ifOutOctets = ifOutOctets; } ! long getSysUpTime() { return sysUpTime; } ! void setSysUpTime(long sysUpTime) { this.sysUpTime = sysUpTime; } ! int getIfOperStatus() { return ifOperStatus; } ! void setIfOperStatus(int ifOperStatus) { this.ifOperStatus = ifOperStatus; } Index: RrdWriter.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/mrtg/server/RrdWriter.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** RrdWriter.java 7 Apr 2004 13:46:05 -0000 1.3 --- RrdWriter.java 19 Apr 2004 13:45:39 -0000 1.4 *************** *** 145,161 **** } ! public int getSampleCount() { return sampleCount; } ! public int getBadSavesCount() { return badSavesCount; } ! public int getGoodSavesCount() { return goodSavesCount; } ! public int getSavesCount() { return getGoodSavesCount() + getBadSavesCount(); } --- 145,161 ---- } ! int getSampleCount() { return sampleCount; } ! int getBadSavesCount() { return badSavesCount; } ! int getGoodSavesCount() { return goodSavesCount; } ! int getSavesCount() { return getGoodSavesCount() + getBadSavesCount(); } |
From: Sasa M. <sa...@us...> - 2004-04-19 13:42:22
|
Update of /cvsroot/jrobin/src/org/jrobin/mrtg/server In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv13324/org/jrobin/mrtg/server Modified Files: Timer.java Log Message: Index: Timer.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/mrtg/server/Timer.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** Timer.java 7 Apr 2004 13:46:06 -0000 1.3 --- Timer.java 19 Apr 2004 13:42:14 -0000 1.4 *************** *** 33,37 **** private volatile boolean active = true; ! public Timer() { start(); } --- 33,37 ---- private volatile boolean active = true; ! Timer() { start(); } |
From: Sasa M. <sa...@us...> - 2004-04-10 10:44:58
|
Update of /cvsroot/jrobin/src/org/jrobin/mrtg/server In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv8333/org/jrobin/mrtg/server Modified Files: Port.java Server.java Log Message: Index: Port.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/mrtg/server/Port.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** Port.java 9 Apr 2004 09:29:17 -0000 1.3 --- Port.java 10 Apr 2004 10:31:30 -0000 1.4 *************** *** 1,250 **** ! /* ============================================================ ! * 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.mrtg.server; ! ! import org.jrobin.core.Util; ! import org.jrobin.mrtg.Debug; ! import org.jrobin.mrtg.MrtgException; ! import org.w3c.dom.Document; ! import org.w3c.dom.Element; ! import org.w3c.dom.Node; ! import org.w3c.dom.NodeList; ! ! import java.util.Date; ! import java.util.Hashtable; ! ! class Port { ! static final int DEFAULT_SAMPLING_INTERVAL = 300; ! ! private int ifIndex = -1; ! private String ifDescr = ""; ! private String ifAlias = ""; ! private String descr = ""; ! private int samplingInterval = DEFAULT_SAMPLING_INTERVAL; ! private boolean active = true; ! private int sampleCount; ! ! private long lastSampleTime; ! private RawSample lastSample; ! private boolean sampling; ! ! Port() { } ! ! Port(Node linkNode) { ! NodeList nodes = linkNode.getChildNodes(); ! for(int i = 0; i < nodes.getLength(); i++) { ! Node node = nodes.item(i); ! String name = node.getNodeName(); ! Node firstChild = node.getFirstChild(); ! String value = (firstChild != null)? firstChild.getNodeValue().trim(): null; ! if(name.equals("ifIndex")) { ! setIfIndex(Integer.parseInt(value)); ! } ! else if(name.equals("ifDescr")) { ! setIfDescr(value); ! } ! else if(name.equals("ifAlias")) { ! setIfAlias(value); ! } ! else if(name.equals("description")) { ! setDescr(value); ! } ! else if(name.equals("samplingInterval")) { ! setSamplingInterval(Integer.parseInt(value)); ! } ! else if(name.equals("active")) { ! setActive(new Boolean(value).booleanValue()); ! } ! } ! } ! ! int getIfIndex() { ! return ifIndex; ! } ! ! void setIfIndex(int ifIndex) { ! this.ifIndex = ifIndex; ! } ! ! String getIfDescr() { ! return ifDescr; ! } ! ! String getIfDescrCore() { ! int index = ifDescr.indexOf("#"); ! if(index != -1) { ! return ifDescr.substring(0, index); ! } ! else { ! return ifDescr; ! } ! } ! ! void setIfDescr(String ifDescr) { ! if(ifDescr != null) { ! this.ifDescr = ifDescr; ! } ! } ! ! String getIfAlias() { ! return ifAlias; ! } ! ! void setIfAlias(String ifAlias) { ! if(ifAlias != null) { ! this.ifAlias = ifAlias; ! } ! } ! ! int getSamplingInterval() { ! return samplingInterval; ! } ! ! void setSamplingInterval(int samplingInterval) { ! this.samplingInterval = samplingInterval; ! } ! ! boolean isActive() { ! return active; ! } ! ! boolean getActive() { ! return active; ! } ! ! void setActive(boolean active) { ! this.active = active; ! } ! ! String getDescr() { ! return descr; ! } ! ! void setDescr(String descr) { ! if(descr != null) { ! this.descr = descr; ! } ! } ! ! public String toString() { ! return ifDescr + " [" + ifIndex + "] " + descr + ", " + ifAlias + " (each " + ! samplingInterval + "sec, active=" + active + ")"; ! } ! ! long getLastSampleTime() { ! return lastSampleTime; ! } ! ! void setLastSampleTime(long lastSampleTime) { ! this.lastSampleTime = lastSampleTime; ! } ! ! boolean isSampling() { ! return sampling; ! } ! ! void setSampling(boolean sampling) { ! this.sampling = sampling; ! } ! ! boolean isDue() { ! if(lastSampleTime == 0) { ! return true; ! } ! long elapsedTime = Util.getTime() - lastSampleTime; ! return elapsedTime >= samplingInterval; ! } ! ! void switchToIfIndex(int ifIndex) throws MrtgException { ! this.ifIndex = ifIndex; ! Server.getInstance().saveHardware(); ! } ! ! void deactivate() throws MrtgException { ! this.active = false; ! Server.getInstance().saveHardware(); ! } ! ! void processSample(RawSample sample) throws MrtgException { ! // check if ifDescr match ! if(!getIfDescrCore().equals(sample.getIfDescr())) { ! // something changed on the router ! switchToIfIndex(-1); ! return; ! } ! sample.setIfDescr(ifDescr); ! if(lastSample != null && lastSample.getSysUpTime() >= sample.getSysUpTime() ) { ! // sysUpTime decreased ! sample.setValid(false); ! } ! Debug.print("Saving sample: " + sample); ! Server.getInstance().getRrdWriter().store(sample); ! sampleCount++; ! lastSample = sample; ! lastSampleTime = sample.getTimestamp(); ! } ! ! Hashtable getLinkInfo() { ! Hashtable link = new Hashtable(); ! link.put("ifIndex", new Integer(ifIndex)); ! link.put("ifDescr", ifDescr); ! link.put("ifAlias", ifAlias); ! link.put("descr", descr); ! link.put("samplingInterval", new Integer(samplingInterval)); ! link.put("active", new Boolean(active)); ! link.put("sampleCount", new Integer(sampleCount)); ! if(lastSample != null) { ! link.put("lastSampleTime", new Date(lastSampleTime * 1000L)); ! link.put("ifInOctets", String.valueOf(lastSample.getIfInOctets())); ! link.put("ifOutOctets", String.valueOf(lastSample.getIfOutOctets())); ! link.put("ifOperStatus", String.valueOf(lastSample.getIfOperStatus())); ! } ! return link; ! } ! ! void appendXml(Element routerElem) { ! Document doc = routerElem.getOwnerDocument(); ! Element linkElem = doc.createElement("interface"); ! routerElem.appendChild(linkElem); ! Element ifIndexElem = doc.createElement("ifIndex"); ! ifIndexElem.appendChild(doc.createTextNode("" + ifIndex)); ! linkElem.appendChild(ifIndexElem); ! Element ifDescrElem = doc.createElement("ifDescr"); ! ifDescrElem.appendChild(doc.createTextNode(ifDescr)); ! linkElem.appendChild(ifDescrElem); ! Element ifAliasElem = doc.createElement("ifAlias"); ! ifAliasElem.appendChild(doc.createTextNode(ifAlias)); ! linkElem.appendChild(ifAliasElem); ! Element descrElem = doc.createElement("description"); ! descrElem.appendChild(doc.createTextNode(descr)); ! linkElem.appendChild(descrElem); ! Element samplElem = doc.createElement("samplingInterval"); ! samplElem.appendChild(doc.createTextNode("" + samplingInterval)); ! linkElem.appendChild(samplElem); ! Element activeElem = doc.createElement("active"); ! activeElem.appendChild(doc.createTextNode("" + active)); ! linkElem.appendChild(activeElem); ! } ! } --- 1,250 ---- ! /* ============================================================ ! * 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.mrtg.server; ! ! import org.jrobin.core.Util; ! import org.jrobin.mrtg.Debug; ! import org.jrobin.mrtg.MrtgException; ! import org.w3c.dom.Document; ! import org.w3c.dom.Element; ! import org.w3c.dom.Node; ! import org.w3c.dom.NodeList; ! ! import java.util.Date; ! import java.util.Hashtable; ! ! class Port { ! static final int DEFAULT_SAMPLING_INTERVAL = 300; ! ! private int ifIndex = -1; ! private String ifDescr = ""; ! private String ifAlias = ""; ! private String descr = ""; ! private int samplingInterval = DEFAULT_SAMPLING_INTERVAL; ! private boolean active = true; ! private int sampleCount; ! ! private long lastSampleTime; ! private RawSample lastSample; ! private boolean sampling; ! ! Port() { } ! ! Port(Node linkNode) { ! NodeList nodes = linkNode.getChildNodes(); ! for(int i = 0; i < nodes.getLength(); i++) { ! Node node = nodes.item(i); ! String name = node.getNodeName(); ! Node firstChild = node.getFirstChild(); ! String value = (firstChild != null)? firstChild.getNodeValue().trim(): null; ! if(name.equals("ifIndex")) { ! setIfIndex(Integer.parseInt(value)); ! } ! else if(name.equals("ifDescr")) { ! setIfDescr(value); ! } ! else if(name.equals("ifAlias")) { ! setIfAlias(value); ! } ! else if(name.equals("description")) { ! setDescr(value); ! } ! else if(name.equals("samplingInterval")) { ! setSamplingInterval(Integer.parseInt(value)); ! } ! else if(name.equals("active")) { ! setActive(new Boolean(value).booleanValue()); ! } ! } ! } ! ! int getIfIndex() { ! return ifIndex; ! } ! ! void setIfIndex(int ifIndex) { ! this.ifIndex = ifIndex; ! } ! ! String getIfDescr() { ! return ifDescr; ! } ! ! String getIfDescrCore() { ! int index = ifDescr.indexOf("#"); ! if(index != -1) { ! return ifDescr.substring(0, index); ! } ! else { ! return ifDescr; ! } ! } ! ! void setIfDescr(String ifDescr) { ! if(ifDescr != null) { ! this.ifDescr = ifDescr; ! } ! } ! ! String getIfAlias() { ! return ifAlias; ! } ! ! void setIfAlias(String ifAlias) { ! if(ifAlias != null) { ! this.ifAlias = ifAlias; ! } ! } ! ! int getSamplingInterval() { ! return samplingInterval; ! } ! ! void setSamplingInterval(int samplingInterval) { ! this.samplingInterval = samplingInterval; ! } ! ! boolean isActive() { ! return active; ! } ! ! boolean getActive() { ! return active; ! } ! ! void setActive(boolean active) { ! this.active = active; ! } ! ! String getDescr() { ! return descr; ! } ! ! void setDescr(String descr) { ! if(descr != null) { ! this.descr = descr; ! } ! } ! ! public String toString() { ! return ifDescr + " [" + ifIndex + "] " + descr + ", " + ifAlias + " (each " + ! samplingInterval + "sec, active=" + active + ")"; ! } ! ! long getLastSampleTime() { ! return lastSampleTime; ! } ! ! void setLastSampleTime(long lastSampleTime) { ! this.lastSampleTime = lastSampleTime; ! } ! ! boolean isSampling() { ! return sampling; ! } ! ! void setSampling(boolean sampling) { ! this.sampling = sampling; ! } ! ! boolean isDue() { ! if(lastSampleTime == 0) { ! return true; ! } ! long elapsedTime = Util.getTime() - lastSampleTime; ! return elapsedTime >= samplingInterval; ! } ! ! void switchToIfIndex(int ifIndex) throws MrtgException { ! this.ifIndex = ifIndex; ! Server.getInstance().saveHardware(); ! } ! ! void deactivate() throws MrtgException { ! this.active = false; ! Server.getInstance().saveHardware(); ! } ! ! void processSample(RawSample sample) throws MrtgException { ! // check if ifDescr match ! if(!getIfDescrCore().equals(sample.getIfDescr())) { ! // something changed on the router ! switchToIfIndex(-1); ! return; ! } ! sample.setIfDescr(ifDescr); ! if(lastSample != null && lastSample.getSysUpTime() >= sample.getSysUpTime() ) { ! // sysUpTime decreased ! sample.setValid(false); ! } ! Debug.print("Saving sample: " + sample); ! Server.getInstance().getRrdWriter().store(sample); ! sampleCount++; ! lastSample = sample; ! lastSampleTime = sample.getTimestamp(); ! } ! ! Hashtable getLinkInfo() { ! Hashtable link = new Hashtable(); ! link.put("ifIndex", new Integer(ifIndex)); ! link.put("ifDescr", ifDescr); ! link.put("ifAlias", ifAlias); ! link.put("descr", descr); ! link.put("samplingInterval", new Integer(samplingInterval)); ! link.put("active", new Boolean(active)); ! link.put("sampleCount", new Integer(sampleCount)); ! if(lastSample != null) { ! link.put("lastSampleTime", new Date(lastSampleTime * 1000L)); ! link.put("ifInOctets", String.valueOf(lastSample.getIfInOctets())); ! link.put("ifOutOctets", String.valueOf(lastSample.getIfOutOctets())); ! link.put("ifOperStatus", String.valueOf(lastSample.getIfOperStatus())); ! } ! return link; ! } ! ! void appendXml(Element routerElem) { ! Document doc = routerElem.getOwnerDocument(); ! Element linkElem = doc.createElement("interface"); ! routerElem.appendChild(linkElem); ! Element ifIndexElem = doc.createElement("ifIndex"); ! ifIndexElem.appendChild(doc.createTextNode("" + ifIndex)); ! linkElem.appendChild(ifIndexElem); ! Element ifDescrElem = doc.createElement("ifDescr"); ! ifDescrElem.appendChild(doc.createTextNode(ifDescr)); ! linkElem.appendChild(ifDescrElem); ! Element ifAliasElem = doc.createElement("ifAlias"); ! ifAliasElem.appendChild(doc.createTextNode(ifAlias)); ! linkElem.appendChild(ifAliasElem); ! Element descrElem = doc.createElement("description"); ! descrElem.appendChild(doc.createTextNode(descr)); ! linkElem.appendChild(descrElem); ! Element samplElem = doc.createElement("samplingInterval"); ! samplElem.appendChild(doc.createTextNode("" + samplingInterval)); ! linkElem.appendChild(samplElem); ! Element activeElem = doc.createElement("active"); ! activeElem.appendChild(doc.createTextNode("" + active)); ! linkElem.appendChild(activeElem); ! } ! } Index: Server.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/mrtg/server/Server.java,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** Server.java 9 Apr 2004 09:29:17 -0000 1.11 --- Server.java 10 Apr 2004 10:31:30 -0000 1.12 *************** *** 1,296 **** ! /* ============================================================ ! * 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.mrtg.server; ! ! import org.jrobin.core.RrdDb; ! import org.jrobin.core.RrdDbPool; ! import org.jrobin.mrtg.MrtgException; ! import org.jrobin.mrtg.MrtgConstants; ! import org.w3c.dom.Document; ! import org.w3c.dom.Element; ! import org.w3c.dom.NodeList; ! ! import javax.xml.parsers.DocumentBuilder; ! import javax.xml.parsers.DocumentBuilderFactory; ! import javax.xml.transform.OutputKeys; ! import javax.xml.transform.Transformer; ! import javax.xml.transform.TransformerFactory; ! import javax.xml.transform.dom.DOMSource; ! import javax.xml.transform.stream.StreamResult; ! import java.io.File; ! import java.io.FileOutputStream; ! import java.io.IOException; ! import java.io.FileWriter; ! import java.util.Date; ! import java.util.Hashtable; ! import java.util.Vector; ! ! public class Server implements MrtgConstants { ! private static Server instance; ! ! private DeviceList deviceList; ! private Date startDate; ! ! private Timer timer; ! private RrdWriter rrdWriter; ! private Listener listener; ! ! private boolean active = false; ! ! public synchronized static Server getInstance() { ! if (instance == null) { ! instance = new Server(); ! } ! return instance; ! } ! ! private Server() { ! RrdDb.setLockMode(RrdDb.NO_LOCKS); ! RrdDbPool.getInstance().setCapacity(POOL_CAPACITY); ! } ! ! public synchronized void start(String[] acceptedClients) throws MrtgException { ! if(active) { ! throw new MrtgException("Cannot start Server, already started"); ! } ! // create template files ! try { ! createXmlTemplateIfNecessary(Config.getRrdTemplateFile(), RRD_TEMPLATE_STR); ! createXmlTemplateIfNecessary(Config.getGraphTemplateFile(), GRAPH_TEMPLATE_STR); ! } ! catch(IOException ioe) { ! throw new MrtgException(ioe); ! } ! // load configuration ! String hwFile = Config.getHardwareFile(); ! if(new File(hwFile).exists()) { ! loadHardware(); ! } ! else { ! saveHardware(); ! } ! // create threads ! rrdWriter = new RrdWriter(); ! timer = new Timer(); ! listener = new Listener(acceptedClients); ! startDate = new Date(); ! active = true; ! } ! ! private void createXmlTemplateIfNecessary(String filePath, String fileContent) ! throws IOException { ! File file = new File(filePath); ! if(!file.exists()) { ! FileWriter writer = new FileWriter(filePath, false); ! writer.write(fileContent); ! writer.flush(); ! writer.close(); ! } ! } ! ! public synchronized void stop() throws MrtgException { ! if(!active) { ! throw new MrtgException("Cannot stop Server, not started"); ! } ! rrdWriter.terminate(); ! timer.terminate(); ! listener.terminate(); ! active = false; ! try { ! RrdDbPool.getInstance().reset(); ! } catch (IOException e) { ! throw new MrtgException(e); ! } ! } ! ! void saveHardware() throws MrtgException { ! if(deviceList == null) { ! deviceList = new DeviceList(); ! } ! try { ! DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); ! factory.setValidating(false); ! factory.setNamespaceAware(false); ! DocumentBuilder builder = factory.newDocumentBuilder(); ! Document doc = builder.newDocument(); ! Element root = doc.createElement("mrtg"); ! doc.appendChild(root); ! Vector routers = deviceList.getRouters(); ! for(int i = 0; i < routers.size(); i++) { ! Device router = (Device) routers.get(i); ! router.appendXml(root); ! } ! TransformerFactory tFactory = TransformerFactory.newInstance(); ! Transformer transformer = tFactory.newTransformer(); ! transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "no"); ! transformer.setOutputProperty(OutputKeys.METHOD, "xml"); ! transformer.setOutputProperty(OutputKeys.INDENT, "yes"); ! transformer.setOutputProperty(OutputKeys.MEDIA_TYPE, "text/xml"); ! transformer.setOutputProperty(OutputKeys.STANDALONE, "yes"); ! DOMSource source = new DOMSource(root); ! FileOutputStream destination = new FileOutputStream(Config.getHardwareFile()); ! StreamResult result = new StreamResult(destination); ! transformer.transform(source, result); ! destination.close(); ! } catch (Exception e) { ! throw new MrtgException(e); ! } ! } ! ! private void loadHardware() throws MrtgException { ! try { ! DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); ! factory.setValidating(false); ! factory.setNamespaceAware(false); ! DocumentBuilder builder = factory.newDocumentBuilder(); ! Document doc = builder.parse(new File(Config.getHardwareFile())); ! Element root = doc.getDocumentElement(); ! NodeList nodes = root.getElementsByTagName("router"); ! deviceList = new DeviceList(); ! Vector routers = deviceList.getRouters(); ! for(int i = 0; i < nodes.getLength(); i++) { ! routers.add(new Device(nodes.item(i))); ! } ! } catch (Exception e) { ! throw new MrtgException(e); ! } ! } ! ! public String toString() { ! return deviceList.toString(); ! } ! ! synchronized int addRouter(String host, String community, String descr, boolean active) ! throws MrtgException { ! int retCode = deviceList.addRouter(host, community, descr, active); ! if(retCode == 0) { ! saveHardware(); ! } ! return retCode; ! } ! ! synchronized int updateRouter(String host, String community, String descr, boolean active) ! throws MrtgException { ! int retCode = deviceList.updateRouter(host, community, descr, active); ! if(retCode == 0) { ! saveHardware(); ! } ! return retCode; ! } ! ! synchronized int removeRouter(String host) throws MrtgException { ! int retCode = deviceList.removeRouter(host); ! if(retCode == 0) { ! saveHardware(); ! } ! return retCode; ! } ! ! synchronized int addLink(String host, String ifDescr, String descr, int samplingInterval, ! boolean active) ! throws MrtgException { ! int retCode = deviceList.addLink(host, ifDescr, descr, samplingInterval, active); ! if(retCode == 0) { ! saveHardware(); ! } ! return retCode; ! } ! ! synchronized int updateLink(String host, String ifDescr, String descr, ! int samplingInterval, boolean active) ! throws MrtgException { ! int retCode = deviceList.updateLink(host, ifDescr, descr, samplingInterval, active); ! if(retCode == 0) { ! saveHardware(); ! } ! return retCode; ! } ! ! synchronized int removeLink(String host, String ifDescr) throws MrtgException { ! int retCode = deviceList.removeLink(host, ifDescr); ! if(retCode == 0) { ! saveHardware(); ! if(REMOVE_RRD_FOR_DEACTIVATED_LINK) { ! // remove the underlying RRD file ! String rrdFile = RrdWriter.getRrdFilename(host, ifDescr); ! new File(rrdFile).delete(); ! } ! } ! return retCode; ! } ! ! synchronized byte[] getPngGraph(String host, String ifDescr, long start, long stop) ! throws MrtgException { ! Plotter grapher = new Plotter(host, ifDescr); ! return grapher.getPngGraphBytes(start, stop); ! } ! ! synchronized Device[] getRouters() { ! return (Device[]) deviceList.getRouters().toArray(new Device[0]); ! } ! ! String[] getAvailableLinks(String host) throws MrtgException { ! Device router = deviceList.getRouterByHost(host); ! try { ! if(router != null) { ! return router.getAvailableLinks(); ! } ! else { ! return null; ! } ! } catch (IOException e) { ! throw new MrtgException(e); ! } ! } ! ! DeviceList getDeviceList() { ! return deviceList; ! } ! ! RrdWriter getRrdWriter() { ! return rrdWriter; ! } ! ! Date getStartDate() { ! return startDate; ! } ! ! Hashtable getServerInfo() { ! Hashtable hash = new Hashtable(); ! hash.put("sampleCount", new Integer(rrdWriter.getSampleCount())); ! hash.put("savesCount", new Integer(rrdWriter.getSavesCount())); ! hash.put("goodSavesCount", new Integer(rrdWriter.getGoodSavesCount())); ! hash.put("badSavesCount", new Integer(rrdWriter.getBadSavesCount())); ! hash.put("startDate", startDate); ! return hash; ! } ! ! public static void main(String[] acceptedClients) throws Exception { ! Server s = Server.getInstance(); ! s.start(acceptedClients); ! } ! ! } ! --- 1,296 ---- ! /* ============================================================ ! * 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.mrtg.server; ! ! import org.jrobin.core.RrdDb; ! import org.jrobin.core.RrdDbPool; ! import org.jrobin.mrtg.MrtgException; ! import org.jrobin.mrtg.MrtgConstants; ! import org.w3c.dom.Document; ! import org.w3c.dom.Element; ! import org.w3c.dom.NodeList; ! ! import javax.xml.parsers.DocumentBuilder; ! import javax.xml.parsers.DocumentBuilderFactory; ! import javax.xml.transform.OutputKeys; ! import javax.xml.transform.Transformer; ! import javax.xml.transform.TransformerFactory; ! import javax.xml.transform.dom.DOMSource; ! import javax.xml.transform.stream.StreamResult; ! import java.io.File; ! import java.io.FileOutputStream; ! import java.io.IOException; ! import java.io.FileWriter; ! import java.util.Date; ! import java.util.Hashtable; ! import java.util.Vector; ! ! public class Server implements MrtgConstants { ! private static Server instance; ! ! private DeviceList deviceList; ! private Date startDate; ! ! private Timer timer; ! private RrdWriter rrdWriter; ! private Listener listener; ! ! private boolean active = false; ! ! public synchronized static Server getInstance() { ! if (instance == null) { ! instance = new Server(); ! } ! return instance; ! } ! ! private Server() { ! RrdDb.setLockMode(RrdDb.NO_LOCKS); ! RrdDbPool.getInstance().setCapacity(POOL_CAPACITY); ! } ! ! public synchronized void start(String[] acceptedClients) throws MrtgException { ! if(active) { ! throw new MrtgException("Cannot start Server, already started"); ! } ! // create template files ! try { ! createXmlTemplateIfNecessary(Config.getRrdTemplateFile(), RRD_TEMPLATE_STR); ! createXmlTemplateIfNecessary(Config.getGraphTemplateFile(), GRAPH_TEMPLATE_STR); ! } ! catch(IOException ioe) { ! throw new MrtgException(ioe); ! } ! // load configuration ! String hwFile = Config.getHardwareFile(); ! if(new File(hwFile).exists()) { ! loadHardware(); ! } ! else { ! saveHardware(); ! } ! // create threads ! rrdWriter = new RrdWriter(); ! timer = new Timer(); ! listener = new Listener(acceptedClients); ! startDate = new Date(); ! active = true; ! } ! ! private void createXmlTemplateIfNecessary(String filePath, String fileContent) ! throws IOException { ! File file = new File(filePath); ! if(!file.exists()) { ! FileWriter writer = new FileWriter(filePath, false); ! writer.write(fileContent); ! writer.flush(); ! writer.close(); ! } ! } ! ! public synchronized void stop() throws MrtgException { ! if(!active) { ! throw new MrtgException("Cannot stop Server, not started"); ! } ! rrdWriter.terminate(); ! timer.terminate(); ! listener.terminate(); ! active = false; ! try { ! RrdDbPool.getInstance().reset(); ! } catch (IOException e) { ! throw new MrtgException(e); ! } ! } ! ! void saveHardware() throws MrtgException { ! if(deviceList == null) { ! deviceList = new DeviceList(); ! } ! try { ! DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); ! factory.setValidating(false); ! factory.setNamespaceAware(false); ! DocumentBuilder builder = factory.newDocumentBuilder(); ! Document doc = builder.newDocument(); ! Element root = doc.createElement("mrtg"); ! doc.appendChild(root); ! Vector routers = deviceList.getRouters(); ! for(int i = 0; i < routers.size(); i++) { ! Device router = (Device) routers.get(i); ! router.appendXml(root); ! } ! TransformerFactory tFactory = TransformerFactory.newInstance(); ! Transformer transformer = tFactory.newTransformer(); ! transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "no"); ! transformer.setOutputProperty(OutputKeys.METHOD, "xml"); ! transformer.setOutputProperty(OutputKeys.INDENT, "yes"); ! transformer.setOutputProperty(OutputKeys.MEDIA_TYPE, "text/xml"); ! transformer.setOutputProperty(OutputKeys.STANDALONE, "yes"); ! DOMSource source = new DOMSource(root); ! FileOutputStream destination = new FileOutputStream(Config.getHardwareFile()); ! StreamResult result = new StreamResult(destination); ! transformer.transform(source, result); ! destination.close(); ! } catch (Exception e) { ! throw new MrtgException(e); ! } ! } ! ! private void loadHardware() throws MrtgException { ! try { ! DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); ! factory.setValidating(false); ! factory.setNamespaceAware(false); ! DocumentBuilder builder = factory.newDocumentBuilder(); ! Document doc = builder.parse(new File(Config.getHardwareFile())); ! Element root = doc.getDocumentElement(); ! NodeList nodes = root.getElementsByTagName("router"); ! deviceList = new DeviceList(); ! Vector routers = deviceList.getRouters(); ! for(int i = 0; i < nodes.getLength(); i++) { ! routers.add(new Device(nodes.item(i))); ! } ! } catch (Exception e) { ! throw new MrtgException(e); ! } ! } ! ! public String toString() { ! return deviceList.toString(); ! } ! ! synchronized int addRouter(String host, String community, String descr, boolean active) ! throws MrtgException { ! int retCode = deviceList.addRouter(host, community, descr, active); ! if(retCode == 0) { ! saveHardware(); ! } ! return retCode; ! } ! ! synchronized int updateRouter(String host, String community, String descr, boolean active) ! throws MrtgException { ! int retCode = deviceList.updateRouter(host, community, descr, active); ! if(retCode == 0) { ! saveHardware(); ! } ! return retCode; ! } ! ! synchronized int removeRouter(String host) throws MrtgException { ! int retCode = deviceList.removeRouter(host); ! if(retCode == 0) { ! saveHardware(); ! } ! return retCode; ! } ! ! synchronized int addLink(String host, String ifDescr, String descr, int samplingInterval, ! boolean active) ! throws MrtgException { ! int retCode = deviceList.addLink(host, ifDescr, descr, samplingInterval, active); ! if(retCode == 0) { ! saveHardware(); ! } ! return retCode; ! } ! ! synchronized int updateLink(String host, String ifDescr, String descr, ! int samplingInterval, boolean active) ! throws MrtgException { ! int retCode = deviceList.updateLink(host, ifDescr, descr, samplingInterval, active); ! if(retCode == 0) { ! saveHardware(); ! } ! return retCode; ! } ! ! synchronized int removeLink(String host, String ifDescr) throws MrtgException { ! int retCode = deviceList.removeLink(host, ifDescr); ! if(retCode == 0) { ! saveHardware(); ! if(REMOVE_RRD_FOR_DEACTIVATED_LINK) { ! // remove the underlying RRD file ! String rrdFile = RrdWriter.getRrdFilename(host, ifDescr); ! new File(rrdFile).delete(); ! } ! } ! return retCode; ! } ! ! synchronized byte[] getPngGraph(String host, String ifDescr, long start, long stop) ! throws MrtgException { ! Plotter grapher = new Plotter(host, ifDescr); ! return grapher.getPngGraphBytes(start, stop); ! } ! ! synchronized Device[] getRouters() { ! return (Device[]) deviceList.getRouters().toArray(new Device[0]); ! } ! ! String[] getAvailableLinks(String host) throws MrtgException { ! Device router = deviceList.getRouterByHost(host); ! try { ! if(router != null) { ! return router.getAvailableLinks(); ! } ! else { ! return null; ! } ! } catch (IOException e) { ! throw new MrtgException(e); ! } ! } ! ! DeviceList getDeviceList() { ! return deviceList; ! } ! ! RrdWriter getRrdWriter() { ! return rrdWriter; ! } ! ! Date getStartDate() { ! return startDate; ! } ! ! Hashtable getServerInfo() { ! Hashtable hash = new Hashtable(); ! hash.put("sampleCount", new Integer(rrdWriter.getSampleCount())); ! hash.put("savesCount", new Integer(rrdWriter.getSavesCount())); ! hash.put("goodSavesCount", new Integer(rrdWriter.getGoodSavesCount())); ! hash.put("badSavesCount", new Integer(rrdWriter.getBadSavesCount())); ! hash.put("startDate", startDate); ! return hash; ! } ! ! public static void main(String[] acceptedClients) throws Exception { ! Server s = Server.getInstance(); ! s.start(acceptedClients); ! } ! ! } ! |
From: Sasa M. <sa...@us...> - 2004-04-09 14:20:43
|
Update of /cvsroot/jrobin/src/org/jrobin/mrtg/client In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv29424/org/jrobin/mrtg/client Modified Files: Client.java Log Message: small intervention Index: Client.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/mrtg/client/Client.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** Client.java 9 Apr 2004 09:40:09 -0000 1.6 --- Client.java 9 Apr 2004 14:07:24 -0000 1.7 *************** *** 40,44 **** static final String TITLE = "JRobin-MRTG client"; static final String SUBTITLE = "http://www.jrobin.org"; ! static final String COPYRIGHT = "\u00A9 2003,2004 Sasa Markovic"; static final String ICON = "mrtg-res/icon.png"; --- 40,44 ---- static final String TITLE = "JRobin-MRTG client"; static final String SUBTITLE = "http://www.jrobin.org"; ! static final String COPYRIGHT = "Copyright \u00A9 2004 Sasa Markovic"; static final String ICON = "mrtg-res/icon.png"; |
From: Sasa M. <sa...@us...> - 2004-04-09 09:53:28
|
Update of /cvsroot/jrobin/src/org/jrobin/mrtg/client In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9389/org/jrobin/mrtg/client Modified Files: Client.java Log Message: Just a copyright message :) Index: Client.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/mrtg/client/Client.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** Client.java 9 Dec 2003 12:22:04 -0000 1.5 --- Client.java 9 Apr 2004 09:40:09 -0000 1.6 *************** *** 40,44 **** static final String TITLE = "JRobin-MRTG client"; static final String SUBTITLE = "http://www.jrobin.org"; ! static final String COPYRIGHT = "Copyright \u00A9 2003 Sasa Markovic"; static final String ICON = "mrtg-res/icon.png"; --- 40,44 ---- static final String TITLE = "JRobin-MRTG client"; static final String SUBTITLE = "http://www.jrobin.org"; ! static final String COPYRIGHT = "\u00A9 2003,2004 Sasa Markovic"; static final String ICON = "mrtg-res/icon.png"; |
From: Sasa M. <sa...@us...> - 2004-04-09 09:42:35
|
Update of /cvsroot/jrobin/src/org/jrobin/mrtg/server In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv7402/org/jrobin/mrtg/server Modified Files: Port.java Server.java Log Message: MRTG: Allowed for multiple interfaces with the same name Index: Port.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/mrtg/server/Port.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** Port.java 8 Apr 2004 12:00:01 -0000 1.2 --- Port.java 9 Apr 2004 09:29:17 -0000 1.3 *************** *** 1,249 **** ! /* ============================================================ ! * 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.mrtg.server; ! ! import org.jrobin.core.Util; ! import org.jrobin.mrtg.Debug; ! import org.jrobin.mrtg.MrtgException; ! import org.w3c.dom.Document; ! import org.w3c.dom.Element; ! import org.w3c.dom.Node; ! import org.w3c.dom.NodeList; ! ! import java.util.Date; ! import java.util.Hashtable; ! ! class Port { ! static final int DEFAULT_SAMPLING_INTERVAL = 300; ! ! private int ifIndex = -1; ! private String ifDescr = ""; ! private String ifAlias = ""; ! private String descr = ""; ! private int samplingInterval = DEFAULT_SAMPLING_INTERVAL; ! private boolean active = true; ! private int sampleCount; ! ! private long lastSampleTime; ! private RawSample lastSample; ! private boolean sampling; ! ! Port() { } ! ! Port(Node linkNode) { ! NodeList nodes = linkNode.getChildNodes(); ! for(int i = 0; i < nodes.getLength(); i++) { ! Node node = nodes.item(i); ! String name = node.getNodeName(); ! Node firstChild = node.getFirstChild(); ! String value = (firstChild != null)? firstChild.getNodeValue().trim(): null; ! if(name.equals("ifIndex")) { ! setIfIndex(Integer.parseInt(value)); ! } ! else if(name.equals("ifDescr")) { ! setIfDescr(value); ! } ! else if(name.equals("ifAlias")) { ! setIfAlias(value); ! } ! else if(name.equals("description")) { ! setDescr(value); ! } ! else if(name.equals("samplingInterval")) { ! setSamplingInterval(Integer.parseInt(value)); ! } ! else if(name.equals("active")) { ! setActive(new Boolean(value).booleanValue()); ! } ! } ! } ! ! int getIfIndex() { ! return ifIndex; ! } ! ! void setIfIndex(int ifIndex) { ! this.ifIndex = ifIndex; ! } ! ! String getIfDescr() { ! return ifDescr; ! } ! ! String getIfDescrCore() { ! int index = ifDescr.indexOf("#"); ! if(index != -1) { ! return ifDescr.substring(0, index); ! } ! else { ! return ifDescr; ! } ! } ! ! void setIfDescr(String ifDescr) { ! if(ifDescr != null) { ! this.ifDescr = ifDescr; ! } ! } ! ! String getIfAlias() { ! return ifAlias; ! } ! ! void setIfAlias(String ifAlias) { ! if(ifAlias != null) { ! this.ifAlias = ifAlias; ! } ! } ! ! int getSamplingInterval() { ! return samplingInterval; ! } ! ! void setSamplingInterval(int samplingInterval) { ! this.samplingInterval = samplingInterval; ! } ! ! boolean isActive() { ! return active; ! } ! ! boolean getActive() { ! return active; ! } ! ! void setActive(boolean active) { ! this.active = active; ! } ! ! String getDescr() { ! return descr; ! } ! ! void setDescr(String descr) { ! if(descr != null) { ! this.descr = descr; ! } ! } ! ! public String toString() { ! return ifDescr + " [" + ifIndex + "] " + descr + ", " + ifAlias + " (each " + ! samplingInterval + "sec, active=" + active + ")"; ! } ! ! long getLastSampleTime() { ! return lastSampleTime; ! } ! ! void setLastSampleTime(long lastSampleTime) { ! this.lastSampleTime = lastSampleTime; ! } ! ! boolean isSampling() { ! return sampling; ! } ! ! void setSampling(boolean sampling) { ! this.sampling = sampling; ! } ! ! boolean isDue() { ! if(lastSampleTime == 0) { ! return true; ! } ! long elapsedTime = Util.getTime() - lastSampleTime; ! return elapsedTime >= samplingInterval; ! } ! ! void switchToIfIndex(int ifIndex) throws MrtgException { ! this.ifIndex = ifIndex; ! Server.getInstance().saveHardware(); ! } ! ! void deactivate() throws MrtgException { ! this.active = false; ! Server.getInstance().saveHardware(); ! } ! ! void processSample(RawSample sample) throws MrtgException { ! // check if ifDescr match ! if(!getIfDescrCore().equals(sample.getIfDescr())) { ! // something changed on the router ! switchToIfIndex(-1); ! return; ! } ! if(lastSample != null && lastSample.getSysUpTime() >= sample.getSysUpTime() ) { ! // sysUpTime decreased ! sample.setValid(false); ! } ! Debug.print("Saving sample: " + sample); ! Server.getInstance().getRrdWriter().store(sample); ! sampleCount++; ! lastSample = sample; ! lastSampleTime = sample.getTimestamp(); ! } ! ! Hashtable getLinkInfo() { ! Hashtable link = new Hashtable(); ! link.put("ifIndex", new Integer(ifIndex)); ! link.put("ifDescr", ifDescr); ! link.put("ifAlias", ifAlias); ! link.put("descr", descr); ! link.put("samplingInterval", new Integer(samplingInterval)); ! link.put("active", new Boolean(active)); ! link.put("sampleCount", new Integer(sampleCount)); ! if(lastSample != null) { ! link.put("lastSampleTime", new Date(lastSampleTime * 1000L)); ! link.put("ifInOctets", String.valueOf(lastSample.getIfInOctets())); ! link.put("ifOutOctets", String.valueOf(lastSample.getIfOutOctets())); ! link.put("ifOperStatus", String.valueOf(lastSample.getIfOperStatus())); ! } ! return link; ! } ! ! void appendXml(Element routerElem) { ! Document doc = routerElem.getOwnerDocument(); ! Element linkElem = doc.createElement("interface"); ! routerElem.appendChild(linkElem); ! Element ifIndexElem = doc.createElement("ifIndex"); ! ifIndexElem.appendChild(doc.createTextNode("" + ifIndex)); ! linkElem.appendChild(ifIndexElem); ! Element ifDescrElem = doc.createElement("ifDescr"); ! ifDescrElem.appendChild(doc.createTextNode(ifDescr)); ! linkElem.appendChild(ifDescrElem); ! Element ifAliasElem = doc.createElement("ifAlias"); ! ifAliasElem.appendChild(doc.createTextNode(ifAlias)); ! linkElem.appendChild(ifAliasElem); ! Element descrElem = doc.createElement("description"); ! descrElem.appendChild(doc.createTextNode(descr)); ! linkElem.appendChild(descrElem); ! Element samplElem = doc.createElement("samplingInterval"); ! samplElem.appendChild(doc.createTextNode("" + samplingInterval)); ! linkElem.appendChild(samplElem); ! Element activeElem = doc.createElement("active"); ! activeElem.appendChild(doc.createTextNode("" + active)); ! linkElem.appendChild(activeElem); ! } ! } --- 1,250 ---- ! /* ============================================================ ! * 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.mrtg.server; ! ! import org.jrobin.core.Util; ! import org.jrobin.mrtg.Debug; ! import org.jrobin.mrtg.MrtgException; ! import org.w3c.dom.Document; ! import org.w3c.dom.Element; ! import org.w3c.dom.Node; ! import org.w3c.dom.NodeList; ! ! import java.util.Date; ! import java.util.Hashtable; ! ! class Port { ! static final int DEFAULT_SAMPLING_INTERVAL = 300; ! ! private int ifIndex = -1; ! private String ifDescr = ""; ! private String ifAlias = ""; ! private String descr = ""; ! private int samplingInterval = DEFAULT_SAMPLING_INTERVAL; ! private boolean active = true; ! private int sampleCount; ! ! private long lastSampleTime; ! private RawSample lastSample; ! private boolean sampling; ! ! Port() { } ! ! Port(Node linkNode) { ! NodeList nodes = linkNode.getChildNodes(); ! for(int i = 0; i < nodes.getLength(); i++) { ! Node node = nodes.item(i); ! String name = node.getNodeName(); ! Node firstChild = node.getFirstChild(); ! String value = (firstChild != null)? firstChild.getNodeValue().trim(): null; ! if(name.equals("ifIndex")) { ! setIfIndex(Integer.parseInt(value)); ! } ! else if(name.equals("ifDescr")) { ! setIfDescr(value); ! } ! else if(name.equals("ifAlias")) { ! setIfAlias(value); ! } ! else if(name.equals("description")) { ! setDescr(value); ! } ! else if(name.equals("samplingInterval")) { ! setSamplingInterval(Integer.parseInt(value)); ! } ! else if(name.equals("active")) { ! setActive(new Boolean(value).booleanValue()); ! } ! } ! } ! ! int getIfIndex() { ! return ifIndex; ! } ! ! void setIfIndex(int ifIndex) { ! this.ifIndex = ifIndex; ! } ! ! String getIfDescr() { ! return ifDescr; ! } ! ! String getIfDescrCore() { ! int index = ifDescr.indexOf("#"); ! if(index != -1) { ! return ifDescr.substring(0, index); ! } ! else { ! return ifDescr; ! } ! } ! ! void setIfDescr(String ifDescr) { ! if(ifDescr != null) { ! this.ifDescr = ifDescr; ! } ! } ! ! String getIfAlias() { ! return ifAlias; ! } ! ! void setIfAlias(String ifAlias) { ! if(ifAlias != null) { ! this.ifAlias = ifAlias; ! } ! } ! ! int getSamplingInterval() { ! return samplingInterval; ! } ! ! void setSamplingInterval(int samplingInterval) { ! this.samplingInterval = samplingInterval; ! } ! ! boolean isActive() { ! return active; ! } ! ! boolean getActive() { ! return active; ! } ! ! void setActive(boolean active) { ! this.active = active; ! } ! ! String getDescr() { ! return descr; ! } ! ! void setDescr(String descr) { ! if(descr != null) { ! this.descr = descr; ! } ! } ! ! public String toString() { ! return ifDescr + " [" + ifIndex + "] " + descr + ", " + ifAlias + " (each " + ! samplingInterval + "sec, active=" + active + ")"; ! } ! ! long getLastSampleTime() { ! return lastSampleTime; ! } ! ! void setLastSampleTime(long lastSampleTime) { ! this.lastSampleTime = lastSampleTime; ! } ! ! boolean isSampling() { ! return sampling; ! } ! ! void setSampling(boolean sampling) { ! this.sampling = sampling; ! } ! ! boolean isDue() { ! if(lastSampleTime == 0) { ! return true; ! } ! long elapsedTime = Util.getTime() - lastSampleTime; ! return elapsedTime >= samplingInterval; ! } ! ! void switchToIfIndex(int ifIndex) throws MrtgException { ! this.ifIndex = ifIndex; ! Server.getInstance().saveHardware(); ! } ! ! void deactivate() throws MrtgException { ! this.active = false; ! Server.getInstance().saveHardware(); ! } ! ! void processSample(RawSample sample) throws MrtgException { ! // check if ifDescr match ! if(!getIfDescrCore().equals(sample.getIfDescr())) { ! // something changed on the router ! switchToIfIndex(-1); ! return; ! } ! sample.setIfDescr(ifDescr); ! if(lastSample != null && lastSample.getSysUpTime() >= sample.getSysUpTime() ) { ! // sysUpTime decreased ! sample.setValid(false); ! } ! Debug.print("Saving sample: " + sample); ! Server.getInstance().getRrdWriter().store(sample); ! sampleCount++; ! lastSample = sample; ! lastSampleTime = sample.getTimestamp(); ! } ! ! Hashtable getLinkInfo() { ! Hashtable link = new Hashtable(); ! link.put("ifIndex", new Integer(ifIndex)); ! link.put("ifDescr", ifDescr); ! link.put("ifAlias", ifAlias); ! link.put("descr", descr); ! link.put("samplingInterval", new Integer(samplingInterval)); ! link.put("active", new Boolean(active)); ! link.put("sampleCount", new Integer(sampleCount)); ! if(lastSample != null) { ! link.put("lastSampleTime", new Date(lastSampleTime * 1000L)); ! link.put("ifInOctets", String.valueOf(lastSample.getIfInOctets())); ! link.put("ifOutOctets", String.valueOf(lastSample.getIfOutOctets())); ! link.put("ifOperStatus", String.valueOf(lastSample.getIfOperStatus())); ! } ! return link; ! } ! ! void appendXml(Element routerElem) { ! Document doc = routerElem.getOwnerDocument(); ! Element linkElem = doc.createElement("interface"); ! routerElem.appendChild(linkElem); ! Element ifIndexElem = doc.createElement("ifIndex"); ! ifIndexElem.appendChild(doc.createTextNode("" + ifIndex)); ! linkElem.appendChild(ifIndexElem); ! Element ifDescrElem = doc.createElement("ifDescr"); ! ifDescrElem.appendChild(doc.createTextNode(ifDescr)); ! linkElem.appendChild(ifDescrElem); ! Element ifAliasElem = doc.createElement("ifAlias"); ! ifAliasElem.appendChild(doc.createTextNode(ifAlias)); ! linkElem.appendChild(ifAliasElem); ! Element descrElem = doc.createElement("description"); ! descrElem.appendChild(doc.createTextNode(descr)); ! linkElem.appendChild(descrElem); ! Element samplElem = doc.createElement("samplingInterval"); ! samplElem.appendChild(doc.createTextNode("" + samplingInterval)); ! linkElem.appendChild(samplElem); ! Element activeElem = doc.createElement("active"); ! activeElem.appendChild(doc.createTextNode("" + active)); ! linkElem.appendChild(activeElem); ! } ! } Index: Server.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/mrtg/server/Server.java,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** Server.java 8 Apr 2004 12:00:01 -0000 1.10 --- Server.java 9 Apr 2004 09:29:17 -0000 1.11 *************** *** 1,284 **** ! /* ============================================================ ! * 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.mrtg.server; ! ! import org.jrobin.core.RrdDb; ! import org.jrobin.core.RrdDbPool; ! import org.jrobin.mrtg.MrtgException; ! import org.jrobin.mrtg.MrtgConstants; ! import org.w3c.dom.Document; ! import org.w3c.dom.Element; ! import org.w3c.dom.NodeList; ! ! import javax.xml.parsers.DocumentBuilder; ! import javax.xml.parsers.DocumentBuilderFactory; ! import javax.xml.transform.OutputKeys; ! import javax.xml.transform.Transformer; ! import javax.xml.transform.TransformerFactory; ! import javax.xml.transform.dom.DOMSource; ! import javax.xml.transform.stream.StreamResult; ! import java.io.File; ! import java.io.FileOutputStream; ! import java.io.IOException; ! import java.io.FileWriter; ! import java.util.Date; ! import java.util.Hashtable; ! import java.util.Vector; ! ! public class Server implements MrtgConstants { ! private static Server instance; ! ! private DeviceList deviceList; ! private Date startDate; ! ! private Timer timer; ! private RrdWriter rrdWriter; ! private Listener listener; ! ! private boolean active = false; ! ! public synchronized static Server getInstance() { ! if (instance == null) { ! instance = new Server(); ! } ! return instance; ! } ! ! private Server() { ! RrdDb.setLockMode(RrdDb.NO_LOCKS); ! RrdDbPool.getInstance().setCapacity(POOL_CAPACITY); ! } ! ! public synchronized void start(String[] acceptedClients) throws MrtgException { ! if(active) { ! throw new MrtgException("Cannot start Server, already started"); ! } ! // create template files ! try { ! createXmlTemplateIfNecessary(Config.getRrdTemplateFile(), RRD_TEMPLATE_STR); ! createXmlTemplateIfNecessary(Config.getGraphTemplateFile(), GRAPH_TEMPLATE_STR); ! } ! catch(IOException ioe) { ! throw new MrtgException(ioe); ! } ! // load configuration ! String hwFile = Config.getHardwareFile(); ! if(new File(hwFile).exists()) { ! loadHardware(); ! } ! else { ! saveHardware(); ! } ! // create threads ! rrdWriter = new RrdWriter(); ! timer = new Timer(); ! listener = new Listener(acceptedClients); ! startDate = new Date(); ! active = true; ! } ! ! private void createXmlTemplateIfNecessary(String filePath, String fileContent) ! throws IOException { ! File file = new File(filePath); ! if(!file.exists()) { ! FileWriter writer = new FileWriter(filePath, false); ! writer.write(fileContent); ! writer.flush(); ! writer.close(); ! } ! } ! ! public synchronized void stop() throws MrtgException { ! if(!active) { ! throw new MrtgException("Cannot stop Server, not started"); ! } ! rrdWriter.terminate(); ! timer.terminate(); ! listener.terminate(); ! active = false; ! try { ! RrdDbPool.getInstance().reset(); ! } catch (IOException e) { ! throw new MrtgException(e); ! } ! } ! ! void saveHardware() throws MrtgException { ! if(deviceList == null) { ! deviceList = new DeviceList(); ! } ! try { ! DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); ! factory.setValidating(false); ! factory.setNamespaceAware(false); ! DocumentBuilder builder = factory.newDocumentBuilder(); ! Document doc = builder.newDocument(); ! Element root = doc.createElement("mrtg"); ! doc.appendChild(root); ! Vector routers = deviceList.getRouters(); ! for(int i = 0; i < routers.size(); i++) { ! Device router = (Device) routers.get(i); ! router.appendXml(root); ! } ! TransformerFactory tFactory = TransformerFactory.newInstance(); ! Transformer transformer = tFactory.newTransformer(); ! transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "no"); ! transformer.setOutputProperty(OutputKeys.METHOD, "xml"); ! transformer.setOutputProperty(OutputKeys.INDENT, "yes"); ! transformer.setOutputProperty(OutputKeys.MEDIA_TYPE, "text/xml"); ! transformer.setOutputProperty(OutputKeys.STANDALONE, "yes"); ! DOMSource source = new DOMSource(root); ! FileOutputStream destination = new FileOutputStream(Config.getHardwareFile()); ! StreamResult result = new StreamResult(destination); ! transformer.transform(source, result); ! destination.close(); ! } catch (Exception e) { ! throw new MrtgException(e); ! } ! } ! ! private void loadHardware() throws MrtgException { ! try { ! DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); ! factory.setValidating(false); ! factory.setNamespaceAware(false); ! DocumentBuilder builder = factory.newDocumentBuilder(); ! Document doc = builder.parse(new File(Config.getHardwareFile())); ! Element root = doc.getDocumentElement(); ! NodeList nodes = root.getElementsByTagName("router"); ! deviceList = new DeviceList(); ! Vector routers = deviceList.getRouters(); ! for(int i = 0; i < nodes.getLength(); i++) { ! routers.add(new Device(nodes.item(i))); ! } ! } catch (Exception e) { ! throw new MrtgException(e); ! } ! } ! ! public String toString() { ! return deviceList.toString(); ! } ! ! synchronized int addRouter(String host, String community, String descr, boolean active) ! throws MrtgException { ! int retCode = deviceList.addRouter(host, community, descr, active); ! saveHardware(); ! return retCode; ! } ! ! synchronized int updateRouter(String host, String community, String descr, boolean active) ! throws MrtgException { ! int retCode = deviceList.updateRouter(host, community, descr, active); ! saveHardware(); ! return retCode; ! } ! ! synchronized int removeRouter(String host) throws MrtgException { ! int retCode = deviceList.removeRouter(host); ! saveHardware(); ! return retCode; ! } ! ! synchronized int addLink(String host, String ifDescr, String descr, int samplingInterval, ! boolean active) ! throws MrtgException { ! int retCode = deviceList.addLink(host, ifDescr, descr, samplingInterval, active); ! saveHardware(); ! return retCode; ! } ! ! synchronized int updateLink(String host, String ifDescr, String descr, ! int samplingInterval, boolean active) ! throws MrtgException { ! int retCode = deviceList.updateLink(host, ifDescr, descr, samplingInterval, active); ! saveHardware(); ! return retCode; ! } ! ! synchronized int removeLink(String host, String ifDescr) throws MrtgException { ! int retCode = deviceList.removeLink(host, ifDescr); ! saveHardware(); ! if(retCode == 0 && REMOVE_RRD_FOR_DEACTIVATED_LINK) { ! // remove the underlying RRD file ! String rrdFile = RrdWriter.getRrdFilename(host, ifDescr); ! new File(rrdFile).delete(); ! } ! return retCode; ! } ! ! synchronized byte[] getPngGraph(String host, String ifDescr, long start, long stop) ! throws MrtgException { ! Plotter grapher = new Plotter(host, ifDescr); ! return grapher.getPngGraphBytes(start, stop); ! } ! ! synchronized Device[] getRouters() { ! return (Device[]) deviceList.getRouters().toArray(new Device[0]); ! } ! ! String[] getAvailableLinks(String host) throws MrtgException { ! Device router = deviceList.getRouterByHost(host); ! try { ! if(router != null) { ! return router.getAvailableLinks(); ! } ! else { ! return null; ! } ! } catch (IOException e) { ! throw new MrtgException(e); ! } ! } ! ! DeviceList getDeviceList() { ! return deviceList; ! } ! ! RrdWriter getRrdWriter() { ! return rrdWriter; ! } ! ! Date getStartDate() { ! return startDate; ! } ! ! Hashtable getServerInfo() { ! Hashtable hash = new Hashtable(); ! hash.put("sampleCount", new Integer(rrdWriter.getSampleCount())); ! hash.put("savesCount", new Integer(rrdWriter.getSavesCount())); ! hash.put("goodSavesCount", new Integer(rrdWriter.getGoodSavesCount())); ! hash.put("badSavesCount", new Integer(rrdWriter.getBadSavesCount())); ! hash.put("startDate", startDate); ! return hash; ! } ! ! public static void main(String[] acceptedClients) throws Exception { ! Server s = Server.getInstance(); ! s.start(acceptedClients); ! } ! ! } ! --- 1,296 ---- ! /* ============================================================ ! * 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.mrtg.server; ! ! import org.jrobin.core.RrdDb; ! import org.jrobin.core.RrdDbPool; ! import org.jrobin.mrtg.MrtgException; ! import org.jrobin.mrtg.MrtgConstants; ! import org.w3c.dom.Document; ! import org.w3c.dom.Element; ! import org.w3c.dom.NodeList; ! ! import javax.xml.parsers.DocumentBuilder; ! import javax.xml.parsers.DocumentBuilderFactory; ! import javax.xml.transform.OutputKeys; ! import javax.xml.transform.Transformer; ! import javax.xml.transform.TransformerFactory; ! import javax.xml.transform.dom.DOMSource; ! import javax.xml.transform.stream.StreamResult; ! import java.io.File; ! import java.io.FileOutputStream; ! import java.io.IOException; ! import java.io.FileWriter; ! import java.util.Date; ! import java.util.Hashtable; ! import java.util.Vector; ! ! public class Server implements MrtgConstants { ! private static Server instance; ! ! private DeviceList deviceList; ! private Date startDate; ! ! private Timer timer; ! private RrdWriter rrdWriter; ! private Listener listener; ! ! private boolean active = false; ! ! public synchronized static Server getInstance() { ! if (instance == null) { ! instance = new Server(); ! } ! return instance; ! } ! ! private Server() { ! RrdDb.setLockMode(RrdDb.NO_LOCKS); ! RrdDbPool.getInstance().setCapacity(POOL_CAPACITY); ! } ! ! public synchronized void start(String[] acceptedClients) throws MrtgException { ! if(active) { ! throw new MrtgException("Cannot start Server, already started"); ! } ! // create template files ! try { ! createXmlTemplateIfNecessary(Config.getRrdTemplateFile(), RRD_TEMPLATE_STR); ! createXmlTemplateIfNecessary(Config.getGraphTemplateFile(), GRAPH_TEMPLATE_STR); ! } ! catch(IOException ioe) { ! throw new MrtgException(ioe); ! } ! // load configuration ! String hwFile = Config.getHardwareFile(); ! if(new File(hwFile).exists()) { ! loadHardware(); ! } ! else { ! saveHardware(); ! } ! // create threads ! rrdWriter = new RrdWriter(); ! timer = new Timer(); ! listener = new Listener(acceptedClients); ! startDate = new Date(); ! active = true; ! } ! ! private void createXmlTemplateIfNecessary(String filePath, String fileContent) ! throws IOException { ! File file = new File(filePath); ! if(!file.exists()) { ! FileWriter writer = new FileWriter(filePath, false); ! writer.write(fileContent); ! writer.flush(); ! writer.close(); ! } ! } ! ! public synchronized void stop() throws MrtgException { ! if(!active) { ! throw new MrtgException("Cannot stop Server, not started"); ! } ! rrdWriter.terminate(); ! timer.terminate(); ! listener.terminate(); ! active = false; ! try { ! RrdDbPool.getInstance().reset(); ! } catch (IOException e) { ! throw new MrtgException(e); ! } ! } ! ! void saveHardware() throws MrtgException { ! if(deviceList == null) { ! deviceList = new DeviceList(); ! } ! try { ! DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); ! factory.setValidating(false); ! factory.setNamespaceAware(false); ! DocumentBuilder builder = factory.newDocumentBuilder(); ! Document doc = builder.newDocument(); ! Element root = doc.createElement("mrtg"); ! doc.appendChild(root); ! Vector routers = deviceList.getRouters(); ! for(int i = 0; i < routers.size(); i++) { ! Device router = (Device) routers.get(i); ! router.appendXml(root); ! } ! TransformerFactory tFactory = TransformerFactory.newInstance(); ! Transformer transformer = tFactory.newTransformer(); ! transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "no"); ! transformer.setOutputProperty(OutputKeys.METHOD, "xml"); ! transformer.setOutputProperty(OutputKeys.INDENT, "yes"); ! transformer.setOutputProperty(OutputKeys.MEDIA_TYPE, "text/xml"); ! transformer.setOutputProperty(OutputKeys.STANDALONE, "yes"); ! DOMSource source = new DOMSource(root); ! FileOutputStream destination = new FileOutputStream(Config.getHardwareFile()); ! StreamResult result = new StreamResult(destination); ! transformer.transform(source, result); ! destination.close(); ! } catch (Exception e) { ! throw new MrtgException(e); ! } ! } ! ! private void loadHardware() throws MrtgException { ! try { ! DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); ! factory.setValidating(false); ! factory.setNamespaceAware(false); ! DocumentBuilder builder = factory.newDocumentBuilder(); ! Document doc = builder.parse(new File(Config.getHardwareFile())); ! Element root = doc.getDocumentElement(); ! NodeList nodes = root.getElementsByTagName("router"); ! deviceList = new DeviceList(); ! Vector routers = deviceList.getRouters(); ! for(int i = 0; i < nodes.getLength(); i++) { ! routers.add(new Device(nodes.item(i))); ! } ! } catch (Exception e) { ! throw new MrtgException(e); ! } ! } ! ! public String toString() { ! return deviceList.toString(); ! } ! ! synchronized int addRouter(String host, String community, String descr, boolean active) ! throws MrtgException { ! int retCode = deviceList.addRouter(host, community, descr, active); ! if(retCode == 0) { ! saveHardware(); ! } ! return retCode; ! } ! ! synchronized int updateRouter(String host, String community, String descr, boolean active) ! throws MrtgException { ! int retCode = deviceList.updateRouter(host, community, descr, active); ! if(retCode == 0) { ! saveHardware(); ! } ! return retCode; ! } ! ! synchronized int removeRouter(String host) throws MrtgException { ! int retCode = deviceList.removeRouter(host); ! if(retCode == 0) { ! saveHardware(); ! } ! return retCode; ! } ! ! synchronized int addLink(String host, String ifDescr, String descr, int samplingInterval, ! boolean active) ! throws MrtgException { ! int retCode = deviceList.addLink(host, ifDescr, descr, samplingInterval, active); ! if(retCode == 0) { ! saveHardware(); ! } ! return retCode; ! } ! ! synchronized int updateLink(String host, String ifDescr, String descr, ! int samplingInterval, boolean active) ! throws MrtgException { ! int retCode = deviceList.updateLink(host, ifDescr, descr, samplingInterval, active); ! if(retCode == 0) { ! saveHardware(); ! } ! return retCode; ! } ! ! synchronized int removeLink(String host, String ifDescr) throws MrtgException { ! int retCode = deviceList.removeLink(host, ifDescr); ! if(retCode == 0) { ! saveHardware(); ! if(REMOVE_RRD_FOR_DEACTIVATED_LINK) { ! // remove the underlying RRD file ! String rrdFile = RrdWriter.getRrdFilename(host, ifDescr); ! new File(rrdFile).delete(); ! } ! } ! return retCode; ! } ! ! synchronized byte[] getPngGraph(String host, String ifDescr, long start, long stop) ! throws MrtgException { ! Plotter grapher = new Plotter(host, ifDescr); ! return grapher.getPngGraphBytes(start, stop); ! } ! ! synchronized Device[] getRouters() { ! return (Device[]) deviceList.getRouters().toArray(new Device[0]); ! } ! ! String[] getAvailableLinks(String host) throws MrtgException { ! Device router = deviceList.getRouterByHost(host); ! try { ! if(router != null) { ! return router.getAvailableLinks(); ! } ! else { ! return null; ! } ! } catch (IOException e) { ! throw new MrtgException(e); ! } ! } ! ! DeviceList getDeviceList() { ! return deviceList; ! } ! ! RrdWriter getRrdWriter() { ! return rrdWriter; ! } ! ! Date getStartDate() { ! return startDate; ! } ! ! Hashtable getServerInfo() { ! Hashtable hash = new Hashtable(); ! hash.put("sampleCount", new Integer(rrdWriter.getSampleCount())); ! hash.put("savesCount", new Integer(rrdWriter.getSavesCount())); ! hash.put("goodSavesCount", new Integer(rrdWriter.getGoodSavesCount())); ! hash.put("badSavesCount", new Integer(rrdWriter.getBadSavesCount())); ! hash.put("startDate", startDate); ! return hash; ! } ! ! public static void main(String[] acceptedClients) throws Exception { ! Server s = Server.getInstance(); ! s.start(acceptedClients); ! } ! ! } ! |
From: Sasa M. <sa...@us...> - 2004-04-08 12:13:11
|
Update of /cvsroot/jrobin/src/org/jrobin/mrtg In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24435/org/jrobin/mrtg Modified Files: MrtgConstants.java Log Message: MRTG: Allowed for duplicate interface names found on a SNMP enabled device Index: MrtgConstants.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/mrtg/MrtgConstants.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** MrtgConstants.java 11 Mar 2004 13:54:26 -0000 1.5 --- MrtgConstants.java 8 Apr 2004 12:00:00 -0000 1.6 *************** *** 45,48 **** --- 45,51 ---- int GRAPH_WIDTH = 502, GRAPH_HEIGHT = 234; + // should we remove a RRD file if link is removed from the client + boolean REMOVE_RRD_FOR_DEACTIVATED_LINK = true; + // initial template for RrdDef String RRD_TEMPLATE_STR = |
From: Sasa M. <sa...@us...> - 2004-04-08 12:13:10
|
Update of /cvsroot/jrobin/src/org/jrobin/mrtg/server In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24435/org/jrobin/mrtg/server Modified Files: Device.java Poller.java Port.java Server.java Log Message: MRTG: Allowed for duplicate interface names found on a SNMP enabled device Index: Poller.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/mrtg/server/Poller.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** Poller.java 7 Apr 2004 13:46:05 -0000 1.2 --- Poller.java 8 Apr 2004 12:00:01 -0000 1.3 *************** *** 30,36 **** import java.net.InetAddress; import java.net.SocketException; ! import java.util.Iterator; ! import java.util.Map; ! import java.util.TreeMap; class Poller { --- 30,34 ---- import java.net.InetAddress; import java.net.SocketException; ! import java.util.*; class Poller { *************** *** 115,120 **** } ! public Map walk(String base) throws IOException { ! TreeMap map = new TreeMap(); String baseOid = getNumericOid(base); String currentOid = baseOid; --- 113,118 ---- } ! public SortedMap walk(String base) throws IOException { ! SortedMap map = new TreeMap(); String baseOid = getNumericOid(base); String currentOid = baseOid; *************** *** 143,148 **** } public int getIfIndexByIfDescr(String ifDescr) throws IOException { ! Map map = walk("ifDescr"); Iterator it = map.keySet().iterator(); while(it.hasNext()) { --- 141,168 ---- } + public SortedMap walkIfDescr() throws IOException { + SortedMap rawInterfacesMap = walk("ifDescr"); + SortedMap enumeratedInterfacesMap = new TreeMap(); + Collection enumeratedInterfaces = enumeratedInterfacesMap.values(); + // check for duplicate interface names + // append integer suffix to duplicated name + Iterator iter = rawInterfacesMap.keySet().iterator(); + while(iter.hasNext()) { + Integer ifIndex = (Integer) iter.next(); + String ifDescr = (String) rawInterfacesMap.get(ifIndex); + if(enumeratedInterfaces.contains(ifDescr)) { + int ifDescrSuffix = 1; + while(enumeratedInterfaces.contains(ifDescr + "#" + ifDescrSuffix)) { + ifDescrSuffix++; + } + ifDescr += "#" + ifDescrSuffix; + } + enumeratedInterfacesMap.put(ifIndex, ifDescr); + } + return enumeratedInterfacesMap; + } + public int getIfIndexByIfDescr(String ifDescr) throws IOException { ! SortedMap map = walkIfDescr(); Iterator it = map.keySet().iterator(); while(it.hasNext()) { Index: Port.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/mrtg/server/Port.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** Port.java 9 Dec 2003 12:22:04 -0000 1.1 --- Port.java 8 Apr 2004 12:00:01 -0000 1.2 *************** *** 93,96 **** --- 93,106 ---- } + String getIfDescrCore() { + int index = ifDescr.indexOf("#"); + if(index != -1) { + return ifDescr.substring(0, index); + } + else { + return ifDescr; + } + } + void setIfDescr(String ifDescr) { if(ifDescr != null) { *************** *** 180,184 **** void processSample(RawSample sample) throws MrtgException { // check if ifDescr match ! if(!ifDescr.equals(sample.getIfDescr())) { // something changed on the router switchToIfIndex(-1); --- 190,194 ---- void processSample(RawSample sample) throws MrtgException { // check if ifDescr match ! if(!getIfDescrCore().equals(sample.getIfDescr())) { // something changed on the router switchToIfIndex(-1); Index: Server.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/mrtg/server/Server.java,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** Server.java 11 Mar 2004 13:54:26 -0000 1.9 --- Server.java 8 Apr 2004 12:00:01 -0000 1.10 *************** *** 119,122 **** --- 119,127 ---- listener.terminate(); active = false; + try { + RrdDbPool.getInstance().reset(); + } catch (IOException e) { + throw new MrtgException(e); + } } *************** *** 217,223 **** int retCode = deviceList.removeLink(host, ifDescr); saveHardware(); ! // remove the underlying RRD file ! String rrdFile = RrdWriter.getRrdFilename(host, ifDescr); ! new File(rrdFile).delete(); return retCode; } --- 222,230 ---- int retCode = deviceList.removeLink(host, ifDescr); saveHardware(); ! if(retCode == 0 && REMOVE_RRD_FOR_DEACTIVATED_LINK) { ! // remove the underlying RRD file ! String rrdFile = RrdWriter.getRrdFilename(host, ifDescr); ! new File(rrdFile).delete(); ! } return retCode; } *************** *** 273,276 **** --- 280,284 ---- s.start(acceptedClients); } + } Index: Device.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/mrtg/server/Device.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** Device.java 9 Dec 2003 12:22:04 -0000 1.1 --- Device.java 8 Apr 2004 12:00:01 -0000 1.2 *************** *** 158,162 **** try { comm = new Poller(host, community); ! Map links = comm.walk("ifDescr"); return (String[]) links.values().toArray(new String[0]); } --- 158,162 ---- try { comm = new Poller(host, community); ! Map links = comm.walkIfDescr(); return (String[]) links.values().toArray(new String[0]); } |
From: Sasa M. <sa...@us...> - 2004-04-07 13:59:06
|
Update of /cvsroot/jrobin/src/org/jrobin/mrtg/server In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv32462/org/jrobin/mrtg/server Modified Files: Poller.java RrdWriter.java Timer.java Log Message: MRTG: SNMP port on a router can be now different from default (161). THE CODE WILL NOT COMPILE WITHOUT PATCHED VERSION OF SNMP LIBRARY! Index: Poller.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/mrtg/server/Poller.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** Poller.java 9 Dec 2003 12:22:04 -0000 1.1 --- Poller.java 7 Apr 2004 13:46:05 -0000 1.2 *************** *** 59,64 **** public Poller(String host, String community) throws IOException { ! InetAddress hostAddress = InetAddress.getByName(host); ! comm = new SNMPv1CommunicationInterface(0, hostAddress, community); comm.setSocketTimeout(SNMP_TIMEOUT * 1000); } --- 59,74 ---- public Poller(String host, String community) throws IOException { ! // check for port information ! String snmpHost = host; ! int snmpPort = SNMPv1CommunicationInterface.DEFAULT_SNMPPORT; ! int colonIndex = host.indexOf(":"); ! if(colonIndex != -1) { ! // port specified ! snmpHost = host.substring(0, colonIndex); ! String portStr = host.substring(colonIndex + 1); ! snmpPort = Integer.parseInt(portStr); ! } ! InetAddress snmpHostAddress = InetAddress.getByName(snmpHost); ! comm = new SNMPv1CommunicationInterface(0, snmpHostAddress, community, snmpPort); comm.setSocketTimeout(SNMP_TIMEOUT * 1000); } Index: Timer.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/mrtg/server/Timer.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** Timer.java 11 Mar 2004 13:54:26 -0000 1.2 --- Timer.java 7 Apr 2004 13:46:06 -0000 1.3 *************** *** 52,56 **** new SnmpReader(router, link).start(); try { ! sleep(SCHEDULER_DELAY); } catch (InterruptedException e) { e.printStackTrace(); --- 52,56 ---- new SnmpReader(router, link).start(); try { ! sleep((long)(1 + Math.random() * SCHEDULER_DELAY)); } catch (InterruptedException e) { e.printStackTrace(); Index: RrdWriter.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/mrtg/server/RrdWriter.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** RrdWriter.java 8 Mar 2004 13:14:39 -0000 1.2 --- RrdWriter.java 7 Apr 2004 13:46:05 -0000 1.3 *************** *** 119,123 **** static String getRrdFilename(String host, String ifDescr) { ! String filename = ifDescr.replaceAll("[^0-9a-zA-Z]", "_") + "@" + host + ".rrd"; return Config.getRrdDir() + filename; } --- 119,124 ---- static String getRrdFilename(String host, String ifDescr) { ! String filename = ifDescr.replaceAll("[^0-9a-zA-Z]", "_") + ! "@" + host.replaceFirst(":", "_") + ".rrd"; return Config.getRrdDir() + filename; } |
From: Sasa M. <sa...@us...> - 2004-03-31 12:13:53
|
Update of /cvsroot/jrobin/src/org/jrobin/mrtg/server In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18873/org/jrobin/mrtg/server Modified Files: Listener.java Log Message: Arne, pick xmlrpc library from our 1.3.0 release to make this code compile! :) Index: Listener.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/mrtg/server/Listener.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** Listener.java 30 Mar 2004 22:57:45 -0000 1.3 --- Listener.java 31 Mar 2004 12:02:00 -0000 1.4 *************** *** 30,34 **** import org.jrobin.mrtg.MrtgException; - import java.io.IOException; import java.util.Date; import java.util.Hashtable; --- 30,33 ---- *************** *** 39,57 **** Listener(String[] clients) throws MrtgException { ! try { ! webServer = new WebServer(SERVER_PORT); ! webServer.addHandler("mrtg", new EventHandler()); ! if(clients != null && clients.length > 0) { ! webServer.setParanoid(true); ! for(int i = 0; i < clients.length; i++) { ! webServer.acceptClient(clients[i]); ! } } - webServer.start(); - Debug.print("XmlRpcServer started on port " + SERVER_PORT); - } - catch ( IOException e ) { - throw new MrtgException( e ); } } --- 38,51 ---- Listener(String[] clients) throws MrtgException { ! webServer = new WebServer(SERVER_PORT); ! webServer.addHandler("mrtg", new EventHandler()); ! if(clients != null && clients.length > 0) { ! webServer.setParanoid(true); ! for(int i = 0; i < clients.length; i++) { ! webServer.acceptClient(clients[i]); } } + webServer.start(); + Debug.print("XmlRpcServer started on port " + SERVER_PORT); } |
From: Arne V. <cob...@us...> - 2004-03-30 23:09:42
|
Update of /cvsroot/jrobin/src/org/jrobin/graph In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv17048/src/org/jrobin/graph Modified Files: RpnCalculator.java RrdGraph.java Grapher.java ValueGrid.java ValueAxisUnit.java Source.java Cdef.java Log Message: JRobin 1.3.1 - Changed ValueGrid for different base values - Added SAMPLES and STEP RPN constants Index: RpnCalculator.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/graph/RpnCalculator.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** RpnCalculator.java 7 Nov 2003 08:23:19 -0000 1.1 --- RpnCalculator.java 30 Mar 2004 22:57:44 -0000 1.2 *************** *** 81,85 **** --- 81,88 ---- public static final byte TKN_OR = 37; public static final byte TKN_XOR = 38; + public static final byte TKN_SAMPLES = 39; + public static final byte TKN_STEP = 40; + private double step; private Source[] sources; private ArrayList stack = new ArrayList(); *************** *** 92,99 **** * Constructs a RPN calculator object by providing the source array to use for value lookups. * @param sources Table containing all retrieved datasources of the graph definition. */ ! RpnCalculator( Source[] sources ) { ! this.sources = sources; } --- 95,104 ---- * Constructs a RPN calculator object by providing the source array to use for value lookups. * @param sources Table containing all retrieved datasources of the graph definition. + * @param step Time in seconds that one sample represents. */ ! RpnCalculator( Source[] sources, double step ) { ! this.sources = sources; ! this.step = step; } *************** *** 312,315 **** --- 317,328 ---- push(((x1 != 0 && x2 == 0) || (x1 == 0 && x2 != 0))? 1: 0); break; + + case TKN_SAMPLES: + push( cdef.getSampleCount() ); + break; + + case TKN_STEP: + push( step ); + break; } } Index: ValueAxisUnit.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/graph/ValueAxisUnit.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** ValueAxisUnit.java 1 Mar 2004 08:50:25 -0000 1.3 --- ValueAxisUnit.java 30 Mar 2004 22:57:45 -0000 1.4 *************** *** 42,53 **** // -- Members // ================================================================ - - private double gridStep = 2; - private double labelStep = 10; // ================================================================ // -- Constructors ! // ================================================================ /** * Creates a ValueAxisUnit based on a minor and major grid step. --- 42,52 ---- // -- Members // ================================================================ + private double gridStep = 2; + private double labelStep = 10; // ================================================================ // -- Constructors ! // ================================================================ /** * Creates a ValueAxisUnit based on a minor and major grid step. *************** *** 60,66 **** { this.gridStep = gridStep; ! this.labelStep = labelStep; } ! double getGridStep() { return gridStep; --- 59,65 ---- { this.gridStep = gridStep; ! this.labelStep = labelStep; } ! double getGridStep() { return gridStep; *************** *** 84,89 **** ValueMarker[] getValueMarkers( double lower, double upper ) { ! double minPoint = 0.0d; ! double majPoint = 0.0d; // Find the first visible gridpoint --- 83,88 ---- ValueMarker[] getValueMarkers( double lower, double upper ) { ! double minPoint = 0.0d; ! double majPoint = 0.0d; // Find the first visible gridpoint Index: ValueGrid.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/graph/ValueGrid.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** ValueGrid.java 11 Nov 2003 11:44:11 -0000 1.3 --- ValueGrid.java 30 Mar 2004 22:57:45 -0000 1.4 *************** *** 39,42 **** --- 39,47 ---- private double upper; + private double baseValue = ValueFormatter.DEFAULT_BASE; + private double[] scaleValues = new double[] { + 1e18, 1e15, 1e12, 1e9, 1e6, 1e3, 1e0, 1e-3, 1e-6, 1e-9, 1e-12, 1e-15 + }; + private ValueAxisUnit vAxis; *************** *** 55,59 **** * ValueAxisUnit is null, one will be automatically determined. */ ! ValueGrid( GridRange gr, double low, double up, ValueAxisUnit vAxis ) { double grLower = Double.MAX_VALUE; --- 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; *************** *** 70,73 **** --- 75,91 ---- this.upper = up; this.vAxis = vAxis; + baseValue = base; + + // 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 *************** *** 122,146 **** shifted = upper; double mod = 1.0; ! while ( shifted > 10 ) { shifted /= 10; ! mod *= 10; } ! while ( shifted < 1 ) { shifted *= 10; ! mod /= 10; } ! // Create nice grid based on 'fixed' ranges if ( shifted <= 1.5 ) ! vAxis = new ValueAxisUnit( 0.1*mod, 0.5*mod ); else if ( shifted <= 3 ) ! vAxis = new ValueAxisUnit( 0.2*mod, 1.0*mod ); else if ( shifted <= 5 ) ! vAxis = new ValueAxisUnit( 0.5*mod, 1.0*mod ); else if ( shifted <= 9 ) ! vAxis = new ValueAxisUnit( 0.5*mod, 2.0*mod ); else ! vAxis = new ValueAxisUnit( 1.0*mod, 5.0*mod ); } } --- 140,181 ---- shifted = upper; + // Find the scaled unit for this range double mod = 1.0; ! int scaleIndex = scaleValues.length - 1; ! while ( scaleIndex >= 0 && scaleValues[scaleIndex] < shifted ) ! scaleIndex--; ! ! // Keep the rest of division ! double left = shifted % scaleValues[scaleIndex + 1]; ! shifted = shifted / scaleValues[++scaleIndex]; ! ! // While rest > 10, divide by 10 ! while ( shifted > 10.0 ) { shifted /= 10; ! mod *= 10; } ! ! while ( shifted < 1.0 ) { shifted *= 10; ! mod /= 10; } ! ! left = left / scaleValues[scaleIndex]; ! if ( left > 0.9 || left == 0.00 ) { ! scaleIndex--; ! mod = 1.0; ! } ! // Create nice grid based on 'fixed' ranges if ( shifted <= 1.5 ) ! vAxis = new ValueAxisUnit( 0.1 * mod * scaleValues[scaleIndex], 0.5 * mod * scaleValues[scaleIndex] ); else if ( shifted <= 3 ) ! vAxis = new ValueAxisUnit( 0.2 * mod * scaleValues[scaleIndex], 1.0 * mod * scaleValues[scaleIndex] ); else if ( shifted <= 5 ) ! vAxis = new ValueAxisUnit( 0.5 * mod * scaleValues[scaleIndex], 1.0 * mod * scaleValues[scaleIndex] ); else if ( shifted <= 9 ) ! vAxis = new ValueAxisUnit( 0.5 * mod * scaleValues[scaleIndex], 2.0 * mod * scaleValues[scaleIndex] ); else ! vAxis = new ValueAxisUnit( 0.1 * mod * scaleValues[scaleIndex], 0.5 * mod * scaleValues[scaleIndex] ); } } Index: Grapher.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/graph/Grapher.java,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** Grapher.java 1 Mar 2004 12:02:46 -0000 1.7 --- Grapher.java 30 Mar 2004 22:57:45 -0000 1.8 *************** *** 352,359 **** sourceIndex.put( cdefList[i].getName(), new Integer(tblPos++) ); } ! ! // RPN calculator for the Cdefs ! RpnCalculator rpnCalc = new RpnCalculator( sources ); ! // Fill the array for all datasources timestamps = new long[numPoints]; --- 352,356 ---- sourceIndex.put( cdefList[i].getName(), new Integer(tblPos++) ); } ! // Fill the array for all datasources timestamps = new long[numPoints]; *************** *** 364,370 **** } for (int i = 0; i < numPoints; i++) { ! long t = (long) (startTime + i * ((endTime - startTime) / (double)(numPoints - 1))); int pos = 0; --- 361,370 ---- } + // RPN calculator for the Cdefs + RpnCalculator rpnCalc = new RpnCalculator( sources, (endTime - startTime) / (double) numPoints ); + for (int i = 0; i < numPoints; i++) { ! long t = (long) (startTime + i * ((endTime - startTime) / (double) (numPoints - 1))); int pos = 0; *************** *** 521,525 **** } ! vGrid = new ValueGrid( range, lowerValue, upperValue, graphDef.getValueAxis() ); tGrid = new TimeGrid( graphDef.getStartTime(), ( graphDef.getEndTime() != 0 ? graphDef.getEndTime() : calculatedEndTime ), graphDef.getTimeAxis() ); --- 521,525 ---- } ! vGrid = new ValueGrid( range, lowerValue, upperValue, graphDef.getValueAxis(), graphDef.getBaseValue() ); tGrid = new TimeGrid( graphDef.getStartTime(), ( graphDef.getEndTime() != 0 ? graphDef.getEndTime() : calculatedEndTime ), graphDef.getTimeAxis() ); Index: Source.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/graph/Source.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** Source.java 15 Jan 2004 22:24:30 -0000 1.4 --- Source.java 30 Mar 2004 22:57:45 -0000 1.5 *************** *** 139,142 **** --- 139,146 ---- } + long getSampleCount() { + return ( values != null ? values.length : 0 ); + } + // ================================================================ Index: Cdef.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/graph/Cdef.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** Cdef.java 1 Mar 2004 08:50:25 -0000 1.4 --- Cdef.java 30 Mar 2004 22:57:45 -0000 1.5 *************** *** 179,182 **** --- 179,187 ---- else if ( tkn.equals("XOR") ) tokens[i] = RpnCalculator.TKN_XOR; + // Extra tokens for JRobin + else if ( tkn.equals("SAMPLES") ) + tokens[i] = RpnCalculator.TKN_SAMPLES; + else if ( tkn.equals("STEP") ) + tokens[i] = RpnCalculator.TKN_STEP; else throw new RrdException("Unknown token enocuntered: " + tkn); Index: RrdGraph.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/graph/RrdGraph.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** RrdGraph.java 11 Mar 2004 13:54:25 -0000 1.5 --- RrdGraph.java 30 Mar 2004 22:57:45 -0000 1.6 *************** *** 76,80 **** /** * Constructs a new JRobin graph object. ! * @param usePool True if this should object should use RrdDbPool */ public RrdGraph( boolean usePool ) --- 76,80 ---- /** * Constructs a new JRobin graph object. ! * @param usePool True if this object should use RrdDbPool */ public RrdGraph( boolean usePool ) |
From: Arne V. <cob...@us...> - 2004-03-30 23:09:27
|
Update of /cvsroot/jrobin/src/org/jrobin/mrtg/server In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv17048/src/org/jrobin/mrtg/server Modified Files: Listener.java Log Message: JRobin 1.3.1 - Changed ValueGrid for different base values - Added SAMPLES and STEP RPN constants Index: Listener.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/mrtg/server/Listener.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** Listener.java 20 Jan 2004 10:07:50 -0000 1.2 --- Listener.java 30 Mar 2004 22:57:45 -0000 1.3 *************** *** 30,33 **** --- 30,34 ---- import org.jrobin.mrtg.MrtgException; + import java.io.IOException; import java.util.Date; import java.util.Hashtable; *************** *** 38,51 **** Listener(String[] clients) throws MrtgException { ! webServer = new WebServer(SERVER_PORT); ! webServer.addHandler("mrtg", new EventHandler()); ! if(clients != null && clients.length > 0) { ! webServer.setParanoid(true); ! for(int i = 0; i < clients.length; i++) { ! webServer.acceptClient(clients[i]); } } - webServer.start(); - Debug.print("XmlRpcServer started on port " + SERVER_PORT); } --- 39,57 ---- Listener(String[] clients) throws MrtgException { ! try { ! webServer = new WebServer(SERVER_PORT); ! webServer.addHandler("mrtg", new EventHandler()); ! if(clients != null && clients.length > 0) { ! webServer.setParanoid(true); ! for(int i = 0; i < clients.length; i++) { ! webServer.acceptClient(clients[i]); ! } } + webServer.start(); + Debug.print("XmlRpcServer started on port " + SERVER_PORT); + } + catch ( IOException e ) { + throw new MrtgException( e ); } } |
From: Sasa M. <sa...@us...> - 2004-03-30 13:00:19
|
Update of /cvsroot/jrobin/src/org/jrobin/core In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19569/org/jrobin/core Modified Files: Archive.java Log Message: XFF bug resolved (?) Index: Archive.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/core/Archive.java,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** Archive.java 30 Mar 2004 09:55:22 -0000 1.13 --- Archive.java 30 Mar 2004 12:48:42 -0000 1.14 *************** *** 192,199 **** // should store long arcSteps = steps.get(); long nanSteps = state.getNanSteps(); ! double nanPct = (double) nanSteps / (double) arcSteps; double accumValue = state.getAccumValue(); ! if(nanPct < xff.get() && !Double.isNaN(accumValue)) { if(consolFun.get().equals("AVERAGE")) { accumValue /= (arcSteps - nanSteps); --- 192,200 ---- // should store long arcSteps = steps.get(); + double arcXff = xff.get(); long nanSteps = state.getNanSteps(); ! //double nanPct = (double) nanSteps / (double) arcSteps; double accumValue = state.getAccumValue(); ! if(nanSteps <= arcXff * arcSteps && !Double.isNaN(accumValue)) { if(consolFun.get().equals("AVERAGE")) { accumValue /= (arcSteps - nanSteps); |
From: Sasa M. <sa...@us...> - 2004-03-30 10:07:02
|
Update of /cvsroot/jrobin/src/org/jrobin/core In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv23258/org/jrobin/core Modified Files: Archive.java Robin.java Log Message: XFF bug resolved Index: Archive.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/core/Archive.java,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** Archive.java 26 Mar 2004 08:47:05 -0000 1.12 --- Archive.java 30 Mar 2004 09:55:22 -0000 1.13 *************** *** 195,199 **** double nanPct = (double) nanSteps / (double) arcSteps; double accumValue = state.getAccumValue(); ! if(nanPct <= xff.get() && !Double.isNaN(accumValue)) { if(consolFun.get().equals("AVERAGE")) { accumValue /= (arcSteps - nanSteps); --- 195,199 ---- double nanPct = (double) nanSteps / (double) arcSteps; double accumValue = state.getAccumValue(); ! if(nanPct < xff.get() && !Double.isNaN(accumValue)) { if(consolFun.get().equals("AVERAGE")) { accumValue /= (arcSteps - nanSteps); Index: Robin.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/core/Robin.java,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** Robin.java 26 Mar 2004 08:47:05 -0000 1.9 --- Robin.java 30 Mar 2004 09:55:22 -0000 1.10 *************** *** 103,109 **** String dump() throws IOException { StringBuffer buffer = new StringBuffer("Robin " + pointer.get() + "/" + rows + ": "); ! int startPos = pointer.get(); ! for(int i = startPos; i < startPos + rows; i++) { ! buffer.append(Util.formatDouble(values.get(i % rows), true) + " "); } buffer.append("\n"); --- 103,109 ---- String dump() throws IOException { StringBuffer buffer = new StringBuffer("Robin " + pointer.get() + "/" + rows + ": "); ! double[] values = getValues(); ! for(int i = 0; i < values.length; i++) { ! buffer.append(Util.formatDouble(values[i], true) + " "); } buffer.append("\n"); |
From: Sasa M. <sa...@us...> - 2004-03-29 14:49:57
|
Update of /cvsroot/jrobin/src/org/jrobin/core In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4289/org/jrobin/core Modified Files: RrdDouble.java RrdInt.java RrdLong.java RrdPrimitive.java RrdString.java Log Message: Squeeze the lemon. StressTest cut from 1hr to 40mins, Demo cut from 20sec to 16sec. Index: RrdString.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/core/RrdString.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** RrdString.java 27 Nov 2003 10:22:58 -0000 1.4 --- RrdString.java 29 Mar 2004 14:38:28 -0000 1.5 *************** *** 47,50 **** --- 47,51 ---- } cache = new String(c).trim(); + cached = true; } } *************** *** 56,73 **** void set(String value) throws IOException { ! cache = value.trim(); ! RrdFile rrdFile = getRrdFile(); ! rrdFile.seek(getPointer()); ! for(int i = 0; i < SIZE; i++) { ! if(i < cache.length()) { ! rrdFile.writeChar(cache.charAt(i)); ! } ! else { ! rrdFile.writeChar(' '); } } } String get() { return cache; } --- 57,79 ---- void set(String value) throws IOException { ! value = value.trim(); ! if(!cached || !cache.equals(value)) { ! RrdFile rrdFile = getRrdFile(); ! rrdFile.seek(getPointer()); ! for(int i = 0; i < SIZE; i++) { ! if(i < value.length()) { ! rrdFile.writeChar(value.charAt(i)); ! } ! else { ! rrdFile.writeChar(' '); ! } } + cache = value; + cached = true; } } String get() { + assert cached: "Not cached!"; return cache; } Index: RrdInt.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/core/RrdInt.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** RrdInt.java 27 Nov 2003 10:22:58 -0000 1.4 --- RrdInt.java 29 Mar 2004 14:38:28 -0000 1.5 *************** *** 43,46 **** --- 43,47 ---- rrdFile.seek(getPointer()); cache = rrdFile.readInt(); + cached = true; } } *************** *** 52,62 **** void set(int value) throws IOException { ! cache = value; ! RrdFile rrdFile = getRrdFile(); ! rrdFile.seek(getPointer()); ! rrdFile.writeInt(cache); } int get() { return cache; } --- 53,67 ---- void set(int value) throws IOException { ! if(!cached || cache != value) { ! RrdFile rrdFile = getRrdFile(); ! rrdFile.seek(getPointer()); ! rrdFile.writeInt(value); ! cache = value; ! cached = true; ! } } int get() { + assert cached: "Not cached!"; return cache; } Index: RrdLong.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/core/RrdLong.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** RrdLong.java 27 Nov 2003 10:22:58 -0000 1.4 --- RrdLong.java 29 Mar 2004 14:38:28 -0000 1.5 *************** *** 43,46 **** --- 43,47 ---- rrdFile.seek(getPointer()); cache = rrdFile.readLong(); + cached = true; } } *************** *** 52,62 **** void set(long value) throws IOException { ! cache = value; ! RrdFile rrdFile = getRrdFile(); ! rrdFile.seek(getPointer()); ! rrdFile.writeLong(cache); } long get() { return cache; } --- 53,67 ---- void set(long value) throws IOException { ! if(!cached || cache != value) { ! RrdFile rrdFile = getRrdFile(); ! rrdFile.seek(getPointer()); ! rrdFile.writeLong(value); ! cache = value; ! cached = true; ! } } long get() { + assert cached: "Not cached!"; return cache; } Index: RrdDouble.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/core/RrdDouble.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** RrdDouble.java 27 Nov 2003 10:22:58 -0000 1.4 --- RrdDouble.java 29 Mar 2004 14:38:28 -0000 1.5 *************** *** 43,46 **** --- 43,47 ---- rrdFile.seek(getPointer()); cache = rrdFile.readDouble(); + cached = true; } } *************** *** 52,62 **** void set(double value) throws IOException { ! cache = value; ! RrdFile rrdFile = getRrdFile(); ! rrdFile.seek(getPointer()); ! rrdFile.writeDouble(cache); } double get() { return cache; } --- 53,67 ---- void set(double value) throws IOException { ! if(!cached || cache != value) { ! RrdFile rrdFile = getRrdFile(); ! rrdFile.seek(getPointer()); ! rrdFile.writeDouble(value); ! cache = value; ! cached = true; ! } } double get() { + assert cached: "Not cached!"; return cache; } Index: RrdPrimitive.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/core/RrdPrimitive.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** RrdPrimitive.java 27 Nov 2003 14:15:11 -0000 1.3 --- RrdPrimitive.java 29 Mar 2004 14:38:28 -0000 1.4 *************** *** 32,36 **** private long pointer; private int byteCount; ! RrdPrimitive(RrdUpdater parent, int byteCount) throws IOException { this.parent = parent; --- 32,38 ---- private long pointer; private int byteCount; ! ! protected boolean cached = false; ! RrdPrimitive(RrdUpdater parent, int byteCount) throws IOException { this.parent = parent; |
From: Sasa M. <sa...@us...> - 2004-03-29 14:49:57
|
Update of /cvsroot/jrobin/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4289 Modified Files: StressTest.java Log Message: Squeeze the lemon. StressTest cut from 1hr to 40mins, Demo cut from 20sec to 16sec. Index: StressTest.java =================================================================== RCS file: /cvsroot/jrobin/src/StressTest.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** StressTest.java 24 Mar 2004 13:55:53 -0000 1.1 --- StressTest.java 29 Mar 2004 14:38:27 -0000 1.2 *************** *** 102,105 **** --- 102,106 ---- printLapTime("Buffered reader created, processing data"); int count = 0; + Date updateStart = new Date(); for(String line; (line = r.readLine()) != null;) { Sample sample = rrd.createSample(); *************** *** 107,111 **** sample.setAndUpdate(line); if(++count % 1000 == 0) { ! printLapTime(count + " samples stored"); } } --- 108,114 ---- sample.setAndUpdate(line); if(++count % 1000 == 0) { ! Date now = new Date(); ! long speed = (long)(count * 1000.0 / (now.getTime() - updateStart.getTime())); ! printLapTime(count + " samples stored, " + speed + " updates/sec"); } } |
From: Sasa M. <sa...@us...> - 2004-03-26 08:58:02
|
Update of /cvsroot/jrobin/src/org/jrobin/core In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv3248/org/jrobin/core Modified Files: Archive.java Robin.java RrdDoubleArray.java RrdFile.java Log Message: Performance improvements Index: Robin.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/core/Robin.java,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** Robin.java 24 Mar 2004 13:55:52 -0000 1.8 --- Robin.java 26 Mar 2004 08:47:05 -0000 1.9 *************** *** 66,75 **** */ public double[] getValues() throws IOException { ! double[] result = new double[rows]; ! int start = pointer.get(); ! for(int i = start, j = 0; i < start + rows; i++, j++) { ! result[j] = values.get(i % rows); ! } ! return result; } --- 66,70 ---- */ public double[] getValues() throws IOException { ! return getValues(0, rows); } *************** *** 81,88 **** } - // TODO: NOT TESTED ENOUGH // stores the same value several times void bulkStore(double newValue, int bulkCount) throws IOException { ! assert bulkCount <= rows: "Invalid number of bulk updates"; int position = pointer.get(); // update tail --- 76,83 ---- } // stores the same value several times void bulkStore(double newValue, int bulkCount) throws IOException { ! assert bulkCount <= rows: "Invalid number of bulk updates: " + bulkCount + ! " rows=" + rows; int position = pointer.get(); // update tail *************** *** 91,98 **** pointer.set((position + tailUpdateCount) % rows); // do we need to update from the start? ! int startUpdateCount = bulkCount - tailUpdateCount; ! if(startUpdateCount > 0) { ! values.set(0, newValue, startUpdateCount); ! pointer.set(startUpdateCount); } } --- 86,93 ---- pointer.set((position + tailUpdateCount) % rows); // do we need to update from the start? ! int headUpdateCount = bulkCount - tailUpdateCount; ! if(headUpdateCount > 0) { ! values.set(0, newValue, headUpdateCount); ! pointer.set(headUpdateCount); } } *************** *** 122,126 **** */ public double getValue(int index) throws IOException { ! return values.get((pointer.get() + index) % rows); } --- 117,145 ---- */ public double getValue(int index) throws IOException { ! int arrayIndex = (pointer.get() + index) % rows; ! return values.get(arrayIndex); ! } ! ! double[] getValues(int index, int count) throws IOException { ! assert count <= rows: "Too many values requested: " + count + " rows=" + rows; ! int startIndex = (pointer.get() + index) % rows; ! int tailReadCount = Math.min(rows - startIndex, count); ! double[] tailValues = values.get(startIndex, tailReadCount); ! if(tailReadCount < count) { ! int headReadCount = count - tailReadCount; ! double[] headValues = values.get(0, headReadCount); ! double[] values = new double[count]; ! int k = 0; ! for(int i = 0; i < tailValues.length; i++) { ! values[k++] = tailValues[i]; ! } ! for(int i = 0; i < headValues.length; i++) { ! values[k++] = headValues[i]; ! } ! return values; ! } ! else { ! return tailValues; ! } } Index: RrdDoubleArray.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/core/RrdDoubleArray.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** RrdDoubleArray.java 24 Mar 2004 13:55:52 -0000 1.3 --- RrdDoubleArray.java 26 Mar 2004 08:47:05 -0000 1.4 *************** *** 62,64 **** --- 62,72 ---- } + double[] get(int index, int count) throws IOException { + assert index + count <= length: "Invalid index/count supplied: " + index + + "/" + count + " (length=" + length + ")"; + RrdFile rrdFile = getRrdFile(); + rrdFile.seek(getPointer() + index * RrdDouble.SIZE); + return rrdFile.readDouble(count); + } + } Index: RrdFile.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/core/RrdFile.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** RrdFile.java 24 Mar 2004 13:55:52 -0000 1.5 --- RrdFile.java 26 Mar 2004 08:47:05 -0000 1.6 *************** *** 33,37 **** import java.util.LinkedList; import java.util.List; - import java.util.Arrays; /** --- 33,36 ---- *************** *** 180,188 **** void writeDouble(double value, int count) throws IOException { ! // THIS IS SLOW! RandomAccessFile is crap ! // for(int i = 0; i < count; i++) { ! // super.writeDouble(value); ! // } ! // HACK to speed things up! long valueAsLong = Double.doubleToLongBits(value); byte[] valueAsBytes = new byte[8]; --- 179,183 ---- void writeDouble(double value, int count) throws IOException { ! // HACK: Speed things up! long valueAsLong = Double.doubleToLongBits(value); byte[] valueAsBytes = new byte[8]; *************** *** 212,214 **** --- 207,232 ---- } + double[] readDouble(int count) throws IOException { + // HACK: Speed this up + double[] values = new double[count]; + int byteCount = 8 * count; + byte[] image = new byte[byteCount]; + if(super.read(image) == -1) { + throw new IOException("End of file reached"); + } + for(int i = 0, k = -1; i < count; i++) { + long valueAsLong = + ((image[++k] & 0xFFL) << 56) | + ((image[++k] & 0xFFL) << 48) | + ((image[++k] & 0xFFL) << 40) | + ((image[++k] & 0xFFL) << 32) | + ((image[++k] & 0xFFL) << 24) | + ((image[++k] & 0xFFL) << 16) | + ((image[++k] & 0xFFL) << 8) | + ((image[++k] & 0xFFL) ); + values[i] = Double.longBitsToDouble(valueAsLong); + } + image = null; + return values; + } } Index: Archive.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/core/Archive.java,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** Archive.java 24 Mar 2004 13:55:52 -0000 1.11 --- Archive.java 26 Mar 2004 08:47:05 -0000 1.12 *************** *** 159,170 **** } } - // update robin in bulk int bulkUpdateCount = (int) Math.min(numUpdates / steps.get(), (long) rows.get()); - //TODO: Check this - //for(long i = 0; i < bulkUpdates; i++) { - // robin.store(value); - //} - // OLD CODE ENDS robin.bulkStore(value, bulkUpdateCount); // update remaining steps --- 159,164 ---- *************** *** 335,354 **** long[] timestamps = new long[ptsCount]; double[][] values = new double[dsCount][ptsCount]; for(int ptIndex = 0; ptIndex < ptsCount; ptIndex++) { long time = fetchStart + ptIndex * arcStep; timestamps[ptIndex] = time; ! if(time >= startTime && time <= endTime) { ! // inbound time ! int robinIndex = (int)((time - startTime) / arcStep); ! for(int i = 0; i < dsCount; i++) { ! int dsIndex = parentDb.getDsIndex(dsToFetch[i]); ! values[i][ptIndex] = robins[dsIndex].getValue(robinIndex); ! } ! } ! else { ! // time out of bounds ! for(int i = 0; i < dsCount; i++) { ! values[i][ptIndex] = Double.NaN; } } } --- 329,356 ---- long[] timestamps = new long[ptsCount]; double[][] values = new double[dsCount][ptsCount]; + long matchStartTime = Math.max(fetchStart, startTime); + long matchEndTime = Math.min(fetchEnd, endTime); + double[][] robinValues = null; + if(matchStartTime <= matchEndTime) { + // preload robin values + int matchCount = (int)((matchEndTime - matchStartTime) / arcStep + 1); + int matchStartIndex = (int)((matchStartTime - startTime) / arcStep); + robinValues = new double[dsCount][]; + for(int i = 0; i < dsCount; i++) { + int dsIndex = parentDb.getDsIndex(dsToFetch[i]); + robinValues[i] = robins[dsIndex].getValues(matchStartIndex, matchCount); + } + } for(int ptIndex = 0; ptIndex < ptsCount; ptIndex++) { long time = fetchStart + ptIndex * arcStep; timestamps[ptIndex] = time; ! for(int i = 0; i < dsCount; i++) { ! double value = Double.NaN; ! if(time >= matchStartTime && time <= matchEndTime) { ! // inbound time ! int robinValueIndex = (int)((time - matchStartTime) / arcStep); ! value = robinValues[i][robinValueIndex]; } + values[i][ptIndex] = value; } } |
From: Sasa M. <sa...@us...> - 2004-03-24 14:06:30
|
Update of /cvsroot/jrobin/src/org/jrobin/core In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31594/org/jrobin/core Modified Files: Archive.java Robin.java RrdDoubleArray.java RrdFile.java Log Message: creation of big rrd files (> 1Mb) seriously improved Index: Archive.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/core/Archive.java,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** Archive.java 8 Dec 2003 13:47:40 -0000 1.10 --- Archive.java 24 Mar 2004 13:55:52 -0000 1.11 *************** *** 159,167 **** } } // update robin in bulk ! long bulkUpdates = Math.min(numUpdates / steps.get(), (long) rows.get()); ! for(long i = 0; i < bulkUpdates; i++) { ! robin.store(value); ! } // update remaining steps long remainingUpdates = numUpdates % steps.get(); --- 159,171 ---- } } + // update robin in bulk ! int bulkUpdateCount = (int) Math.min(numUpdates / steps.get(), (long) rows.get()); ! //TODO: Check this ! //for(long i = 0; i < bulkUpdates; i++) { ! // robin.store(value); ! //} ! // OLD CODE ENDS ! robin.bulkStore(value, bulkUpdateCount); // update remaining steps long remainingUpdates = numUpdates % steps.get(); Index: RrdFile.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/core/RrdFile.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** RrdFile.java 19 Feb 2004 12:23:57 -0000 1.4 --- RrdFile.java 24 Mar 2004 13:55:52 -0000 1.5 *************** *** 33,36 **** --- 33,37 ---- import java.util.LinkedList; import java.util.List; + import java.util.Arrays; /** *************** *** 178,180 **** --- 179,214 ---- } + void writeDouble(double value, int count) throws IOException { + // THIS IS SLOW! RandomAccessFile is crap + // for(int i = 0; i < count; i++) { + // super.writeDouble(value); + // } + // HACK to speed things up! + long valueAsLong = Double.doubleToLongBits(value); + byte[] valueAsBytes = new byte[8]; + // high byte comes first + valueAsBytes[7] = (byte)(valueAsLong & 0xFFL); + valueAsBytes[6] = (byte)((valueAsLong >>> 8) & 0xFFL); + valueAsBytes[5] = (byte)((valueAsLong >>> 16) & 0xFFL); + valueAsBytes[4] = (byte)((valueAsLong >>> 24) & 0xFFL); + valueAsBytes[3] = (byte)((valueAsLong >>> 32) & 0xFFL); + valueAsBytes[2] = (byte)((valueAsLong >>> 40) & 0xFFL); + valueAsBytes[1] = (byte)((valueAsLong >>> 48) & 0xFFL); + valueAsBytes[0] = (byte)((valueAsLong >>> 56) & 0xFFL); + // memory hungry, but very efficient + byte[] image = new byte[count * 8]; + for(int i = 0, k = 0; i < count; i++) { + image[k++] = valueAsBytes[0]; + image[k++] = valueAsBytes[1]; + image[k++] = valueAsBytes[2]; + image[k++] = valueAsBytes[3]; + image[k++] = valueAsBytes[4]; + image[k++] = valueAsBytes[5]; + image[k++] = valueAsBytes[6]; + image[k++] = valueAsBytes[7]; + } + super.write(image); + image = null; + } + } Index: RrdDoubleArray.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/core/RrdDoubleArray.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** RrdDoubleArray.java 27 Nov 2003 14:15:11 -0000 1.2 --- RrdDoubleArray.java 24 Mar 2004 13:55:52 -0000 1.3 *************** *** 39,60 **** super(updater, length * RrdDouble.SIZE); this.length = length; ! for(int i = 0; i < length; i++) { ! set(i, initVal); ! } } void set(int index, double value) throws IOException { ! if(index >= length) { ! throw new IOException("Invalid index supplied: " + index + ", max = " + length); ! } RrdFile rrdFile = getRrdFile(); rrdFile.seek(getPointer() + index * RrdDouble.SIZE); ! rrdFile.writeDouble(value); } double get(int index) throws IOException { ! if(index >= length) { ! throw new IOException("Invalid index supplied: " + index + ", max = " + length); ! } RrdFile rrdFile = getRrdFile(); rrdFile.seek(getPointer() + index * RrdDouble.SIZE); --- 39,60 ---- super(updater, length * RrdDouble.SIZE); this.length = length; ! set(0, initVal, length); } void set(int index, double value) throws IOException { ! set(index, value, 1); ! } ! ! void set(int index, double value, int count) throws IOException { ! // rollovers not allowed! ! assert index + count <= length: "Invalid robin index supplied: index=" + index + ! ", count=" + count + ", length=" + length; RrdFile rrdFile = getRrdFile(); rrdFile.seek(getPointer() + index * RrdDouble.SIZE); ! rrdFile.writeDouble(value, count); } double get(int index) throws IOException { ! assert index < length: "Invalid index supplied: " + index + ", length=" + length; RrdFile rrdFile = getRrdFile(); rrdFile.seek(getPointer() + index * RrdDouble.SIZE); Index: Robin.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/core/Robin.java,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** Robin.java 8 Dec 2003 13:47:40 -0000 1.7 --- Robin.java 24 Mar 2004 13:55:52 -0000 1.8 *************** *** 74,77 **** --- 74,78 ---- } + // stores single value void store(double newValue) throws IOException { int position = pointer.get(); *************** *** 80,83 **** --- 81,101 ---- } + // TODO: NOT TESTED ENOUGH + // stores the same value several times + void bulkStore(double newValue, int bulkCount) throws IOException { + assert bulkCount <= rows: "Invalid number of bulk updates"; + int position = pointer.get(); + // update tail + int tailUpdateCount = Math.min(rows - position, bulkCount); + values.set(position, newValue, tailUpdateCount); + pointer.set((position + tailUpdateCount) % rows); + // do we need to update from the start? + int startUpdateCount = bulkCount - tailUpdateCount; + if(startUpdateCount > 0) { + values.set(0, newValue, startUpdateCount); + pointer.set(startUpdateCount); + } + } + /** * Returns the underlying RrdFile object. |
From: Sasa M. <sa...@us...> - 2004-03-24 14:06:30
|
Update of /cvsroot/jrobin/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31594 Added Files: StressTest.java Log Message: creation of big rrd files (> 1Mb) seriously improved --- NEW FILE: StressTest.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. * * This library is free software; you can redistribute it and/or modify it under the terms * of the GNU Lesser General Public License as published by the Free Software Foundation; * either version 2.1 of the License, or (at your option) any later version. * * Developers: Sasa Markovic (sa...@jr...) * Arne Vandamme (cob...@jr...) * * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License along with this * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, * Boston, MA 02111-1307, USA. */ import org.jrobin.core.*; import org.jrobin.graph.RrdGraphDef; import org.jrobin.graph.RrdGraph; import java.io.IOException; import java.io.BufferedReader; import java.io.FileReader; import java.util.Date; import java.awt.*; class StressTest { public static final String RRD_PATH = Util.getJRobinDemoPath("stress.rrd"); public static final long RRD_START = 946710000L; public static final long RRD_STEP = 30; public static final String RRD_DATASOURCE_NAME = "T"; public static final int RRD_DATASOURCE_COUNT = 6; public static final long TIME_START = 1060142010L; public static final long TIME_END = 1080013472L; public static final String PNG_PATH = Util.getJRobinDemoPath("stress.png"); public static final int PNG_WIDTH = 400; public static final int PNG_HEIGHT = 250; public static void printLapTime(String message) { System.out.println(message + " " + Util.getLapTime()); } public static void main(String[] args) throws RrdException, IOException { if(args.length == 0) { System.out.println("Usage: StressTest [path to stress-test.txt file]"); System.out.println("You can download separate stress-test.txt file from:"); System.out.println("http://www.sourceforge.net/projects/jrobin"); System.exit(-1); } System.out.println("********************************************************************"); System.out.println("* JRobinStressTest *"); System.out.println("* *"); System.out.println("* This demo creates single RRD file and tries to update it *"); System.out.println("* more than 600.000 times. Real data (> 20Mb) is obtained from the *"); System.out.println("* stress-test.txt file provided by Vadim Tkachenko *"); System.out.println("* (http://diy-zoning.sourceforge.net). *"); System.out.println("* *"); System.out.println("* Finally, a single PNG graph will be created from the RRD file. *"); System.out.println("* The stress test takes about one hour to complete on a 1.6GHz *"); System.out.println("* computer with 256MB of RAM. *"); System.out.println("********************************************************************"); printLapTime("Starting demo at " + new Date()); // create RRD database printLapTime("Creating RRD definition"); RrdDef def = new RrdDef(RRD_PATH); def.setStartTime(RRD_START); def.setStep(RRD_STEP); for(int i = 0; i < RRD_DATASOURCE_COUNT; i++) { def.addDatasource(RRD_DATASOURCE_NAME + i, "GAUGE", 90, -60, 85); } def.addArchive("LAST", 0.5, 1, 5760); def.addArchive("MIN", 0.5, 1, 5760); def.addArchive("MAX", 0.5, 1, 5760); def.addArchive("AVERAGE", 0.5, 5, 13824); def.addArchive("MIN", 0.5, 5, 13824); def.addArchive("MAX", 0.5, 5, 13824); def.addArchive("AVERAGE", 0.5, 60, 16704); def.addArchive("MIN", 0.5, 60, 16704); def.addArchive("MAX", 0.5, 60, 16704); def.addArchive("AVERAGE", 0.5, 1440, 50000); def.addArchive("MIN", 0.5, 1440, 50000); def.addArchive("MAX", 0.5, 1440, 50000); //printLapTime(def.dump()); printLapTime("Definition created, creating RRD file"); RrdDbPool pool = RrdDbPool.getInstance(); RrdDb rrd = pool.requestRrdDb(def); printLapTime("RRD file created: " + RRD_PATH); BufferedReader r = new BufferedReader(new FileReader(args[0])); printLapTime("Buffered reader created, processing data"); int count = 0; for(String line; (line = r.readLine()) != null;) { Sample sample = rrd.createSample(); try { sample.setAndUpdate(line); if(++count % 1000 == 0) { printLapTime(count + " samples stored"); } } catch(RrdException e) { printLapTime("RRD ERROR: " + line); } } pool.release(rrd); printLapTime("FINISHED: " + count + " samples stored"); // GRAPH printLapTime("Creating composite graph definition"); RrdGraphDef gdef = new RrdGraphDef(TIME_START, TIME_END); gdef.setTitle("Temperatures"); gdef.setVerticalLabel("Fahrenheits"); final Color[] colors = { Color.RED, Color.GREEN, Color.BLUE, Color.MAGENTA, Color.CYAN, Color.ORANGE }; // datasources for(int i = 0; i < RRD_DATASOURCE_COUNT; i++) { String name = RRD_DATASOURCE_NAME + i; gdef.datasource(name, RRD_PATH, name, "AVERAGE"); } // lines for(int i = 0; i < RRD_DATASOURCE_COUNT; i++) { String name = RRD_DATASOURCE_NAME + i; gdef.line(name, colors[i], name); } gdef.comment("@c"); gdef.comment("\nOriginal data provided by diy-zoning.sf.net@c"); printLapTime("Graph definition created"); RrdGraph g = new RrdGraph(gdef, true); g.saveAsPNG(PNG_PATH, PNG_WIDTH, PNG_HEIGHT); printLapTime("Graph saved: " + PNG_PATH); printLapTime("Finished at " + new Date()); } } |
From: Sasa M. <sa...@us...> - 2004-03-22 09:37:29
|
Update of /cvsroot/jrobin/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv29326 Modified Files: Demo.java Log Message: final tweaks Index: Demo.java =================================================================== RCS file: /cvsroot/jrobin/src/Demo.java,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** Demo.java 22 Mar 2004 09:20:12 -0000 1.12 --- Demo.java 22 Mar 2004 09:27:13 -0000 1.13 *************** *** 175,179 **** static void println(String msg) { ! System.out.println(msg + " " + Util.getLapTime()); } --- 175,180 ---- static void println(String msg) { ! //System.out.println(msg + " " + Util.getLapTime()); ! System.out.println(msg); } |
From: Sasa M. <sa...@us...> - 2004-03-22 09:30:44
|
Update of /cvsroot/jrobin/src/org/jrobin/core In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv27847/org/jrobin/core Modified Files: Util.java Log Message: final tweaks Index: Util.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/core/Util.java,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** Util.java 26 Feb 2004 13:15:54 -0000 1.12 --- Util.java 22 Mar 2004 09:20:12 -0000 1.13 *************** *** 446,449 **** --- 446,464 ---- } } + + private static Date lastLap = new Date(); + + /** + * Function used for debugging purposes and performance bottlenecks detection. + * Probably of no use for end users of JRobin. + * @return String representing time in seconds since last + * <code>getLapTime()</code> method call. + */ + public static String getLapTime() { + Date newLap = new Date(); + double seconds = (newLap.getTime() - lastLap.getTime()) / 1000.0; + lastLap = newLap; + return "[" + seconds + " sec]"; + } } |