From: Sasa M. <sa...@us...> - 2004-09-20 15:10:31
|
Update of /cvsroot/jrobin/src/org/jrobin/core In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv23449/org/jrobin/core Modified Files: ArcDef.java Archive.java Datasource.java DsDef.java FetchData.java RrdDataSet.java RrdDb.java RrdDef.java Added Files: ConsolFuns.java DsTypes.java Log Message: Strings like "AVERAGE" or "GAUGE" replaced with constants like ConsolFuns.AVERAGE and DsTypes.GAUGE. This change does not affect existing JRobin-based code (since constants are defined as Strings) Index: FetchData.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/core/FetchData.java,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** FetchData.java 12 Jul 2004 13:35:16 -0000 1.8 --- FetchData.java 20 Sep 2004 15:10:18 -0000 1.9 *************** *** 54,58 **** * the values returned with {@link #getTimestamps() getTimestamps()} method.<p> */ ! public class FetchData implements RrdDataSet { private FetchRequest request; private Archive matchingArchive; --- 54,58 ---- * the values returned with {@link #getTimestamps() getTimestamps()} method.<p> */ ! public class FetchData implements RrdDataSet, ConsolFuns { private FetchRequest request; private Archive matchingArchive; *************** *** 276,280 **** * @param dsName Datasource name * @param consolFun Consolidation function to be applied to fetched datasource values. ! * Valid consolidation functions are MIN, MAX, LAST and AVERAGE * @return MIN, MAX, LAST or AVERAGE value calculated from the fetched data * for the given datasource name --- 276,281 ---- * @param dsName Datasource name * @param consolFun Consolidation function to be applied to fetched datasource values. ! * Valid consolidation functions are MIN, MAX, LAST and AVERAGE (these string constants ! * are conveniently defined in the {@link ConsolFuns} class). * @return MIN, MAX, LAST or AVERAGE value calculated from the fetched data * for the given datasource name *************** *** 290,299 **** * data. For example, if you have a gauge datasource named 'foots' but you wont to * find the maximum fetched value in meters use something like:</p> ! * <code>getAggregate("foots", "MAX", "value,0.3048,*");</code> * Note that 'value' in the RPN expression is a reserved word and stands for the * original value (value fetched from RRD)</p> * @param dsName Datasource name * @param consolFun Consolidation function to be applied to fetched datasource values. ! * Valid consolidation functions are MIN, MAX, LAST and AVERAGE * @return MIN, MAX, LAST or AVERAGE value calculated from the fetched data * for the given datasource name --- 291,301 ---- * data. For example, if you have a gauge datasource named 'foots' but you wont to * find the maximum fetched value in meters use something like:</p> ! * <code>getAggregate("foots", ConsolFuns.MAX, "value,0.3048,*");</code> * Note that 'value' in the RPN expression is a reserved word and stands for the * original value (value fetched from RRD)</p> * @param dsName Datasource name * @param consolFun Consolidation function to be applied to fetched datasource values. ! * Valid consolidation functions are MIN, MAX, LAST and AVERAGE (these string constants ! * are conveniently defined in the {@link ConsolFuns} class) * @return MIN, MAX, LAST or AVERAGE value calculated from the fetched data * for the given datasource name *************** *** 302,315 **** public double getAggregate(String dsName, String consolFun, String rpnExpression) throws RrdException { ! if(consolFun.equals("MAX")) { return getMax(dsName, rpnExpression); } ! else if(consolFun.equals("MIN")) { return getMin(dsName, rpnExpression); } ! else if(consolFun.equals("LAST")) { return getLast(dsName, rpnExpression); } ! else if(consolFun.equals("AVERAGE")) { return getAverage(dsName, rpnExpression); } --- 304,317 ---- public double getAggregate(String dsName, String consolFun, String rpnExpression) throws RrdException { ! if(consolFun.equals(MAX)) { return getMax(dsName, rpnExpression); } ! else if(consolFun.equals(MIN)) { return getMin(dsName, rpnExpression); } ! else if(consolFun.equals(LAST)) { return getLast(dsName, rpnExpression); } ! else if(consolFun.equals(AVERAGE)) { return getAverage(dsName, rpnExpression); } Index: RrdDataSet.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/core/RrdDataSet.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** RrdDataSet.java 10 Jul 2004 00:06:29 -0000 1.2 --- RrdDataSet.java 20 Sep 2004 15:10:18 -0000 1.3 *************** *** 128,132 **** * @param dsName Datasource name * @param consolFun Consolidation function to be applied to set datasource values datasource. ! * Valid consolidation functions are MIN, MAX, LAST and AVERAGE * @return MIN, MAX, LAST or AVERAGE value calculated from the dataset for the given datasource name * @throws RrdException Thrown if the given datasource name cannot be found in the dataset. --- 128,133 ---- * @param dsName Datasource name * @param consolFun Consolidation function to be applied to set datasource values datasource. ! * Valid consolidation functions are MIN, MAX, LAST and AVERAGE (these string constants ! * are conveniently defined in the {@link ConsolFuns} class) * @return MIN, MAX, LAST or AVERAGE value calculated from the dataset for the given datasource name * @throws RrdException Thrown if the given datasource name cannot be found in the dataset. Index: RrdDef.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/core/RrdDef.java,v retrieving revision 1.15 retrieving revision 1.16 diff -C2 -d -r1.15 -r1.16 *** RrdDef.java 18 Aug 2004 08:02:17 -0000 1.15 --- RrdDef.java 20 Sep 2004 15:10:18 -0000 1.16 *************** *** 197,201 **** * @param dsName Data source name. * @param dsType Data source type. Valid types are "COUNTER", ! * "GAUGE", "DERIVE" and "ABSOLUTE". * @param heartbeat Data source heartbeat. * @param minValue Minimal acceptable value. Use <code>Double.NaN</code> if unknown. --- 197,202 ---- * @param dsName Data source name. * @param dsType Data source type. Valid types are "COUNTER", ! * "GAUGE", "DERIVE" and "ABSOLUTE" (these string constants are conveniently defined in ! * the {@link DsTypes} class). * @param heartbeat Data source heartbeat. * @param minValue Minimal acceptable value. Use <code>Double.NaN</code> if unknown. *************** *** 311,315 **** * <a href="../../../../man/rrdcreate.html" target="man">rrdcreate man page</a>.</p> * @param consolFun Consolidation function. Valid values are "AVERAGE", ! * "MIN", "MAX" and "LAST" * @param xff X-files factor. Valid values are between 0 and 1. * @param steps Number of archive steps --- 312,317 ---- * <a href="../../../../man/rrdcreate.html" target="man">rrdcreate man page</a>.</p> * @param consolFun Consolidation function. Valid values are "AVERAGE", ! * "MIN", "MAX" and "LAST" (these constants are also defined in the ! * {@link ConsolFuns} class) * @param xff X-files factor. Valid values are between 0 and 1. * @param steps Number of archive steps Index: Datasource.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/core/Datasource.java,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** Datasource.java 22 Jul 2004 09:34:10 -0000 1.7 --- Datasource.java 20 Sep 2004 15:10:18 -0000 1.8 *************** *** 39,43 **** */ ! public class Datasource implements RrdUpdater { private RrdDb parentDb; // definition --- 39,43 ---- */ ! public class Datasource implements RrdUpdater, DsTypes { private RrdDb parentDb; // definition *************** *** 208,225 **** if(newTime - oldTime <= heartbeat.get()) { String type = dsType.get(); ! if(type.equals("GAUGE")) { updateValue = newValue; } ! else if(type.equals("ABSOLUTE")) { if(!Double.isNaN(newValue)) { updateValue = newValue / (newTime - oldTime); } } ! else if(type.equals("DERIVE")) { if(!Double.isNaN(newValue) && !Double.isNaN(oldValue)) { updateValue = (newValue - oldValue) / (newTime - oldTime); } } ! else if(type.equals("COUNTER")) { if(!Double.isNaN(newValue) && !Double.isNaN(oldValue)) { double diff = newValue - oldValue; --- 208,225 ---- if(newTime - oldTime <= heartbeat.get()) { String type = dsType.get(); ! if(type.equals(GAUGE)) { updateValue = newValue; } ! else if(type.equals(ABSOLUTE)) { if(!Double.isNaN(newValue)) { updateValue = newValue / (newTime - oldTime); } } ! else if(type.equals(DERIVE)) { if(!Double.isNaN(newValue) && !Double.isNaN(oldValue)) { updateValue = (newValue - oldValue) / (newTime - oldTime); } } ! else if(type.equals(COUNTER)) { if(!Double.isNaN(newValue) && !Double.isNaN(oldValue)) { double diff = newValue - oldValue; --- NEW FILE: ConsolFuns.java --- /* ============================================================ * JRobin : Pure java implementation of RRDTool's functionality * ============================================================ * * Project Info: http://www.jrobin.org * Project Lead: Sasa Markovic (sa...@jr...); * * (C) Copyright 2003, by Sasa Markovic. * * Developers: Sasa Markovic (sa...@jr...) * Arne Vandamme (cob...@jr...) * * This library is free software; you can redistribute it and/or modify it under the terms * of the GNU Lesser General Public License as published by the Free Software Foundation; * either version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License along with this * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, * Boston, MA 02111-1307, USA. */ package org.jrobin.core; /** * Simple interface to represent available consolidation functions */ public interface ConsolFuns { /** Constant to represent AVERAGE consolidation function */ public static final String AVERAGE = "AVERAGE"; /** Constant to represent MIN consolidation function */ public static final String MIN = "MIN"; /** Constant to represent MAX consolidation function */ public static final String MAX = "MAX"; /** Constant to represent LAST consolidation function */ public static final String LAST = "LAST"; } --- NEW FILE: DsTypes.java --- /* ============================================================ * JRobin : Pure java implementation of RRDTool's functionality * ============================================================ * * Project Info: http://www.jrobin.org * Project Lead: Sasa Markovic (sa...@jr...); * * (C) Copyright 2003, by Sasa Markovic. * * Developers: Sasa Markovic (sa...@jr...) * Arne Vandamme (cob...@jr...) * * This library is free software; you can redistribute it and/or modify it under the terms * of the GNU Lesser General Public License as published by the Free Software Foundation; * either version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License along with this * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, * Boston, MA 02111-1307, USA. */ package org.jrobin.core; /** * Simple interface to represent available datasource types. */ public interface DsTypes { /** Constant to represent GAUGE datasource type */ public static final String GAUGE = "GAUGE"; /** Constant to represent COUNTER datasource type */ public static final String COUNTER = "COUNTER"; /** Constant to represent DERIVE datasource type */ public static final String DERIVE = "DERIVE"; /** Constant to represent ABSOLUTE datasource type */ public static final String ABSOLUTE = "ABSOLUTE"; } Index: DsDef.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/core/DsDef.java,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** DsDef.java 19 Aug 2004 10:53:52 -0000 1.7 --- DsDef.java 20 Sep 2004 15:10:18 -0000 1.8 *************** *** 42,48 **** * @author <a href="mailto:sa...@jr...">Sasa Markovic</a> */ ! public class DsDef { /** array of valid source types */ ! public static final String[] DS_TYPES = { "GAUGE", "COUNTER", "DERIVE", "ABSOLUTE" }; private String dsName, dsType; --- 42,48 ---- * @author <a href="mailto:sa...@jr...">Sasa Markovic</a> */ ! public class DsDef implements DsTypes { /** array of valid source types */ ! public static final String[] DS_TYPES = { GAUGE, COUNTER, DERIVE, ABSOLUTE }; private String dsName, dsType; *************** *** 52,57 **** /** * <p>Creates new data source definition object. This object should be passed as argument ! * to {@link org.jrobin.core.RrdDef#addDatasource(org.jrobin.core.DsDef) addDatasource()} method of ! * {@link org.jrobin.core.RrdDb RrdDb} object.</p> * * <p>For the complete explanation of all source definition parameters, see RRDTool's --- 52,57 ---- /** * <p>Creates new data source definition object. This object should be passed as argument ! * to {@link org.jrobin.core.RrdDef#addDatasource(org.jrobin.core.DsDef) addDatasource()} ! * method of {@link org.jrobin.core.RrdDb RrdDb} object.</p> * * <p>For the complete explanation of all source definition parameters, see RRDTool's *************** *** 60,64 **** * @param dsName Data source name. * @param dsType Data source type. Valid values are "COUNTER", "GAUGE", "DERIVE" ! * and "ABSOLUTE" * @param heartbeat Hearbeat * @param minValue Minimal value. Use <code>Double.NaN</code> if unknown. --- 60,65 ---- * @param dsName Data source name. * @param dsType Data source type. Valid values are "COUNTER", "GAUGE", "DERIVE" ! * and "ABSOLUTE" (these string constants are conveniently defined in the ! * {@link DsTypes} class). * @param heartbeat Hearbeat * @param minValue Minimal value. Use <code>Double.NaN</code> if unknown. Index: ArcDef.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/core/ArcDef.java,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** ArcDef.java 20 Jul 2004 08:21:01 -0000 1.7 --- ArcDef.java 20 Sep 2004 15:10:18 -0000 1.8 *************** *** 43,49 **** */ ! public class ArcDef { /** array of valid consolidation function names */ ! public static final String CONSOL_FUNS[] = { "AVERAGE", "MAX", "MIN", "LAST" }; private String consolFun; --- 43,49 ---- */ ! public class ArcDef implements ConsolFuns { /** array of valid consolidation function names */ ! public static final String CONSOL_FUNS[] = { AVERAGE, MAX, MIN, LAST }; private String consolFun; *************** *** 60,64 **** * * @param consolFun Consolidation function. Allowed values are "AVERAGE", "MIN", ! * "MAX" and "LAST". * @param xff X-files factor, between 0 and 1. * @param steps Number of archive steps. --- 60,65 ---- * * @param consolFun Consolidation function. Allowed values are "AVERAGE", "MIN", ! * "MAX" and "LAST" (these string constants are conveniently defined in the ! * {@link ConsolFuns} class). * @param xff X-files factor, between 0 and 1. * @param steps Number of archive steps. Index: Archive.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/core/Archive.java,v retrieving revision 1.16 retrieving revision 1.17 diff -C2 -d -r1.16 -r1.17 *** Archive.java 22 Jul 2004 09:34:10 -0000 1.16 --- Archive.java 20 Sep 2004 15:10:18 -0000 1.17 *************** *** 39,43 **** * @author <a href="mailto:sa...@jr...">Sasa Markovic</a> */ ! public class Archive implements RrdUpdater { private RrdDb parentDb; // definition --- 39,43 ---- * @author <a href="mailto:sa...@jr...">Sasa Markovic</a> */ ! public class Archive implements RrdUpdater, ConsolFuns { private RrdDb parentDb; // definition *************** *** 149,162 **** } else { ! if(consolFun.get().equals("MIN")) { state.setAccumValue(Util.min(state.getAccumValue(), value)); } ! else if(consolFun.get().equals("MAX")) { state.setAccumValue(Util.max(state.getAccumValue(), value)); } ! else if(consolFun.get().equals("LAST")) { state.setAccumValue(value); } ! else if(consolFun.get().equals("AVERAGE")) { state.setAccumValue(Util.sum(state.getAccumValue(), value)); } --- 149,162 ---- } else { ! if(consolFun.get().equals(MIN)) { state.setAccumValue(Util.min(state.getAccumValue(), value)); } ! else if(consolFun.get().equals(MAX)) { state.setAccumValue(Util.max(state.getAccumValue(), value)); } ! else if(consolFun.get().equals(LAST)) { state.setAccumValue(value); } ! else if(consolFun.get().equals(AVERAGE)) { state.setAccumValue(Util.sum(state.getAccumValue(), value)); } *************** *** 172,176 **** double accumValue = state.getAccumValue(); if(nanSteps <= arcXff * arcSteps && !Double.isNaN(accumValue)) { ! if(consolFun.get().equals("AVERAGE")) { accumValue /= (arcSteps - nanSteps); } --- 172,176 ---- double accumValue = state.getAccumValue(); if(nanSteps <= arcXff * arcSteps && !Double.isNaN(accumValue)) { ! if(consolFun.get().equals(AVERAGE)) { accumValue /= (arcSteps - nanSteps); } *************** *** 185,189 **** /** ! * Returns archive consolidation function (AVERAGE, MIN, MAX or LAST). * @return Archive consolidation function. * @throws IOException Thrown in case of I/O error. --- 185,189 ---- /** ! * Returns archive consolidation function ("AVERAGE", "MIN", "MAX" or "LAST"). * @return Archive consolidation function. * @throws IOException Thrown in case of I/O error. Index: RrdDb.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/core/RrdDb.java,v retrieving revision 1.28 retrieving revision 1.29 diff -C2 -d -r1.28 -r1.29 *** RrdDb.java 18 Aug 2004 12:49:46 -0000 1.28 --- RrdDb.java 20 Sep 2004 15:10:18 -0000 1.29 *************** *** 106,119 **** * // create new RRD definition * RrdDef def = new RrdDef("test.rrd", 300); ! * def.addDatasource("input", "COUNTER", 600, 0, Double.NaN); ! * def.addDatasource("output", "COUNTER", 600, 0, Double.NaN); ! * def.addArchive("AVERAGE", 0.5, 1, 600); ! * def.addArchive("AVERAGE", 0.5, 6, 700); ! * def.addArchive("AVERAGE", 0.5, 24, 797); ! * def.addArchive("AVERAGE", 0.5, 288, 775); ! * def.addArchive("MAX", 0.5, 1, 600); ! * def.addArchive("MAX", 0.5, 6, 700); ! * def.addArchive("MAX", 0.5, 24, 797); ! * def.addArchive("MAX", 0.5, 288, 775); * * // RRD definition is now completed, create the database! --- 106,119 ---- * // create new RRD definition * RrdDef def = new RrdDef("test.rrd", 300); ! * def.addDatasource("input", DsTypes.COUNTER, 600, 0, Double.NaN); ! * def.addDatasource("output", DsTypes.COUNTER, 600, 0, Double.NaN); ! * def.addArchive(ConsolFuns.AVERAGE, 0.5, 1, 600); ! * def.addArchive(ConsolFuns.AVERAGE, 0.5, 6, 700); ! * def.addArchive(ConsolFuns.AVERAGE, 0.5, 24, 797); ! * def.addArchive(ConsolFuns.AVERAGE, 0.5, 288, 775); ! * def.addArchive(ConsolFuns.MAX, 0.5, 1, 600); ! * def.addArchive(ConsolFuns.MAX, 0.5, 6, 700); ! * def.addArchive(ConsolFuns.MAX, 0.5, 24, 797); ! * def.addArchive(ConsolFuns.MAX, 0.5, 288, 775); * * // RRD definition is now completed, create the database! *************** *** 514,518 **** * method to actually fetch data from the RRD file.</p> * @param consolFun Consolidation function to be used in fetch request. Allowed values are ! * "AVERAGE", "MIN", "MAX" and "LAST". * @param fetchStart Starting timestamp for fetch request. * @param fetchEnd Ending timestamp for fetch request. --- 514,519 ---- * method to actually fetch data from the RRD file.</p> * @param consolFun Consolidation function to be used in fetch request. Allowed values are ! * "AVERAGE", "MIN", "MAX" and "LAST" (these constants are conveniently defined in the ! * {@link ConsolFuns} class). * @param fetchStart Starting timestamp for fetch request. * @param fetchEnd Ending timestamp for fetch request. *************** *** 538,542 **** * * @param consolFun Consolidation function to be used in fetch request. Allowed values are ! * "AVERAGE", "MIN", "MAX" and "LAST". * @param fetchStart Starting timestamp for fetch request. * @param fetchEnd Ending timestamp for fetch request. --- 539,544 ---- * * @param consolFun Consolidation function to be used in fetch request. Allowed values are ! * "AVERAGE", "MIN", "MAX" and "LAST" (these constants are conveniently defined in the ! * {@link ConsolFuns} class). * @param fetchStart Starting timestamp for fetch request. * @param fetchEnd Ending timestamp for fetch request. |