|
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;
|