You can subscribe to this list here.
| 2003 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
(11) |
Oct
(60) |
Nov
(68) |
Dec
(10) |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 2004 |
Jan
(10) |
Feb
(15) |
Mar
(30) |
Apr
(20) |
May
(32) |
Jun
(30) |
Jul
(61) |
Aug
(13) |
Sep
(14) |
Oct
(13) |
Nov
(28) |
Dec
(10) |
| 2005 |
Jan
(7) |
Feb
(5) |
Mar
|
Apr
(2) |
May
|
Jun
|
Jul
|
Aug
|
Sep
(4) |
Oct
|
Nov
|
Dec
|
| 2006 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
(15) |
| 2007 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
(20) |
Aug
(35) |
Sep
(3) |
Oct
(2) |
Nov
|
Dec
|
| 2008 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
(14) |
Sep
(2) |
Oct
|
Nov
|
Dec
|
| 2010 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
(3) |
| 2011 |
Jan
|
Feb
|
Mar
|
Apr
(5) |
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
|
From: <sa...@us...> - 2003-12-04 13:21:07
|
Update of /cvsroot/jrobin/src/org/jrobin/mrtg/client
In directory sc8-pr-cvs1:/tmp/cvs-serv7205/org/jrobin/mrtg/client
Modified Files:
AboutDialog.java Client.java HostDialog.java
Log Message:
Major enhancements to Inspector swing app. Supports interactive add/edit/remove operations on RRD datasources/archives. Several methods added to RrdToolkit - no plans to extend it further.
Index: AboutDialog.java
===================================================================
RCS file: /cvsroot/jrobin/src/org/jrobin/mrtg/client/AboutDialog.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** AboutDialog.java 10 Nov 2003 08:52:29 -0000 1.2
--- AboutDialog.java 4 Dec 2003 13:21:03 -0000 1.3
***************
*** 35,38 ****
--- 35,39 ----
class AboutDialog extends JDialog {
static final String TITLE = "About JRobin";
+ static final String EMAIL = "sa...@eu...";
static final String LOGO = "mrtg-res/logo.png";
private static final int GAP = 3;
***************
*** 79,83 ****
box.add(copyrightLabel);
box.add(Box.createVerticalStrut(GAP));
! JLabel emailLabel = new JLabel("sa...@jr...");
emailLabel.setHorizontalAlignment(JLabel.CENTER);
emailLabel.setAlignmentX(0.5F);
--- 80,84 ----
box.add(copyrightLabel);
box.add(Box.createVerticalStrut(GAP));
! JLabel emailLabel = new JLabel(EMAIL);
emailLabel.setHorizontalAlignment(JLabel.CENTER);
emailLabel.setAlignmentX(0.5F);
Index: Client.java
===================================================================
RCS file: /cvsroot/jrobin/src/org/jrobin/mrtg/client/Client.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** Client.java 10 Nov 2003 08:52:29 -0000 1.3
--- Client.java 4 Dec 2003 13:21:03 -0000 1.4
***************
*** 38,42 ****
class Client extends JFrame {
! static final String TITLE = "JRobin-MRTG client 1.2.0";
static final String SUBTITLE = "http://www.jrobin.org";
static final String COPYRIGHT = "Copyright \u00A9 2003 Sasa Markovic";
--- 38,42 ----
class Client extends JFrame {
! static final String TITLE = "JRobin-MRTG client";
static final String SUBTITLE = "http://www.jrobin.org";
static final String COPYRIGHT = "Copyright \u00A9 2003 Sasa Markovic";
Index: HostDialog.java
===================================================================
RCS file: /cvsroot/jrobin/src/org/jrobin/mrtg/client/HostDialog.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** HostDialog.java 10 Nov 2003 08:52:29 -0000 1.2
--- HostDialog.java 4 Dec 2003 13:21:03 -0000 1.3
***************
*** 35,39 ****
class HostDialog extends JDialog {
private static final String HOST_FILENAME = System.getProperty("user.home") +
! System.getProperty("file.separator") + "last-mrtg-host";
private static final String DEFAULT_HOST = "localhost";
private static final String TITLE = "Select JRobin-MRTG host";
--- 35,39 ----
class HostDialog extends JDialog {
private static final String HOST_FILENAME = System.getProperty("user.home") +
! System.getProperty("file.separator") + ".last-mrtg-host";
private static final String DEFAULT_HOST = "localhost";
private static final String TITLE = "Select JRobin-MRTG host";
|
|
From: <sa...@us...> - 2003-12-04 13:21:06
|
Update of /cvsroot/jrobin/src/org/jrobin/core
In directory sc8-pr-cvs1:/tmp/cvs-serv7205/org/jrobin/core
Modified Files:
RrdToolkit.java
Log Message:
Major enhancements to Inspector swing app. Supports interactive add/edit/remove operations on RRD datasources/archives. Several methods added to RrdToolkit - no plans to extend it further.
Index: RrdToolkit.java
===================================================================
RCS file: /cvsroot/jrobin/src/org/jrobin/core/RrdToolkit.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** RrdToolkit.java 28 Nov 2003 13:24:46 -0000 1.4
--- RrdToolkit.java 4 Dec 2003 13:21:03 -0000 1.5
***************
*** 268,271 ****
--- 268,360 ----
}
+ /**
+ * Sets datasource heartbeat to a new value.
+ * @param sourcePath Path to exisiting RRD file (will be updated)
+ * @param datasourceName Name of the datasource in the specified RRD file
+ * @param newHeartbeat New datasource heartbeat
+ * @throws RrdException Thrown in case of JRobin specific error
+ * @throws IOException Thrown in case of I/O error
+ */
+ public void setDsHeartbeat(String sourcePath, String datasourceName,
+ long newHeartbeat) throws RrdException, IOException {
+ RrdDb rrd = new RrdDb(sourcePath);
+ Datasource ds = rrd.getDatasource(datasourceName);
+ ds.setHeartbeat(newHeartbeat);
+ rrd.close();
+ }
+
+ /**
+ * Sets datasource min value to a new value
+ * @param sourcePath Path to exisiting RRD file (will be updated)
+ * @param datasourceName Name of the datasource in the specified RRD file
+ * @param newMinValue New min value for the datasource
+ * @param filterArchivedValues set to <code>true</code> if archived values less than
+ * <code>newMinValue</code> should be set to NaN; set to false, otherwise.
+ * @throws RrdException Thrown in case of JRobin specific error
+ * @throws IOException Thrown in case of I/O error
+ */
+ public void setDsMinValue(String sourcePath, String datasourceName,
+ double newMinValue, boolean filterArchivedValues) throws RrdException, IOException {
+ RrdDb rrd = new RrdDb(sourcePath);
+ Datasource ds = rrd.getDatasource(datasourceName);
+ ds.setMinValue(newMinValue, filterArchivedValues);
+ rrd.close();
+ }
+
+ /**
+ * Sets datasource max value to a new value.
+ * @param sourcePath Path to exisiting RRD file (will be updated)
+ * @param datasourceName Name of the datasource in the specified RRD file
+ * @param newMaxValue New max value for the datasource
+ * @param filterArchivedValues set to <code>true</code> if archived values greater than
+ * <code>newMaxValue</code> should be set to NaN; set to false, otherwise.
+ * @throws RrdException Thrown in case of JRobin specific error
+ * @throws IOException Thrown in case of I/O error
+ */
+ public void setDsMaxValue(String sourcePath, String datasourceName,
+ double newMaxValue, boolean filterArchivedValues) throws RrdException, IOException {
+ RrdDb rrd = new RrdDb(sourcePath);
+ Datasource ds = rrd.getDatasource(datasourceName);
+ ds.setMaxValue(newMaxValue, filterArchivedValues);
+ rrd.close();
+ }
+
+ /**
+ * Updates valid value range for the given datasource.
+ * @param sourcePath Path to exisiting RRD file (will be updated)
+ * @param datasourceName Name of the datasource in the specified RRD file
+ * @param newMinValue New min value for the datasource
+ * @param newMaxValue New max value for the datasource
+ * @param filterArchivedValues set to <code>true</code> if archived values outside
+ * of the specified min/max range should be replaced with NaNs.
+ * @throws RrdException Thrown in case of JRobin specific error
+ * @throws IOException Thrown in case of I/O error
+ */
+ public void setDsMinMaxValue(String sourcePath, String datasourceName,
+ double newMinValue, double newMaxValue, boolean filterArchivedValues)
+ throws RrdException, IOException {
+ RrdDb rrd = new RrdDb(sourcePath);
+ Datasource ds = rrd.getDatasource(datasourceName);
+ ds.setMinMaxValue(newMinValue, newMaxValue, filterArchivedValues);
+ rrd.close();
+ }
+
+ /**
+ * Sets single archive's X-files factor to a new value.
+ * @param sourcePath Path to existing RRD file (will be updated)
+ * @param consolFun Consolidation function of the target archive
+ * @param steps Number of sptes of the target archive
+ * @param newXff New X-files factor for the target archive
+ * @throws RrdException Thrown in case of JRobin specific error
+ * @throws IOException Thrown in case of I/O error
+ */
+ public void setArcXff(String sourcePath, String consolFun, int steps,
+ double newXff) throws RrdException, IOException {
+ RrdDb rrd = new RrdDb(sourcePath);
+ Archive arc = rrd.getArchive(consolFun, steps);
+ arc.setXff(newXff);
+ rrd.close();
+ }
+
private static void deleteFile(File file) throws IOException {
if(file.exists() && !file.delete()) {
***************
*** 274,290 ****
}
- public static void main(String[] args) throws RrdException, IOException {
- String file = "c:/test.rrd";
- RrdToolkit tool = RrdToolkit.getInstance();
- DsDef dsDef1 = new DsDef("XXX", "GAUGE", 666, -1, Double.NaN);
- DsDef dsDef2 = new DsDef("YYY", "GAUGE", 777, +1, Double.NaN);
- tool.addDatasource(file, dsDef1, true);
- tool.addDatasource(file, dsDef2, false);
- tool.removeDatasource(file, "ftpUsers", false);
- tool.removeDatasource(file, "XXX", false);
- ArcDef arcDef1 = new ArcDef("LAST", 0.22222, 13, 567);
- tool.addArchive(file, arcDef1, false);
- tool.removeArchive(file, "MAX", 6, false);
- }
}
--- 363,366 ----
|
|
From: <sa...@us...> - 2003-12-02 10:18:22
|
Update of /cvsroot/jrobin/src/org/jrobin/core In directory sc8-pr-cvs1:/tmp/cvs-serv13563/org/jrobin/core Modified Files: ArcState.java Archive.java Datasource.java Header.java RrdDb.java Sample.java Log Message: Minor changes Index: ArcState.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/core/ArcState.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** ArcState.java 30 Nov 2003 08:14:07 -0000 1.5 --- ArcState.java 2 Dec 2003 10:18:17 -0000 1.6 *************** *** 1,131 **** ! /* ============================================================ ! * JRobin : Pure java implementation of RRDTool's functionality ! * ============================================================ ! * ! * Project Info: http://www.jrobin.org ! * Project Lead: Sasa Markovic (sa...@jr...); ! * ! * (C) Copyright 2003, by Sasa Markovic. ! * ! * Developers: Sasa Markovic (sa...@jr...) ! * Arne Vandamme (cob...@jr...) ! * ! * This library is free software; you can redistribute it and/or modify it under the terms ! * of the GNU Lesser General Public License as published by the Free Software Foundation; ! * either version 2.1 of the License, or (at your option) any later version. ! * ! * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; ! * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. ! * See the GNU Lesser General Public License for more details. ! * ! * You should have received a copy of the GNU Lesser General Public License along with this ! * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, ! * Boston, MA 02111-1307, USA. ! */ ! ! package org.jrobin.core; ! ! import java.io.IOException; ! ! /** ! * Class to represent internal RRD archive state for a single datasource. Objects of this ! * class are never manipulated directly, it's up to JRobin framework to manage ! * internal arcihve states.<p> ! * ! * @author <a href="mailto:sa...@jr...">Sasa Markovic</a> ! */ ! public class ArcState implements RrdUpdater { ! private Archive parentArc; ! ! private RrdDouble accumValue; ! private RrdLong nanSteps; ! ! ArcState(Archive parentArc) throws IOException { ! this.parentArc = parentArc; ! if(getRrdFile().getMode() == RrdFile.MODE_CREATE) { ! // should initialize ! Header header = parentArc.getParentDb().getHeader(); ! long step = header.getStep(); ! long lastUpdateTime = header.getLastUpdateTime(); ! long arcStep = parentArc.getArcStep(); ! long nan = (Util.normalize(lastUpdateTime, step) - ! Util.normalize(lastUpdateTime, arcStep)) / step; ! accumValue = new RrdDouble(Double.NaN, this); ! nanSteps = new RrdLong(nan, this); ! } ! else { ! accumValue = new RrdDouble(this); ! nanSteps = new RrdLong(this); ! } ! } ! ! /** ! * Returns the underlying RrdFile object. ! * @return Underlying RrdFile object. ! */ ! public RrdFile getRrdFile() { ! return parentArc.getParentDb().getRrdFile(); ! } ! ! String dump() { ! return "accumValue:" + accumValue.get() + " nanSteps:" + nanSteps.get() + "\n"; ! } ! ! void setNanSteps(long value) throws IOException { ! nanSteps.set(value); ! } ! ! /** ! * Returns the number of currently accumulated NaN steps. ! * ! * @return Number of currently accumulated NaN steps. ! */ ! public long getNanSteps() { ! return nanSteps.get(); ! } ! ! void setAccumValue(double value) throws IOException { ! accumValue.set(value); ! } ! ! /** ! * Returns the value accumulated so far. ! * ! * @return Accumulated value ! */ ! public double getAccumValue() { ! return accumValue.get(); ! } ! ! /** ! * Returns the Archive object to which this ArcState object belongs. ! * ! * @return Parent Archive object. ! */ ! public Archive getParent() { ! return parentArc; ! } ! ! void appendXml(XmlWriter writer) throws IOException { ! writer.startTag("ds"); ! writer.writeTag("value", accumValue.get()); ! writer.writeTag("unknown_datapoints", nanSteps.get()); ! writer.closeTag(); // ds ! } ! ! /** ! * Copies object's internal state to another ArcState object. ! * @param other New ArcState object to copy state to ! * @throws IOException Thrown in case of I/O error ! * @throws RrdException Thrown if supplied argument is not an ArcState object ! */ ! public void copyStateTo(RrdUpdater other) throws IOException, RrdException { ! if(!(other instanceof ArcState)) { ! throw new RrdException( ! "Cannot copy ArcState object to " + other.getClass().getName()); ! } ! ArcState arcState = (ArcState) other; ! arcState.accumValue.set(accumValue.get()); ! arcState.nanSteps.set(nanSteps.get()); ! } ! } --- 1,131 ---- ! /* ============================================================ ! * JRobin : Pure java implementation of RRDTool's functionality ! * ============================================================ ! * ! * Project Info: http://www.jrobin.org ! * Project Lead: Sasa Markovic (sa...@jr...); ! * ! * (C) Copyright 2003, by Sasa Markovic. ! * ! * Developers: Sasa Markovic (sa...@jr...) ! * Arne Vandamme (cob...@jr...) ! * ! * This library is free software; you can redistribute it and/or modify it under the terms ! * of the GNU Lesser General Public License as published by the Free Software Foundation; ! * either version 2.1 of the License, or (at your option) any later version. ! * ! * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; ! * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. ! * See the GNU Lesser General Public License for more details. ! * ! * You should have received a copy of the GNU Lesser General Public License along with this ! * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, ! * Boston, MA 02111-1307, USA. ! */ ! ! package org.jrobin.core; ! ! import java.io.IOException; ! ! /** ! * Class to represent internal RRD archive state for a single datasource. Objects of this ! * class are never manipulated directly, it's up to JRobin framework to manage ! * internal arcihve states.<p> ! * ! * @author <a href="mailto:sa...@jr...">Sasa Markovic</a> ! */ ! public class ArcState implements RrdUpdater { ! private Archive parentArc; ! ! private RrdDouble accumValue; ! private RrdLong nanSteps; ! ! ArcState(Archive parentArc) throws IOException { ! this.parentArc = parentArc; ! if(getRrdFile().getMode() == RrdFile.MODE_CREATE) { ! // should initialize ! Header header = parentArc.getParentDb().getHeader(); ! long step = header.getStep(); ! long lastUpdateTime = header.getLastUpdateTime(); ! long arcStep = parentArc.getArcStep(); ! long nan = (Util.normalize(lastUpdateTime, step) - ! Util.normalize(lastUpdateTime, arcStep)) / step; ! accumValue = new RrdDouble(Double.NaN, this); ! nanSteps = new RrdLong(nan, this); ! } ! else { ! accumValue = new RrdDouble(this); ! nanSteps = new RrdLong(this); ! } ! } ! ! /** ! * Returns the underlying RrdFile object. ! * @return Underlying RrdFile object. ! */ ! public RrdFile getRrdFile() { ! return parentArc.getParentDb().getRrdFile(); ! } ! ! String dump() { ! return "accumValue:" + accumValue.get() + " nanSteps:" + nanSteps.get() + "\n"; ! } ! ! void setNanSteps(long value) throws IOException { ! nanSteps.set(value); ! } ! ! /** ! * Returns the number of currently accumulated NaN steps. ! * ! * @return Number of currently accumulated NaN steps. ! */ ! public long getNanSteps() { ! return nanSteps.get(); ! } ! ! void setAccumValue(double value) throws IOException { ! accumValue.set(value); ! } ! ! /** ! * Returns the value accumulated so far. ! * ! * @return Accumulated value ! */ ! public double getAccumValue() { ! return accumValue.get(); ! } ! ! /** ! * Returns the Archive object to which this ArcState object belongs. ! * ! * @return Parent Archive object. ! */ ! public Archive getParent() { ! return parentArc; ! } ! ! void appendXml(XmlWriter writer) throws IOException { ! writer.startTag("ds"); ! writer.writeTag("value", accumValue.get()); ! writer.writeTag("unknown_datapoints", nanSteps.get()); ! writer.closeTag(); // ds ! } ! ! /** ! * Copies object's internal state to another ArcState object. ! * @param other New ArcState object to copy state to ! * @throws IOException Thrown in case of I/O error ! * @throws RrdException Thrown if supplied argument is not an ArcState object ! */ ! public void copyStateTo(RrdUpdater other) throws IOException, RrdException { ! if(!(other instanceof ArcState)) { ! throw new RrdException( ! "Cannot copy ArcState object to " + other.getClass().getName()); ! } ! ArcState arcState = (ArcState) other; ! arcState.accumValue.set(accumValue.get()); ! arcState.nanSteps.set(nanSteps.get()); ! } ! } Index: Archive.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/core/Archive.java,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** Archive.java 30 Nov 2003 08:14:09 -0000 1.8 --- Archive.java 2 Dec 2003 10:18:17 -0000 1.9 *************** *** 1,426 **** ! /* ============================================================ ! * JRobin : Pure java implementation of RRDTool's functionality ! * ============================================================ ! * ! * Project Info: http://www.jrobin.org ! * Project Lead: Sasa Markovic (sa...@jr...); ! * ! * (C) Copyright 2003, by Sasa Markovic. ! * ! * Developers: Sasa Markovic (sa...@jr...) ! * Arne Vandamme (cob...@jr...) ! * ! * This library is free software; you can redistribute it and/or modify it under the terms ! * of the GNU Lesser General Public License as published by the Free Software Foundation; ! * either version 2.1 of the License, or (at your option) any later version. ! * ! * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; ! * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. ! * See the GNU Lesser General Public License for more details. ! * ! * You should have received a copy of the GNU Lesser General Public License along with this ! * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, ! * Boston, MA 02111-1307, USA. ! */ ! ! package org.jrobin.core; ! ! import java.io.IOException; ! ! /** ! * Class to represent single RRD archive in a RRD file with its internal state. ! * Normally, you don't need methods to manipulate archive objects directly ! * because JRobin framework does it automatically for you.<p> ! * ! * Each archive object consists of three parts: archive definition, archive state objects ! * (one state object for each datasource) and round robin archives (one round robin for ! * each datasource). API (read-only) is provided to access each of theese parts.<p> ! * ! * @author <a href="mailto:sa...@jr...">Sasa Markovic</a> ! */ ! public class Archive implements RrdUpdater { ! private RrdDb parentDb; ! // definition ! private RrdString consolFun; ! private RrdDouble xff; ! private RrdInt steps, rows; ! // state ! private Robin[] robins; ! private ArcState[] states; ! ! // first time creation ! Archive(RrdDb parentDb, ArcDef arcDef) throws IOException { ! this.parentDb = parentDb; ! consolFun = new RrdString(arcDef.getConsolFun(), this); ! xff = new RrdDouble(arcDef.getXff(), this); ! steps = new RrdInt(arcDef.getSteps(), this); ! rows = new RrdInt(arcDef.getRows(), this); ! int n = parentDb.getHeader().getDsCount(); ! robins = new Robin[n]; ! states = new ArcState[n]; ! for(int i = 0; i < n; i++) { ! states[i] = new ArcState(this); ! robins[i] = new Robin(this, rows.get()); ! } ! } ! ! // read from file ! Archive(RrdDb parentDb) throws IOException { ! this.parentDb = parentDb; ! consolFun = new RrdString(this); ! xff = new RrdDouble(this); ! steps = new RrdInt(this); ! rows = new RrdInt(this); ! int n = parentDb.getHeader().getDsCount(); ! states = new ArcState[n]; ! robins = new Robin[n]; ! for(int i = 0; i < n; i++) { ! states[i] = new ArcState(this); ! robins[i] = new Robin(this, rows.get()); ! } ! } ! ! // read from XML ! Archive(RrdDb parentDb, XmlReader reader, int arcIndex) throws IOException, RrdException { ! this.parentDb = parentDb; ! consolFun = new RrdString(reader.getConsolFun(arcIndex), this); ! xff = new RrdDouble(reader.getXff(arcIndex), this); ! steps = new RrdInt(reader.getSteps(arcIndex), this); ! rows = new RrdInt(reader.getRows(arcIndex), this); ! int dsCount = reader.getDsCount(); ! states = new ArcState[dsCount]; ! robins = new Robin[dsCount]; ! for(int dsIndex = 0; dsIndex < dsCount; dsIndex++) { ! // restore state ! states[dsIndex] = new ArcState(this); ! states[dsIndex].setAccumValue(reader.getStateAccumValue(arcIndex, dsIndex)); ! states[dsIndex].setNanSteps(reader.getStateNanSteps(arcIndex, dsIndex)); ! // restore robins ! robins[dsIndex] = new Robin(this, rows.get()); ! double[] values = reader.getValues(arcIndex, dsIndex); ! for(int j = 0; j < values.length; j++) { ! robins[dsIndex].store(values[j]); ! } ! } ! } ! ! /** ! * Returns archive time step in seconds. Archive step is equal to RRD file step ! * multiplied with the number of archive steps. ! * ! * @return Archive time step in seconds ! */ ! public long getArcStep() { ! long step = parentDb.getHeader().getStep(); ! return step * steps.get(); ! } ! ! String dump() throws IOException { ! StringBuffer buffer = new StringBuffer("== ARCHIVE ==\n"); ! buffer.append("RRA:" + consolFun.get() + ":" + xff.get() + ":" + ! steps.get() + ":" + rows.get() + "\n"); ! buffer.append("interval [" + getStartTime() + ", " + getEndTime() + "]" + "\n"); ! for(int i = 0; i < robins.length; i++) { ! buffer.append(states[i].dump()); ! buffer.append(robins[i].dump()); ! } ! return buffer.toString(); ! } ! ! RrdDb getParentDb() { ! return parentDb; ! } ! ! /** ! * Returns the underlying RrdFile object. ! * @return Underlying RrdFile object ! */ ! public RrdFile getRrdFile() { ! return parentDb.getRrdFile(); ! } ! ! void archive(int dsIndex, double value, long numUpdates) throws IOException { ! Robin robin = robins[dsIndex]; ! ArcState state = states[dsIndex]; ! long step = parentDb.getHeader().getStep(); ! long lastUpdateTime = parentDb.getHeader().getLastUpdateTime(); ! long updateTime = Util.normalize(lastUpdateTime, step) + step; ! long arcStep = getArcStep(); ! // finish current step ! while(numUpdates > 0) { ! accumulate(state, value); ! numUpdates--; ! if(updateTime % arcStep == 0) { ! finalizeStep(state, robin); ! break; ! } ! else { ! updateTime += step; ! } ! } ! // 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(); ! for(long i = 0; i < remainingUpdates; i++) { ! accumulate(state, value); ! } ! } ! ! private void accumulate(ArcState state, double value) throws IOException { ! if(Double.isNaN(value)) { ! state.setNanSteps(state.getNanSteps() + 1); ! } ! 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)); ! } ! } ! } ! ! private void finalizeStep(ArcState state, Robin robin) throws IOException { ! // 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); ! } ! robin.store(accumValue); ! } ! else { ! robin.store(Double.NaN); ! } ! state.setAccumValue(Double.NaN); ! state.setNanSteps(0); ! } ! ! /** ! * Returns archive consolidation function (AVERAGE, MIN, MAX or LAST). ! * @return Archive consolidation function. ! */ ! public String getConsolFun() { ! return consolFun.get(); ! } ! ! /** ! * Returns archive X-files factor. ! * @return Archive X-files factor (between 0 and 1). ! */ ! public double getXff() { ! return xff.get(); ! } ! ! /** ! * Returns the number of archive steps. ! * @return Number of archive steps. ! */ ! public int getSteps() { ! return steps.get(); ! } ! ! /** ! * Returns the number of archive rows. ! * @return Number of archive rows. ! */ ! public int getRows() { ! return rows.get(); ! } ! ! /** ! * Returns current starting timestamp. This value is not constant. ! * @return Timestamp corresponding to the first archive row ! */ ! public long getStartTime() { ! long endTime = getEndTime(); ! long arcStep = getArcStep(); ! long numRows = rows.get(); ! return endTime - (numRows - 1) * arcStep; ! } ! ! /** ! * Returns current ending timestamp. This value is not constant. ! * @return Timestamp corresponding to the last archive row ! */ ! public long getEndTime() { ! long arcStep = getArcStep(); ! long lastUpdateTime = parentDb.getHeader().getLastUpdateTime(); ! return Util.normalize(lastUpdateTime, arcStep); ! } ! ! /** ! * Returns the underlying archive state object. Each datasource has its ! * corresponding ArcState object (archive states are managed independently ! * for each RRD datasource). ! * @param dsIndex Datasource index ! * @return Underlying archive state object ! */ ! public ArcState getArcState(int dsIndex) { ! return states[dsIndex]; ! } ! ! /** ! * Returns the underlying round robin archive. Robins are used to store actual ! * archive values on a per-datasource basis. ! * @param dsIndex Index of the datasource in the RRD file. ! * @return Underlying round robin archive for the given datasource. ! */ ! public Robin getRobin(int dsIndex) { ! return robins[dsIndex]; ! } ! ! FetchPoint[] fetch(FetchRequest request) throws IOException, RrdException { ! if(request.getFilter() != null) { ! throw new RrdException("fetch() method does not support filtered datasources." + ! " Use fetchData() to get filtered fetch data."); ! } ! long arcStep = getArcStep(); ! long fetchStart = Util.normalize(request.getFetchStart(), arcStep); ! long fetchEnd = Util.normalize(request.getFetchEnd(), arcStep); ! if(fetchEnd < request.getFetchEnd()) { ! fetchEnd += arcStep; ! } ! long startTime = getStartTime(); ! long endTime = getEndTime(); ! int dsCount = robins.length; ! int ptsCount = (int) ((fetchEnd - fetchStart) / arcStep + 1); ! FetchPoint[] points = new FetchPoint[ptsCount]; ! for(int i = 0; i < ptsCount; i++) { ! long time = fetchStart + i * arcStep; ! FetchPoint point = new FetchPoint(time, dsCount); ! if(time >= startTime && time <= endTime) { ! int robinIndex = (int)((time - startTime) / arcStep); ! for(int j = 0; j < dsCount; j++) { ! point.setValue(j, robins[j].getValue(robinIndex)); ! } ! } ! points[i] = point; ! } ! return points; ! } ! ! FetchData fetchData(FetchRequest request) throws IOException, RrdException { ! long arcStep = getArcStep(); ! long fetchStart = Util.normalize(request.getFetchStart(), arcStep); ! long fetchEnd = Util.normalize(request.getFetchEnd(), arcStep); ! if(fetchEnd < request.getFetchEnd()) { ! fetchEnd += arcStep; ! } ! long startTime = getStartTime(); ! long endTime = getEndTime(); ! String[] dsToFetch = request.getFilter(); ! if(dsToFetch == null) { ! dsToFetch = parentDb.getDsNames(); ! } ! int dsCount = dsToFetch.length; ! int ptsCount = (int) ((fetchEnd - fetchStart) / arcStep + 1); ! long[] timestamps = new long[ptsCount]; ! double[][] values = new double[dsCount][ptsCount]; ! for(int ptIndex = 0; ptIndex < ptsCount; ptIndex++) { ! long time = fetchStart + ptIndex * arcStep; ! timestamps[ptIndex] = time; ! if(time >= startTime && time <= endTime) { ! // inbound time ! int robinIndex = (int)((time - startTime) / arcStep); ! for(int 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; ! } ! } ! } ! FetchData fetchData = new FetchData(this, request); ! fetchData.setTimestamps(timestamps); ! fetchData.setValues(values); ! return fetchData; ! } ! ! void appendXml(XmlWriter writer) throws IOException { ! writer.startTag("rra"); ! writer.writeTag("cf", consolFun.get()); ! writer.writeComment(getArcStep() + " seconds"); ! writer.writeTag("pdp_per_row", steps.get()); ! writer.writeTag("xff", xff.get()); ! writer.startTag("cdp_prep"); ! for(int i = 0; i < states.length; i++) { ! states[i].appendXml(writer); ! } ! writer.closeTag(); // cdp_prep ! writer.startTag("database"); ! long startTime = getStartTime(); ! for(int i = 0; i < rows.get(); i++) { ! long time = startTime + i * getArcStep(); ! writer.writeComment(Util.getDate(time) + " / " + time); ! writer.startTag("row"); ! for(int j = 0; j < robins.length; j++) { ! writer.writeTag("v", robins[j].getValue(i)); ! } ! writer.closeTag(); // row ! } ! writer.closeTag(); // database ! writer.closeTag(); // rra ! } ! ! /** ! * Copies object's internal state to another Archive object. ! * @param other New Archive object to copy state to ! * @throws IOException Thrown in case of I/O error ! * @throws RrdException Thrown if supplied argument is not an Archive object ! */ ! public void copyStateTo(RrdUpdater other) throws IOException, RrdException { ! if(!(other instanceof Archive)) { ! throw new RrdException( ! "Cannot copy Archive object to " + other.getClass().getName()); ! } ! Archive arc = (Archive) other; ! if(!arc.consolFun.get().equals(consolFun.get())) { ! throw new RrdException("Incompatible consolidation functions"); ! } ! if(arc.steps.get() != steps.get()) { ! throw new RrdException("Incompatible number of steps"); ! } ! if(arc.rows.get() != rows.get()) { ! throw new RrdException("Incompatible number of rows"); ! } ! int count = parentDb.getHeader().getDsCount(); ! for(int i = 0; i < count; i++) { ! int j = Util.getMatchingDatasourceIndex(parentDb, i, arc.parentDb); ! if(j >= 0) { ! states[i].copyStateTo(arc.states[j]); ! robins[i].copyStateTo(arc.robins[j]); ! } ! } ! } ! ! /** ! * Sets X-files factor to a new value. ! * @param xff New X-files factor value. Must be >= 0 and < 1. ! * @throws RrdException Thrown if invalid value is supplied ! * @throws IOException Thrown in case of I/O error ! */ ! public void setXff(double xff) throws RrdException, IOException { ! if(xff < 0D || xff >= 1D) { ! throw new RrdException("Invalid xff supplied (" + xff + "), must be >= 0 and < 1"); ! } ! this.xff.set(xff); ! } ! } --- 1,426 ---- ! /* ============================================================ ! * JRobin : Pure java implementation of RRDTool's functionality ! * ============================================================ ! * ! * Project Info: http://www.jrobin.org ! * Project Lead: Sasa Markovic (sa...@jr...); ! * ! * (C) Copyright 2003, by Sasa Markovic. ! * ! * Developers: Sasa Markovic (sa...@jr...) ! * Arne Vandamme (cob...@jr...) ! * ! * This library is free software; you can redistribute it and/or modify it under the terms ! * of the GNU Lesser General Public License as published by the Free Software Foundation; ! * either version 2.1 of the License, or (at your option) any later version. ! * ! * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; ! * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. ! * See the GNU Lesser General Public License for more details. ! * ! * You should have received a copy of the GNU Lesser General Public License along with this ! * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, ! * Boston, MA 02111-1307, USA. ! */ ! ! package org.jrobin.core; ! ! import java.io.IOException; ! ! /** ! * Class to represent single RRD archive in a RRD file with its internal state. ! * Normally, you don't need methods to manipulate archive objects directly ! * because JRobin framework does it automatically for you.<p> ! * ! * Each archive object consists of three parts: archive definition, archive state objects ! * (one state object for each datasource) and round robin archives (one round robin for ! * each datasource). API (read-only) is provided to access each of theese parts.<p> ! * ! * @author <a href="mailto:sa...@jr...">Sasa Markovic</a> ! */ ! public class Archive implements RrdUpdater { ! private RrdDb parentDb; ! // definition ! private RrdString consolFun; ! private RrdDouble xff; ! private RrdInt steps, rows; ! // state ! private Robin[] robins; ! private ArcState[] states; ! ! // first time creation ! Archive(RrdDb parentDb, ArcDef arcDef) throws IOException { ! this.parentDb = parentDb; ! consolFun = new RrdString(arcDef.getConsolFun(), this); ! xff = new RrdDouble(arcDef.getXff(), this); ! steps = new RrdInt(arcDef.getSteps(), this); ! rows = new RrdInt(arcDef.getRows(), this); ! int n = parentDb.getHeader().getDsCount(); ! robins = new Robin[n]; ! states = new ArcState[n]; ! for(int i = 0; i < n; i++) { ! states[i] = new ArcState(this); ! robins[i] = new Robin(this, rows.get()); ! } ! } ! ! // read from file ! Archive(RrdDb parentDb) throws IOException { ! this.parentDb = parentDb; ! consolFun = new RrdString(this); ! xff = new RrdDouble(this); ! steps = new RrdInt(this); ! rows = new RrdInt(this); ! int n = parentDb.getHeader().getDsCount(); ! states = new ArcState[n]; ! robins = new Robin[n]; ! for(int i = 0; i < n; i++) { ! states[i] = new ArcState(this); ! robins[i] = new Robin(this, rows.get()); ! } ! } ! ! // read from XML ! Archive(RrdDb parentDb, XmlReader reader, int arcIndex) throws IOException, RrdException { ! this.parentDb = parentDb; ! consolFun = new RrdString(reader.getConsolFun(arcIndex), this); ! xff = new RrdDouble(reader.getXff(arcIndex), this); ! steps = new RrdInt(reader.getSteps(arcIndex), this); ! rows = new RrdInt(reader.getRows(arcIndex), this); ! int dsCount = reader.getDsCount(); ! states = new ArcState[dsCount]; ! robins = new Robin[dsCount]; ! for(int dsIndex = 0; dsIndex < dsCount; dsIndex++) { ! // restore state ! states[dsIndex] = new ArcState(this); ! states[dsIndex].setAccumValue(reader.getStateAccumValue(arcIndex, dsIndex)); ! states[dsIndex].setNanSteps(reader.getStateNanSteps(arcIndex, dsIndex)); ! // restore robins ! robins[dsIndex] = new Robin(this, rows.get()); ! double[] values = reader.getValues(arcIndex, dsIndex); ! for(int j = 0; j < values.length; j++) { ! robins[dsIndex].store(values[j]); ! } ! } ! } ! ! /** ! * Returns archive time step in seconds. Archive step is equal to RRD file step ! * multiplied with the number of archive steps. ! * ! * @return Archive time step in seconds ! */ ! public long getArcStep() { ! long step = parentDb.getHeader().getStep(); ! return step * steps.get(); ! } ! ! String dump() throws IOException { ! StringBuffer buffer = new StringBuffer("== ARCHIVE ==\n"); ! buffer.append("RRA:" + consolFun.get() + ":" + xff.get() + ":" + ! steps.get() + ":" + rows.get() + "\n"); ! buffer.append("interval [" + getStartTime() + ", " + getEndTime() + "]" + "\n"); ! for(int i = 0; i < robins.length; i++) { ! buffer.append(states[i].dump()); ! buffer.append(robins[i].dump()); ! } ! return buffer.toString(); ! } ! ! RrdDb getParentDb() { ! return parentDb; ! } ! ! /** ! * Returns the underlying RrdFile object. ! * @return Underlying RrdFile object ! */ ! public RrdFile getRrdFile() { ! return parentDb.getRrdFile(); ! } ! ! void archive(int dsIndex, double value, long numUpdates) throws IOException { ! Robin robin = robins[dsIndex]; ! ArcState state = states[dsIndex]; ! long step = parentDb.getHeader().getStep(); ! long lastUpdateTime = parentDb.getHeader().getLastUpdateTime(); ! long updateTime = Util.normalize(lastUpdateTime, step) + step; ! long arcStep = getArcStep(); ! // finish current step ! while(numUpdates > 0) { ! accumulate(state, value); ! numUpdates--; ! if(updateTime % arcStep == 0) { ! finalizeStep(state, robin); ! break; ! } ! else { ! updateTime += step; ! } ! } ! // 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(); ! for(long i = 0; i < remainingUpdates; i++) { ! accumulate(state, value); ! } ! } ! ! private void accumulate(ArcState state, double value) throws IOException { ! if(Double.isNaN(value)) { ! state.setNanSteps(state.getNanSteps() + 1); ! } ! 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)); ! } ! } ! } ! ! private void finalizeStep(ArcState state, Robin robin) throws IOException { ! // 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); ! } ! robin.store(accumValue); ! } ! else { ! robin.store(Double.NaN); ! } ! state.setAccumValue(Double.NaN); ! state.setNanSteps(0); ! } ! ! /** ! * Returns archive consolidation function (AVERAGE, MIN, MAX or LAST). ! * @return Archive consolidation function. ! */ ! public String getConsolFun() { ! return consolFun.get(); ! } ! ! /** ! * Returns archive X-files factor. ! * @return Archive X-files factor (between 0 and 1). ! */ ! public double getXff() { ! return xff.get(); ! } ! ! /** ! * Returns the number of archive steps. ! * @return Number of archive steps. ! */ ! public int getSteps() { ! return steps.get(); ! } ! ! /** ! * Returns the number of archive rows. ! * @return Number of archive rows. ! */ ! public int getRows() { ! return rows.get(); ! } ! ! /** ! * Returns current starting timestamp. This value is not constant. ! * @return Timestamp corresponding to the first archive row ! */ ! public long getStartTime() { ! long endTime = getEndTime(); ! long arcStep = getArcStep(); ! long numRows = rows.get(); ! return endTime - (numRows - 1) * arcStep; ! } ! ! /** ! * Returns current ending timestamp. This value is not constant. ! * @return Timestamp corresponding to the last archive row ! */ ! public long getEndTime() { ! long arcStep = getArcStep(); ! long lastUpdateTime = parentDb.getHeader().getLastUpdateTime(); ! return Util.normalize(lastUpdateTime, arcStep); ! } ! ! /** ! * Returns the underlying archive state object. Each datasource has its ! * corresponding ArcState object (archive states are managed independently ! * for each RRD datasource). ! * @param dsIndex Datasource index ! * @return Underlying archive state object ! */ ! public ArcState getArcState(int dsIndex) { ! return states[dsIndex]; ! } ! ! /** ! * Returns the underlying round robin archive. Robins are used to store actual ! * archive values on a per-datasource basis. ! * @param dsIndex Index of the datasource in the RRD file. ! * @return Underlying round robin archive for the given datasource. ! */ ! public Robin getRobin(int dsIndex) { ! return robins[dsIndex]; ! } ! ! FetchPoint[] fetch(FetchRequest request) throws IOException, RrdException { ! if(request.getFilter() != null) { ! throw new RrdException("fetch() method does not support filtered datasources." + ! " Use fetchData() to get filtered fetch data."); ! } ! long arcStep = getArcStep(); ! long fetchStart = Util.normalize(request.getFetchStart(), arcStep); ! long fetchEnd = Util.normalize(request.getFetchEnd(), arcStep); ! if(fetchEnd < request.getFetchEnd()) { ! fetchEnd += arcStep; ! } ! long startTime = getStartTime(); ! long endTime = getEndTime(); ! int dsCount = robins.length; ! int ptsCount = (int) ((fetchEnd - fetchStart) / arcStep + 1); ! FetchPoint[] points = new FetchPoint[ptsCount]; ! for(int i = 0; i < ptsCount; i++) { ! long time = fetchStart + i * arcStep; ! FetchPoint point = new FetchPoint(time, dsCount); ! if(time >= startTime && time <= endTime) { ! int robinIndex = (int)((time - startTime) / arcStep); ! for(int j = 0; j < dsCount; j++) { ! point.setValue(j, robins[j].getValue(robinIndex)); ! } ! } ! points[i] = point; ! } ! return points; ! } ! ! FetchData fetchData(FetchRequest request) throws IOException, RrdException { ! long arcStep = getArcStep(); ! long fetchStart = Util.normalize(request.getFetchStart(), arcStep); ! long fetchEnd = Util.normalize(request.getFetchEnd(), arcStep); ! if(fetchEnd < request.getFetchEnd()) { ! fetchEnd += arcStep; ! } ! long startTime = getStartTime(); ! long endTime = getEndTime(); ! String[] dsToFetch = request.getFilter(); ! if(dsToFetch == null) { ! dsToFetch = parentDb.getDsNames(); ! } ! int dsCount = dsToFetch.length; ! int ptsCount = (int) ((fetchEnd - fetchStart) / arcStep + 1); ! long[] timestamps = new long[ptsCount]; ! double[][] values = new double[dsCount][ptsCount]; ! for(int ptIndex = 0; ptIndex < ptsCount; ptIndex++) { ! long time = fetchStart + ptIndex * arcStep; ! timestamps[ptIndex] = time; ! if(time >= startTime && time <= endTime) { ! // inbound time ! int robinIndex = (int)((time - startTime) / arcStep); ! for(int 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; ! } ! } ! } ! FetchData fetchData = new FetchData(this, request); ! fetchData.setTimestamps(timestamps); ! fetchData.setValues(values); ! return fetchData; ! } ! ! void appendXml(XmlWriter writer) throws IOException { ! writer.startTag("rra"); ! writer.writeTag("cf", consolFun.get()); ! writer.writeComment(getArcStep() + " seconds"); ! writer.writeTag("pdp_per_row", steps.get()); ! writer.writeTag("xff", xff.get()); ! writer.startTag("cdp_prep"); ! for(int i = 0; i < states.length; i++) { ! states[i].appendXml(writer); ! } ! writer.closeTag(); // cdp_prep ! writer.startTag("database"); ! long startTime = getStartTime(); ! for(int i = 0; i < rows.get(); i++) { ! long time = startTime + i * getArcStep(); ! writer.writeComment(Util.getDate(time) + " / " + time); ! writer.startTag("row"); ! for(int j = 0; j < robins.length; j++) { ! writer.writeTag("v", robins[j].getValue(i)); ! } ! writer.closeTag(); // row ! } ! writer.closeTag(); // database ! writer.closeTag(); // rra ! } ! ! /** ! * Copies object's internal state to another Archive object. ! * @param other New Archive object to copy state to ! * @throws IOException Thrown in case of I/O error ! * @throws RrdException Thrown if supplied argument is not an Archive object ! */ ! public void copyStateTo(RrdUpdater other) throws IOException, RrdException { ! if(!(other instanceof Archive)) { ! throw new RrdException( ! "Cannot copy Archive object to " + other.getClass().getName()); ! } ! Archive arc = (Archive) other; ! if(!arc.consolFun.get().equals(consolFun.get())) { ! throw new RrdException("Incompatible consolidation functions"); ! } ! if(arc.steps.get() != steps.get()) { ! throw new RrdException("Incompatible number of steps"); ! } ! if(arc.rows.get() != rows.get()) { ! throw new RrdException("Incompatible number of rows"); ! } ! int count = parentDb.getHeader().getDsCount(); ! for(int i = 0; i < count; i++) { ! int j = Util.getMatchingDatasourceIndex(parentDb, i, arc.parentDb); ! if(j >= 0) { ! states[i].copyStateTo(arc.states[j]); ! robins[i].copyStateTo(arc.robins[j]); ! } ! } ! } ! ! /** ! * Sets X-files factor to a new value. ! * @param xff New X-files factor value. Must be >= 0 and < 1. ! * @throws RrdException Thrown if invalid value is supplied ! * @throws IOException Thrown in case of I/O error ! */ ! public void setXff(double xff) throws RrdException, IOException { ! if(xff < 0D || xff >= 1D) { ! throw new RrdException("Invalid xff supplied (" + xff + "), must be >= 0 and < 1"); ! } ! this.xff.set(xff); ! } ! } Index: Datasource.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/core/Datasource.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** Datasource.java 30 Nov 2003 08:14:09 -0000 1.4 --- Datasource.java 2 Dec 2003 10:18:17 -0000 1.5 *************** *** 1,415 **** ! /* ============================================================ ! * JRobin : Pure java implementation of RRDTool's functionality ! * ============================================================ ! * ! * Project Info: http://www.jrobin.org ! * Project Lead: Sasa Markovic (sa...@jr...); ! * ! * (C) Copyright 2003, by Sasa Markovic. ! * ! * Developers: Sasa Markovic (sa...@jr...) ! * Arne Vandamme (cob...@jr...) ! * ! * This library is free software; you can redistribute it and/or modify it under the terms ! * of the GNU Lesser General Public License as published by the Free Software Foundation; ! * either version 2.1 of the License, or (at your option) any later version. ! * ! * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; ! * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. ! * See the GNU Lesser General Public License for more details. ! * ! * You should have received a copy of the GNU Lesser General Public License along with this ! * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, ! * Boston, MA 02111-1307, USA. ! */ ! ! package org.jrobin.core; ! ! import java.io.IOException; ! ! /** ! * Class to represent single datasource within RRD file. Each datasource object holds the ! * following information: datasource definition (once set, never changed) and ! * datasource state variables (changed whenever RRD file gets updated).<p> ! * ! * Normally, you don't need to manipluate Datasource objects directly, it's up to ! * JRobin framework to do it for you. ! * ! * @author <a href="mailto:sa...@jr...">Sasa Markovic</a> ! */ ! public class Datasource implements RrdUpdater { ! private RrdDb parentDb; ! // definition ! private RrdString dsName, dsType; ! private RrdLong heartbeat; ! private RrdDouble minValue, maxValue; ! // state variables ! private RrdDouble lastValue; ! private RrdLong nanSeconds; ! private RrdDouble accumValue; ! ! Datasource(RrdDb parentDb, DsDef dsDef) throws IOException { ! this.parentDb = parentDb; ! dsName = new RrdString(dsDef.getDsName(), this); ! dsType = new RrdString(dsDef.getDsType(), this); ! heartbeat = new RrdLong(dsDef.getHeartbeat(), this); ! minValue = new RrdDouble(dsDef.getMinValue(), this); ! maxValue = new RrdDouble(dsDef.getMaxValue(), this); ! lastValue = new RrdDouble(Double.NaN, this); ! accumValue = new RrdDouble(0.0, this); ! Header header = parentDb.getHeader(); ! nanSeconds = new RrdLong(header.getLastUpdateTime() % header.getStep(), this); ! } ! ! Datasource(RrdDb parentDb) throws IOException { ! this.parentDb = parentDb; ! dsName = new RrdString(this); ! dsType = new RrdString(this); ! heartbeat = new RrdLong(this); ! minValue = new RrdDouble(this); ! maxValue = new RrdDouble(this); ! lastValue = new RrdDouble(this); ! accumValue = new RrdDouble(this); ! nanSeconds = new RrdLong(this); ! } ! ! Datasource(RrdDb parentDb, XmlReader reader, int dsIndex) throws IOException, RrdException { ! this.parentDb = parentDb; ! dsName = new RrdString(reader.getDsName(dsIndex), this); ! dsType = new RrdString(reader.getDsType(dsIndex), this); ! heartbeat = new RrdLong(reader.getHeartbeat(dsIndex), this); ! minValue = new RrdDouble(reader.getMinValue(dsIndex), this); ! maxValue = new RrdDouble(reader.getMaxValue(dsIndex), this); ! lastValue = new RrdDouble(reader.getLastValue(dsIndex), this); ! accumValue = new RrdDouble(reader.getAccumValue(dsIndex), this); ! nanSeconds = new RrdLong(reader.getNanSeconds(dsIndex), this); ! } ! ! String dump() { ! return "== DATASOURCE ==\n" + ! "DS:" + dsName.get() + ":" + dsType.get() + ":" + ! heartbeat.get() + ":" + minValue.get() + ":" + ! maxValue.get() + "\nlastValue:" + lastValue.get() + ! " nanSeconds:" + nanSeconds.get() + ! " accumValue:" + accumValue.get() + "\n"; ! } ! ! /** ! * Returns the underlying RrdFile object. ! * @return Underlying RrdFile object. ! */ ! public RrdFile getRrdFile() { ! return parentDb.getRrdFile(); ! } ! ! /** ! * Returns datasource name. ! * @return Datasource name ! */ ! public String getDsName() { ! return dsName.get(); ! } ! ! /** ! * Returns datasource type (GAUGE, COUNTER, DERIVE, ABSOLUTE). ! * ! * @return Datasource type. ! */ ! public String getDsType() { ! return dsType.get(); ! } ! ! /** ! * Returns datasource heartbeat ! * ! * @return Datasource heartbeat ! */ ! public long getHeartbeat() { ! return heartbeat.get(); ! } ! ! /** ! * Returns mimimal allowed value of the datasource. ! * ! * @return Minimal value allowed. ! */ ! public double getMinValue() { ! return minValue.get(); ! } ! ! /** ! * Returns maximal allowed value of the datasource. ! * ! * @return Maximal value allowed. ! */ ! public double getMaxValue() { ! return maxValue.get(); ! } ! ! /** ! * Returns last known value of the datasource. ! * ! * @return Last datasource value. ! */ ! public double getLastValue() { ! return lastValue.get(); ! } ! ! /** ! * Returns value this datasource accumulated so far. ! * ! * @return Accumulated datasource value. ! */ ! public double getAccumValue() { ! return accumValue.get(); ! } ! ! /** ! * Returns the number of accumulated NaN seconds. ! * ! * @return Accumulated NaN seconds. ! */ ! public long getNanSeconds() { ! return nanSeconds.get(); ! } ! ! void process(long newTime, double newValue) throws IOException, RrdException { ! Header header = parentDb.getHeader(); ! long step = header.getStep(); ! long oldTime = header.getLastUpdateTime(); ! long startTime = Util.normalize(oldTime, step); ! long endTime = startTime + step; ! double oldValue = lastValue.get(); ! double updateValue = calculateUpdateValue(oldTime, oldValue, newTime, newValue); ! if(newTime < endTime) { ! accumulate(oldTime, newTime, updateValue); ! } ! else { ! // should store something ! long boundaryTime = Util.normalize(newTime, step); ! accumulate(oldTime, boundaryTime, updateValue); ! double value = calculateTotal(startTime, boundaryTime); ! // how many updates? ! long numSteps= (boundaryTime - endTime) / step + 1L; ! // ACTION! ! parentDb.archive(this, value, numSteps); ! // cleanup ! nanSeconds.set(0); ! accumValue.set(0.0); ! accumulate(boundaryTime, newTime, updateValue); ! } ! } ! ! private double calculateUpdateValue(long oldTime, double oldValue, ! long newTime, double newValue) throws IOException { ! double updateValue = Double.NaN; ! 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; ! double max32bit = Math.pow(2, 32); ! double max64bit = Math.pow(2, 64); ! if(diff < 0) { ! diff += max32bit; ! } ! if(diff < 0) { ! diff += max64bit - max32bit; ! } ! if(diff >= 0) { ! updateValue = diff / (newTime - oldTime); ! } ! } ! } ! if(!Double.isNaN(updateValue)) { ! double minVal = minValue.get(); ! double maxVal = maxValue.get(); ! if(!Double.isNaN(minVal) && updateValue < minVal) { ! updateValue = Double.NaN; ! } ! if(!Double.isNaN(maxVal) && updateValue > maxVal) { ! updateValue = Double.NaN; ! } ! } ! } ! lastValue.set(newValue); ! return updateValue; ! } ! ! private void accumulate(long oldTime, long newTime, double updateValue) throws IOException { ! if(Double.isNaN(updateValue)) { ! nanSeconds.set(nanSeconds.get() + (newTime - oldTime)); ! } ! else { ! accumValue.set(accumValue.get() + updateValue * (newTime - oldTime)); ! } ! } ! ! private double calculateTotal(long startTime, long boundaryTime) { ! double totalValue = Double.NaN; ! long validSeconds = boundaryTime - startTime - nanSeconds.get(); ! if(nanSeconds.get() <= heartbeat.get() && validSeconds > 0) { ! totalValue = accumValue.get() / validSeconds; ! } ! return totalValue; ! } ! ! void appendXml(XmlWriter writer) throws IOException { ! writer.startTag("ds"); ! writer.writeTag("name", dsName.get()); ! writer.writeTag("type", dsType.get()); ! writer.writeTag("minimal_heartbeat", heartbeat.get()); ! writer.writeTag("min", minValue.get()); ! writer.writeTag("max", maxValue.get()); ! writer.writeComment("PDP Status"); ! writer.writeTag("last_ds", lastValue.get(), "UNKN"); ! writer.writeTag("value", accumValue.get()); ! writer.writeTag("unknown_sec", nanSeconds.get()); ! writer.closeTag(); // ds ! } ! ! /** ! * Copies object's internal state to another Datasource object. ! * @param other New Datasource object to copy state to ! * @throws IOException Thrown in case of I/O error ! * @throws RrdException Thrown if supplied argument is not a Datasource object ! */ ! public void copyStateTo(RrdUpdater other) throws IOException, RrdException { ! if(!(other instanceof Datasource)) { ! throw new RrdException( ! "Cannot copy Datasource object to " + other.getClass().getName()); ! } ! Datasource datasource = (Datasource) other; ! if(!datasource.dsName.get().equals(dsName.get())) { ! throw new RrdException("Incomaptible datasource names"); ! } ! if(!datasource.dsType.get().equals(dsType.get())) { ! throw new RrdException("Incomaptible datasource types"); ! } ! datasource.lastValue.set(lastValue.get()); ! datasource.nanSeconds.set(nanSeconds.get()); ! datasource.accumValue.set(accumValue.get()); ! } ! ! /** ! * Returns index of this Datasource object in a RRD file. ! * @return Datasource index in a RRD file. ! */ ! public int getDsIndex() { ! try { ! return parentDb.getDsIndex(dsName.get()); ! } ! catch(RrdException e) { ! return -1; ! } ! } ! ! /** ! * Sets datasource heartbeat to a new value. ! * @param heartbeat New heartbeat value ! * @throws IOException Thrown in case of I/O error ! * @throws RrdException Thrown if invalid (non-positive) heartbeat value is specified. ! */ ! public void setHeartbeat(long heartbeat) throws RrdException, IOException { ! if(heartbeat < 1L) { ! throw new RrdException("Invalid heartbeat specified: " + heartbeat); ! } ! this.heartbeat.set(heartbeat); ! } ! ! /** ! * Sets minimum allowed value for this datasource. If <code>filterArchivedValues</code> ! * argment is set to true, all archived values less then <code>minValue</code> will ! * be fixed to NaN. ! * @param minValue New minimal value. Specify <code>Double.NaN</code> if no minimal ! * value should be set ! * @param filterArchivedValues true, if archived datasource values should be fixed; ! * false, otherwise. ! * @throws IOException Thrown in case of I/O error ! * @throws RrdException Thrown if invalid minValue was supplied (not less then maxValue) ! */ ! public void setMinValue(double minValue, boolean filterArchivedValues) ! throws IOException, RrdException { ! double maxValue = this.maxValue.get(); ! if(!Double.isNaN(minValue) && !Double.isNaN(maxValue) && minValue >= maxValue) { ! throw new RrdException("Invalid min/max values: " + minValue + "/" + maxValue); ! } ! this.minValue.set(minValue); ! if(!Double.isNaN(minValue) && filterArchivedValues) { ! int dsIndex = getDsIndex(); ! Archive[] archives = parentDb.getArchives(); ! for(int i = 0; i < archives.length; i++) { ! archives[i].getRobin(dsIndex).filterValues(minValue, Double.NaN); ! } ! } ! } ! ! /** ! * Sets maximum allowed value for this datasource. If <code>filterArchivedValues</code> ! * argment is set to true, all archived values greater then <code>maxValue</code> will ! * be fixed to NaN. ! * @param maxValue New maximal value. Specify <code>Double.NaN</code> if no max ! * value should be set. ! * @param filterArchivedValues true, if archived datasource values should be fixed; ! * false, otherwise. ! * @throws IOException Thrown in case of I/O error ! * @throws RrdException Thrown if invalid maxValue was supplied (not greater then minValue) ! */ ! public void setMaxValue(double maxValue, boolean filterArchivedValues) ! throws IOException, RrdException { ! double minValue = this.minValue.get(); ! if(!Double.isNaN(minValue) && !Double.isNaN(maxValue) && minValue >= maxValue) { ! throw new RrdException("Invalid min/max values: " + minValue + "/" + maxValue); ! } ! this.maxValue.set(maxValue); ! if(!Double.isNaN(maxValue) && filterArchivedValues) { ! int dsIndex = getDsIndex(); ! Archive[] archives = parentDb.getArchives(); ! for(int i = 0; i < archives.length; i++) { ! archives[i].getRobin(dsIndex).filterValues(Double.NaN, maxValue); ! } ! } ! } ! ! /** ! * Sets min/max values allowed for this datasource. If <code>filterArchivedValues</code> ! * argment is set to true, all archived values less then <code>minValue</code> or ! * greater then <code>maxValue</code> will be fixed to NaN. ! * @param minValue New minimal value. Specify <code>Double.NaN</code> if no min ! * value should be set. ! * @param maxValue New maximal value. Specify <code>Double.NaN</code> if no max ! * value should be set. ! * @param filterArchivedValues true, if archived datasource values should be fixed; ! * false, otherwise. ! * @throws IOException Thrown in case of I/O error ! * @throws RrdException Thrown if invalid min/max values were supplied ! */ ! public void setMinMaxValue(double minValue, double maxValue, boolean filterArchivedValues) ! throws IOException, RrdException { ! if(!Double.isNaN(minValue) && !Double.isNaN(maxValue) && minValue >= maxValue) { ! throw new RrdException("Invalid min/max values: " + minValue + "/" + maxValue); ! } ! this.minValue.set(minValue); ! this.maxValue.set(maxValue); ! if(!(Double.isNaN(minValue) && Double.isNaN(maxValue)) && filterArchivedValues) { ! int dsIndex = getDsIndex(); ! Archive[] archives = parentDb.getArchives(); ! for(int i = 0; i < archives.length; i++) { ! archives[i].getRobin(dsIndex).filterValues(minValue, maxValue); ! } ! } ! } ! } --- 1,420 ---- ! /* ============================================================ ! * JRobin : Pure java implementation of RRDTool's functionality ! * ============================================================ ! * ! * Project Info: http://www.jrobin.org ! * Project Lead: Sasa Markovic (sa...@jr...); ! * ! * (C) Copyright 2003, by Sasa Markovic. ! * ! * Developers: Sasa Markovic (sa...@jr...) ! * Arne Vandamme (cob...@jr...) ! * ! * This library is free software; you can redistribute it and/or modify it under the terms ! * of the GNU Lesser General Public License as published by the Free Software Foundation; ! * either version 2.1 of the License, or (at your option) any later version. ! * ! * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; ! * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. ! * See the GNU Lesser General Public License for more details. ! * ! * You should have received a copy of the GNU Lesser General Public License along with this ! * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, ! * Boston, MA 02111-1307, USA. ! */ ! ! package org.jrobin.core; ! ! import java.io.IOException; ! ! /** ! * Class to represent single datasource within RRD file. Each datasource object holds the ! * following information: datasource definition (once set, never changed) and ! * datasource state variables (changed whenever RRD file gets updated).<p> ! * ! * Normally, you don't need to manipluate Datasource objects directly, it's up to ! * JRobin framework to do it for you. ! * ! * @author <a href="mailto:sa...@jr...">Sasa Markovic</a> ! */ ! ! public class Datasource implements RrdUpdater { ! private RrdDb parentDb; ! // definition ! private RrdString dsName, dsType; ! private RrdLong heartbeat; ! private RrdDouble minValue, maxValue; ! ! // state variables ! private RrdDouble lastValue; ! private RrdLong nanSeconds; ! private RrdDouble accumValue; ! ! Datasource(RrdDb parentDb, DsDef dsDef) throws IOException { ! this.parentDb = parentDb; ! dsName = new RrdString(dsDef.getDsName(), this); ! dsType = new RrdString(dsDef.getDsType(), this); ! heartbeat = new RrdLong(dsDef.getHeartbeat(), this); ! minValue = new RrdDouble(dsDef.getMinValue(), this); ! maxValue = new RrdDouble(dsDef.getMaxValue(), this); ! lastValue = new RrdDouble(Double.NaN, this); ! accumValue = new RrdDouble(0.0, this); ! Header header = parentDb.getHeader(); ! nanSeconds = new RrdLong(header.getLastUpdateTime() % header.getStep(), this); ! } ! ! Datasource(RrdDb parentDb) throws IOException { ! this.parentDb = parentDb; ! dsName = new RrdString(this); ! dsType = new RrdString(this); ! heartbeat = new RrdLong(this); ! minValue = new RrdDouble(this); ! maxValue = new RrdDouble(this); ! lastValue = new RrdDouble(this); ! accumValue = new RrdDouble(this); ! nanSeconds = new RrdLong(this); ! } ! ! Datasource(RrdDb parentDb, XmlReader reader, int dsIndex) throws IOException, RrdException { ! this.parentDb = parentDb; ! dsName = new RrdString(reader.getDsName(dsIndex), this); ! dsType = new RrdString(reader.getDsType(dsIndex), this); ! heartbeat = new RrdLong(reader.getHeartbeat(dsIndex), this); ! minValue = new RrdDouble(reader.getMinValue(dsIndex), this); ! maxValue = new RrdDouble(reader.getMaxValue(dsIndex), this); ! lastValue = new RrdDouble(reader.getLastValue(dsIndex), this); ! accumValue = new RrdDouble(reader.getAccumValue(dsIndex), this); ! nanSeconds = new RrdLong(reader.getNanSeconds(dsIndex), this); ! } ! ! String dump() { ! return "== DATASOURCE ==\n" + ! "DS:" + dsName.get() + ":" + dsType.get() + ":" + ! heartbeat.get() + ":" + minValue.get() + ":" + ! maxValue.get() + "\nlastValue:" + lastValue.get() + ! " nanSeconds:" + nanSeconds.get() + ! " accumValue:" + accumValue.get() + "\n"; ! } ! ! /** ! * Returns the underlying RrdFile object. ! * @return Underlying RrdFile object. ! */ ! public RrdFile getRrdFile() { ! return parentDb.getRrdFile(); ! } ! ! /** ! * Returns datasource name. ! * @return Datasource name ! */ ! public String getDsName() { ! return dsName.get(); ! } ! ! /** ! * Returns datasource type (GAUGE, COUNTER, DERIVE, ABSOLUTE). ! * ! * @return Datasource type. ! */ ! public String getDsType() { ! return dsType.get(); ! } ! ! /** ! * Returns datasource heartbeat ! * ! * @return Datasource heartbeat ! */ ! ! public long getHeartbeat() { ! return heartbeat.get(); ! } ! ! /** ! * Returns mimimal allowed value of the datasource. ! * ! * @return Minimal value allowed. ! */ ! public double getMinValue() { ! return minValue.get(); ! } ! ! /** ! * Returns maximal allowed value of the datasource. ! * ! * @return Maximal value allowed. ! */ ! public double getMaxValue() { ! return maxValue.get(); ! } ! ! /** ! * Returns last known value of the datasource. ! * ! * @return Last datasource value. ! */ ! public double getLastValue() { ! return lastValue.get(); ! } ! ! /** ! * Returns value this datasource accumulated so far. ! * ! * @return Accumulated datasource value. ! */ ! public double getAccumValue() { ! return accumValue.get(); ! } ! ! /** ! * Returns the number of accumulated NaN seconds. ! * ! * @return Accumulated NaN seconds. ! */ ! public long getNanSeconds() { ! return nanSeconds.get(); ! } ! ! void process(long newTime, double newValue) throws IOException, RrdException { ! Header header = parentDb.getHeader(); ! long step = header.getStep(); ! long oldTime = header.getLastUpdateTime(); ! long startTime = Util.normalize(oldTime, step); ! long endTime = startTime + step; ! double oldValue = lastValue.get(); ! double updateValue = calculateUpdateValue(oldTime, oldValue, newTime, newValue); ! if(newTime < endTime) { ! accumulate(oldTime, newTime, updateValue); ! } ! else { ! // should store something ! long boundaryTime = Util.normalize(newTime, step); ! accumulate(oldTime, boundaryTime, updateValue); ! double value = calculateTotal(startTime, boundaryTime); ! // how many updates? ! long numSteps= (boundaryTime - endTime) / step + 1L; ! // ACTION! ! parentDb.archive(this, value, numSteps); ! // cleanup ! nanSeconds.set(0); ! accumValue.set(0.0); ! accumulate(boundaryTime, newTime, updateValue); ! } ! } ! ! private double calculateUpdateValue(long oldTime, double oldValue, ! long newTime, double newValue) throws IOException... [truncated message content] |
Update of /cvsroot/jrobin/src/org/jrobin/core In directory sc8-pr-cvs1:/tmp/cvs-serv31519 Modified Files: ArcState.java Archive.java Datasource.java Header.java Robin.java RrdDb.java Sample.java Log Message: Added option to change Min/Max values for datasource and fix archived values accordingly. Added option to change heartbeat, xff etc... Index: ArcState.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/core/ArcState.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** ArcState.java 27 Nov 2003 14:15:11 -0000 1.4 --- ArcState.java 30 Nov 2003 08:14:07 -0000 1.5 *************** *** 1,133 **** ! /* ============================================================ ! * JRobin : Pure java implementation of RRDTool's functionality ! * ============================================================ ! * ! * Project Info: http://www.jrobin.org ! * Project Lead: Sasa Markovic (sa...@jr...); ! * ! * (C) Copyright 2003, by Sasa Markovic. ! * ! * Developers: Sasa Markovic (sa...@jr...) ! * Arne Vandamme (cob...@jr...) ! * ! * This library is free software; you can redistribute it and/or modify it under the terms ! * of the GNU Lesser General Public License as published by the Free Software Foundation; ! * either version 2.1 of the License, or (at your option) any later version. ! * ! * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; ! * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. ! * See the GNU Lesser General Public License for more details. ! * ! * You should have received a copy of the GNU Lesser General Public License along with this ! * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, ! * Boston, MA 02111-1307, USA. ! */ ! ! package org.jrobin.core; ! ! import java.io.IOException; ! ! /** ! * Class to represent internal RRD archive state for a single datasource. Objects of this ! * class are never manipulated directly, it's up to JRobin framework to manage ! * internal arcihve states.<p> ! * ! * @author <a href="mailto:sa...@jr...">Sasa Markovic</a> ! */ ! public class ArcState implements RrdUpdater { ! private Archive parentArc; ! ! private RrdDouble accumValue; ! private RrdLong nanSteps; ! ! ArcState(Archive parentArc) throws IOException { ! this.parentArc = parentArc; ! if(getRrdFile().getMode() == RrdFile.MODE_CREATE) { ! // should initialize ! Header header = parentArc.getParentDb().getHeader(); ! long step = header.getStep(); ! long lastUpdateTime = header.getLastUpdateTime(); ! long arcStep = parentArc.getArcStep(); ! long nan = (Util.normalize(lastUpdateTime, step) - ! Util.normalize(lastUpdateTime, arcStep)) / step; ! accumValue = new RrdDouble(Double.NaN, this); ! nanSteps = new RrdLong(nan, this); ! } ! else { ! accumValue = new RrdDouble(this); ! nanSteps = new RrdLong(this); ! } ! } ! ! /** ! * Returns the underlying RrdFile object. ! * @return Underlying RrdFile object. ! */ ! public RrdFile getRrdFile() { ! return parentArc.getParentDb().getRrdFile(); ! } ! ! String dump() throws IOException { ! return "accumValue:" + accumValue.get() + " nanSteps:" + nanSteps.get() + "\n"; ! } ! ! void setNanSteps(long value) throws IOException { ! nanSteps.set(value); ! } ! ! /** ! * Returns the number of currently accumulated NaN steps. ! * ! * @return Number of currently accumulated NaN steps. ! * @throws IOException Thrown in case of IO specific error ! */ ! public long getNanSteps() throws IOException { ! return nanSteps.get(); ! } ! ! void setAccumValue(double value) throws IOException { ! accumValue.set(value); ! } ! ! /** ! * Returns the value accumulated so far. ! * ! * @return Accumulated value ! * @throws IOException Thrown in case of IO specific error ! */ ! public double getAccumValue() throws IOException { ! return accumValue.get(); ! } ! ! /** ! * Returns the Archive object to which this ArcState object belongs. ! * ! * @return Parent Archive object. ! */ ! public Archive getParent() { ! return parentArc; ! } ! ! void appendXml(XmlWriter writer) throws IOException { ! writer.startTag("ds"); ! writer.writeTag("value", accumValue.get()); ! writer.writeTag("unknown_datapoints", nanSteps.get()); ! writer.closeTag(); // ds ! } ! ! /** ! * Copies object's internal state to another ArcState object. ! * @param other New ArcState object to copy state to ! * @throws IOException Thrown in case of I/O error ! * @throws RrdException Thrown if supplied argument is not an ArcState object ! */ ! public void copyStateTo(RrdUpdater other) throws IOException, RrdException { ! if(!(other instanceof ArcState)) { ! throw new RrdException( ! "Cannot copy ArcState object to " + other.getClass().getName()); ! } ! ArcState arcState = (ArcState) other; ! arcState.accumValue.set(accumValue.get()); ! arcState.nanSteps.set(nanSteps.get()); ! } ! } --- 1,131 ---- ! /* ============================================================ ! * JRobin : Pure java implementation of RRDTool's functionality ! * ============================================================ ! * ! * Project Info: http://www.jrobin.org ! * Project Lead: Sasa Markovic (sa...@jr...); ! * ! * (C) Copyright 2003, by Sasa Markovic. ! * ! * Developers: Sasa Markovic (sa...@jr...) ! * Arne Vandamme (cob...@jr...) ! * ! * This library is free software; you can redistribute it and/or modify it under the terms ! * of the GNU Lesser General Public License as published by the Free Software Foundation; ! * either version 2.1 of the License, or (at your option) any later version. ! * ! * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; ! * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. ! * See the GNU Lesser General Public License for more details. ! * ! * You should have received a copy of the GNU Lesser General Public License along with this ! * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, ! * Boston, MA 02111-1307, USA. ! */ ! ! package org.jrobin.core; ! ! import java.io.IOException; ! ! /** ! * Class to represent internal RRD archive state for a single datasource. Objects of this ! * class are never manipulated directly, it's up to JRobin framework to manage ! * internal arcihve states.<p> ! * ! * @author <a href="mailto:sa...@jr...">Sasa Markovic</a> ! */ ! public class ArcState implements RrdUpdater { ! private Archive parentArc; ! ! private RrdDouble accumValue; ! private RrdLong nanSteps; ! ! ArcState(Archive parentArc) throws IOException { ! this.parentArc = parentArc; ! if(getRrdFile().getMode() == RrdFile.MODE_CREATE) { ! // should initialize ! Header header = parentArc.getParentDb().getHeader(); ! long step = header.getStep(); ! long lastUpdateTime = header.getLastUpdateTime(); ! long arcStep = parentArc.getArcStep(); ! long nan = (Util.normalize(lastUpdateTime, step) - ! Util.normalize(lastUpdateTime, arcStep)) / step; ! accumValue = new RrdDouble(Double.NaN, this); ! nanSteps = new RrdLong(nan, this); ! } ! else { ! accumValue = new RrdDouble(this); ! nanSteps = new RrdLong(this); ! } ! } ! ! /** ! * Returns the underlying RrdFile object. ! * @return Underlying RrdFile object. ! */ ! public RrdFile getRrdFile() { ! return parentArc.getParentDb().getRrdFile(); ! } ! ! String dump() { ! return "accumValue:" + accumValue.get() + " nanSteps:" + nanSteps.get() + "\n"; ! } ! ! void setNanSteps(long value) throws IOException { ! nanSteps.set(value); ! } ! ! /** ! * Returns the number of currently accumulated NaN steps. ! * ! * @return Number of currently accumulated NaN steps. ! */ ! public long getNanSteps() { ! return nanSteps.get(); ! } ! ! void setAccumValue(double value) throws IOException { ! accumValue.set(value); ! } ! ! /** ! * Returns the value accumulated so far. ! * ! * @return Accumulated value ! */ ! public double getAccumValue() { ! return accumValue.get(); ! } ! ! /** ! * Returns the Archive object to which this ArcState object belongs. ! * ! * @return Parent Archive object. ! */ ! public Archive getParent() { ! return parentArc; ! } ! ! void appendXml(XmlWriter writer) throws IOException { ! writer.startTag("ds"); ! writer.writeTag("value", accumValue.get()); ! writer.writeTag("unknown_datapoints", nanSteps.get()); ! writer.closeTag(); // ds ! } ! ! /** ! * Copies object's internal state to another ArcState object. ! * @param other New ArcState object to copy state to ! * @throws IOException Thrown in case of I/O error ! * @throws RrdException Thrown if supplied argument is not an ArcState object ! */ ! public void copyStateTo(RrdUpdater other) throws IOException, RrdException { ! if(!(other instanceof ArcState)) { ! throw new RrdException( ! "Cannot copy ArcState object to " + other.getClass().getName()); ! } ! ArcState arcState = (ArcState) other; ! arcState.accumValue.set(accumValue.get()); ! arcState.nanSteps.set(nanSteps.get()); ! } ! } Index: Archive.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/core/Archive.java,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** Archive.java 28 Nov 2003 13:24:46 -0000 1.7 --- Archive.java 30 Nov 2003 08:14:09 -0000 1.8 *************** *** 1,419 **** ! /* ============================================================ ! * JRobin : Pure java implementation of RRDTool's functionality ! * ============================================================ ! * ! * Project Info: http://www.jrobin.org ! * Project Lead: Sasa Markovic (sa...@jr...); ! * ! * (C) Copyright 2003, by Sasa Markovic. ! * ! * Developers: Sasa Markovic (sa...@jr...) ! * Arne Vandamme (cob...@jr...) ! * ! * This library is free software; you can redistribute it and/or modify it under the terms ! * of the GNU Lesser General Public License as published by the Free Software Foundation; ! * either version 2.1 of the License, or (at your option) any later version. ! * ! * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; ! * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. ! * See the GNU Lesser General Public License for more details. ! * ! * You should have received a copy of the GNU Lesser General Public License along with this ! * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, ! * Boston, MA 02111-1307, USA. ! */ ! ! package org.jrobin.core; ! ! import java.io.IOException; ! ! /** ! * Class to represent single RRD archive in a RRD file with its internal state. ! * Normally, you don't need methods to manipulate archive objects directly ! * because JRobin framework does it automatically for you.<p> ! * ! * Each archive object consists of three parts: archive definition, archive state objects ! * (one state object for each datasource) and round robin archives (one round robin for ! * each datasource). API (read-only) is provided to access each of theese parts.<p> ! * ! * @author <a href="mailto:sa...@jr...">Sasa Markovic</a> ! */ ! public class Archive implements RrdUpdater { ! private RrdDb parentDb; ! // definition ! private RrdString consolFun; ! private RrdDouble xff; ! private RrdInt steps, rows; ! // state ! private Robin[] robins; ! private ArcState[] states; ! ! // first time creation ! Archive(RrdDb parentDb, ArcDef arcDef) throws IOException { ! this.parentDb = parentDb; ! consolFun = new RrdString(arcDef.getConsolFun(), this); ! xff = new RrdDouble(arcDef.getXff(), this); ! steps = new RrdInt(arcDef.getSteps(), this); ! rows = new RrdInt(arcDef.getRows(), this); ! int n = parentDb.getHeader().getDsCount(); ! robins = new Robin[n]; ! states = new ArcState[n]; ! for(int i = 0; i < n; i++) { ! states[i] = new ArcState(this); ! robins[i] = new Robin(this, rows.get()); ! } ! } ! ! // read from file ! Archive(RrdDb parentDb) throws IOException { ! this.parentDb = parentDb; ! consolFun = new RrdString(this); ! xff = new RrdDouble(this); ! steps = new RrdInt(this); ! rows = new RrdInt(this); ! int n = parentDb.getHeader().getDsCount(); ! states = new ArcState[n]; ! robins = new Robin[n]; ! for(int i = 0; i < n; i++) { ! states[i] = new ArcState(this); ! robins[i] = new Robin(this, rows.get()); ! } ! } ! ! Archive(RrdDb parentDb, XmlReader reader, int arcIndex) throws IOException, RrdException { ! this.parentDb = parentDb; ! consolFun = new RrdString(reader.getConsolFun(arcIndex), this); ! xff = new RrdDouble(reader.getXff(arcIndex), this); ! steps = new RrdInt(reader.getSteps(arcIndex), this); ! rows = new RrdInt(reader.getRows(arcIndex), this); ! int dsCount = reader.getDsCount(); ! states = new ArcState[dsCount]; ! robins = new Robin[dsCount]; ! for(int dsIndex = 0; dsIndex < dsCount; dsIndex++) { ! // restore state ! states[dsIndex] = new ArcState(this); ! states[dsIndex].setAccumValue(reader.getStateAccumValue(arcIndex, dsIndex)); ! states[dsIndex].setNanSteps(reader.getStateNanSteps(arcIndex, dsIndex)); ! // restore robins ! robins[dsIndex] = new Robin(this, rows.get()); ! double[] values = reader.getValues(arcIndex, dsIndex); ! for(int j = 0; j < values.length; j++) { ! robins[dsIndex].store(values[j]); ! } ! } ! } ! ! /** ! * Returns archive time step in seconds. Archive step is equal to RRD file step ! * multiplied with the number of archive steps. ! * ! * @return Archive time step in seconds ! * @throws IOException Thrown in case of IO error ! */ ! public long getArcStep() throws IOException { ! long step = parentDb.getHeader().getStep(); ! return step * steps.get(); ! } ! ! String dump() throws IOException { ! StringBuffer buffer = new StringBuffer("== ARCHIVE ==\n"); ! buffer.append("RRA:" + consolFun.get() + ":" + xff.get() + ":" + ! steps.get() + ":" + rows.get() + "\n"); ! buffer.append("interval [" + getStartTime() + ", " + getEndTime() + "]" + "\n"); ! for(int i = 0; i < robins.length; i++) { ! buffer.append(states[i].dump()); ! buffer.append(robins[i].dump()); ! } ! return buffer.toString(); ! } ! ! RrdDb getParentDb() { ! return parentDb; ! } ! ! /** ! * Returns the underlying RrdFile object. ! * @return Underlying RrdFile object ! */ ! public RrdFile getRrdFile() { ! return parentDb.getRrdFile(); ! } ! ! void archive(int dsIndex, double value, long numUpdates) throws IOException { ! Robin robin = robins[dsIndex]; ! ArcState state = states[dsIndex]; ! long step = parentDb.getHeader().getStep(); ! long lastUpdateTime = parentDb.getHeader().getLastUpdateTime(); ! long updateTime = Util.normalize(lastUpdateTime, step) + step; ! long arcStep = getArcStep(); ! // finish current step ! while(numUpdates > 0) { ! accumulate(state, value); ! numUpdates--; ! if(updateTime % arcStep == 0) { ! finalizeStep(state, robin); ! break; ! } ! else { ! updateTime += step; ! } ! } ! // 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(); ! for(long i = 0; i < remainingUpdates; i++) { ! accumulate(state, value); ! } ! } ! ! private void accumulate(ArcState state, double value) throws IOException { ! if(Double.isNaN(value)) { ! state.setNanSteps(state.getNanSteps() + 1); ! } ! 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)); ! } ! } ! } ! ! private void finalizeStep(ArcState state, Robin robin) throws IOException { ! // 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); ! } ! robin.store(accumValue); ! } ! else { ! robin.store(Double.NaN); ! } ! state.setAccumValue(Double.NaN); ! state.setNanSteps(0); ! } ! ! /** ! * Returns archive consolidation function (AVERAGE, MIN, MAX or LAST). ! * @return Archive consolidation function. ! * @throws IOException Thrown in case of IO related error ! */ ! public String getConsolFun() throws IOException { ! return consolFun.get(); ! } ! ! /** ! * Returns archive X-files factor. ! * @return Archive X-files factor (between 0 and 1). ! * @throws IOException Thrown in case of IO related error ! */ ! public double getXff() throws IOException { ! return xff.get(); ! } ! ! /** ! * Returns the number of archive steps. ! * @return Number of archive steps. ! * @throws IOException Thrown in case of IO related error ! */ ! public int getSteps() throws IOException { ! return steps.get(); ! } ! ! /** ! * Returns the number of archive rows. ! * @return Number of archive rows. ! * @throws IOException Thrown in case of IO related error ! */ ! public int getRows() throws IOException{ ! return rows.get(); ! } ! ! /** ! * Returns current starting timestamp. This value is not constant. ! * @return Timestamp corresponding to the first archive row ! * @throws IOException Thrown in case of IO related error ! */ ! public long getStartTime() throws IOException { ! long endTime = getEndTime(); ! long arcStep = getArcStep(); ! long numRows = rows.get(); ! return endTime - (numRows - 1) * arcStep; ! } ! ! /** ! * Returns current ending timestamp. This value is not constant. ! * @return Timestamp corresponding to the last archive row ! * @throws IOException Thrown in case of IO related error ! */ ! public long getEndTime() throws IOException { ! long arcStep = getArcStep(); ! long lastUpdateTime = parentDb.getHeader().getLastUpdateTime(); ! return Util.normalize(lastUpdateTime, arcStep); ! } ! ! /** ! * Returns the underlying archive state object. Each datasource has its ! * corresponding ArcState object (archive states are managed independently ! * for each RRD datasource). ! * @param dsIndex Datasource index ! * @return Underlying archive state object ! */ ! public ArcState getArcState(int dsIndex) { ! return states[dsIndex]; ! } ! ! /** ! * Returns the underlying round robin archive. Robins are used to store actual ! * archive values on a per-datasource basis. ! * @param dsIndex Index of the datasource in the RRD file. ! * @return Underlying round robin archive for the given datasource. ! */ ! public Robin getRobin(int dsIndex) { ! return robins[dsIndex]; ! } ! ! FetchPoint[] fetch(FetchRequest request) throws IOException, RrdException { ! if(request.getFilter() != null) { ! throw new RrdException("fetch() method does not support filtered datasources." + ! " Use fetchData() to get filtered fetch data."); ! } ! long arcStep = getArcStep(); ! long fetchStart = Util.normalize(request.getFetchStart(), arcStep); ! long fetchEnd = Util.normalize(request.getFetchEnd(), arcStep); ! if(fetchEnd < request.getFetchEnd()) { ! fetchEnd += arcStep; ! } ! long startTime = getStartTime(); ! long endTime = getEndTime(); ! int dsCount = robins.length; ! int ptsCount = (int) ((fetchEnd - fetchStart) / arcStep + 1); ! FetchPoint[] points = new FetchPoint[ptsCount]; ! for(int i = 0; i < ptsCount; i++) { ! long time = fetchStart + i * arcStep; ! FetchPoint point = new FetchPoint(time, dsCount); ! if(time >= startTime && time <= endTime) { ! int robinIndex = (int)((time - startTime) / arcStep); ! for(int j = 0; j < dsCount; j++) { ! point.setValue(j, robins[j].getValue(robinIndex)); ! } ! } ! points[i] = point; ! } ! return points; ! } ! ! FetchData fetchData(FetchRequest request) throws IOException, RrdException { ! long arcStep = getArcStep(); ! long fetchStart = Util.normalize(request.getFetchStart(), arcStep); ! long fetchEnd = Util.normalize(request.getFetchEnd(), arcStep); ! if(fetchEnd < request.getFetchEnd()) { ! fetchEnd += arcStep; ! } ! long startTime = getStartTime(); ! long endTime = getEndTime(); ! String[] dsToFetch = request.getFilter(); ! if(dsToFetch == null) { ! dsToFetch = parentDb.getDsNames(); ! } ! int dsCount = dsToFetch.length; ! int ptsCount = (int) ((fetchEnd - fetchStart) / arcStep + 1); ! long[] timestamps = new long[ptsCount]; ! double[][] values = new double[dsCount][ptsCount]; ! for(int ptIndex = 0; ptIndex < ptsCount; ptIndex++) { ! long time = fetchStart + ptIndex * arcStep; ! timestamps[ptIndex] = time; ! if(time >= startTime && time <= endTime) { ! // inbound time ! int robinIndex = (int)((time - startTime) / arcStep); ! for(int 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; ! } ! } ! } ! FetchData fetchData = new FetchData(this, request); ! fetchData.setTimestamps(timestamps); ! fetchData.setValues(values); ! return fetchData; ! } ! ! void appendXml(XmlWriter writer) throws IOException { ! writer.startTag("rra"); ! writer.writeTag("cf", consolFun.get()); ! writer.writeComment(getArcStep() + " seconds"); ! writer.writeTag("pdp_per_row", steps.get()); ! writer.writeTag("xff", xff.get()); ! writer.startTag("cdp_prep"); ! for(int i = 0; i < states.length; i++) { ! states[i].appendXml(writer); ! } ! writer.closeTag(); // cdp_prep ! writer.startTag("database"); ! long startTime = getStartTime(); ! for(int i = 0; i < rows.get(); i++) { ! long time = startTime + i * getArcStep(); ! writer.writeComment(Util.getDate(time) + " / " + time); ! writer.startTag("row"); ! for(int j = 0; j < robins.length; j++) { ! writer.writeTag("v", robins[j].getValue(i)); ! } ! writer.closeTag(); // row ! } ! writer.closeTag(); // database ! writer.closeTag(); // rra ! } ! ! /** ! * Copies object's internal state to another Archive object. ! * @param other New Archive object to copy state to ! * @throws IOException Thrown in case of I/O error ! * @throws RrdException Thrown if supplied argument is not an Archive object ! */ ! public void copyStateTo(RrdUpdater other) throws IOException, RrdException { ! if(!(other instanceof Archive)) { ! throw new RrdException( ! "Cannot copy Archive object to " + other.getClass().getName()); ! } ! Archive arc = (Archive) other; ! if(!arc.consolFun.get().equals(consolFun.get())) { ! throw new RrdException("Incompatible consolidation functions"); ! } ! if(arc.steps.get() != steps.get()) { ! throw new RrdException("Incompatible number of steps"); ! } ! if(arc.rows.get() != rows.get()) { ! throw new RrdException("Incompatible number of rows"); ! } ! int count = parentDb.getHeader().getDsCount(); ! for(int i = 0; i < count; i++) { ! int j = Util.getMatchingDatasourceIndex(parentDb, i, arc.parentDb); ! if(j >= 0) { ! states[i].copyStateTo(arc.states[j]); ! robins[i].copyStateTo(arc.robins[j]); ! } ! } ! } ! } --- 1,426 ---- ! /* ============================================================ ! * JRobin : Pure java implementation of RRDTool's functionality ! * ============================================================ ! * ! * Project Info: http://www.jrobin.org ! * Project Lead: Sasa Markovic (sa...@jr...); ! * ! * (C) Copyright 2003, by Sasa Markovic. ! * ! * Developers: Sasa Markovic (sa...@jr...) ! * Arne Vandamme (cob...@jr...) ! * ! * This library is free software; you can redistribute it and/or modify it under the terms ! * of the GNU Lesser General Public License as published by the Free Software Foundation; ! * either version 2.1 of the License, or (at your option) any later version. ! * ! * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; ! * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. ! * See the GNU Lesser General Public License for more details. ! * ! * You should have received a copy of the GNU Lesser General Public License along with this ! * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, ! * Boston, MA 02111-1307, USA. ! */ ! ! package org.jrobin.core; ! ! import java.io.IOException; ! ! /** ! * Class to represent single RRD archive in a RRD file with its internal state. ! * Normally, you don't need methods to manipulate archive objects directly ! * because JRobin framework does it automatically for you.<p> ! * ! * Each archive object consists of three parts: archive definition, archive state objects ! * (one state object for each datasource) and round robin archives (one round robin for ! * each datasource). API (read-only) is provided to access each of theese parts.<p> ! * ! * @author <a href="mailto:sa...@jr...">Sasa Markovic</a> ! */ ! public class Archive implements RrdUpdater { ! private RrdDb parentDb; ! // definition ! private RrdString consolFun; ! private RrdDouble xff; ! private RrdInt steps, rows; ! // state ! private Robin[] robins; ! private ArcState[] states; ! ! // first time creation ! Archive(RrdDb parentDb, ArcDef arcDef) throws IOException { ! this.parentDb = parentDb; ! consolFun = new RrdString(arcDef.getConsolFun(), this); ! xff = new RrdDouble(arcDef.getXff(), this); ! steps = new RrdInt(arcDef.getSteps(), this); ! rows = new RrdInt(arcDef.getRows(), this); ! int n = parentDb.getHeader().getDsCount(); ! robins = new Robin[n]; ! states = new ArcState[n]; ! for(int i = 0; i < n; i++) { ! states[i] = new ArcState(this); ! robins[i] = new Robin(this, rows.get()); ! } ! } ! ! // read from file ! Archive(RrdDb parentDb) throws IOException { ! this.parentDb = parentDb; ! consolFun = new RrdString(this); ! xff = new RrdDouble(this); ! steps = new RrdInt(this); ! rows = new RrdInt(this); ! int n = parentDb.getHeader().getDsCount(); ! states = new ArcState[n]; ! robins = new Robin[n]; ! for(int i = 0; i < n; i++) { ! states[i] = new ArcState(this); ! robins[i] = new Robin(this, rows.get()); ! } ! } ! ! // read from XML ! Archive(RrdDb parentDb, XmlReader reader, int arcIndex) throws IOException, RrdException { ! this.parentDb = parentDb; ! consolFun = new RrdString(reader.getConsolFun(arcIndex), this); ! xff = new RrdDouble(reader.getXff(arcIndex), this); ! steps = new RrdInt(reader.getSteps(arcIndex), this); ! rows = new RrdInt(reader.getRows(arcIndex), this); ! int dsCount = reader.getDsCount(); ! states = new ArcState[dsCount]; ! robins = new Robin[dsCount]; ! for(int dsIndex = 0; dsIndex < dsCount; dsIndex++) { ! // restore state ! states[dsIndex] = new ArcState(this); ! states[dsIndex].setAccumValue(reader.getStateAccumValue(arcIndex, dsIndex)); ! states[dsIndex].setNanSteps(reader.getStateNanSteps(arcIndex, dsIndex)); ! // restore robins ! robins[dsIndex] = new Robin(this, rows.get()); ! double[] values = reader.getValues(arcIndex, dsIndex); ! for(int j = 0; j < values.length; j++) { ! robins[dsIndex].store(values[j]); ! } ! } ! } ! ! /** ! * Returns archive time step in seconds. Archive step is equal to RRD file step ! * multiplied with the number of archive steps. ! * ! * @return Archive time step in seconds ! */ ! public long getArcStep() { ! long step = parentDb.getHeader().getStep(); ! return step * steps.get(); ! } ! ! String dump() throws IOException { ! StringBuffer buffer = new StringBuffer("== ARCHIVE ==\n"); ! buffer.append("RRA:" + consolFun.get() + ":" + xff.get() + ":" + ! steps.get() + ":" + rows.get() + "\n"); ! buffer.append("interval [" + getStartTime() + ", " + getEndTime() + "]" + "\n"); ! for(int i = 0; i < robins.length; i++) { ! buffer.append(states[i].dump()); ! buffer.append(robins[i].dump()); ! } ! return buffer.toString(); ! } ! ! RrdDb getParentDb() { ! return parentDb; ! } ! ! /** ! * Returns the underlying RrdFile object. ! * @return Underlying RrdFile object ! */ ! public RrdFile getRrdFile() { ! return parentDb.getRrdFile(); ! } ! ! void archive(int dsIndex, double value, long numUpdates) throws IOException { ! Robin robin = robins[dsIndex]; ! ArcState state = states[dsIndex]; ! long step = parentDb.getHeader().getStep(); ! long lastUpdateTime = parentDb.getHeader().getLastUpdateTime(); ! long updateTime = Util.normalize(lastUpdateTime, step) + step; ! long arcStep = getArcStep(); ! // finish current step ! while(numUpdates > 0) { ! accumulate(state, value); ! numUpdates--; ! if(updateTime % arcStep == 0) { ! finalizeStep(state, robin); ! break; ! } ! else { ! updateTime += step; ! } ! } ! // 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(); ! for(long i = 0; i < remainingUpdates; i++) { ! accumulate(state, value); ! } ! } ! ! private void accumulate(ArcState state, double value) throws IOException { ! if(Double.isNaN(value)) { ! state.setNanSteps(state.getNanSteps() + 1); ! } ! 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)); ! } ! } ! } ! ! private void finalizeStep(ArcState state, Robin robin) throws IOException { ! // 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); ! } ! robin.store(accumValue); ! } ! else { ! robin.store(Double.NaN); ! } ! state.setAccumValue(Double.NaN); ! state.setNanSteps(0); ! } ! ! /** ! * Returns archive consolidation function (AVERAGE, MIN, MAX or LAST). ! * @return Archive consolidation function. ! */ ! public String getConsolFun() { ! return consolFun.get(); ! } ! ! /** ! * Returns archive X-files factor. ! * @return Archive X-files factor (between 0 and 1). ! */ ! public double getXff() { ! return xff.get(); ! } ! ! /** ! * Returns the number of archive steps. ! * @return Number of archive steps. ! */ ! public int getSteps() { ! return steps.get(); ! } ! ! /** ! * Returns the number of archive rows. ! * @return Number of archive rows. ! */ ! public int getRows() { ! return rows.get(); ! } ! ! /** ! * Returns current starting timestamp. This value is not constant. ! * @return Timestamp corresponding to the first archive row ! */ ! public long getStartTime() { ! long endTime = getEndTime(); ! long arcStep = getArcStep(); ! long numRows = rows.get(); ! return endTime - (numRows - 1) * arcStep; ! } ! ! /** ! * Returns current ending timestamp. This value is not constant. ! * @return Timestamp corresponding to the last archive row ! */ ! public long getEndTime() { ! long arcStep = getArcStep(); ! long lastUpdateTime = parentDb.getHeader().getLastUpdateTime(); ! return Util.normalize(lastUpdateTime, arcStep); ! } ! ! /** ! * Returns the underlying archive state object. Each datasource has its ! * corresponding ArcState object (archive states are managed independently ! * for each RRD datasource). ! * @param dsIndex Datasource index ! * @return Underlying archive state object ! */ ! public ArcState getArcState(int dsIndex) { ! return states[dsIndex]; ! } ! ! /** ! * Returns the underlying round robin archive. Robins are used to store actual ! * archive values on a per-datasource basis. ! * @param dsIndex Index of the datasource in the RRD file. ! * @return Underlying round robin archive for the given datasource. ! */ ! public Robin getRobin(int dsIndex) { ! return robins[dsIndex]; ! } ! ! FetchPoint[] fetch(FetchRequest request) throws IOException, RrdException { ! if(request.getFilter() != null) { ! throw new RrdException("fetch() method does not support filtered datasources." + ! " Use fetchData() to get filtered fetch data."); ! } ! long arcStep = getArcStep(); ! long fetchStart = Util.normalize(request.getFetchStart(), arcStep); ! long fetchEnd = Util.normalize(request.getFetchEnd(), arcStep); ! if(fetchEnd < request.getFetchEnd()) { ! fetchEnd += arcStep; ! } ! long startTime = getStartTime(); ! long endTime = getEndTime(); ! int dsCount = robins.length; ! int ptsCount = (int) ((fetchEnd - fetchStart) / arcStep + 1); ! FetchPoint[] points = new FetchPoint[ptsCount]; ! for(int i = 0; i < ptsCount; i++) { ! long time = fetchStart + i * arcStep; ! FetchPoint point = new FetchPoint(time, dsCount); ! if(time >= startTime && time <= endTime) { ! int robinIndex = (int)((time - startTime) / arcStep); ! for(int j = 0; j < dsCount; j++) { ! point.setValue(j, robins[j].getValue(robinIndex)); ! } ! } ! points[i] = point; ! } ! return points; ! } ! ! FetchData fetchData(FetchRequest request) throws IOException, RrdException { ! long arcStep = getArcStep(); ! long fetchStart = Util.normalize(request.getFetchStart(), arcStep); ! long fetchEnd = Util.normalize(request.getFetchEnd(), arcStep); ! if(fetchEnd < request.getFetchEnd()) { ! fetchEnd += arcStep; ! } ! long startTime = getStartTime(); ! long endTime = getEndTime(); ! String[] dsToFetch = request.getFilter(); ! if(dsToFetch == null) { ! dsToFetch = parentDb.getDsNames(); ! } ! int dsCount = dsToFetch.length; ! int ptsCount = (int) ((fetchEnd - fetchStart) / arcStep + 1); ! long[] timestamps = new long[ptsCount]; ! double[][] values = new double[dsCount][ptsCount]; ! for(int ptIndex = 0; ptIndex < ptsCount; ptIndex++) { ! long time = fetchStart + ptIndex * arcStep; ! timestamps[ptIndex] = time; ! if(time >= startTime && time <= endTime) { ! // inbound time ! int robinIndex = (int)((time - startTime) / arcStep); ! for(int 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; ! } ! } ! } ! FetchData fetchData = new FetchData(this, request); ! fetchData.setTimestamps(timestamps); ! fetchData.setValues(values); ! return fetchData; ! } ! ! void appendXml(XmlWriter writer) throws IOException { ! writer.startTag("rra"); ! writer.writeTag("cf", consolFun.get()); ! writer.writeComment(getArcStep() + " seconds"); ! writer.writeTag("pdp_per_row", steps.get()); ! writer.writeTag("xff", xff.get()); ! writer.startTag("cdp_prep"); ! for(int i = 0; i < states.length; i++) { ! states[i].appendXml(writer); ! } ! writer.closeTag(); // cdp_prep ! writer.startTag("database"); ! long startTime = getStartTime(); ! for(int i = 0; i < rows.get(); i++) { ! long time = startTime + i * getArcStep(); ! writer.writeComment(Util.getDate(time) + " / " + time); ! writer.startTag("row"); ! for(int j = 0; j < robins.length; j++) { ! writer.writeTag("v", robins[j].getValue(i)); ! } ! writer.closeTag(); // row ! } ! writer.closeTag(); // database ! writer.closeTag(); // rra ! } ! ! /** ! * Copies object's internal state to another Archive object. ! * @param other New Archive object to copy state to ! * @throws IOException Thrown in case of I/O error ! * @throws RrdException Thrown if supplied argument is not an Archive object ! */ ! public void copyStateTo(RrdUpdater other) throws IOException, RrdException { ! if(!(other instanceof Archive)) { ! throw new RrdException( ! "Cannot copy Archive object to " + other.getClass().getName()); ! } ! Archive arc = (Archive) other; ! if(!arc.consolFun.get().equals(consolFun.get())) { ! throw new RrdException("Incompatible consolidation functions"); ! } ! if(arc.steps.get() != steps.get()) { ! throw new RrdException("Incompatible number of steps"); ! } ! if(arc.rows.get() != rows.get()) { ! throw new RrdException("Incompatible number of rows"); ! } ! int count = parentDb.getHeader().getDsCount(); ! for(int i = 0; i < count; i++) { ! int j = Util.getMatchingDatasourceIndex(parentDb, i, arc.parentDb); ! if(j >= 0) { ! states[i].copyStateTo(arc.states[j]); ! robins[i].copyStateTo(arc.robins[j]); ! } ! } ! } ! ! /** ! * Sets X-files factor to a new value. ! * @param xff New X-files factor value. Must be >= 0 and < 1. ! * @throws RrdException Thrown if invalid value is supplied ! * @throws IOException Thrown in case of I/O error ! */ ! public void setXff(double xff) throws RrdException, IOException { ! if(xff < 0D || xff >= 1D) { ! throw new RrdException("Invalid xff supplied (" + xff + "), must be >= 0 and < 1"); ! } ! this.xff.set(xff); ! } ! } Index: Datasource.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/core/Datasource.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** Datasource.java 27 Nov 2003 14:15:11 -0000 1.3 --- Datasource.java 30 Nov 2003 08:14:09 -0000 1.4 *************** *** 1,315 **** ! /* ============================================================ ! * JRobin : Pure java implementation of RRDTool's functionality ! * ============================================================ ! * ! * Project Info: http://www.jrobin.org ! * Project Lead: Sasa Markovic (sa...@jr...); ! * ! * (C) Copyright 2003, by Sasa Markovic. ! * ! * Developers: Sasa Markovic (sa...@jr...) ! * Arne Vandamme (cob...@jr...) ! * ! * This library is free software; you can redistribute it and/or modify it under the terms ! * of the GNU Lesser General Public License as published by the Free Software Foundation; ! * either version 2.1 of the License, or (at your option) any later version. ! * ! * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; ! * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. ! * See the GNU Lesser General Public License for more details. ! * ! * You should have received a copy of the GNU Lesser General Public License along with this ! * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, ! * Boston, MA 02111-1307, USA. ! */ ! ! package org.jrobin.core; ! ! import java.io.IOException; ! ! /** ! * Class to represent single datasource within RRD file. Each datasource object holds the ! * following information: datasource definition (once set, never changed) and ! * datasource state variables (changed whenever RRD file gets updated).<p> ! * ! * Normally, you don't need to manipluate Datasource objects directly, it's up to ! * JRobin framework to do it for you. ! * ! * @author <a href="mailto:sa...@jr...">Sasa Markovic</a> ! */ ! public class Datasource implements RrdUpdater { ! private RrdDb parentDb; ! // definition ! private RrdString dsName, dsType; ! private RrdLong heartbeat; ! private RrdDouble minValue, maxValue; ! // state variables ! private RrdDouble lastValue; ! private RrdLong nanSeconds; ! private RrdDouble accumValue; ! ! Datasource(RrdDb parentDb, DsDef dsDef) throws IOException { ! this.parentDb = parentDb; ! dsName = new RrdString(dsDef.getDsName(), this); ! dsType = new RrdString(dsDef.getDsType(), this); ! heartbeat = new RrdLong(dsDef.getHeartbeat(), this); ! minValue = new RrdDouble(dsDef.getMinValue(), this); ! maxValue = new RrdDouble(dsDef.getMaxValue(), this); ! lastValue = new RrdDouble(Double.NaN, this); ! accumValue = new RrdDouble(0.0, this); ! Header header = parentDb.getHeader(); ! nanSeconds = new RrdLong(header.getLastUpdateTime() % header.getStep(), this); ! } ! ! Datasource(RrdDb parentDb) throws IOException { ! this.parentDb = parentDb; ! dsName = new RrdString(this); ! dsType = new RrdString(this); ! heartbeat = new RrdLong(this); ! minValue = new RrdDouble(this); ! maxValue = new RrdDouble(this); ! lastValue = new RrdDouble(this); ! accumValue = new RrdDouble(this); ! nanSeconds = new RrdLong(this); ! } ! ! Datasource(RrdDb parentDb, XmlReader reader, int dsIndex) throws IOException, RrdException { ! this.parentDb = parentDb; ! dsName = new RrdString(reader.getDsName(dsIndex), this); ! dsType = new RrdString(reader.getDsType(dsIndex), this); ! heartbeat = new RrdLong(reader.getHeartbeat(dsIndex), this); ! minValue = new RrdDouble(reader.getMinValue(dsIndex), this); ! maxValue = new RrdDouble(reader.getMaxValue(dsIndex), this); ! lastValue = new RrdDouble(reader.getLastValue(dsIndex), this); ! accumValue = new RrdDouble(reader.getAccumValue(dsIndex), this); ! nanSeconds = new RrdLong(reader.getNanSeconds(dsIndex), this); ! } ! ! String dump() throws IOException { ! return "== DATASOURCE ==\n" + ! "DS:" + dsName.get() + ":" + dsType.get() + ":" + ! heartbeat.get() + ":" + minValue.get() + ":" + ! maxValue.get() + "\nlastValue:" + lastValue.get() + ! " nanSeconds:" + nanSeconds.get() + ! " accumValue:" + accumValue.get() + "\n"; ! } ! ! /** ! * Returns the underlying RrdFile object. ! * @return Underlying RrdFile object. ! */ ! public RrdFile getRrdFile() { ! return parentDb.getRrdFile(); ! } ! ! /** ! * Returns datasource name. ! * @return Datasource name ! * @throws IOException Thrown in case of IO related error ! */ ! public String getDsName() throws IOException { ! return dsName.get(); ! } ! ! /** ! * Returns datasource type (GAUGE, COUNTER, DERIVE, ABSOLUTE). ! * ! * @return Datasource type. ! * @throws IOException Thrown in case of IO related error ! */ ! public String getDsType() throws IOException { ! return dsType.get(); ! } ! ! /** ! * Returns datasource heartbeat ! * ! * @return Datasource heartbeat ! * @throws IOException Thrown in case of IO related error ! */ ! public long getHeartbeat() throws IOException { ! return heartbeat.get(); ! } ! ! /** ! * Returns mimimal allowed value of the datasource. ! * ! * @return Minimal value allowed. ! * @throws IOException Thrown in case of IO related error ! */ ! public double getMinValue() throws IOException { ! return minValue.get(); ! } ! ! /** ! * Returns maximal allowed value of the datasource. ! * ! * @return Maximal value allowed. ! * @throws IOException Thrown in case of IO related error ! */ ! public double getMaxValue() throws IOException { ! return maxValue.get(); ! } ! ! /** ! * Returns last known value of the datasource. ! * ! * @return Last datasource value. ! * @throws IOException Thrown in case of IO related error ! */ ! public double getLastValue() throws IOException { ! return lastValue.get(); ! } ! ! /** ! * Returns value this datasource accumulated so far. ! * ! * @return Accumulated datasource value. ! * @throws IOException Thrown in case of IO related error ! */ ! public double getAccumValue() throws IOException { ! return accumValue.get(); ! } ! ! /** ! * Returns the number of accumulated NaN seconds. ! * ! * @return Accumulated NaN seconds. ! * @throws IOException Thrown in case of IO related error ! */ ! public long getNanSeconds() throws IOException { ! return nanSeconds.get(); ! } ! ! void process(long newTime, double newValue) throws IOException, RrdException { ! Header header = parentDb.getHeader(); ! long step = header.getStep(); ! long oldTime = header.getLastUpdateTime(); ! long startTime = Util.normalize(oldTime, step); ! long endTime = startTime + step; ! double oldValue = lastValue.get(); ! double updateValue = calculateUpdateValue(oldTime, oldValue, newTime, newValue); ! if(newTime < endTime) { ! accumulate(oldTime, newTime, updateValue); ! } ! else { ! // should store something ! long boundaryTime = Util.normalize(newTime, step); ! accumulate(oldTime, boundaryTime, updateValue); ! double value = calculateTotal(startTime, boundaryTime); ! // how many updates? ! long numSteps= (boundaryTime - endTime) / step + 1L; ! // ACTION! ! parentDb.archive(this, value, numSteps); ! // cleanup ! nanSeconds.set(0); ! accumValue.set(0.0); ! accumulate(boundaryTime, newTime, updateValue); ! } ! } ! ! private double calculateUpdateValue(long oldTime, double oldValue, ! long newTime, double newValue) throws IOException { ! double updateValue = Double.NaN; ! 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; ! double max32bit = Math.pow(2, 32); ! double max64bit = Math.pow(2, 64); ! if(diff < 0) { ! diff += max32bit; ! } ! if(diff < 0) { ! diff += max64bit - max32bit; ! } ! if(diff >= 0) { ! updateValue = diff / (newTime - oldTime); ! } ! } ! } ! if(!Double.isNaN(updateValue)) { ! double minVal = minValue.get(); ! double maxVal = maxValue.get(); ! if(!Double.isNaN(minVal) && updateValue < minVal) { ! updateValue = Double.NaN; ! } ! if(!Double.isNaN(maxVal) && updateValue > maxVal) { ! updateValue = Double.NaN; ! } ! } ! } ! lastValue.set(newValue); ! return updateValue; ! } ! ! private void accumulate(long oldTime, long newTime, double updateValue) throws IOException { ! if(Double.isNaN(updateValue)) { ! nanSeconds.set(nanSeconds.get() + (newTime - oldTime)); ! } ! else { ! accumValue.set(accumValue.get() + updateValue * (newTime - oldTime)); ! } ! } ! ! private double calculateTotal(long startTime, long boundaryTime) { ! double totalValue = Double.NaN; ! long validSeconds = boundaryTime - startTime - nanSeconds.get(); ! if(nanSeconds.get() <= heartbeat.get() && validSeconds > 0) { ! totalValue = accumValue.get() / validSeconds; ! } ! return totalValue; ! } ! ! void appendXml(XmlWriter writer) throws IOException { ! writer.startTag("ds"); ! writer.writeTag("name", dsName.get()); ! writer.writeTag("type", dsType.get()); ! writer.writeTag("minimal_heartbeat", heartbeat.get()); ! writer.writeTag("min", minValue.get()); ! writer.writeTag("max", maxValue.get()); ! writer.writeComment("PDP Status"); ! writer.writeTag("last_ds", lastValue.get(), "UNKN"); ! writer.writeTag("value", accumValue.get()); ! writer.writeTag("unknown_sec", nanSeconds.get()); ! writer.closeTag(); // ds ! } ! ! /** ! * Copies object's internal state to another Datasource object. ! * @param other New Datasource object to copy state to ! * @throws IOException Thrown in case of I/O error ! * @throws RrdException Thrown if supplied argument is not a Datasource object ! */ ! public void copyStateTo(RrdUpdater other) throws IOException, RrdException { ! if(!(other instanceof Datasource)) { ! throw new RrdException( ! "Cannot copy Datasource object to " + other.getClass().getName()); ! } ! Datasource datasource = (Datasource) other; ! if(!datasource.dsName.get().equals(dsName.get())) { ! throw new RrdException("Incomaptible datasource names"); ! } ! if(!datasource.dsType.get().equals(dsType.get())) { ! throw new RrdException("Incomaptible datasource types"); ! } ! datasource.lastValue.set(lastValue.get()); ! datasource.nanSeconds.set(nanSeconds.get()); ! datasource.accumValue.set(accumValue.get()); ! } ! ! } --- 1,415 ---- ! /* ============================================================ ! * JRobin : Pure java implementation of RRDTool's functionality ! * ============================================================ ! * ! * Project Info: http://www.jrobin.org ! * Project Lead: Sasa Markovic (sa...@jr...); ! * ! * (C) Copyright 2003, by Sasa Markovic. ! * ! * Developers: Sasa Markovic (sa...@jr...) ! * Arne Vandamme (cob...@jr...) ! * ! * This library is free software; you can redistribute it and/or modify it under the terms ! * of the GNU Lesser General Public License as published by the Free Software Foundation; ! * either version 2.1 of the License, or (at your option) any later version. ! * ! * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; ! * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. ! * See the GNU Lesser General Public License for more details. ! * ! * You should have received a copy of the GNU Lesser General Public License along with this ! * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, ! * Boston, MA 02111-1307, USA. ! */ ! ! package org.jrobin.core; ! ! import java.io.IOException; ! ! /** ! * Class to represent single datasource within RRD file. Each datasource object holds the ! * following information: datasource definition (once set, never changed) and ! * datasource state variables (changed whenever RRD file gets updated).<p> ! * ! * Normally, you don't need to manipluate Datasource objects directly, it's up to ! * JRobin framework to do it for you. ! * ! * @author <a href="mailto:sa...@jr...">Sasa Markovic</a> ! */ ! public class Datasource implements RrdUpdater { ! private RrdDb parentDb; ! // definition ! private RrdString dsName, dsType; ! private RrdLong heartbeat; ! private RrdDouble minValue, maxValue; ! // state variables ! private RrdDouble lastValue; ! private RrdLong nanSeconds; ! private RrdDouble accumValue; ! ! Datasource(RrdDb parentDb, DsDef dsDef) throws IOException { ! this.parentDb = parentDb; ! dsName = new RrdString(dsDef.getDsName(), this); ! dsType = new RrdString(dsDef.getDsType(), this); ! heartbeat = new RrdLong(dsDef.getHeartbeat(), this); ! minValue = new RrdDouble(dsDef.getMinValue(), this); ! maxValue = new RrdDouble(dsDef.getMaxValue(), this); ! lastValue = new RrdDouble(Double.NaN, this); ! accumValue = new RrdDouble(0.0, this); ! Header header = parentDb.getHeader(); ! nanSeconds = new RrdLong(header.getLastUpdateTime() % header.getStep(), this); ! } ! ! Datasource(RrdDb parentDb) throws IOException { ! this.parentDb = parentDb; ! dsName = new RrdString(this); ! dsType = new RrdString(this); ! heartbeat = new RrdLong(this); ! minValue = new RrdDouble(this); ! maxValue = new RrdDouble(this); ! lastValue = new RrdDouble(this); ! accumValue = new RrdDouble(this); ! nanSeconds = new RrdLong(this); ! } ! ! Datasource(RrdDb parentDb, XmlReader reader, int dsIndex) throws IOException, RrdException { ! this.parentDb = parentDb; ! dsName = new RrdString(reader.getDsName(dsIndex), this); ! dsType = new RrdString(reader.getDsType(dsIndex), this); ! heartbeat = new RrdLong(reader.getHeartbeat(dsIndex), this); ! minValue = new RrdDouble(reader.getMinValue(dsIndex), this); ! maxValue = new RrdDouble(reader.getMaxValue(dsIndex), this); ! lastValue = new RrdDouble(reader.getLastValue(dsIndex), this); ! accumValue = new RrdDouble(reader.getAccumValue(dsIndex), this); ! nanSeconds = new RrdLong(reader.getNanSeconds(dsIndex), this); ! } ! ! String dump() { ! return "== DATASOURCE ==\n" + ! "DS:" + dsName.get() + ":" + dsType.get() + ":" + ! heartbeat.get() + ":" + minValue.get() + ":" + ! maxValue.get() + "\nlastValue:" + lastValue.get() + ! " nanSeconds:" + nanSeconds.get() + ! " accumValue:" + accumValue.get() + "\n"; ! } ! ! /** ! * Returns the underlying RrdFile object. ! * @return Underlying RrdFile object. ! */ ! public RrdFile getRrdFile() { ! return parentDb.getRrdFile(); ! } ! ! /** ! * Returns datasource name. ! * @return Datasource name ! */ ! public String getDsName() { ! return dsName.get(); ! } ! ! /** ! * Returns datasource type (GAUGE, COUNTER, DERIVE, ABSOLUTE). ! * ! * @return Datasource type. ! */ ! public String getDsType() { ! return dsType.get(); ! } ! ! /** ! * Returns datasource heartbeat ! * ! * @return Datasource heartbeat ! */ ! public long getHeartbeat() { ! return heartbeat.get(); ! } ! ! /** ! * Returns mimimal allowed value of the datasource. ! * ! * @return Minimal value allowed. ! */ ! public double getMinValue() { ! return minValue.get(); ! } ! ! /** ! * Returns maximal allowed value of the datasource. ! * ! * @return Maximal value allowed. ! */ ! public double getMaxValue() { ! return maxValue.get(); ! } ! ! /** ! * Returns last known value of the datasource. ! * ! * @return Last datasource value. ! */ ! public double getLastValue() { ! return lastValue.get(); ! } ! ! /** ! * Returns value this datasource accumulated so far. ! * ! * @return Accumulated datasource value. ! */ ! public double getAccumValue() { ! return accumValue.get(); ! } ! ! /** ! * Returns the number of accumulated NaN seconds. ! * ! * @return Accumulated NaN seconds. ! */ ! public long getNanSeconds() { ! return nanSeconds.get(); ! } ! ! void process(long newTime, double newValue) throws IOException, RrdException { ! Header header = parentDb.getHeader(); ! long step = header.getStep(); ! long oldTime = header.getLastUpdateTime(); ! long startTime = Util.normalize(oldTime, step); ! long endTime = startTime + step; ! double oldValue = lastValue.get(); ! double updateValue = calculateUpdateValue(oldTime, oldValue, newTime, newValue); ! if(newTime < endTime) { ! accumulate(oldTime, newTime, updateValue); ! } ! else { ! // should store something ! long boundaryTime = Util.normalize(newTime, step); ! accumulate(oldTime, boundaryTime, updateValue); ! double value = calculateTotal(startTime, boundaryTime); ! // how many updates? ! long numSteps= (boundaryTime - endTime) / step + 1L; ! // ACTION! ! parentDb.archive(this, value, numSteps); ! // cleanup ! nanSeconds.set(0); ! accumValue.set(0.0); ! accumulate(boundaryTime, newTime, updateValue); ! } ! } ! ! private double calculateUpdateValue(long oldTime, double oldValue, ! long newTime, double newValue) throws IOException { ! double updateValue = Double.NaN; ! 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; ! double max32bit = Math.pow(2, 32); ! double max64bit = Math.pow(2, 64); ! if(diff < 0) { ! diff += max32bit; ! } ! if(diff < 0) { ! diff += max64bit - max32bit; ! } ! if(diff >= 0) { ! updateValue = diff / (newTime - oldTime); ! } ! } ! } ! if(!Double.isNaN(updateValue)) { ! double minVal = minValue.get(); ! double maxVal = maxValue.get(); ! if(!Double.isNaN(minVal) && updateValue < minVal) { ! updateValue = Double.NaN; ! } ! if(!Double.isNaN(maxVal) && updateValue > maxVal) { ! updateValue = Double.NaN; ! } ! } ! } ! lastValue.set(newValue); ! return updateValue; ! } ! ! private void accumulate(long oldTime, long newTime, double updateValue) throws IOException { ! if(Double.isNaN(updateValue)) { ! nanSeconds.set(nanSeconds.get() + (newTime - oldTime)); ! } ! else { ! accumValue.set(accumValue.get() + updateValue * (newTime - oldTime)); ! } ! } ! ! private double calculateTotal(long startTime, long boundaryTime) { ! double totalValue = Double.NaN; ! long validSeconds = boundaryTime - startTime - nanSeconds.get(); ! if(nanSeconds.get() <= heartbeat.get() && validSeconds > 0) { ! totalValue = accumValue.get() / validSeconds; ! } ! return totalValue; ! } ! ! void appendXml(XmlWriter writer) throws IOException { ! writer.startTag("ds"); ! writer.writeTag("name", dsName.get()); ! writer.writeTag("type", dsType.get()); ! writer.writeTag("minimal_heartbeat", heartbeat.get()); ! writer.writeTag("min", minValue.get()); ! writer.writeTag("max", maxValue.get()); ! writer.writeComment("PDP Status"); ! writer.writeTag("last_ds", lastValue.get(), "UNKN"); ! writer.writeTag("value", accumValue.get()); ! writer.writeTag("unknown_sec", nanSeconds.get()); ! writer.closeTag(); // ds ! } ! ! /** ! * Copies object's internal state to another Datasource object. ! * @param other New Datasource object to copy state to ! * @throws IOException Thrown in case of I/O error ! * @throws RrdException Thrown if supplied argument is not a Datasource object ! */ ! public void copyStateTo(RrdUpdater other) throws IOException, RrdException { ! if(!(other instanceof Datasource)) { ! throw new RrdException( ! "Cannot copy Datasource object to " + other.getClass().getName()); ! } ! Datasource datasource = (Datasource) other; ! if(!datasource.dsName.get().equals(dsName.get())) { ! throw new RrdException("Incomaptible datasource names"); ! } ! if(!datasource.dsType.get().equals(dsType.get())) { ! throw new RrdException("Incomaptible datasource types"); ! } ! datasource.lastValue.set(lastValue.get()); ! datasource.nanSeconds.set(nanSeconds.get()); ! datasource.accumValue.set(accumValue.get()); ! } ! ! /** ! * Returns index of this Datasource obj... [truncated message content] |
|
From: <sa...@us...> - 2003-11-28 13:24:49
|
Update of /cvsroot/jrobin/src/org/jrobin/core
In directory sc8-pr-cvs1:/tmp/cvs-serv8426/org/jrobin/core
Modified Files:
Archive.java RrdDb.java RrdDef.java RrdToolkit.java Util.java
Log Message:
Added RRDToolkit class to perform some less frequent but very useful operations on a RRD file as whole. So far so good: you can now add and remove datasource definitions to a RRD still preserving already existing data in it.
Index: Archive.java
===================================================================
RCS file: /cvsroot/jrobin/src/org/jrobin/core/Archive.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -d -r1.6 -r1.7
*** Archive.java 27 Nov 2003 15:53:33 -0000 1.6
--- Archive.java 28 Nov 2003 13:24:46 -0000 1.7
***************
*** 410,416 ****
int count = parentDb.getHeader().getDsCount();
for(int i = 0; i < count; i++) {
! String dsName = parentDb.getDatasource(i).getDsName();
! if(arc.getParentDb().getDatasource(dsName) != null) {
! int j = arc.getParentDb().getDsIndex(dsName);
states[i].copyStateTo(arc.states[j]);
robins[i].copyStateTo(arc.robins[j]);
--- 410,415 ----
int count = parentDb.getHeader().getDsCount();
for(int i = 0; i < count; i++) {
! int j = Util.getMatchingDatasourceIndex(parentDb, i, arc.parentDb);
! if(j >= 0) {
states[i].copyStateTo(arc.states[j]);
robins[i].copyStateTo(arc.robins[j]);
Index: RrdDb.java
===================================================================
RCS file: /cvsroot/jrobin/src/org/jrobin/core/RrdDb.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -d -r1.6 -r1.7
*** RrdDb.java 27 Nov 2003 15:53:33 -0000 1.6
--- RrdDb.java 28 Nov 2003 13:24:46 -0000 1.7
***************
*** 660,676 ****
"Cannot copy RrdDb object to " + other.getClass().getName());
}
! RrdDb rrd = (RrdDb) other;
! header.copyStateTo(rrd.header);
for(int i = 0; i < datasources.length; i++) {
! Datasource matchingDatasource = rrd.getDatasource(datasources[i].getDsName());
! if(matchingDatasource != null) {
! datasources[i].copyStateTo(matchingDatasource);
}
}
for(int i = 0; i < archives.length; i++) {
! Archive matchingArchive = rrd.getArchive(
! archives[i].getConsolFun(), archives[i].getSteps());
! if(matchingArchive != null) {
! archives[i].copyStateTo(matchingArchive);
}
}
--- 660,675 ----
"Cannot copy RrdDb object to " + other.getClass().getName());
}
! RrdDb otherRrd = (RrdDb) other;
! header.copyStateTo(otherRrd.header);
for(int i = 0; i < datasources.length; i++) {
! int j = Util.getMatchingDatasourceIndex(this, i, otherRrd);
! if(j >= 0) {
! datasources[i].copyStateTo(otherRrd.datasources[j]);
}
}
for(int i = 0; i < archives.length; i++) {
! int j = Util.getMatchingArchiveIndex(this, i, otherRrd);
! if(j >= 0) {
! archives[i].copyStateTo(otherRrd.archives[j]);
}
}
Index: RrdDef.java
===================================================================
RCS file: /cvsroot/jrobin/src/org/jrobin/core/RrdDef.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** RrdDef.java 27 Nov 2003 14:15:11 -0000 1.4
--- RrdDef.java 28 Nov 2003 13:24:46 -0000 1.5
***************
*** 319,321 ****
--- 319,332 ----
throw new RrdException("Could not find datasource named '" + dsName + "'");
}
+
+ void removeArchive(String consolFun, int steps) throws RrdException {
+ for(int i = 0; i < arcDefs.size(); i++) {
+ ArcDef arcDef = (ArcDef) arcDefs.get(i);
+ if(arcDef.getConsolFun().equals(consolFun) && arcDef.getSteps() == steps) {
+ arcDefs.remove(i);
+ return;
+ }
+ }
+ throw new RrdException("Could not find archive " + consolFun + "/" + steps);
+ }
}
Index: RrdToolkit.java
===================================================================
RCS file: /cvsroot/jrobin/src/org/jrobin/core/RrdToolkit.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** RrdToolkit.java 27 Nov 2003 15:53:33 -0000 1.3
--- RrdToolkit.java 28 Nov 2003 13:24:46 -0000 1.4
***************
*** 1,15 ****
! /**
! * Created by IntelliJ IDEA.
! * User: Administrator
! * Date: Nov 27, 2003
! * Time: 12:21:37 PM
! * To change this template use Options | File Templates.
*/
package org.jrobin.core;
import java.io.IOException;
/**
! * Class used to perform less important but complex operations on RRD files (like adding
! * a new datasource to a RRD file).
*/
public class RrdToolkit {
--- 1,41 ----
! /* ============================================================
! * JRobin : Pure java implementation of RRDTool's functionality
! * ============================================================
! *
! * Project Info: http://www.jrobin.org
! * Project Lead: Sasa Markovic (sa...@jr...);
! *
! * (C) Copyright 2003, by Sasa Markovic.
! *
! * Developers: Sasa Markovic (sa...@jr...)
! * Arne Vandamme (cob...@jr...)
! *
! * This library is free software; you can redistribute it and/or modify it under the terms
! * of the GNU Lesser General Public License as published by the Free Software Foundation;
! * either version 2.1 of the License, or (at your option) any later version.
! *
! * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
! * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
! * See the GNU Lesser General Public License for more details.
! *
! * You should have received a copy of the GNU Lesser General Public License along with this
! * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
! * Boston, MA 02111-1307, USA.
*/
package org.jrobin.core;
import java.io.IOException;
+ import java.io.File;
/**
! * <p>Class used to perform various complex operations on RRD files. Use an instance of the
! * RrdToolkit class to:</p>
! * <ul>
! * <li>add datasource to a RRD file.
! * <li>add archive to a RRD file.
! * <li>remove datasource from a RRD file.
! * <li>remove archive from a RRD file.
! * </ul>
! * <p>All these operations can be performed on the copy of the original RRD file, or on the
! * original file itself (with possible backup file creation)</p>
*/
public class RrdToolkit {
***************
*** 56,59 ****
--- 82,108 ----
/**
+ * <p>Adds one more datasource to a RRD file.</p>
+ * <p>WARNING: This method is potentialy dangerous! It will modify your RRD file.
+ * It is highly recommended to preserve the original RRD file (<i>saveBackup</i>
+ * should be set to <code>true</code>). The backup file will be created in the same
+ * directory as the original one with <code>.bak</code> extension added to the
+ * original name.</p>
+ * <p>Before applying this method, be sure that the specified RRD file is not in use
+ * (not open)</p>
+ * @param sourcePath path to a RRD file to add datasource to.
+ * @param newDatasource Datasource definition to be added to the RRD file
+ * @param saveBackup true, if backup of the original file should be created;
+ * false, otherwise
+ * @throws IOException Thrown in case of I/O error
+ * @throws RrdException Thrown in case of JRobin specific error
+ */
+ public void addDatasource(String sourcePath, DsDef newDatasource, boolean saveBackup)
+ throws IOException, RrdException {
+ String destPath = Util.getTmpFilename();
+ addDatasource(sourcePath, destPath, newDatasource);
+ copyFile(destPath, sourcePath, saveBackup);
+ }
+
+ /**
* Creates a new RRD file with one datasource removed. RRD file is created based on the
* existing one (the original RRD file is not modified at all). All remaining data from
***************
*** 65,69 ****
* @throws RrdException Thrown in case of JRobin specific error
*/
-
public void removeDatasource(String sourcePath, String destPath, String dsName)
throws IOException, RrdException {
--- 114,117 ----
***************
*** 82,85 ****
--- 130,156 ----
/**
+ * <p>Removes single datasource from a RRD file.</p>
+ * <p>WARNING: This method is potentialy dangerous! It will modify your RRD file.
+ * It is highly recommended to preserve the original RRD file (<i>saveBackup</i>
+ * should be set to <code>true</code>). The backup file will be created in the same
+ * directory as the original one with <code>.bak</code> extension added to the
+ * original name.</p>
+ * <p>Before applying this method, be sure that the specified RRD file is not in use
+ * (not open)</p>
+ * @param sourcePath path to a RRD file to remove datasource from.
+ * @param dsName Name of the Datasource to be removed from the RRD file
+ * @param saveBackup true, if backup of the original file should be created;
+ * false, otherwise
+ * @throws IOException Thrown in case of I/O error
+ * @throws RrdException Thrown in case of JRobin specific error
+ */
+ public void removeDatasource(String sourcePath, String dsName, boolean saveBackup)
+ throws IOException, RrdException {
+ String destPath = Util.getTmpFilename();
+ removeDatasource(sourcePath, destPath, dsName);
+ copyFile(destPath, sourcePath, saveBackup);
+ }
+
+ /**
* Creates a new RRD file with one more archive in it. RRD file is created based on the
* existing one (the original RRD file is not modified at all). All data from
***************
*** 106,113 ****
}
public static void main(String[] args) throws RrdException, IOException {
! DsDef dsDef = new DsDef("XXX", "GAUGE", 666, -1, Double.NaN);
! RrdToolkit.getInstance().addDatasource("demo.rrd", "demo2.rrd", dsDef);
! RrdToolkit.getInstance().removeDatasource("demo2.rrd", "demo3.rrd", "sun");
}
}
--- 177,289 ----
}
+ /**
+ * <p>Adds one more archive to a RRD file.</p>
+ * <p>WARNING: This method is potentialy dangerous! It will modify your RRD file.
+ * It is highly recommended to preserve the original RRD file (<i>saveBackup</i>
+ * should be set to <code>true</code>). The backup file will be created in the same
+ * directory as the original one with <code>.bak</code> extension added to the
+ * original name.</p>
+ * <p>Before applying this method, be sure that the specified RRD file is not in use
+ * (not open)</p>
+ * @param sourcePath path to a RRD file to add datasource to.
+ * @param newArchive Archive definition to be added to the RRD file
+ * @param saveBackup true, if backup of the original file should be created;
+ * false, otherwise
+ * @throws IOException Thrown in case of I/O error
+ * @throws RrdException Thrown in case of JRobin specific error
+ */
+ public void addArchive(String sourcePath, ArcDef newArchive, boolean saveBackup)
+ throws IOException, RrdException {
+ String destPath = Util.getTmpFilename();
+ addArchive(sourcePath, destPath, newArchive);
+ copyFile(destPath, sourcePath, saveBackup);
+ }
+
+ /**
+ * Creates a new RRD file with one archive removed. RRD file is created based on the
+ * existing one (the original RRD file is not modified at all). All relevant data from
+ * the original RRD file is copied to the new one.
+ * @param sourcePath path to a RRD file to import data from (will not be modified)
+ * @param destPath path to a new RRD file (will be created)
+ * @param consolFun Consolidation function of Archive which should be removed
+ * @param steps Number of steps for Archive which should be removed
+ * @throws IOException Thrown in case of I/O error
+ * @throws RrdException Thrown in case of JRobin specific error
+ */
+ public void removeArchive(String sourcePath, String destPath, String consolFun, int steps)
+ throws IOException, RrdException {
+ if(Util.sameFilePath(sourcePath, destPath)) {
+ throw new RrdException("Source and destination paths are the same");
+ }
+ RrdDb rrdSource = new RrdDb(sourcePath);
+ RrdDef rrdDef = rrdSource.getRrdDef();
+ rrdDef.setPath(destPath);
+ rrdDef.removeArchive(consolFun, steps);
+ RrdDb rrdDest = new RrdDb(rrdDef);
+ rrdSource.copyStateTo(rrdDest);
+ rrdSource.close();
+ rrdDest.close();
+ }
+
+ /**
+ * <p>Removes one archive from a RRD file.</p>
+ * <p>WARNING: This method is potentialy dangerous! It will modify your RRD file.
+ * It is highly recommended to preserve the original RRD file (<i>saveBackup</i>
+ * should be set to <code>true</code>). The backup file will be created in the same
+ * directory as the original one with <code>.bak</code> extension added to the
+ * original name.</p>
+ * <p>Before applying this method, be sure that the specified RRD file is not in use
+ * (not open)</p>
+ * @param sourcePath path to a RRD file to add datasource to.
+ * @param consolFun Consolidation function of Archive which should be removed
+ * @param steps Number of steps for Archive which should be removed
+ * @param saveBackup true, if backup of the original file should be created;
+ * false, otherwise
+ * @throws IOException Thrown in case of I/O error
+ * @throws RrdException Thrown in case of JRobin specific error
+ */
+ public void removeArchive(String sourcePath, String consolFun, int steps,
+ boolean saveBackup) throws IOException, RrdException {
+ String destPath = Util.getTmpFilename();
+ removeArchive(sourcePath, destPath, consolFun, steps);
+ copyFile(destPath, sourcePath, saveBackup);
+ }
+
+ private static void copyFile(String sourcePath, String destPath, boolean saveBackup)
+ throws IOException {
+ File source = new File(sourcePath);
+ File dest = new File(destPath);
+ if(saveBackup) {
+ String backupPath = destPath + ".bak";
+ File backup = new File(backupPath);
+ deleteFile(backup);
+ if(!dest.renameTo(backup)) {
+ throw new IOException("Could not create backup file " + backupPath);
+ }
+ }
+ deleteFile(dest);
+ if(!source.renameTo(dest)) {
+ throw new IOException("Could not create file " + destPath + " from " + sourcePath);
+ }
+ }
+
+ private static void deleteFile(File file) throws IOException {
+ if(file.exists() && !file.delete()) {
+ throw new IOException("Could not delete file: " + file.getCanonicalPath());
+ }
+ }
+
public static void main(String[] args) throws RrdException, IOException {
! String file = "c:/test.rrd";
! RrdToolkit tool = RrdToolkit.getInstance();
! DsDef dsDef1 = new DsDef("XXX", "GAUGE", 666, -1, Double.NaN);
! DsDef dsDef2 = new DsDef("YYY", "GAUGE", 777, +1, Double.NaN);
! tool.addDatasource(file, dsDef1, true);
! tool.addDatasource(file, dsDef2, false);
! tool.removeDatasource(file, "ftpUsers", false);
! tool.removeDatasource(file, "XXX", false);
! ArcDef arcDef1 = new ArcDef("LAST", 0.22222, 13, 567);
! tool.addArchive(file, arcDef1, false);
! tool.removeArchive(file, "MAX", 6, false);
}
}
Index: Util.java
===================================================================
RCS file: /cvsroot/jrobin/src/org/jrobin/core/Util.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** Util.java 27 Nov 2003 14:37:20 -0000 1.5
--- Util.java 28 Nov 2003 13:24:46 -0000 1.6
***************
*** 205,208 ****
--- 205,233 ----
}
+ static int getMatchingDatasourceIndex(RrdDb rrd1, int dsIndex, RrdDb rrd2)
+ throws IOException {
+ String dsName = rrd1.getDatasource(dsIndex).getDsName();
+ try {
+ return rrd2.getDsIndex(dsName);
+ } catch (RrdException e) {
+ return -1;
+ }
+ }
+
+ static int getMatchingArchiveIndex(RrdDb rrd1, int arcIndex, RrdDb rrd2)
+ throws IOException {
+ Archive archive = rrd1.getArchive(arcIndex);
+ String consolFun = archive.getConsolFun();
+ int steps = archive.getSteps();
+ try {
+ return rrd2.getArcIndex(consolFun, steps);
+ } catch (RrdException e) {
+ return -1;
+ }
+ }
+
+ static String getTmpFilename() throws IOException {
+ return File.createTempFile("JROBIN_", ".tmp").getCanonicalPath();
+ }
}
|
|
From: <sa...@us...> - 2003-11-27 15:53:37
|
Update of /cvsroot/jrobin/src/org/jrobin/core
In directory sc8-pr-cvs1:/tmp/cvs-serv24316/org/jrobin/core
Modified Files:
Archive.java RrdDb.java RrdToolkit.java
Log Message:
Added RRDToolkit class to perform some less frequent but very useful operations on a RRD file as whole. So far so good: you can now add and remove datasource definitions to a RRD still preserving already existing data in it.
Index: Archive.java
===================================================================
RCS file: /cvsroot/jrobin/src/org/jrobin/core/Archive.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** Archive.java 27 Nov 2003 14:15:11 -0000 1.5
--- Archive.java 27 Nov 2003 15:53:33 -0000 1.6
***************
*** 408,417 ****
throw new RrdException("Incompatible number of rows");
}
! int count = Math.min(
! parentDb.getHeader().getDsCount(),
! arc.parentDb.getHeader().getDsCount());
for(int i = 0; i < count; i++) {
! states[i].copyStateTo(arc.states[i]);
! robins[i].copyStateTo(arc.robins[i]);
}
}
--- 408,419 ----
throw new RrdException("Incompatible number of rows");
}
! int count = parentDb.getHeader().getDsCount();
for(int i = 0; i < count; i++) {
! String dsName = parentDb.getDatasource(i).getDsName();
! if(arc.getParentDb().getDatasource(dsName) != null) {
! int j = arc.getParentDb().getDsIndex(dsName);
! states[i].copyStateTo(arc.states[j]);
! robins[i].copyStateTo(arc.robins[j]);
! }
}
}
Index: RrdDb.java
===================================================================
RCS file: /cvsroot/jrobin/src/org/jrobin/core/RrdDb.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** RrdDb.java 27 Nov 2003 14:15:11 -0000 1.5
--- RrdDb.java 27 Nov 2003 15:53:33 -0000 1.6
***************
*** 662,672 ****
RrdDb rrd = (RrdDb) other;
header.copyStateTo(rrd.header);
! int dsCount = Math.min(header.getDsCount(), rrd.header.getDsCount());
! for(int i = 0; i < dsCount; i++) {
! datasources[i].copyStateTo(rrd.datasources[i]);
}
! int arcCount = Math.min(header.getArcCount(), rrd.header.getArcCount());
! for(int i = 0; i < arcCount; i++) {
! archives[i].copyStateTo(rrd.archives[i]);
}
}
--- 662,729 ----
RrdDb rrd = (RrdDb) other;
header.copyStateTo(rrd.header);
! for(int i = 0; i < datasources.length; i++) {
! Datasource matchingDatasource = rrd.getDatasource(datasources[i].getDsName());
! if(matchingDatasource != null) {
! datasources[i].copyStateTo(matchingDatasource);
! }
}
! for(int i = 0; i < archives.length; i++) {
! Archive matchingArchive = rrd.getArchive(
! archives[i].getConsolFun(), archives[i].getSteps());
! if(matchingArchive != null) {
! archives[i].copyStateTo(matchingArchive);
! }
! }
! }
!
! /**
! * Returns Datasource object corresponding to the given datasource name.
! * @param dsName Datasource name
! * @return Datasource object corresponding to the give datasource name or null
! * if not found.
! * @throws IOException Thrown in case of I/O error
! */
! public Datasource getDatasource(String dsName) throws IOException {
! try {
! return getDatasource(getDsIndex(dsName));
! }
! catch (RrdException e) {
! return null;
! }
! }
!
! /**
! * Returns index of Archive object with the given consolidation function and the number
! * of steps. Exception is thrown if such archive could not be found.
! * @param consolFun Consolidation function
! * @param steps Number of archive steps
! * @return Requested Archive object
! * @throws IOException Thrown in case of I/O error
! * @throws RrdException Thrown if no such archive could be found
! */
! public int getArcIndex(String consolFun, int steps) throws RrdException, IOException {
! for(int i = 0; i < archives.length; i++) {
! if(archives[i].getConsolFun().equals(consolFun) &&
! archives[i].getSteps() == steps) {
! return i;
! }
! }
! throw new RrdException("Could not find archive " + consolFun + "/" + steps);
! }
!
! /**
! * Returns Archive object with the given consolidation function and the number
! * of steps.
! * @param consolFun Consolidation function
! * @param steps Number of archive steps
! * @return Requested Archive object or null if no such archive could be found
! * @throws IOException Thrown in case of I/O error
! */
! public Archive getArchive(String consolFun, int steps) throws IOException {
! try {
! return getArchive(getArcIndex(consolFun, steps));
! }
! catch (RrdException e) {
! return null;
}
}
Index: RrdToolkit.java
===================================================================
RCS file: /cvsroot/jrobin/src/org/jrobin/core/RrdToolkit.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** RrdToolkit.java 27 Nov 2003 14:37:20 -0000 1.2
--- RrdToolkit.java 27 Nov 2003 15:53:33 -0000 1.3
***************
*** 66,71 ****
*/
- /*
- Still buggy! Will fix later
public void removeDatasource(String sourcePath, String destPath, String dsName)
throws IOException, RrdException {
--- 66,69 ----
***************
*** 82,86 ****
rrdDest.close();
}
- */
/**
--- 80,83 ----
***************
*** 112,117 ****
DsDef dsDef = new DsDef("XXX", "GAUGE", 666, -1, Double.NaN);
RrdToolkit.getInstance().addDatasource("demo.rrd", "demo2.rrd", dsDef);
! ArcDef arcDef = new ArcDef("LAST", 0.666, 77, 888);
! RrdToolkit.getInstance().addArchive("demo2.rrd", "demo3.rrd", arcDef);
}
}
--- 109,113 ----
DsDef dsDef = new DsDef("XXX", "GAUGE", 666, -1, Double.NaN);
RrdToolkit.getInstance().addDatasource("demo.rrd", "demo2.rrd", dsDef);
! RrdToolkit.getInstance().removeDatasource("demo2.rrd", "demo3.rrd", "sun");
}
}
|
|
From: <sa...@us...> - 2003-11-27 14:37:25
|
Update of /cvsroot/jrobin/src/org/jrobin/core
In directory sc8-pr-cvs1:/tmp/cvs-serv10071/org/jrobin/core
Modified Files:
RrdToolkit.java Util.java
Log Message:
Added RRDToolkit class to perform some less frequent but very useful operations on a RRD file as whole. So far so good: you can now add and remove datasource definitions to a RRD still preserving already existing data in it.
Index: RrdToolkit.java
===================================================================
RCS file: /cvsroot/jrobin/src/org/jrobin/core/RrdToolkit.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** RrdToolkit.java 27 Nov 2003 14:15:11 -0000 1.1
--- RrdToolkit.java 27 Nov 2003 14:37:20 -0000 1.2
***************
*** 35,39 ****
* the original RRD file is copied to the new one.
* @param sourcePath path to a RRD file to import data from (will not be modified)
! * @param destPath path to new RRD file (will be created)
* @param newDatasource Datasource definition to be added to the new RRD file
* @throws IOException Thrown in case of I/O error
--- 35,39 ----
* the original RRD file is copied to the new one.
* @param sourcePath path to a RRD file to import data from (will not be modified)
! * @param destPath path to a new RRD file (will be created)
* @param newDatasource Datasource definition to be added to the new RRD file
* @throws IOException Thrown in case of I/O error
***************
*** 42,45 ****
--- 42,48 ----
public void addDatasource(String sourcePath, String destPath, DsDef newDatasource)
throws IOException, RrdException {
+ if(Util.sameFilePath(sourcePath, destPath)) {
+ throw new RrdException("Source and destination paths are the same");
+ }
RrdDb rrdSource = new RrdDb(sourcePath);
RrdDef rrdDef = rrdSource.getRrdDef();
***************
*** 57,67 ****
* the original RRD file is copied to the new one.
* @param sourcePath path to a RRD file to import data from (will not be modified)
! * @param destPath path to new RRD file (will be created)
* @param dsName Name of the Datasource to be removed from the new RRD file
* @throws IOException Thrown in case of I/O error
* @throws RrdException Thrown in case of JRobin specific error
*/
public void removeDatasource(String sourcePath, String destPath, String dsName)
throws IOException, RrdException {
RrdDb rrdSource = new RrdDb(sourcePath);
RrdDef rrdDef = rrdSource.getRrdDef();
--- 60,76 ----
* the original RRD file is copied to the new one.
* @param sourcePath path to a RRD file to import data from (will not be modified)
! * @param destPath path to a new RRD file (will be created)
* @param dsName Name of the Datasource to be removed from the new RRD file
* @throws IOException Thrown in case of I/O error
* @throws RrdException Thrown in case of JRobin specific error
*/
+
+ /*
+ Still buggy! Will fix later
public void removeDatasource(String sourcePath, String destPath, String dsName)
throws IOException, RrdException {
+ if(Util.sameFilePath(sourcePath, destPath)) {
+ throw new RrdException("Source and destination paths are the same");
+ }
RrdDb rrdSource = new RrdDb(sourcePath);
RrdDef rrdDef = rrdSource.getRrdDef();
***************
*** 73,81 ****
rrdDest.close();
}
public static void main(String[] args) throws RrdException, IOException {
DsDef dsDef = new DsDef("XXX", "GAUGE", 666, -1, Double.NaN);
RrdToolkit.getInstance().addDatasource("demo.rrd", "demo2.rrd", dsDef);
! RrdToolkit.getInstance().removeDatasource("demo2.rrd", "demo3.rrd", "XXX");
}
}
--- 82,117 ----
rrdDest.close();
}
+ */
+
+ /**
+ * Creates a new RRD file with one more archive in it. RRD file is created based on the
+ * existing one (the original RRD file is not modified at all). All data from
+ * the original RRD file is copied to the new one.
+ * @param sourcePath path to a RRD file to import data from (will not be modified)
+ * @param destPath path to a new RRD file (will be created)
+ * @param newArchive Archive definition to be added to the new RRD file
+ * @throws IOException Thrown in case of I/O error
+ * @throws RrdException Thrown in case of JRobin specific error
+ */
+ public void addArchive(String sourcePath, String destPath, ArcDef newArchive)
+ throws IOException, RrdException {
+ if(Util.sameFilePath(sourcePath, destPath)) {
+ throw new RrdException("Source and destination paths are the same");
+ }
+ RrdDb rrdSource = new RrdDb(sourcePath);
+ RrdDef rrdDef = rrdSource.getRrdDef();
+ rrdDef.setPath(destPath);
+ rrdDef.addArchive(newArchive);
+ RrdDb rrdDest = new RrdDb(rrdDef);
+ rrdSource.copyStateTo(rrdDest);
+ rrdSource.close();
+ rrdDest.close();
+ }
public static void main(String[] args) throws RrdException, IOException {
DsDef dsDef = new DsDef("XXX", "GAUGE", 666, -1, Double.NaN);
RrdToolkit.getInstance().addDatasource("demo.rrd", "demo2.rrd", dsDef);
! ArcDef arcDef = new ArcDef("LAST", 0.666, 77, 888);
! RrdToolkit.getInstance().addArchive("demo2.rrd", "demo3.rrd", arcDef);
}
}
Index: Util.java
===================================================================
RCS file: /cvsroot/jrobin/src/org/jrobin/core/Util.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** Util.java 17 Nov 2003 08:09:42 -0000 1.4
--- Util.java 27 Nov 2003 14:37:20 -0000 1.5
***************
*** 32,35 ****
--- 32,36 ----
import java.util.GregorianCalendar;
import java.io.File;
+ import java.io.IOException;
/**
***************
*** 196,199 ****
--- 197,206 ----
public static String getJRobinDemoDirectory() {
return (homeDirFile.exists() || homeDirFile.mkdirs())? homeDirPath: null;
+ }
+
+ static boolean sameFilePath(String path1, String path2) throws IOException {
+ File file1 = new File(path1);
+ File file2 = new File(path2);
+ return file1.getCanonicalPath().equals(file2.getCanonicalPath());
}
|
|
From: <sa...@us...> - 2003-11-27 14:15:19
|
Update of /cvsroot/jrobin/src/org/jrobin/core
In directory sc8-pr-cvs1:/tmp/cvs-serv6628/org/jrobin/core
Modified Files:
ArcState.java Archive.java Datasource.java Header.java
Robin.java RrdDb.java RrdDef.java RrdDoubleArray.java
RrdPrimitive.java RrdUpdater.java
Added Files:
RrdToolkit.java
Log Message:
Added RRDToolkit class to perform some less frequent but very useful operations on a RRD file as whole. So far so good: you can now add and remove datasource definitions to a RRD still preserving already existing data in it.
--- NEW FILE: RrdToolkit.java ---
/**
* Created by IntelliJ IDEA.
* User: Administrator
* Date: Nov 27, 2003
* Time: 12:21:37 PM
* To change this template use Options | File Templates.
*/
package org.jrobin.core;
import java.io.IOException;
/**
* Class used to perform less important but complex operations on RRD files (like adding
* a new datasource to a RRD file).
*/
public class RrdToolkit {
private static RrdToolkit ourInstance;
/**
* Returns an instance of RrdToolkit.
* @return Toolkint instance to work with
*/
public synchronized static RrdToolkit getInstance() {
if (ourInstance == null) {
ourInstance = new RrdToolkit();
}
return ourInstance;
}
private RrdToolkit() {
}
/**
* Creates a new RRD file with one more datasource in it. RRD file is created based on the
* existing one (the original RRD file is not modified at all). All data from
* the original RRD file is copied to the new one.
* @param sourcePath path to a RRD file to import data from (will not be modified)
* @param destPath path to new RRD file (will be created)
* @param newDatasource Datasource definition to be added to the new RRD file
* @throws IOException Thrown in case of I/O error
* @throws RrdException Thrown in case of JRobin specific error
*/
public void addDatasource(String sourcePath, String destPath, DsDef newDatasource)
throws IOException, RrdException {
RrdDb rrdSource = new RrdDb(sourcePath);
RrdDef rrdDef = rrdSource.getRrdDef();
rrdDef.setPath(destPath);
rrdDef.addDatasource(newDatasource);
RrdDb rrdDest = new RrdDb(rrdDef);
rrdSource.copyStateTo(rrdDest);
rrdSource.close();
rrdDest.close();
}
/**
* Creates a new RRD file with one datasource removed. RRD file is created based on the
* existing one (the original RRD file is not modified at all). All remaining data from
* the original RRD file is copied to the new one.
* @param sourcePath path to a RRD file to import data from (will not be modified)
* @param destPath path to new RRD file (will be created)
* @param dsName Name of the Datasource to be removed from the new RRD file
* @throws IOException Thrown in case of I/O error
* @throws RrdException Thrown in case of JRobin specific error
*/
public void removeDatasource(String sourcePath, String destPath, String dsName)
throws IOException, RrdException {
RrdDb rrdSource = new RrdDb(sourcePath);
RrdDef rrdDef = rrdSource.getRrdDef();
rrdDef.setPath(destPath);
rrdDef.removeDatasource(dsName);
RrdDb rrdDest = new RrdDb(rrdDef);
rrdSource.copyStateTo(rrdDest);
rrdSource.close();
rrdDest.close();
}
public static void main(String[] args) throws RrdException, IOException {
DsDef dsDef = new DsDef("XXX", "GAUGE", 666, -1, Double.NaN);
RrdToolkit.getInstance().addDatasource("demo.rrd", "demo2.rrd", dsDef);
RrdToolkit.getInstance().removeDatasource("demo2.rrd", "demo3.rrd", "XXX");
}
}
Index: ArcState.java
===================================================================
RCS file: /cvsroot/jrobin/src/org/jrobin/core/ArcState.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** ArcState.java 27 Nov 2003 10:54:07 -0000 1.3
--- ArcState.java 27 Nov 2003 14:15:11 -0000 1.4
***************
*** 41,45 ****
private RrdLong nanSteps;
- // create for the first time
ArcState(Archive parentArc) throws IOException {
this.parentArc = parentArc;
--- 41,44 ----
***************
*** 52,57 ****
long nan = (Util.normalize(lastUpdateTime, step) -
Util.normalize(lastUpdateTime, arcStep)) / step;
- nanSteps = new RrdLong(nan, this);
accumValue = new RrdDouble(Double.NaN, this);
}
else {
--- 51,56 ----
long nan = (Util.normalize(lastUpdateTime, step) -
Util.normalize(lastUpdateTime, arcStep)) / step;
accumValue = new RrdDouble(Double.NaN, this);
+ nanSteps = new RrdLong(nan, this);
}
else {
***************
*** 117,119 ****
--- 116,133 ----
}
+ /**
+ * Copies object's internal state to another ArcState object.
+ * @param other New ArcState object to copy state to
+ * @throws IOException Thrown in case of I/O error
+ * @throws RrdException Thrown if supplied argument is not an ArcState object
+ */
+ public void copyStateTo(RrdUpdater other) throws IOException, RrdException {
+ if(!(other instanceof ArcState)) {
+ throw new RrdException(
+ "Cannot copy ArcState object to " + other.getClass().getName());
+ }
+ ArcState arcState = (ArcState) other;
+ arcState.accumValue.set(accumValue.get());
+ arcState.nanSteps.set(nanSteps.get());
+ }
}
Index: Archive.java
===================================================================
RCS file: /cvsroot/jrobin/src/org/jrobin/core/Archive.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** Archive.java 27 Nov 2003 10:54:07 -0000 1.4
--- Archive.java 27 Nov 2003 14:15:11 -0000 1.5
***************
*** 45,48 ****
--- 45,49 ----
private RrdDouble xff;
private RrdInt steps, rows;
+ // state
private Robin[] robins;
private ArcState[] states;
***************
*** 87,92 ****
rows = new RrdInt(reader.getRows(arcIndex), this);
int dsCount = reader.getDsCount();
- robins = new Robin[dsCount];
states = new ArcState[dsCount];
for(int dsIndex = 0; dsIndex < dsCount; dsIndex++) {
// restore state
--- 88,93 ----
rows = new RrdInt(reader.getRows(arcIndex), this);
int dsCount = reader.getDsCount();
states = new ArcState[dsCount];
+ robins = new Robin[dsCount];
for(int dsIndex = 0; dsIndex < dsCount; dsIndex++) {
// restore state
***************
*** 386,388 ****
--- 387,418 ----
}
+ /**
+ * Copies object's internal state to another Archive object.
+ * @param other New Archive object to copy state to
+ * @throws IOException Thrown in case of I/O error
+ * @throws RrdException Thrown if supplied argument is not an Archive object
+ */
+ public void copyStateTo(RrdUpdater other) throws IOException, RrdException {
+ if(!(other instanceof Archive)) {
+ throw new RrdException(
+ "Cannot copy Archive object to " + other.getClass().getName());
+ }
+ Archive arc = (Archive) other;
+ if(!arc.consolFun.get().equals(consolFun.get())) {
+ throw new RrdException("Incompatible consolidation functions");
+ }
+ if(arc.steps.get() != steps.get()) {
+ throw new RrdException("Incompatible number of steps");
+ }
+ if(arc.rows.get() != rows.get()) {
+ throw new RrdException("Incompatible number of rows");
+ }
+ int count = Math.min(
+ parentDb.getHeader().getDsCount(),
+ arc.parentDb.getHeader().getDsCount());
+ for(int i = 0; i < count; i++) {
+ states[i].copyStateTo(arc.states[i]);
+ robins[i].copyStateTo(arc.robins[i]);
+ }
+ }
}
Index: Datasource.java
===================================================================
RCS file: /cvsroot/jrobin/src/org/jrobin/core/Datasource.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** Datasource.java 10 Nov 2003 08:52:27 -0000 1.2
--- Datasource.java 27 Nov 2003 14:15:11 -0000 1.3
***************
*** 267,271 ****
}
! private double calculateTotal(long startTime, long boundaryTime) throws IOException {
double totalValue = Double.NaN;
long validSeconds = boundaryTime - startTime - nanSeconds.get();
--- 267,271 ----
}
! private double calculateTotal(long startTime, long boundaryTime) {
double totalValue = Double.NaN;
long validSeconds = boundaryTime - startTime - nanSeconds.get();
***************
*** 288,291 ****
--- 288,314 ----
writer.writeTag("unknown_sec", nanSeconds.get());
writer.closeTag(); // ds
+ }
+
+ /**
+ * Copies object's internal state to another Datasource object.
+ * @param other New Datasource object to copy state to
+ * @throws IOException Thrown in case of I/O error
+ * @throws RrdException Thrown if supplied argument is not a Datasource object
+ */
+ public void copyStateTo(RrdUpdater other) throws IOException, RrdException {
+ if(!(other instanceof Datasource)) {
+ throw new RrdException(
+ "Cannot copy Datasource object to " + other.getClass().getName());
+ }
+ Datasource datasource = (Datasource) other;
+ if(!datasource.dsName.get().equals(dsName.get())) {
+ throw new RrdException("Incomaptible datasource names");
+ }
+ if(!datasource.dsType.get().equals(dsType.get())) {
+ throw new RrdException("Incomaptible datasource types");
+ }
+ datasource.lastValue.set(lastValue.get());
+ datasource.nanSeconds.set(nanSeconds.get());
+ datasource.accumValue.set(accumValue.get());
}
Index: Header.java
===================================================================
RCS file: /cvsroot/jrobin/src/org/jrobin/core/Header.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** Header.java 10 Nov 2003 08:52:27 -0000 1.2
--- Header.java 27 Nov 2003 14:15:11 -0000 1.3
***************
*** 165,167 ****
--- 165,181 ----
}
+ /**
+ * Copies object's internal state to another Header object.
+ * @param other New Header object to copy state to
+ * @throws IOException Thrown in case of I/O error
+ * @throws RrdException Thrown if supplied argument is not a Header object
+ */
+ public void copyStateTo(RrdUpdater other) throws IOException, RrdException {
+ if(!(other instanceof Header)) {
+ throw new RrdException(
+ "Cannot copy Header object to " + other.getClass().getName());
+ }
+ Header header = (Header) other;
+ header.lastUpdateTime.set(lastUpdateTime.get());
+ }
}
Index: Robin.java
===================================================================
RCS file: /cvsroot/jrobin/src/org/jrobin/core/Robin.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** Robin.java 27 Nov 2003 10:22:58 -0000 1.4
--- Robin.java 27 Nov 2003 14:15:11 -0000 1.5
***************
*** 125,127 ****
--- 125,148 ----
}
+ /**
+ * Copies object's internal state to another Robin object.
+ * @param other New Robin object to copy state to
+ * @throws IOException Thrown in case of I/O error
+ * @throws RrdException Thrown if supplied argument is not a Robin object or
+ * is a Robin object with different number of rows
+ */
+ public void copyStateTo(RrdUpdater other) throws IOException, RrdException {
+ if(!(other instanceof Robin)) {
+ throw new RrdException(
+ "Cannot copy Archive object to " + other.getClass().getName());
+ }
+ Robin robin = (Robin) other;
+ if(rows != robin.rows) {
+ throw new RrdException("Incompatible number of rows: " + rows +
+ " != " + robin.rows);
+ }
+ robin.pointer.set(pointer.get());
+ // BULK operation, will speed things up
+ robin.values.writeBytes(values.readBytes());
+ }
}
Index: RrdDb.java
===================================================================
RCS file: /cvsroot/jrobin/src/org/jrobin/core/RrdDb.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** RrdDb.java 27 Nov 2003 10:22:58 -0000 1.4
--- RrdDb.java 27 Nov 2003 14:15:11 -0000 1.5
***************
*** 649,664 ****
}
! public static void main(String[] args) throws RrdException, IOException {
! RrdDb rrd = new RrdDb("demo.rrd");
! long t1 = Util.getTimestamp(2003, 4, 1);
! long t2 = Util.getTimestamp(2003, 4, 2);
! FetchData data = rrd.createFetchRequest("AVERAGE", t1, t2).fetchData();
! data.dump();
! System.out.println("MAX : " + data.getAggregate("sun", "MAX"));
! System.out.println("MAX2: " + data.getAggregate("sun", "MAX", "value,2,*"));
! System.out.println("MIN : " + data.getAggregate("sun", "MIN"));
! System.out.println("MIN2: " + data.getAggregate("sun", "MIN", "value,2,*"));
! System.out.println("AVG : " + data.getAggregate("sun", "AVERAGE"));
! System.out.println("AVG2: " + data.getAggregate("sun", "AVERAGE", "value,2,*"));
}
}
--- 649,673 ----
}
! /**
! * Copies object's internal state to another RrdDb object.
! * @param other New RrdDb object to copy state to
! * @throws IOException Thrown in case of I/O error
! * @throws RrdException Thrown if supplied argument is not a compatible RrdDb object
! */
! public void copyStateTo(RrdUpdater other) throws IOException, RrdException {
! if(!(other instanceof RrdDb)) {
! throw new RrdException(
! "Cannot copy RrdDb object to " + other.getClass().getName());
! }
! RrdDb rrd = (RrdDb) other;
! header.copyStateTo(rrd.header);
! int dsCount = Math.min(header.getDsCount(), rrd.header.getDsCount());
! for(int i = 0; i < dsCount; i++) {
! datasources[i].copyStateTo(rrd.datasources[i]);
! }
! int arcCount = Math.min(header.getArcCount(), rrd.header.getArcCount());
! for(int i = 0; i < arcCount; i++) {
! archives[i].copyStateTo(rrd.archives[i]);
! }
}
}
Index: RrdDef.java
===================================================================
RCS file: /cvsroot/jrobin/src/org/jrobin/core/RrdDef.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** RrdDef.java 10 Nov 2003 08:52:27 -0000 1.3
--- RrdDef.java 27 Nov 2003 14:15:11 -0000 1.4
***************
*** 308,310 ****
--- 308,321 ----
return dump();
}
+
+ void removeDatasource(String dsName) throws RrdException {
+ for(int i = 0; i < dsDefs.size(); i++) {
+ DsDef dsDef = (DsDef) dsDefs.get(i);
+ if(dsDef.getDsName().equals(dsName)) {
+ dsDefs.remove(i);
+ return;
+ }
+ }
+ throw new RrdException("Could not find datasource named '" + dsName + "'");
+ }
}
Index: RrdDoubleArray.java
===================================================================
RCS file: /cvsroot/jrobin/src/org/jrobin/core/RrdDoubleArray.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** RrdDoubleArray.java 27 Nov 2003 10:22:58 -0000 1.1
--- RrdDoubleArray.java 27 Nov 2003 14:15:11 -0000 1.2
***************
*** 45,48 ****
--- 45,51 ----
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);
***************
*** 51,54 ****
--- 54,60 ----
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);
Index: RrdPrimitive.java
===================================================================
RCS file: /cvsroot/jrobin/src/org/jrobin/core/RrdPrimitive.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** RrdPrimitive.java 27 Nov 2003 11:21:22 -0000 1.2
--- RrdPrimitive.java 27 Nov 2003 14:15:11 -0000 1.3
***************
*** 63,67 ****
}
! byte[] getBytes() throws IOException {
byte[] b = new byte[byteCount];
RrdFile rrdFile = getRrdFile();
--- 63,67 ----
}
! byte[] readBytes() throws IOException {
byte[] b = new byte[byteCount];
RrdFile rrdFile = getRrdFile();
Index: RrdUpdater.java
===================================================================
RCS file: /cvsroot/jrobin/src/org/jrobin/core/RrdUpdater.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** RrdUpdater.java 10 Nov 2003 08:52:27 -0000 1.2
--- RrdUpdater.java 27 Nov 2003 14:15:11 -0000 1.3
***************
*** 26,29 ****
--- 26,31 ----
package org.jrobin.core;
+ import java.io.IOException;
+
/**
* Interface that has to be implemented for all classes which read from or write to
***************
*** 32,36 ****
* @author <a href="mailto:sa...@jr...">Sasa Markovic</a>
*/
! public interface RrdUpdater {
/**
* Returns associated RrdFile object.
--- 34,38 ----
* @author <a href="mailto:sa...@jr...">Sasa Markovic</a>
*/
! interface RrdUpdater {
/**
* Returns associated RrdFile object.
***************
*** 38,40 ****
--- 40,50 ----
*/
public RrdFile getRrdFile();
+
+ /**
+ * Copies the internal object state to another object of the same type.
+ * @param updater Object to copy the internal state to
+ * @throws IOException Thrown in case of I/O error
+ * @throws RrdException Thrown if supplied argument is not an object of a compatible class
+ */
+ public void copyStateTo(RrdUpdater updater) throws IOException, RrdException;
}
|
|
From: <sa...@us...> - 2003-11-27 11:21:25
|
Update of /cvsroot/jrobin/src/org/jrobin/core
In directory sc8-pr-cvs1:/tmp/cvs-serv14259/org/jrobin/core
Modified Files:
RrdPrimitive.java
Log Message:
Related classes (RrdInt, RrdLong, etc) are now properly rooted. RrdPrimtive class introduced as a base class for all classes mapped to a RRD file. Code should run slightly faster.
Index: RrdPrimitive.java
===================================================================
RCS file: /cvsroot/jrobin/src/org/jrobin/core/RrdPrimitive.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** RrdPrimitive.java 27 Nov 2003 10:22:58 -0000 1.1
--- RrdPrimitive.java 27 Nov 2003 11:21:22 -0000 1.2
***************
*** 65,69 ****
byte[] getBytes() throws IOException {
byte[] b = new byte[byteCount];
! int bytesRead = parent.getRrdFile().read(b);
if(bytesRead != byteCount) {
throw new IOException("Could not read enough bytes (" + byteCount +
--- 65,71 ----
byte[] getBytes() throws IOException {
byte[] b = new byte[byteCount];
! RrdFile rrdFile = getRrdFile();
! rrdFile.seek(pointer);
! int bytesRead = rrdFile.read(b);
if(bytesRead != byteCount) {
throw new IOException("Could not read enough bytes (" + byteCount +
***************
*** 72,75 ****
return b;
}
!
}
--- 74,87 ----
return b;
}
!
! void writeBytes(byte[] b) throws IOException {
! if(b.length != byteCount) {
! throw new IOException("Invalid number of bytes supplied (" + b.length +
! "), exactly " + byteCount + " needed");
! }
! RrdFile rrdFile = getRrdFile();
! rrdFile.seek(pointer);
! rrdFile.write(b);
! }
!
}
|
|
From: <sa...@us...> - 2003-11-27 10:54:11
|
Update of /cvsroot/jrobin/src/org/jrobin/core
In directory sc8-pr-cvs1:/tmp/cvs-serv10180/org/jrobin/core
Modified Files:
ArcState.java Archive.java
Log Message:
Related classes (RrdInt, RrdLong, etc) are now properly rooted. RrdPrimtive class introduced as a base class for all classes mapped to a RRD file. Code should run slightly faster.
Index: ArcState.java
===================================================================
RCS file: /cvsroot/jrobin/src/org/jrobin/core/ArcState.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** ArcState.java 10 Nov 2003 08:52:27 -0000 1.2
--- ArcState.java 27 Nov 2003 10:54:07 -0000 1.3
***************
*** 42,50 ****
// create for the first time
! ArcState(Archive parentArc, boolean newState) throws IOException {
this.parentArc = parentArc;
! accumValue = new RrdDouble(this);
! nanSteps = new RrdLong(this);
! if(newState) {
// should initialize
Header header = parentArc.getParentDb().getHeader();
--- 42,48 ----
// create for the first time
! ArcState(Archive parentArc) throws IOException {
this.parentArc = parentArc;
! if(getRrdFile().getMode() == RrdFile.MODE_CREATE) {
// should initialize
Header header = parentArc.getParentDb().getHeader();
***************
*** 54,59 ****
long nan = (Util.normalize(lastUpdateTime, step) -
Util.normalize(lastUpdateTime, arcStep)) / step;
! nanSteps.set(nan);
! accumValue.set(Double.NaN);
}
}
--- 52,61 ----
long nan = (Util.normalize(lastUpdateTime, step) -
Util.normalize(lastUpdateTime, arcStep)) / step;
! nanSteps = new RrdLong(nan, this);
! accumValue = new RrdDouble(Double.NaN, this);
! }
! else {
! accumValue = new RrdDouble(this);
! nanSteps = new RrdLong(this);
}
}
Index: Archive.java
===================================================================
RCS file: /cvsroot/jrobin/src/org/jrobin/core/Archive.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** Archive.java 27 Nov 2003 10:22:58 -0000 1.3
--- Archive.java 27 Nov 2003 10:54:07 -0000 1.4
***************
*** 59,63 ****
states = new ArcState[n];
for(int i = 0; i < n; i++) {
! states[i] = new ArcState(this, true);
robins[i] = new Robin(this, rows.get());
}
--- 59,63 ----
states = new ArcState[n];
for(int i = 0; i < n; i++) {
! states[i] = new ArcState(this);
robins[i] = new Robin(this, rows.get());
}
***************
*** 75,79 ****
robins = new Robin[n];
for(int i = 0; i < n; i++) {
! states[i] = new ArcState(this, false);
robins[i] = new Robin(this, rows.get());
}
--- 75,79 ----
robins = new Robin[n];
for(int i = 0; i < n; i++) {
! states[i] = new ArcState(this);
robins[i] = new Robin(this, rows.get());
}
***************
*** 91,95 ****
for(int dsIndex = 0; dsIndex < dsCount; dsIndex++) {
// restore state
! states[dsIndex] = new ArcState(this, true);
states[dsIndex].setAccumValue(reader.getStateAccumValue(arcIndex, dsIndex));
states[dsIndex].setNanSteps(reader.getStateNanSteps(arcIndex, dsIndex));
--- 91,95 ----
for(int dsIndex = 0; dsIndex < dsCount; dsIndex++) {
// restore state
! states[dsIndex] = new ArcState(this);
states[dsIndex].setAccumValue(reader.getStateAccumValue(arcIndex, dsIndex));
states[dsIndex].setNanSteps(reader.getStateNanSteps(arcIndex, dsIndex));
|
|
From: <sa...@us...> - 2003-11-27 10:23:01
|
Update of /cvsroot/jrobin/src
In directory sc8-pr-cvs1:/tmp/cvs-serv5669
Modified Files:
Demo.java
Log Message:
Related classes (RrdInt, RrdLong, etc) are now properly rooted. RrdPrimtive class introduced as a base class for all classes mapped to a RRD file. Code should run slightly faster.
Index: Demo.java
===================================================================
RCS file: /cvsroot/jrobin/src/Demo.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -C2 -d -r1.7 -r1.8
*** Demo.java 17 Nov 2003 08:09:41 -0000 1.7
--- Demo.java 27 Nov 2003 10:22:58 -0000 1.8
***************
*** 33,42 ****
--- 33,48 ----
import java.io.IOException;
import java.io.PrintWriter;
+ import java.util.Random;
class Demo {
+ static final long SEED = 1909752002L;
+
+ static final Random RANDOM = new Random(SEED);
static final String HOME = Util.getJRobinDemoDirectory();
static final String FILE = "demo";
+
static final long START = Util.getTimestamp(2003, 4, 1);
static final long END = Util.getTimestamp(2003, 5, 1);
+
static final int MAX_STEP = 300;
***************
*** 76,80 ****
pw.println(rrdDef.dump());
RrdDb rrdDb = new RrdDb(rrdDef);
! println("== RRD file created.");
// update database
--- 82,87 ----
pw.println(rrdDef.dump());
RrdDb rrdDb = new RrdDb(rrdDef);
! rrdDb.close();
! println("== RRD file created and closed.");
// update database
***************
*** 84,87 ****
--- 91,95 ----
MAX_STEP + " seconds (* denotes 1000 updates)");
long t = start; int n = 0;
+ rrdDb = new RrdDb(rrdPath);
Sample sample = rrdDb.createSample();
while(t <= end + 86400L) {
***************
*** 92,96 ****
sample.update();
! t += Math.random() * MAX_STEP + 1;
if(((++n) % 1000) == 0) {
System.out.print("*");
--- 100,104 ----
sample.update();
! t += RANDOM.nextDouble() * MAX_STEP + 1;
if(((++n) % 1000) == 0) {
System.out.print("*");
***************
*** 180,185 ****
long getValue() {
double oldValue = value;
! double increment = Math.random() * step;
! if(Math.random() > 0.5) {
increment *= -1;
}
--- 188,193 ----
long getValue() {
double oldValue = value;
! double increment = Demo.RANDOM.nextDouble() * step;
! if(Demo.RANDOM.nextDouble() > 0.5) {
increment *= -1;
}
|
|
From: <sa...@us...> - 2003-11-27 10:23:01
|
Update of /cvsroot/jrobin/src/org/jrobin/core In directory sc8-pr-cvs1:/tmp/cvs-serv5669/org/jrobin/core Modified Files: Archive.java Robin.java RrdDb.java RrdDouble.java RrdFile.java RrdInt.java RrdLong.java RrdString.java Added Files: RrdDoubleArray.java RrdPrimitive.java Log Message: Related classes (RrdInt, RrdLong, etc) are now properly rooted. RrdPrimtive class introduced as a base class for all classes mapped to a RRD file. Code should run slightly faster. --- NEW FILE: RrdDoubleArray.java --- /* ============================================================ * JRobin : Pure java implementation of RRDTool's functionality * ============================================================ * * Project Info: http://www.jrobin.org * Project Lead: Sasa Markovic (sa...@jr...); * * (C) Copyright 2003, by Sasa Markovic. * * Developers: Sasa Markovic (sa...@jr...) * Arne Vandamme (cob...@jr...) * * This library is free software; you can redistribute it and/or modify it under the terms * of the GNU Lesser General Public License as published by the Free Software Foundation; * either version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License along with this * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, * Boston, MA 02111-1307, USA. */ package org.jrobin.core; import java.io.IOException; class RrdDoubleArray extends RrdPrimitive { private int length; RrdDoubleArray(RrdUpdater updater, int length) throws IOException { super(updater, length * RrdDouble.SIZE); this.length = length; } RrdDoubleArray(RrdUpdater updater, int length, double initVal) throws IOException { 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 { RrdFile rrdFile = getRrdFile(); rrdFile.seek(getPointer() + index * RrdDouble.SIZE); rrdFile.writeDouble(value); } double get(int index) throws IOException { RrdFile rrdFile = getRrdFile(); rrdFile.seek(getPointer() + index * RrdDouble.SIZE); return rrdFile.readDouble(); } } --- NEW FILE: RrdPrimitive.java --- /* ============================================================ * JRobin : Pure java implementation of RRDTool's functionality * ============================================================ * * Project Info: http://www.jrobin.org * Project Lead: Sasa Markovic (sa...@jr...); * * (C) Copyright 2003, by Sasa Markovic. * * Developers: Sasa Markovic (sa...@jr...) * Arne Vandamme (cob...@jr...) * * This library is free software; you can redistribute it and/or modify it under the terms * of the GNU Lesser General Public License as published by the Free Software Foundation; * either version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License along with this * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, * Boston, MA 02111-1307, USA. */ package org.jrobin.core; import java.io.IOException; abstract class RrdPrimitive { private RrdUpdater parent; private long pointer; private int byteCount; RrdPrimitive(RrdUpdater parent, int byteCount) throws IOException { this.parent = parent; // this will set pointer and byteCount parent.getRrdFile().allocate(this, byteCount); } long getPointer() { return pointer; } void setPointer(long pointer) { this.pointer = pointer; } int getByteCount() { return byteCount; } void setByteCount(int byteCount) { this.byteCount = byteCount; } RrdUpdater getParent() { return parent; } RrdFile getRrdFile() { return parent.getRrdFile(); } byte[] getBytes() throws IOException { byte[] b = new byte[byteCount]; int bytesRead = parent.getRrdFile().read(b); if(bytesRead != byteCount) { throw new IOException("Could not read enough bytes (" + byteCount + " bytes requested, " + bytesRead + " bytes obtained"); } return b; } } Index: Archive.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/core/Archive.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** Archive.java 10 Nov 2003 08:52:27 -0000 1.2 --- Archive.java 27 Nov 2003 10:22:58 -0000 1.3 *************** *** 60,64 **** for(int i = 0; i < n; i++) { states[i] = new ArcState(this, true); ! robins[i] = new Robin(this, rows.get(), true); } } --- 60,64 ---- for(int i = 0; i < n; i++) { states[i] = new ArcState(this, true); ! robins[i] = new Robin(this, rows.get()); } } *************** *** 76,80 **** for(int i = 0; i < n; i++) { states[i] = new ArcState(this, false); ! robins[i] = new Robin(this, rows.get(), false); } } --- 76,80 ---- for(int i = 0; i < n; i++) { states[i] = new ArcState(this, false); ! robins[i] = new Robin(this, rows.get()); } } *************** *** 95,99 **** states[dsIndex].setNanSteps(reader.getStateNanSteps(arcIndex, dsIndex)); // restore robins ! robins[dsIndex] = new Robin(this, rows.get(), true); double[] values = reader.getValues(arcIndex, dsIndex); for(int j = 0; j < values.length; j++) { --- 95,99 ---- states[dsIndex].setNanSteps(reader.getStateNanSteps(arcIndex, dsIndex)); // restore robins ! robins[dsIndex] = new Robin(this, rows.get()); double[] values = reader.getValues(arcIndex, dsIndex); for(int j = 0; j < values.length; j++) { Index: Robin.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/core/Robin.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** Robin.java 13 Nov 2003 11:45:35 -0000 1.3 --- Robin.java 27 Nov 2003 10:22:58 -0000 1.4 *************** *** 43,59 **** private Archive parentArc; private RrdInt pointer; ! private RrdDouble values; private int rows; ! Robin(Archive parentArc, int rows, boolean newRobin) throws IOException { this.parentArc = parentArc; this.rows = rows; ! pointer = new RrdInt(this); ! values = new RrdDouble(this, rows); ! if(newRobin) { ! pointer.set(0); ! for(int i = 0; i < rows; i++) { ! values.set(i, Double.NaN); ! } } } --- 43,59 ---- private Archive parentArc; private RrdInt pointer; ! private RrdDoubleArray values; private int rows; ! Robin(Archive parentArc, int rows) throws IOException { this.parentArc = parentArc; this.rows = rows; ! if(getRrdFile().getMode() == RrdFile.MODE_CREATE) { ! pointer = new RrdInt(0, this); ! values = new RrdDoubleArray(this, rows, Double.NaN); ! } ! else { ! pointer = new RrdInt(this); ! values = new RrdDoubleArray(this, rows); } } Index: RrdDb.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/core/RrdDb.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** RrdDb.java 10 Nov 2003 08:52:27 -0000 1.3 --- RrdDb.java 27 Nov 2003 10:22:58 -0000 1.4 *************** *** 107,111 **** public RrdDb(RrdDef rrdDef) throws IOException, RrdException { rrdDef.validate(); ! initializeSetup(rrdDef.getPath()); // create header header = new Header(this, rrdDef); --- 107,111 ---- public RrdDb(RrdDef rrdDef) throws IOException, RrdException { rrdDef.validate(); ! initializeSetup(rrdDef.getPath(), RrdFile.MODE_CREATE); // create header header = new Header(this, rrdDef); *************** *** 123,127 **** } // finalize ! finalizeSetup(true); Util.debug(rrdDef.getRrdToolCommand()); } --- 123,127 ---- } // finalize ! finalizeSetup(); Util.debug(rrdDef.getRrdToolCommand()); } *************** *** 143,147 **** } try { ! initializeSetup(path); // restore header header = new Header(this); --- 143,147 ---- } try { ! initializeSetup(path, RrdFile.MODE_RESTORE); // restore header header = new Header(this); *************** *** 158,162 **** archives[i] = new Archive(this); } ! finalizeSetup(false); } catch(RuntimeException e) { --- 158,162 ---- archives[i] = new Archive(this); } ! finalizeSetup(); } catch(RuntimeException e) { *************** *** 188,192 **** */ public RrdDb(String rrdPath, String xmlPath) throws IOException, RrdException { ! initializeSetup(rrdPath); XmlReader reader = new XmlReader(xmlPath); // create header --- 188,192 ---- */ public RrdDb(String rrdPath, String xmlPath) throws IOException, RrdException { ! initializeSetup(rrdPath, RrdFile.MODE_CREATE); XmlReader reader = new XmlReader(xmlPath); // create header *************** *** 205,225 **** reader = null; // finalize ! finalizeSetup(true); } ! private void initializeSetup(String path) throws IOException { ! file = new RrdFile(path); ! file.setSafeMode(true); } ! private void finalizeSetup(boolean newFile) throws IOException { ! if(newFile) { ! file.truncate(); } ! else if(!file.isEndReached()) { ! throw new IOException("Extra bytes found in RRD file. Not a RRD file at all?"); } ! file.setSafeMode(false); } --- 205,227 ---- reader = null; // finalize ! finalizeSetup(); } ! 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(); } ! else if(mode == RrdFile.MODE_RESTORE) { ! if(!file.isEndReached()) { ! throw new IOException("Extra bytes found in RRD file. Not a RRD file at all?"); ! } } ! file.setMode(RrdFile.MODE_NORMAL); } Index: RrdDouble.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/core/RrdDouble.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** RrdDouble.java 10 Nov 2003 08:52:27 -0000 1.3 --- RrdDouble.java 27 Nov 2003 10:22:58 -0000 1.4 *************** *** 28,81 **** import java.io.IOException; ! class RrdDouble { ! private RrdFile file; ! private long pointer; ! private int count; ! ! private boolean cached = false; ! private double cachedValue; ! ! RrdDouble(RrdUpdater updater, int count) throws IOException { ! this.count = count; ! file = updater.getRrdFile(); ! pointer = file.allocate(RrdFile.DOUBLE_SIZE, count); ! } RrdDouble(RrdUpdater updater) throws IOException { ! this(updater, 1); } ! ! RrdDouble(double initValue, RrdUpdater updater) throws IOException { ! this.count = 1; ! file = updater.getRrdFile(); ! pointer = file.allocate(initValue); ! cached = true; ! cachedValue = initValue; } ! void set(int index, double value) throws IOException { ! assert index < count; ! long readPointer = pointer + index * RrdFile.DOUBLE_SIZE; ! file.writeDouble(readPointer, value); } void set(double value) throws IOException { ! cached = true; ! cachedValue = value; ! set(0, value); ! } ! ! double get(int index) throws IOException { ! assert index < count; ! long readPointer = pointer + index * RrdFile.DOUBLE_SIZE; ! return file.readDouble(readPointer); } ! double get() throws IOException { ! if(!cached) { ! cachedValue = get(0); ! cached = true; ! } ! return cachedValue; } } --- 28,63 ---- import java.io.IOException; ! class RrdDouble extends RrdPrimitive { ! static final int SIZE = 8; ! ! private double cache; RrdDouble(RrdUpdater updater) throws IOException { ! super(updater, SIZE); ! loadCache(); } ! ! void loadCache() throws IOException { ! RrdFile rrdFile = getRrdFile(); ! if(rrdFile.getMode() == RrdFile.MODE_RESTORE) { ! rrdFile.seek(getPointer()); ! cache = rrdFile.readDouble(); ! } } ! RrdDouble(double initValue, RrdUpdater updater) throws IOException { ! super(updater, SIZE); ! set(initValue); } void set(double value) throws IOException { ! cache = value; ! RrdFile rrdFile = getRrdFile(); ! rrdFile.seek(getPointer()); ! rrdFile.writeDouble(cache); } ! double get() { ! return cache; } } Index: RrdFile.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/core/RrdFile.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** RrdFile.java 10 Nov 2003 08:52:27 -0000 1.2 --- RrdFile.java 27 Nov 2003 10:22:58 -0000 1.3 *************** *** 26,33 **** --- 26,36 ---- package org.jrobin.core; + import java.io.File; import java.io.IOException; import java.io.RandomAccessFile; import java.nio.channels.FileChannel; import java.nio.channels.FileLock; + import java.util.LinkedList; + import java.util.List; /** *************** *** 38,61 **** * @author <a href="mailto:sa...@jr...">Sasa Markovic</a> */ ! public class RrdFile { ! /** Maximum acceptable string length (20).*/ ! public static int STRING_LENGTH = 20; ! static final int STRING_SIZE = STRING_LENGTH * 2; ! static final int INT_SIZE = 4; ! static final int LONG_SIZE = 8; ! static final int DOUBLE_SIZE = 8; static final long LOCK_DELAY = 500; // 0.5sec static int lockMode = RrdDb.NO_LOCKS; - private RandomAccessFile file; - private boolean safeMode = true; - private long bookmark; private String filePath; private FileLock fileLock; ! RrdFile(String filePath) throws IOException { this.filePath = filePath; ! file = new RandomAccessFile(filePath, "rw"); lockFile(); } --- 41,62 ---- * @author <a href="mailto:sa...@jr...">Sasa Markovic</a> */ ! public class RrdFile extends RandomAccessFile { ! static final int MODE_NORMAL = 0; ! static final int MODE_RESTORE = 1; ! 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; private String filePath; 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(); } *************** *** 63,67 **** private void lockFile() throws IOException { if(lockMode == RrdDb.WAIT_IF_LOCKED || lockMode == RrdDb.EXCEPTION_IF_LOCKED) { ! FileChannel fileChannel = file.getChannel(); do { fileLock = fileChannel.tryLock(); --- 64,68 ---- private void lockFile() throws IOException { if(lockMode == RrdDb.WAIT_IF_LOCKED || lockMode == RrdDb.EXCEPTION_IF_LOCKED) { ! FileChannel fileChannel = getChannel(); do { fileLock = fileChannel.tryLock(); *************** *** 85,94 **** } ! void close() throws IOException { unlockFile(); ! if(file != null) { ! file.close(); ! file = null; ! } } --- 86,96 ---- } ! /** ! * Closes the underlying RandomAccessFile object. ! * @throws IOException Thrown in case of I/O error ! */ ! public void close() throws IOException { unlockFile(); ! super.close(); } *************** *** 103,233 **** close(); } ! ! void truncate() throws IOException { ! file.setLength(file.getFilePointer()); ! } ! ! boolean isEndReached() throws IOException { ! return file.getFilePointer() == file.length(); ! } ! ! long allocate(int typeSize, int count) throws IOException { ! assert typeSize == STRING_SIZE || typeSize == INT_SIZE || ! typeSize == LONG_SIZE || typeSize == DOUBLE_SIZE; ! long pointer = file.getFilePointer(); ! file.seek(pointer + typeSize * count); ! return pointer; ! } ! ! long allocate(int intVal) throws IOException { ! long pointer = file.getFilePointer(); ! file.writeInt(intVal); ! return pointer; ! } ! ! long allocate(long longVal) throws IOException { ! long pointer = file.getFilePointer(); ! file.writeLong(longVal); ! return pointer; ! } ! ! long allocate(double doubleVal) throws IOException { ! long pointer = file.getFilePointer(); ! file.writeDouble(doubleVal); ! return pointer; ! } ! ! long allocate(String stringVal) throws IOException { ! long pointer = file.getFilePointer(); ! writeStringInternal(stringVal); ! return pointer; ! } ! ! int readInt(long pointer) throws IOException { ! prepareIO(pointer); ! int result = file.readInt(); ! finalizeIO(); ! return result; ! } ! ! long readLong(long pointer) throws IOException { ! prepareIO(pointer); ! long result = file.readLong(); ! finalizeIO(); ! return result; ! } ! ! double readDouble(long pointer) throws IOException { ! prepareIO(pointer); ! double result = file.readDouble(); ! finalizeIO(); ! return result; ! } ! ! String readString(long pointer) throws IOException { ! prepareIO(pointer); ! char[] chars = new char[STRING_LENGTH]; ! for(int i = 0; i < STRING_LENGTH; i++) { ! chars[i] = file.readChar(); ! } ! String result = new String(chars).trim(); ! finalizeIO(); ! return result; ! } ! ! void writeInt(long pointer, int value) throws IOException { ! prepareIO(pointer); ! file.writeInt(value); ! finalizeIO(); ! } ! ! void writeLong(long pointer, long value) throws IOException { ! prepareIO(pointer); ! file.writeLong(value); ! finalizeIO(); ! } ! ! void writeDouble(long pointer, double value) throws IOException { ! prepareIO(pointer); ! file.writeDouble(value); ! finalizeIO(); ! } ! ! void writeString(long pointer, String value) throws IOException { ! prepareIO(pointer); ! writeStringInternal(value); ! finalizeIO(); ! } ! ! private void writeStringInternal(String value) throws IOException { ! for(int i = 0; i < STRING_LENGTH; i++) { ! if(i < value.length()) { ! file.writeChar(value.charAt(i)); ! } ! else { ! file.writeChar(' '); ! } ! } } ! ! private void prepareIO(long pointer) throws IOException { ! if(safeMode) { ! bookmark = file.getFilePointer(); ! } ! file.seek(pointer); } ! ! private void finalizeIO() throws IOException { ! if(safeMode) { ! file.seek(bookmark); } ! } ! boolean isSafeMode() { ! return safeMode; } ! void setSafeMode(boolean safeMode) { ! this.safeMode = safeMode; } --- 105,136 ---- close(); } ! ! RrdPrimitive getPrimitive(int index) { ! return (RrdPrimitive) primitives.get(index); } ! ! void allocate(RrdPrimitive primitive, int byteCount) throws IOException { ! long pointer = getNextPointer(); ! primitive.setPointer(pointer); ! primitive.setByteCount(byteCount); ! primitives.add(primitive); } ! ! private long getNextPointer() { ! long pointer = 0; ! int count = primitives.size(); ! if(count > 0) { ! RrdPrimitive lastPrimitive = getPrimitive(count - 1); ! pointer = lastPrimitive.getPointer() + lastPrimitive.getByteCount(); } ! return pointer; ! } ! void truncateFile() throws IOException { ! setLength(getNextPointer()); } ! boolean isEndReached() throws IOException { ! return getNextPointer() == length(); } *************** *** 239,242 **** --- 142,154 ---- return filePath; } + + /** + * Returns canonical path to RRD file on disk. + * @return RRD file path. + * @throws IOException Thrown in case of I/O error + */ + public String getCanonicalFilePath() throws IOException { + return new File(filePath).getCanonicalPath(); + } /** *************** *** 247,251 **** */ public long getFileSize() throws IOException { ! return file.length(); } --- 159,163 ---- */ public long getFileSize() throws IOException { ! return length(); } *************** *** 257,259 **** --- 169,180 ---- RrdFile.lockMode = lockMode; } + + int getMode() { + return mode; + } + + void setMode(int mode) { + this.mode = mode; + } + } Index: RrdInt.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/core/RrdInt.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** RrdInt.java 10 Nov 2003 08:52:27 -0000 1.3 --- RrdInt.java 27 Nov 2003 10:22:58 -0000 1.4 *************** *** 28,81 **** import java.io.IOException; ! class RrdInt { ! private RrdFile file; ! private long pointer; ! private int count; ! ! private boolean cached = false; ! private int cachedValue; ! ! RrdInt(RrdUpdater updater, int count) throws IOException { ! this.count = count; ! file = updater.getRrdFile(); ! pointer = file.allocate(RrdFile.INT_SIZE, count); ! } RrdInt(RrdUpdater updater) throws IOException { ! this(updater, 1); } ! ! RrdInt(int initValue, RrdUpdater updater) throws IOException { ! this.count = 1; ! file = updater.getRrdFile(); ! pointer = file.allocate(initValue); ! cached = true; ! cachedValue = initValue; } ! ! void set(int index, int value) throws IOException { ! assert index < count; ! long readPointer = pointer + index * RrdFile.INT_SIZE; ! file.writeInt(readPointer, value); } void set(int value) throws IOException { ! cached = true; ! cachedValue = value; ! set(0, value); ! } ! ! int get(int index) throws IOException { ! assert index < count; ! long readPointer = pointer + index * RrdFile.INT_SIZE; ! return file.readInt(readPointer); } ! int get() throws IOException { ! if(!cached) { ! cachedValue = get(0); ! cached = true; ! } ! return cachedValue; } } --- 28,63 ---- import java.io.IOException; ! class RrdInt extends RrdPrimitive { ! static final int SIZE = 4; ! ! private int cache; RrdInt(RrdUpdater updater) throws IOException { ! super(updater, SIZE); ! loadCache(); } ! ! void loadCache() throws IOException { ! RrdFile rrdFile = getRrdFile(); ! if(rrdFile.getMode() == RrdFile.MODE_RESTORE) { ! rrdFile.seek(getPointer()); ! cache = rrdFile.readInt(); ! } } ! ! RrdInt(int initValue, RrdUpdater updater) throws IOException { ! super(updater, SIZE); ! set(initValue); } void set(int value) throws IOException { ! cache = value; ! RrdFile rrdFile = getRrdFile(); ! rrdFile.seek(getPointer()); ! rrdFile.writeInt(cache); } ! int get() { ! return cache; } } Index: RrdLong.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/core/RrdLong.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** RrdLong.java 10 Nov 2003 08:52:27 -0000 1.3 --- RrdLong.java 27 Nov 2003 10:22:58 -0000 1.4 *************** *** 28,81 **** import java.io.IOException; ! class RrdLong { ! private RrdFile file; ! private long pointer; ! private int count; ! ! boolean cached = false; ! long cachedValue; ! ! RrdLong(RrdUpdater updater, int count) throws IOException { ! this.count = count; ! file = updater.getRrdFile(); ! pointer = file.allocate(RrdFile.LONG_SIZE, count); ! } RrdLong(RrdUpdater updater) throws IOException { ! this(updater, 1); } ! ! RrdLong(long initValue, RrdUpdater updater) throws IOException { ! this.count = 1; ! file = updater.getRrdFile(); ! pointer = file.allocate(initValue); ! cached = true; ! cachedValue = initValue; } ! void set(int index, long value) throws IOException { ! assert index < count; ! long readPointer = pointer + index * RrdFile.LONG_SIZE; ! file.writeLong(readPointer, value); } void set(long value) throws IOException { ! cached = true; ! cachedValue = value; ! set(0, value); ! } ! ! long get(int index) throws IOException { ! assert index < count; ! long readPointer = pointer + index * RrdFile.LONG_SIZE; ! return file.readLong(readPointer); } ! long get() throws IOException { ! if(!cached) { ! cachedValue = get(0); ! cached = true; ! } ! return cachedValue; } } --- 28,63 ---- import java.io.IOException; ! class RrdLong extends RrdPrimitive { ! static final int SIZE = 8; ! ! private long cache; RrdLong(RrdUpdater updater) throws IOException { ! super(updater, SIZE); ! loadCache(); } ! ! void loadCache() throws IOException { ! RrdFile rrdFile = getRrdFile(); ! if(rrdFile.getMode() == RrdFile.MODE_RESTORE) { ! rrdFile.seek(getPointer()); ! cache = rrdFile.readLong(); ! } } ! RrdLong(long initValue, RrdUpdater updater) throws IOException { ! super(updater, SIZE); ! set(initValue); } void set(long value) throws IOException { ! cache = value; ! RrdFile rrdFile = getRrdFile(); ! rrdFile.seek(getPointer()); ! rrdFile.writeLong(cache); } ! long get() { ! return cache; } } Index: RrdString.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/core/RrdString.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** RrdString.java 10 Nov 2003 08:52:27 -0000 1.3 --- RrdString.java 27 Nov 2003 10:22:58 -0000 1.4 *************** *** 28,81 **** import java.io.IOException; ! class RrdString { ! private RrdFile file; ! private long pointer; ! private int count; ! ! private boolean cached = false; ! private String cachedValue; ! ! RrdString(RrdUpdater updater, int count) throws IOException { ! this.count = count; ! file = updater.getRrdFile(); ! pointer = file.allocate(RrdFile.STRING_SIZE, count); ! } RrdString(RrdUpdater updater) throws IOException { ! this(updater, 1); } ! ! RrdString(String initValue, RrdUpdater updater) throws IOException { ! this.count = 1; ! file = updater.getRrdFile(); ! pointer = file.allocate(initValue); ! cached = true; ! cachedValue = initValue; } ! void set(int index, String value) throws IOException { ! assert index < count; ! long readPointer = pointer + index * RrdFile.STRING_SIZE; ! file.writeString(readPointer, value); } void set(String value) throws IOException { ! cached = true; ! cachedValue = value; ! set(0, value); ! } ! ! String get(int index) throws IOException { ! assert index < count; ! long readPointer = pointer + index * RrdFile.STRING_SIZE; ! return file.readString(readPointer); } ! String get() throws IOException { ! if(!cached) { ! cachedValue = get(0); ! cached = true; ! } ! return cachedValue; } } --- 28,74 ---- import java.io.IOException; ! class RrdString extends RrdPrimitive { ! private static final int SIZE = 20; ! ! private String cache; RrdString(RrdUpdater updater) throws IOException { ! super(updater, SIZE * 2); ! loadCache(); } ! ! void loadCache() throws IOException { ! RrdFile rrdFile = getRrdFile(); ! if(rrdFile.getMode() == RrdFile.MODE_RESTORE) { ! rrdFile.seek(getPointer()); ! char[] c = new char[SIZE]; ! for(int i = 0; i < SIZE; i++) { ! c[i] = rrdFile.readChar(); ! } ! cache = new String(c).trim(); ! } } ! RrdString(String initValue, RrdUpdater updater) throws IOException { ! super(updater, SIZE * 2); ! set(initValue); } 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; } } |
|
From: <sa...@us...> - 2003-11-24 10:15:49
|
Update of /cvsroot/jrobin/src/org/jrobin/graph
In directory sc8-pr-cvs1:/tmp/cvs-serv18381/org/jrobin/graph
Modified Files:
Source.java
Log Message:
fixed problem with MAX values
Index: Source.java
===================================================================
RCS file: /cvsroot/jrobin/src/org/jrobin/graph/Source.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** Source.java 23 Nov 2003 18:07:58 -0000 1.2
--- Source.java 24 Nov 2003 10:15:43 -0000 1.3
***************
*** 46,51 ****
protected double[] values;
! private double min = Double.POSITIVE_INFINITY;
! private double max = Double.NEGATIVE_INFINITY;
private double lastValue = Double.NaN;
private double totalValue = 0;
--- 46,51 ----
protected double[] values;
! private double min = Double.NaN;
! private double max = Double.NaN;
private double lastValue = Double.NaN;
private double totalValue = 0;
***************
*** 106,113 ****
{
case AGG_MINIMUM:
! return ( min != Double.NEGATIVE_INFINITY && min != Double.POSITIVE_INFINITY ? min : Double.NaN );
case AGG_MAXIMUM:
! return ( max != Double.NEGATIVE_INFINITY && max != Double.POSITIVE_INFINITY ? max : Double.NaN );
case AGG_AVERAGE:
--- 106,113 ----
{
case AGG_MINIMUM:
! return min;
case AGG_MAXIMUM:
! return max;
case AGG_AVERAGE:
|
|
From: <cob...@us...> - 2003-11-23 18:08:01
|
Update of /cvsroot/jrobin/src/org/jrobin/graph
In directory sc8-pr-cvs1:/tmp/cvs-serv18131/src/org/jrobin/graph
Modified Files:
Source.java
Log Message:
fixed 0 as MAX value problem
Index: Source.java
===================================================================
RCS file: /cvsroot/jrobin/src/org/jrobin/graph/Source.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** Source.java 7 Nov 2003 08:23:19 -0000 1.1
--- Source.java 23 Nov 2003 18:07:58 -0000 1.2
***************
*** 46,51 ****
protected double[] values;
! private double min = Double.MAX_VALUE;
! private double max = Double.MIN_VALUE;
private double lastValue = Double.NaN;
private double totalValue = 0;
--- 46,51 ----
protected double[] values;
! private double min = Double.POSITIVE_INFINITY;
! private double max = Double.NEGATIVE_INFINITY;
private double lastValue = Double.NaN;
private double totalValue = 0;
***************
*** 106,113 ****
{
case AGG_MINIMUM:
! return ( min != Double.MIN_VALUE && min != Double.MAX_VALUE ? min : Double.NaN );
case AGG_MAXIMUM:
! return ( max != Double.MIN_VALUE && max != Double.MAX_VALUE ? max : Double.NaN );
case AGG_AVERAGE:
--- 106,113 ----
{
case AGG_MINIMUM:
! return ( min != Double.NEGATIVE_INFINITY && min != Double.POSITIVE_INFINITY ? min : Double.NaN );
case AGG_MAXIMUM:
! return ( max != Double.NEGATIVE_INFINITY && max != Double.POSITIVE_INFINITY ? max : Double.NaN );
case AGG_AVERAGE:
|
|
From: <cob...@us...> - 2003-11-20 20:56:39
|
Update of /cvsroot/jrobin/src/org/jrobin/graph
In directory sc8-pr-cvs1:/tmp/cvs-serv26281/src/org/jrobin/graph
Modified Files:
RrdGraph.java Grapher.java
Log Message:
Added option to specify entire image dimensions
Index: RrdGraph.java
===================================================================
RCS file: /cvsroot/jrobin/src/org/jrobin/graph/RrdGraph.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** RrdGraph.java 7 Nov 2003 09:53:35 -0000 1.2
--- RrdGraph.java 20 Nov 2003 20:56:32 -0000 1.3
***************
*** 65,68 ****
--- 65,69 ----
private int maxPoolSize = DEFAULT_POOLSIZE;
+ private boolean useImageSize = false;
***************
*** 117,120 ****
--- 118,132 ----
// ================================================================
/**
+ * Determines if graph creation should specify dimensions for the chart graphing
+ * are, of for the entire image size. Default is the only the chart graphing
+ * area, this has an impact on the entire image size.
+ * @param specImgSize True if the dimensions for the entire image will be specified, false if only for the chart area.
+ */
+ public void specifyImageSize( boolean specImgSize )
+ {
+ this.useImageSize = specImgSize;
+ }
+
+ /**
* Sets the graph definition to use for the graph construction.
* @param graphDef Graph definition.
***************
*** 378,382 ****
{
// Always regenerate graph
! img = grapher.createImage( width, height, colorType );
return img;
--- 390,397 ----
{
// Always regenerate graph
! if ( useImageSize )
! img = grapher.createImageGlobal( width, height, colorType );
! else
! img = grapher.createImage( width, height, colorType );
return img;
Index: Grapher.java
===================================================================
RCS file: /cvsroot/jrobin/src/org/jrobin/graph/Grapher.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** Grapher.java 20 Nov 2003 09:28:00 -0000 1.4
--- Grapher.java 20 Nov 2003 20:56:32 -0000 1.5
***************
*** 202,205 ****
--- 202,265 ----
}
+ /**
+ * Creates the actual graph based on the GraphDef definition.
+ * The graph is created as a <code>java.awt.image.BufferedImage</code>.
+ * @param cWidth Width of the entire image in pixels.
+ * @param cHeight Height of the entire image in pixels.
+ * @return The created graph as a BufferedImage.
+ * @throws RrdException Thrown in case of a JRobin specific error.
+ * @throws IOException Thrown in case of a I/O related error.
+ */
+ protected BufferedImage createImageGlobal( int cWidth, int cHeight, int colorType ) throws RrdException, IOException
+ {
+ imgWidth = cWidth;
+ imgHeight = cHeight;
+
+ if ( cWidth > 0 ) numPoints = cWidth;
+
+ // Padding depends on grid visibility
+ chart_lpadding = ( graphDef.showMajorGridY() ? graphDef.getChartLeftPadding() : CHART_LPADDING_NM );
+ chart_bpadding = ( graphDef.showMajorGridX() ? CHART_BPADDING : CHART_BPADDING_NM );
+
+ // Size of all lines below chart
+ commentBlock = 0;
+ if ( graphDef.showLegend() )
+ commentBlock = graphDef.getCommentLineCount() * (nfont_height + LINE_PADDING) - LINE_PADDING;
+
+ // x_offset and y_offset define the starting corner of the actual graph
+ x_offset = LBORDER_SPACE;
+ if ( graphDef.getVerticalLabel() != null )
+ x_offset += nfont_height + LINE_PADDING;
+ chartWidth = imgWidth - x_offset - RBORDER_SPACE - chart_lpadding - CHART_RPADDING;
+
+ y_offset = UBORDER_SPACE;
+ if ( graphDef.getTitle() != null ) // Title *always* gets a extra LF automatically
+ y_offset += ((tfont_height + LINE_PADDING) * graphDef.getTitle().getLineCount() + tfont_height) + LINE_PADDING;
+ chartHeight = imgHeight - commentBlock - y_offset - BBORDER_SPACE - CHART_UPADDING - CHART_BPADDING;
+
+ // Create graphics object
+ BufferedImage bImg = new BufferedImage( imgWidth, imgHeight, colorType );
+ Graphics2D graphics = (Graphics2D) bImg.getGraphics();
+
+ // Do the actual graphing
+ calculateSeries(); // calculate all datasources
+
+ plotImageBackground( graphics ); // draw the image background
+
+ plotChart( graphics ); // draw the actual chart
+
+ plotComments( graphics ); // draw all comment lines
+
+ plotOverlay( graphics ); // draw a possible image overlay
+
+ plotSignature( graphics ); // draw the JRobin signature
+
+
+ // Dispose graphics context
+ graphics.dispose();
+
+ return bImg;
+ }
+
// ================================================================
|
|
From: <cob...@us...> - 2003-11-20 09:28:43
|
Update of /cvsroot/jrobin/src/org/jrobin/graph In directory sc8-pr-cvs1:/tmp/cvs-serv32621/src/org/jrobin/graph Modified Files: RrdGraphDef.java Grapher.java Area.java Line.java Added Files: TimeAxisLabel.java Log Message: Fixed stacking on NaN bug Added TimeAxisLabel option --- NEW FILE: TimeAxisLabel.java --- /* ============================================================ * JRobin : Pure java implementation of RRDTool's functionality * ============================================================ * * Project Info: http://www.jrobin.org * Project Lead: Sasa Markovic (sa...@jr...) * * Developers: Sasa Markovic (sa...@jr...) * Arne Vandamme (cob...@jr...) * * (C) Copyright 2003, by Sasa Markovic. * * This library is free software; you can redistribute it and/or modify it under the terms * of the GNU Lesser General Public License as published by the Free Software Foundation; * either version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License along with this * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, * Boston, MA 02111-1307, USA. */ package org.jrobin.graph; import org.jrobin.core.RrdException; /** * <p>Represents the TimeAxis label used in the graph. The TimeAxisLabel object has the same alignment * possibilities as all other text/comment objects in a graph.</p> * * @author Arne Vandamme (cob...@jr...) */ public class TimeAxisLabel extends Comment { // ================================================================ // -- Constructors // ================================================================ /** * Constructs a TimeAxisLabel object based on a text string. * @param text Text string with alignment markers representing the label. * @throws RrdException Thrown in case of a JRobin specific error. */ TimeAxisLabel( String text ) throws RrdException { this.text = text; lfToken = Comment.TKN_ACF; super.parseComment(); // If there's no line end, add centered-line end if ( !super.isCompleteLine() ) { oList.add( "" ); oList.add( super.TKN_ACF ); oList.add( "" ); oList.add( super.TKN_ALF ); this.lineCount += 2; } } } Index: RrdGraphDef.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/graph/RrdGraphDef.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** RrdGraphDef.java 10 Nov 2003 08:52:27 -0000 1.2 --- RrdGraphDef.java 20 Nov 2003 09:28:00 -0000 1.3 *************** *** 224,227 **** --- 224,254 ---- /** + * Sets horizontal (time) axis label. + * <p> + * A horizontal axis label is always center aligned by default, with an extra linefeed to add + * some space before the regular comment lines start. If you wish to remove the extra line of whitespace + * you should specify the alignment in the label using @c, @l or @r. Using the @C, @L or @R markers will + * align the text appropriately, and leave the extra line of whitespace intact. + * </p> + * <p> + * It is possible to use multiple lines and multiple alignment markers for the axis label, in that case + * you should specify alignment for every part of the label to get it to display correctly. When using multiple + * lines, no markers will be added to the end of the last line by default. + * </p> + * @param label Horizontal axis label. + */ + public void setTimeAxisLabel( String label ) throws RrdException + { + if ( label != null ) + { + TimeAxisLabel cmt = new TimeAxisLabel( label ); + commentLines += cmt.getLineCount(); + commentLineShift = (cmt.isCompleteLine() ? 0 : 1); + + comments.add( 0, cmt ); + } + } + + /** * Sets image background color. If not set, back color defaults to a very light gray. * @param backColor Graph background color. Index: Grapher.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/graph/Grapher.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** Grapher.java 18 Nov 2003 12:47:56 -0000 1.3 --- Grapher.java 20 Nov 2003 09:28:00 -0000 1.4 *************** *** 619,623 **** // Position the cursor just below the chart area ! int posy = y_offset + chartHeight + CHART_UPADDING + CHART_BPADDING + nfont_height; int posx = LBORDER_SPACE; --- 619,623 ---- // Position the cursor just below the chart area ! int posy = y_offset + chartHeight + CHART_UPADDING + CHART_BPADDING + ( graphDef.showMajorGridX() ? nfont_height : 0 ); int posx = LBORDER_SPACE; Index: Area.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/graph/Area.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** Area.java 7 Nov 2003 08:23:19 -0000 1.1 --- Area.java 20 Nov 2003 09:28:00 -0000 1.2 *************** *** 89,112 **** ny = g.getY( values[i] ); ! if ( stacked ) { ! py = stackValues[i]; ! ny += stackValues[i]; ! } ! ! if ( visible ) { ! if (nx > ax + 1) // More than one pixel hop, draw intermediate pixels too ! { ! // For each pixel between nx and ax, calculate the y, plot the line ! int co = (ny - ay) / (nx - ax); ! int j = (ax > 0 ? ax : 1 ); // Skip 0 ! for (j = ax; j <= nx; j++) ! if ( ay != Integer.MIN_VALUE && ny != Integer.MIN_VALUE ) ! g.drawLine( j, py, j, ( co * (j - ax) + ay) ); } ! else if ( nx != 0 && py != Integer.MIN_VALUE && ny != Integer.MIN_VALUE ) ! g.drawLine( nx, py, nx, ny ); } stackValues[i] = ny; --- 89,119 ---- ny = g.getY( values[i] ); ! if ( !Double.isNaN(values[i]) ) { ! if ( stacked ) { ! py = stackValues[i]; ! ny += ( stackValues[i] == Integer.MIN_VALUE ? Integer.MIN_VALUE : stackValues[i] ); ! } ! if ( visible ) ! { ! if (nx > ax + 1) // More than one pixel hop, draw intermediate pixels too ! { ! // For each pixel between nx and ax, calculate the y, plot the line ! int co = (ny - ay) / (nx - ax); ! int j = (ax > 0 ? ax : 1 ); // Skip 0 ! ! for (j = ax; j <= nx; j++) ! if ( ay != Integer.MIN_VALUE && ny != Integer.MIN_VALUE ) ! g.drawLine( j, py, j, ( co * (j - ax) + ay) ); ! } ! else if ( nx != 0 && py != Integer.MIN_VALUE && ny != Integer.MIN_VALUE ) ! g.drawLine( nx, py, nx, ny ); } ! ! } + + // Special case with NaN doubles stackValues[i] = ny; Index: Line.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/graph/Line.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** Line.java 7 Nov 2003 08:23:19 -0000 1.1 --- Line.java 20 Nov 2003 09:28:00 -0000 1.2 *************** *** 119,122 **** --- 119,123 ---- g.drawLine( ax, ay, nx, ny ); + stackValues[i] = ny; ax = nx; |
|
From: <sa...@us...> - 2003-11-19 11:37:46
|
Update of /cvsroot/jrobin/src/org/jrobin/graph
In directory sc8-pr-cvs1:/tmp/cvs-serv12580/org/jrobin/graph
Modified Files:
TimeAxisUnit.java
Log Message:
Class made public, some static constants are now public, too.
Index: TimeAxisUnit.java
===================================================================
RCS file: /cvsroot/jrobin/src/org/jrobin/graph/TimeAxisUnit.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** TimeAxisUnit.java 10 Nov 2003 08:52:27 -0000 1.2
--- TimeAxisUnit.java 19 Nov 2003 11:37:40 -0000 1.3
***************
*** 30,34 ****
* @author Arne Vandamme (cob...@jr...)
*/
! class TimeAxisUnit
{
// ================================================================
--- 30,34 ----
* @author Arne Vandamme (cob...@jr...)
*/
! public class TimeAxisUnit
{
// ================================================================
***************
*** 57,67 ****
// Indices in the calendarUnit table
! protected static final int SECOND = 0;
! protected static final int MINUTE = 1;
! protected static final int HOUR = 2;
! protected static final int DAY = 3;
! protected static final int WEEK = 4;
! protected static final int MONTH = 5;
! protected static final int YEAR = 6;
private int gridTime = HOUR; // minor grid
--- 57,74 ----
// 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 int gridTime = HOUR; // minor grid
|
|
From: <sa...@us...> - 2003-11-18 12:48:02
|
Update of /cvsroot/jrobin/src/org/jrobin/graph
In directory sc8-pr-cvs1:/tmp/cvs-serv31753/org/jrobin/graph
Modified Files:
Grapher.java
Log Message:
Fixed problem with consecutive stacked graphs...
Index: Grapher.java
===================================================================
RCS file: /cvsroot/jrobin/src/org/jrobin/graph/Grapher.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** Grapher.java 7 Nov 2003 09:53:35 -0000 1.2
--- Grapher.java 18 Nov 2003 12:47:56 -0000 1.3
***************
*** 463,467 ****
{
plotDefs[i].draw( g, xValues, parentSeries, lastPlotType );
! lastPlotType = plotDefs[i].plotType;
}
--- 463,469 ----
{
plotDefs[i].draw( g, xValues, parentSeries, lastPlotType );
! if(plotDefs[i].plotType != PlotDef.PLOT_STACK) {
! lastPlotType = plotDefs[i].plotType;
! }
}
|
|
From: <sa...@us...> - 2003-11-17 08:10:28
|
Update of /cvsroot/jrobin/src
In directory sc8-pr-cvs1:/tmp/cvs-serv8998
Modified Files:
Demo.java
Log Message:
Final tweaks
Index: Demo.java
===================================================================
RCS file: /cvsroot/jrobin/src/Demo.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -d -r1.6 -r1.7
*** Demo.java 13 Nov 2003 11:45:35 -0000 1.6
--- Demo.java 17 Nov 2003 08:09:41 -0000 1.7
***************
*** 43,47 ****
public static void main(String[] args) throws RrdException, IOException {
// setup
! println("==Starting demo");
RrdDb.setLockMode(RrdDb.NO_LOCKS);
--- 43,47 ----
public static void main(String[] args) throws RrdException, IOException {
// setup
! println("== Starting demo");
RrdDb.setLockMode(RrdDb.NO_LOCKS);
***************
*** 61,65 ****
// creation
! println("==Creating RRD file " + rrdPath);
RrdDef rrdDef = new RrdDef(rrdPath, start - 1, 300);
rrdDef.addDatasource("sun", "GAUGE", 600, 0, Double.NaN);
--- 61,65 ----
// creation
! println("== Creating RRD file " + rrdPath);
RrdDef rrdDef = new RrdDef(rrdPath, start - 1, 300);
rrdDef.addDatasource("sun", "GAUGE", 600, 0, Double.NaN);
***************
*** 67,89 ****
rrdDef.addArchive("AVERAGE", 0.5, 1, 600);
rrdDef.addArchive("AVERAGE", 0.5, 6, 700);
! rrdDef.addArchive("AVERAGE", 0.5, 24, 797);
! rrdDef.addArchive("AVERAGE", 0.5, 288, 775);
rrdDef.addArchive("MAX", 0.5, 1, 600);
rrdDef.addArchive("MAX", 0.5, 6, 700);
! rrdDef.addArchive("MAX", 0.5, 24, 797);
! rrdDef.addArchive("MAX", 0.5, 288, 775);
println(rrdDef.dump());
pw.println(rrdDef.dump());
RrdDb rrdDb = new RrdDb(rrdDef);
! println("==RRD file created.");
// update database
GaugeSource sunSource = new GaugeSource(1200, 20);
GaugeSource shadeSource = new GaugeSource(300, 10);
! println("==Simulating one month of RRD file updates with step not larger than " +
MAX_STEP + " seconds (* denotes 1000 updates)");
long t = start; int n = 0;
Sample sample = rrdDb.createSample();
! while(t <= end) {
sample.setTime(t);
sample.setValue("sun", sunSource.getValue());
--- 67,89 ----
rrdDef.addArchive("AVERAGE", 0.5, 1, 600);
rrdDef.addArchive("AVERAGE", 0.5, 6, 700);
! rrdDef.addArchive("AVERAGE", 0.5, 24, 775);
! rrdDef.addArchive("AVERAGE", 0.5, 288, 797);
rrdDef.addArchive("MAX", 0.5, 1, 600);
rrdDef.addArchive("MAX", 0.5, 6, 700);
! rrdDef.addArchive("MAX", 0.5, 24, 775);
! rrdDef.addArchive("MAX", 0.5, 288, 797);
println(rrdDef.dump());
pw.println(rrdDef.dump());
RrdDb rrdDb = new RrdDb(rrdDef);
! println("== RRD file created.");
// update database
GaugeSource sunSource = new GaugeSource(1200, 20);
GaugeSource shadeSource = new GaugeSource(300, 10);
! println("== Simulating one month of RRD file updates with step not larger than " +
MAX_STEP + " seconds (* denotes 1000 updates)");
long t = start; int n = 0;
Sample sample = rrdDb.createSample();
! while(t <= end + 86400L) {
sample.setTime(t);
sample.setValue("sun", sunSource.getValue());
***************
*** 98,133 ****
}
System.out.println("");
! println("==Finished. RRD file updated " + n + " times");
! println("==Last update time was: " + rrdDb.getLastUpdateTime());
// fetch data
! println("==Fetching data for the whole month");
FetchRequest request = rrdDb.createFetchRequest("AVERAGE", start, end);
println(request.dump());
pw.println(request.dump());
FetchData fetchData = request.fetchData();
! println("==Data fetched. " + fetchData.getRowCount() + " points obtained");
for(int i = 0; i < fetchData.getRowCount(); i++) {
println(fetchData.getRow(i).dump());
}
! println("==Fetch completed");
! println("==Dumping RRD file to XML file " + xmlPath + " (can be restored with RRDTool)");
rrdDb.dumpXml(xmlPath);
! println("==Creating RRD file " + rrdRestoredPath + " from XML file " + xmlPath);
RrdDb rrdRestoredDb = new RrdDb(rrdRestoredPath, xmlPath);
- // dumping RRD file
- //println("==Dumping original RRD file to stdout");
- //println(rrdDb.dump());
- //println("==Dumping restored RRD file to stdout");
- //println(rrdRestoredDb.dump());
-
// close files
! println("==Closing both RRD files");
rrdDb.close();
rrdRestoredDb.close();
// create graph
! println("==Creating graph from the second file");
RrdGraphDef gDef = new RrdGraphDef();
gDef.setTimePeriod(start, end);
--- 98,127 ----
}
System.out.println("");
! println("== Finished. RRD file updated " + n + " times");
! println("== Last update time was: " + rrdDb.getLastUpdateTime());
// fetch data
! println("== Fetching data for the whole month");
FetchRequest request = rrdDb.createFetchRequest("AVERAGE", start, end);
println(request.dump());
pw.println(request.dump());
FetchData fetchData = request.fetchData();
! println("== Data fetched. " + fetchData.getRowCount() + " points obtained");
for(int i = 0; i < fetchData.getRowCount(); i++) {
println(fetchData.getRow(i).dump());
}
! println("== Fetch completed");
! println("== Dumping RRD file to XML file " + xmlPath + " (can be restored with RRDTool)");
rrdDb.dumpXml(xmlPath);
! println("== Creating RRD file " + rrdRestoredPath + " from XML file " + xmlPath);
RrdDb rrdRestoredDb = new RrdDb(rrdRestoredPath, xmlPath);
// close files
! println("== Closing both RRD files");
rrdDb.close();
rrdRestoredDb.close();
// create graph
! println("== Creating graph from the second file");
RrdGraphDef gDef = new RrdGraphDef();
gDef.setTimePeriod(start, end);
***************
*** 152,166 ****
// create graph finally
RrdGraph graph = new RrdGraph(gDef);
! println("==Graph created");
! println("==Saving graph as PNG file " + pngPath);
graph.saveAsPNG(pngPath, 400, 250);
! println("==Saving graph as JPEG file " + jpegPath);
graph.saveAsJPEG(jpegPath, 400, 250, 0.5F);
! println("==Saving graph as GIF file " + gifPath);
graph.saveAsGIF(gifPath, 400, 250);
// demo ends
pw.close();
! println("Demo completed in " +
((System.currentTimeMillis() - startMillis) / 1000.0) + " sec");
}
--- 146,160 ----
// create graph finally
RrdGraph graph = new RrdGraph(gDef);
! println("== Graph created");
! println("== Saving graph as PNG file " + pngPath);
graph.saveAsPNG(pngPath, 400, 250);
! println("== Saving graph as JPEG file " + jpegPath);
graph.saveAsJPEG(jpegPath, 400, 250, 0.5F);
! println("== Saving graph as GIF file " + gifPath);
graph.saveAsGIF(gifPath, 400, 250);
// demo ends
pw.close();
! println("== Demo completed in " +
((System.currentTimeMillis() - startMillis) / 1000.0) + " sec");
}
***************
*** 184,188 ****
}
! double getValue() {
double oldValue = value;
double increment = Math.random() * step;
--- 178,182 ----
}
! long getValue() {
double oldValue = value;
double increment = Math.random() * step;
|
|
From: <sa...@us...> - 2003-11-17 08:10:27
|
Update of /cvsroot/jrobin/src/org/jrobin/core
In directory sc8-pr-cvs1:/tmp/cvs-serv8998/org/jrobin/core
Modified Files:
FetchPoint.java Util.java
Log Message:
Final tweaks
Index: FetchPoint.java
===================================================================
RCS file: /cvsroot/jrobin/src/org/jrobin/core/FetchPoint.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** FetchPoint.java 13 Nov 2003 11:45:35 -0000 1.3
--- FetchPoint.java 17 Nov 2003 08:09:42 -0000 1.4
***************
*** 98,100 ****
--- 98,108 ----
return buffer.toString();
}
+
+ /**
+ * Returns string representing timestamp and all data source values.
+ * @return Fetch point dump.
+ */
+ public String toString() {
+ return dump();
+ }
}
Index: Util.java
===================================================================
RCS file: /cvsroot/jrobin/src/org/jrobin/core/Util.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** Util.java 13 Nov 2003 11:45:35 -0000 1.3
--- Util.java 17 Nov 2003 08:09:42 -0000 1.4
***************
*** 49,52 ****
--- 49,53 ----
df = (DecimalFormat) NumberFormat.getNumberInstance(Locale.ENGLISH);
df.applyPattern(PATTERN);
+ df.setPositivePrefix("+");
}
|
Update of /cvsroot/jrobin/src/org/jrobin/inspector
In directory sc8-pr-cvs1:/tmp/cvs-serv6751/org/jrobin/inspector
Modified Files:
ArchiveTableModel.java DataTableModel.java
DatasourceTableModel.java HeaderTableModel.java
MainTreeModel.java
Log Message:
Removed RrdDbPool for inspector - not appropriate...
Index: ArchiveTableModel.java
===================================================================
RCS file: /cvsroot/jrobin/src/org/jrobin/inspector/ArchiveTableModel.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** ArchiveTableModel.java 12 Nov 2003 13:24:24 -0000 1.3
--- ArchiveTableModel.java 13 Nov 2003 15:33:28 -0000 1.4
***************
*** 38,42 ****
};
private static final String[] COLUMN_NAMES = {"description", "value"};
- private static final RrdDbPool pool = RrdDbPool.getInstance();
private File file;
--- 38,41 ----
***************
*** 85,89 ****
if(dsIndex >= 0 && arcIndex >= 0) {
try {
! RrdDb rrd = pool.requestRrdDb(file.getAbsolutePath());
Archive arc = rrd.getArchive(arcIndex);
ArcState state = arc.getArcState(dsIndex);
--- 84,88 ----
if(dsIndex >= 0 && arcIndex >= 0) {
try {
! RrdDb rrd = new RrdDb(file.getAbsolutePath());
Archive arc = rrd.getArchive(arcIndex);
ArcState state = arc.getArcState(dsIndex);
***************
*** 98,106 ****
"" + arc.getEndTime() + " [" + new Date(arc.getEndTime() * 1000L) + "]"
};
! pool.release(rrd);
}
catch (IOException e) {
}
catch (RrdException e) {
}
}
--- 97,107 ----
"" + arc.getEndTime() + " [" + new Date(arc.getEndTime() * 1000L) + "]"
};
! rrd.close();
}
catch (IOException e) {
+ e.printStackTrace();
}
catch (RrdException e) {
+ e.printStackTrace();
}
}
Index: DataTableModel.java
===================================================================
RCS file: /cvsroot/jrobin/src/org/jrobin/inspector/DataTableModel.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** DataTableModel.java 12 Nov 2003 13:24:25 -0000 1.3
--- DataTableModel.java 13 Nov 2003 15:33:28 -0000 1.4
***************
*** 35,39 ****
class DataTableModel extends AbstractTableModel {
private static final String[] COLUMN_NAMES = {"timestamp", "date", "value"};
- private static final RrdDbPool pool = RrdDbPool.getInstance();
private File file;
--- 35,38 ----
***************
*** 79,83 ****
if(dsIndex >= 0 && arcIndex >= 0) {
try {
! RrdDb rrd = pool.requestRrdDb(file.getAbsolutePath());
Archive arc = rrd.getArchive(arcIndex);
Robin robin = arc.getRobin(dsIndex);
--- 78,82 ----
if(dsIndex >= 0 && arcIndex >= 0) {
try {
! RrdDb rrd = new RrdDb(file.getAbsolutePath());
Archive arc = rrd.getArchive(arcIndex);
Robin robin = arc.getRobin(dsIndex);
***************
*** 94,102 ****
};
}
! pool.release(rrd);
}
catch (IOException e) {
}
catch (RrdException e) {
}
}
--- 93,103 ----
};
}
! rrd.close();
}
catch (IOException e) {
+ e.printStackTrace();
}
catch (RrdException e) {
+ e.printStackTrace();
}
}
Index: DatasourceTableModel.java
===================================================================
RCS file: /cvsroot/jrobin/src/org/jrobin/inspector/DatasourceTableModel.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** DatasourceTableModel.java 12 Nov 2003 13:24:25 -0000 1.3
--- DatasourceTableModel.java 13 Nov 2003 15:33:28 -0000 1.4
***************
*** 28,32 ****
import org.jrobin.core.Datasource;
import org.jrobin.core.RrdException;
- import org.jrobin.core.RrdDbPool;
import javax.swing.table.AbstractTableModel;
--- 28,31 ----
***************
*** 38,42 ****
"max value", "last value", "accum. value", "NaN seconds"};
private static final String[] COLUMN_NAMES = {"description", "value"};
- private static final RrdDbPool pool = RrdDbPool.getInstance();
private File file;
--- 37,40 ----
***************
*** 84,88 ****
if(dsIndex >= 0) {
try {
! RrdDb rrd = pool.requestRrdDb(file.getAbsolutePath());
Datasource ds = rrd.getDatasource(dsIndex);
values = new Object[]{
--- 82,86 ----
if(dsIndex >= 0) {
try {
! RrdDb rrd = new RrdDb(file.getAbsolutePath());
Datasource ds = rrd.getDatasource(dsIndex);
values = new Object[]{
***************
*** 96,104 ****
"" + ds.getNanSeconds()
};
! pool.release(rrd);
}
catch (IOException e) {
}
catch (RrdException e) {
}
}
--- 94,104 ----
"" + ds.getNanSeconds()
};
! rrd.close();
}
catch (IOException e) {
+ e.printStackTrace();
}
catch (RrdException e) {
+ e.printStackTrace();
}
}
Index: HeaderTableModel.java
===================================================================
RCS file: /cvsroot/jrobin/src/org/jrobin/inspector/HeaderTableModel.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** HeaderTableModel.java 12 Nov 2003 13:24:25 -0000 1.3
--- HeaderTableModel.java 13 Nov 2003 15:33:28 -0000 1.4
***************
*** 29,33 ****
import org.jrobin.core.Header;
import org.jrobin.core.RrdException;
- import org.jrobin.core.RrdDbPool;
import javax.swing.table.AbstractTableModel;
--- 29,32 ----
***************
*** 40,44 ****
"datasources", "archives", "size"};
private static final String[] COLUMN_NAMES = {"description", "value"};
- private static final RrdDbPool pool = RrdDbPool.getInstance();
private File file;
--- 39,42 ----
***************
*** 78,82 ****
values = null;
String path = file.getAbsolutePath();
! RrdDb rrd = pool.requestRrdDb(path);
Header header = rrd.getHeader();
String signature = header.getSignature();
--- 76,80 ----
values = null;
String path = file.getAbsolutePath();
! RrdDb rrd = new RrdDb(path);
Header header = rrd.getHeader();
String signature = header.getSignature();
***************
*** 87,91 ****
String archives = "" + header.getArcCount();
String size = rrd.getRrdFile().getFileSize() + " bytes";
! pool.release(rrd);
values = new Object[] {
path, signature, step, lastTimestamp, datasources, archives, size
--- 85,89 ----
String archives = "" + header.getArcCount();
String size = rrd.getRrdFile().getFileSize() + " bytes";
! rrd.close();
values = new Object[] {
path, signature, step, lastTimestamp, datasources, archives, size
Index: MainTreeModel.java
===================================================================
RCS file: /cvsroot/jrobin/src/org/jrobin/inspector/MainTreeModel.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** MainTreeModel.java 12 Nov 2003 13:24:25 -0000 1.3
--- MainTreeModel.java 13 Nov 2003 15:33:28 -0000 1.4
***************
*** 28,32 ****
import org.jrobin.core.RrdDb;
import org.jrobin.core.RrdException;
- import org.jrobin.core.RrdDbPool;
import javax.swing.tree.DefaultTreeModel;
--- 28,31 ----
***************
*** 38,42 ****
private static final DefaultMutableTreeNode INVALID_NODE =
new DefaultMutableTreeNode("No valid RRD file specified");
- private static final RrdDbPool pool = RrdDbPool.getInstance();
private File file;
--- 37,40 ----
***************
*** 50,54 ****
try {
file = newFile;
! RrdDb rrd = pool.requestRrdDb(file.getAbsolutePath());
DefaultMutableTreeNode root = new DefaultMutableTreeNode(new RrdNode(rrd));
int dsCount = rrd.getRrdDef().getDsCount();
--- 48,52 ----
try {
file = newFile;
! RrdDb rrd = new RrdDb(file.getAbsolutePath());
DefaultMutableTreeNode root = new DefaultMutableTreeNode(new RrdNode(rrd));
int dsCount = rrd.getRrdDef().getDsCount();
***************
*** 64,68 ****
root.add(dsNode);
}
! pool.release(rrd);
setRoot(root);
}
--- 62,66 ----
root.add(dsNode);
}
! rrd.close();
setRoot(root);
}
|
|
From: <sa...@us...> - 2003-11-13 11:45:39
|
Update of /cvsroot/jrobin/src/org/jrobin/core
In directory sc8-pr-cvs1:/tmp/cvs-serv27498/org/jrobin/core
Modified Files:
DsDef.java FetchPoint.java Robin.java Sample.java Util.java
XmlWriter.java
Log Message:
Minor code changes
Index: DsDef.java
===================================================================
RCS file: /cvsroot/jrobin/src/org/jrobin/core/DsDef.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** DsDef.java 10 Nov 2003 08:52:27 -0000 1.3
--- DsDef.java 13 Nov 2003 11:45:35 -0000 1.4
***************
*** 153,158 ****
public String dump() {
return "DS:" + dsName + ":" + dsType + ":" + heartbeat +
! ":" + Util.formatDouble(minValue, "U") +
! ":" + Util.formatDouble(maxValue, "U");
}
--- 153,158 ----
public String dump() {
return "DS:" + dsName + ":" + dsType + ":" + heartbeat +
! ":" + Util.formatDouble(minValue, "U", false) +
! ":" + Util.formatDouble(maxValue, "U", false);
}
Index: FetchPoint.java
===================================================================
RCS file: /cvsroot/jrobin/src/org/jrobin/core/FetchPoint.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** FetchPoint.java 10 Nov 2003 08:52:27 -0000 1.2
--- FetchPoint.java 13 Nov 2003 11:45:35 -0000 1.3
***************
*** 93,97 ****
StringBuffer buffer = new StringBuffer(time + ": ");
for(int i = 0; i < values.length; i++) {
! buffer.append(Util.formatDouble(values[i]));
buffer.append(" ");
}
--- 93,97 ----
StringBuffer buffer = new StringBuffer(time + ": ");
for(int i = 0; i < values.length; i++) {
! buffer.append(Util.formatDouble(values[i], true));
buffer.append(" ");
}
Index: Robin.java
===================================================================
RCS file: /cvsroot/jrobin/src/org/jrobin/core/Robin.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** Robin.java 10 Nov 2003 08:52:27 -0000 1.2
--- Robin.java 13 Nov 2003 11:45:35 -0000 1.3
***************
*** 92,96 ****
int startPos = pointer.get();
for(int i = startPos; i < startPos + rows; i++) {
! buffer.append(Util.formatDouble(values.get(i % rows)) + " ");
}
buffer.append("\n");
--- 92,96 ----
int startPos = pointer.get();
for(int i = startPos; i < startPos + rows; i++) {
! buffer.append(Util.formatDouble(values.get(i % rows), true) + " ");
}
buffer.append("\n");
Index: Sample.java
===================================================================
RCS file: /cvsroot/jrobin/src/org/jrobin/core/Sample.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** Sample.java 10 Nov 2003 08:52:27 -0000 1.3
--- Sample.java 13 Nov 2003 11:45:35 -0000 1.4
***************
*** 232,236 ****
for(int i = 0; i < values.length; i++) {
buffer.append(":");
! buffer.append(Util.formatDouble(values[i], "U"));
}
return buffer.toString();
--- 232,236 ----
for(int i = 0; i < values.length; i++) {
buffer.append(":");
! buffer.append(Util.formatDouble(values[i], "U", false));
}
return buffer.toString();
Index: Util.java
===================================================================
RCS file: /cvsroot/jrobin/src/org/jrobin/core/Util.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** Util.java 10 Nov 2003 08:52:27 -0000 1.2
--- Util.java 13 Nov 2003 11:45:35 -0000 1.3
***************
*** 94,106 ****
}
! static String formatDouble(double x, String nanString) {
if(Double.isNaN(x)) {
return nanString;
}
! return df.format(x);
}
! static String formatDouble(double x) {
! return formatDouble(x, "" + Double.NaN);
}
--- 94,109 ----
}
! static String formatDouble(double x, String nanString, boolean forceExponents) {
if(Double.isNaN(x)) {
return nanString;
}
! if(forceExponents) {
! return df.format(x);
! }
! return "" + x;
}
! static String formatDouble(double x, boolean forceExponents) {
! return formatDouble(x, "" + Double.NaN, forceExponents);
}
Index: XmlWriter.java
===================================================================
RCS file: /cvsroot/jrobin/src/org/jrobin/core/XmlWriter.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** XmlWriter.java 10 Nov 2003 08:52:27 -0000 1.2
--- XmlWriter.java 13 Nov 2003 11:45:35 -0000 1.3
***************
*** 66,74 ****
void writeTag(String tag, double value, String nanString) {
! writeTag(tag, Util.formatDouble(value, nanString));
}
void writeTag(String tag, double value) {
! writeTag(tag, Util.formatDouble(value));
}
--- 66,74 ----
void writeTag(String tag, double value, String nanString) {
! writeTag(tag, Util.formatDouble(value, nanString, true));
}
void writeTag(String tag, double value) {
! writeTag(tag, Util.formatDouble(value, true));
}
|
|
From: <sa...@us...> - 2003-11-13 11:45:39
|
Update of /cvsroot/jrobin/src
In directory sc8-pr-cvs1:/tmp/cvs-serv27498
Modified Files:
Demo.java
Log Message:
Minor code changes
Index: Demo.java
===================================================================
RCS file: /cvsroot/jrobin/src/Demo.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** Demo.java 11 Nov 2003 11:44:12 -0000 1.5
--- Demo.java 13 Nov 2003 11:45:35 -0000 1.6
***************
*** 39,43 ****
static final long START = Util.getTimestamp(2003, 4, 1);
static final long END = Util.getTimestamp(2003, 5, 1);
! static final int MAX_STEP = 240;
public static void main(String[] args) throws RrdException, IOException {
--- 39,43 ----
static final long START = Util.getTimestamp(2003, 4, 1);
static final long END = Util.getTimestamp(2003, 5, 1);
! static final int MAX_STEP = 300;
public static void main(String[] args) throws RrdException, IOException {
***************
*** 117,120 ****
--- 117,126 ----
RrdDb rrdRestoredDb = new RrdDb(rrdRestoredPath, xmlPath);
+ // dumping RRD file
+ //println("==Dumping original RRD file to stdout");
+ //println(rrdDb.dump());
+ //println("==Dumping restored RRD file to stdout");
+ //println(rrdRestoredDb.dump());
+
// close files
println("==Closing both RRD files");
***************
*** 188,192 ****
value = 0;
}
! return oldValue;
}
}
--- 194,198 ----
value = 0;
}
! return Math.round(oldValue);
}
}
|
Update of /cvsroot/jrobin/src/org/jrobin/inspector
In directory sc8-pr-cvs1:/tmp/cvs-serv3809/org/jrobin/inspector
Modified Files:
ArchiveTableModel.java DataTableModel.java
DatasourceTableModel.java HeaderTableModel.java
MainTreeModel.java
Log Message:
Inspector switched to RrdDbPool
Index: ArchiveTableModel.java
===================================================================
RCS file: /cvsroot/jrobin/src/org/jrobin/inspector/ArchiveTableModel.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** ArchiveTableModel.java 10 Nov 2003 08:52:27 -0000 1.2
--- ArchiveTableModel.java 12 Nov 2003 13:24:24 -0000 1.3
***************
*** 38,41 ****
--- 38,42 ----
};
private static final String[] COLUMN_NAMES = {"description", "value"};
+ private static final RrdDbPool pool = RrdDbPool.getInstance();
private File file;
***************
*** 84,88 ****
if(dsIndex >= 0 && arcIndex >= 0) {
try {
! RrdDb rrd = new RrdDb(file.getAbsolutePath());
Archive arc = rrd.getArchive(arcIndex);
ArcState state = arc.getArcState(dsIndex);
--- 85,89 ----
if(dsIndex >= 0 && arcIndex >= 0) {
try {
! RrdDb rrd = pool.requestRrdDb(file.getAbsolutePath());
Archive arc = rrd.getArchive(arcIndex);
ArcState state = arc.getArcState(dsIndex);
***************
*** 97,101 ****
"" + arc.getEndTime() + " [" + new Date(arc.getEndTime() * 1000L) + "]"
};
! rrd.close();
}
catch (IOException e) {
--- 98,102 ----
"" + arc.getEndTime() + " [" + new Date(arc.getEndTime() * 1000L) + "]"
};
! pool.release(rrd);
}
catch (IOException e) {
Index: DataTableModel.java
===================================================================
RCS file: /cvsroot/jrobin/src/org/jrobin/inspector/DataTableModel.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** DataTableModel.java 10 Nov 2003 08:52:28 -0000 1.2
--- DataTableModel.java 12 Nov 2003 13:24:25 -0000 1.3
***************
*** 35,38 ****
--- 35,39 ----
class DataTableModel extends AbstractTableModel {
private static final String[] COLUMN_NAMES = {"timestamp", "date", "value"};
+ private static final RrdDbPool pool = RrdDbPool.getInstance();
private File file;
***************
*** 78,82 ****
if(dsIndex >= 0 && arcIndex >= 0) {
try {
! RrdDb rrd = new RrdDb(file.getAbsolutePath());
Archive arc = rrd.getArchive(arcIndex);
Robin robin = arc.getRobin(dsIndex);
--- 79,83 ----
if(dsIndex >= 0 && arcIndex >= 0) {
try {
! RrdDb rrd = pool.requestRrdDb(file.getAbsolutePath());
Archive arc = rrd.getArchive(arcIndex);
Robin robin = arc.getRobin(dsIndex);
***************
*** 93,97 ****
};
}
! rrd.close();
}
catch (IOException e) {
--- 94,98 ----
};
}
! pool.release(rrd);
}
catch (IOException e) {
Index: DatasourceTableModel.java
===================================================================
RCS file: /cvsroot/jrobin/src/org/jrobin/inspector/DatasourceTableModel.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** DatasourceTableModel.java 10 Nov 2003 08:52:28 -0000 1.2
--- DatasourceTableModel.java 12 Nov 2003 13:24:25 -0000 1.3
***************
*** 28,31 ****
--- 28,32 ----
import org.jrobin.core.Datasource;
import org.jrobin.core.RrdException;
+ import org.jrobin.core.RrdDbPool;
import javax.swing.table.AbstractTableModel;
***************
*** 37,40 ****
--- 38,42 ----
"max value", "last value", "accum. value", "NaN seconds"};
private static final String[] COLUMN_NAMES = {"description", "value"};
+ private static final RrdDbPool pool = RrdDbPool.getInstance();
private File file;
***************
*** 82,86 ****
if(dsIndex >= 0) {
try {
! RrdDb rrd = new RrdDb(file.getAbsolutePath());
Datasource ds = rrd.getDatasource(dsIndex);
values = new Object[]{
--- 84,88 ----
if(dsIndex >= 0) {
try {
! RrdDb rrd = pool.requestRrdDb(file.getAbsolutePath());
Datasource ds = rrd.getDatasource(dsIndex);
values = new Object[]{
***************
*** 94,98 ****
"" + ds.getNanSeconds()
};
! rrd.close();
}
catch (IOException e) {
--- 96,100 ----
"" + ds.getNanSeconds()
};
! pool.release(rrd);
}
catch (IOException e) {
Index: HeaderTableModel.java
===================================================================
RCS file: /cvsroot/jrobin/src/org/jrobin/inspector/HeaderTableModel.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** HeaderTableModel.java 10 Nov 2003 08:52:28 -0000 1.2
--- HeaderTableModel.java 12 Nov 2003 13:24:25 -0000 1.3
***************
*** 29,32 ****
--- 29,33 ----
import org.jrobin.core.Header;
import org.jrobin.core.RrdException;
+ import org.jrobin.core.RrdDbPool;
import javax.swing.table.AbstractTableModel;
***************
*** 39,42 ****
--- 40,44 ----
"datasources", "archives", "size"};
private static final String[] COLUMN_NAMES = {"description", "value"};
+ private static final RrdDbPool pool = RrdDbPool.getInstance();
private File file;
***************
*** 76,80 ****
values = null;
String path = file.getAbsolutePath();
! RrdDb rrd = new RrdDb(path);
Header header = rrd.getHeader();
String signature = header.getSignature();
--- 78,82 ----
values = null;
String path = file.getAbsolutePath();
! RrdDb rrd = pool.requestRrdDb(path);
Header header = rrd.getHeader();
String signature = header.getSignature();
***************
*** 85,89 ****
String archives = "" + header.getArcCount();
String size = rrd.getRrdFile().getFileSize() + " bytes";
! rrd.close();
values = new Object[] {
path, signature, step, lastTimestamp, datasources, archives, size
--- 87,91 ----
String archives = "" + header.getArcCount();
String size = rrd.getRrdFile().getFileSize() + " bytes";
! pool.release(rrd);
values = new Object[] {
path, signature, step, lastTimestamp, datasources, archives, size
Index: MainTreeModel.java
===================================================================
RCS file: /cvsroot/jrobin/src/org/jrobin/inspector/MainTreeModel.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** MainTreeModel.java 10 Nov 2003 08:52:28 -0000 1.2
--- MainTreeModel.java 12 Nov 2003 13:24:25 -0000 1.3
***************
*** 28,31 ****
--- 28,32 ----
import org.jrobin.core.RrdDb;
import org.jrobin.core.RrdException;
+ import org.jrobin.core.RrdDbPool;
import javax.swing.tree.DefaultTreeModel;
***************
*** 37,40 ****
--- 38,42 ----
private static final DefaultMutableTreeNode INVALID_NODE =
new DefaultMutableTreeNode("No valid RRD file specified");
+ private static final RrdDbPool pool = RrdDbPool.getInstance();
private File file;
***************
*** 48,52 ****
try {
file = newFile;
! RrdDb rrd = new RrdDb(file.getAbsolutePath());
DefaultMutableTreeNode root = new DefaultMutableTreeNode(new RrdNode(rrd));
int dsCount = rrd.getRrdDef().getDsCount();
--- 50,54 ----
try {
file = newFile;
! RrdDb rrd = pool.requestRrdDb(file.getAbsolutePath());
DefaultMutableTreeNode root = new DefaultMutableTreeNode(new RrdNode(rrd));
int dsCount = rrd.getRrdDef().getDsCount();
***************
*** 62,66 ****
root.add(dsNode);
}
! rrd.close();
setRoot(root);
}
--- 64,68 ----
root.add(dsNode);
}
! pool.release(rrd);
setRoot(root);
}
|
|
From: <sa...@us...> - 2003-11-12 10:22:34
|
Update of /cvsroot/jrobin/src/org/jrobin/core
In directory sc8-pr-cvs1:/tmp/cvs-serv5554/org/jrobin/core
Modified Files:
RrdDbPool.java
Log Message:
MRTD demo now uses RrdDbPool for maximum performance
Index: RrdDbPool.java
===================================================================
RCS file: /cvsroot/jrobin/src/org/jrobin/core/RrdDbPool.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** RrdDbPool.java 10 Nov 2003 08:52:27 -0000 1.2
--- RrdDbPool.java 12 Nov 2003 10:22:09 -0000 1.3
***************
*** 100,104 ****
* which still does not force garbage collector to run.
*/
! public static final int OPEN_FILES_DESIRED = 50;
private HashMap rrdMap = new HashMap();
--- 100,105 ----
* which still does not force garbage collector to run.
*/
! public static final int INITIAL_CAPACITY = 50;
! private static int capacity = INITIAL_CAPACITY;
private HashMap rrdMap = new HashMap();
***************
*** 216,219 ****
--- 217,224 ----
*/
public synchronized void release(RrdDb rrdDb) throws IOException, RrdException {
+ if(rrdDb == null) {
+ // we don't want NullPointerException
+ return;
+ }
RrdFile rrdFile = rrdDb.getRrdFile();
if(rrdFile == null) {
***************
*** 235,239 ****
private void gc() throws IOException {
int mapSize = rrdMap.size();
! if(mapSize <= OPEN_FILES_DESIRED) {
// nothing to do
debug("GC: no need to run");
--- 240,244 ----
private void gc() throws IOException {
int mapSize = rrdMap.size();
! if(mapSize <= capacity) {
// nothing to do
debug("GC: no need to run");
***************
*** 315,318 ****
--- 320,343 ----
}
return buff.toString();
+ }
+
+ /**
+ * Returns maximum number of internally open RRD files
+ * which still does not force garbage collector to run.
+ *
+ * @return Desired nuber of open files held in the pool.
+ */
+ public static int getCapacity() {
+ return capacity;
+ }
+
+ /**
+ * Sets maximum number of internally open RRD files
+ * which still does not force garbage collector to run.
+ *
+ * @param capacity Desired number of open files to hold in the pool
+ */
+ public static void setCapacity(int capacity) {
+ RrdDbPool.capacity = capacity;
}
|