From: Tarus B. <ta...@us...> - 2006-12-21 18:02:52
|
Update of /cvsroot/jrobin/src/org/jrobin/demo In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv9082/org/jrobin/demo Modified Files: Demo.java MinMax.java Test.java Added Files: HeartbeatFix.java Log Message: Adding the new 1.5.4 code Index: Demo.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/demo/Demo.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** Demo.java 25 Nov 2004 12:14:54 -0000 1.5 --- Demo.java 21 Dec 2006 18:02:43 -0000 1.6 *************** *** 1,226 **** ! /* ============================================================ ! * JRobin : Pure java implementation of RRDTool's functionality ! * ============================================================ ! * ! * Project Info: http://www.jrobin.org ! * Project Lead: Sasa Markovic (sa...@jr...); ! * ! * (C) Copyright 2003, by Sasa Markovic. ! * ! * This library is free software; you can redistribute it and/or modify it under the terms ! * of the GNU Lesser General Public License as published by the Free Software Foundation; ! * either version 2.1 of the License, or (at your option) any later version. ! * ! * Developers: Sasa Markovic (sa...@jr...) ! * Arne Vandamme (cob...@jr...) ! * ! * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; ! * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. ! * See the GNU Lesser General Public License for more details. ! * ! * You should have received a copy of the GNU Lesser General Public License along with this ! * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, ! * Boston, MA 02111-1307, USA. ! */ ! ! package org.jrobin.demo; ! ! import org.jrobin.core.*; ! import org.jrobin.graph.RrdGraph; ! import org.jrobin.graph.RrdGraphDef; ! ! import java.awt.*; ! import java.io.BufferedOutputStream; ! import java.io.FileOutputStream; ! 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 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; ! ! public static void main(String[] args) throws RrdException, IOException { ! println("== Starting demo"); ! RrdDb.setLockMode(RrdDb.NO_LOCKS); ! long startMillis = System.currentTimeMillis(); ! if(args.length > 0) { ! println("Setting default backend factory to " + args[0]); ! RrdDb.setDefaultFactory(args[0]); ! } ! long start = START; ! long end = END; ! String rrdPath = Util.getJRobinDemoPath(FILE + ".rrd"); ! String xmlPath = Util.getJRobinDemoPath(FILE + ".xml"); ! String rrdRestoredPath = Util.getJRobinDemoPath(FILE + "_restored.rrd"); ! String pngPath = Util.getJRobinDemoPath(FILE + ".png"); ! String jpegPath = Util.getJRobinDemoPath(FILE + ".jpeg"); ! String gifPath = Util.getJRobinDemoPath(FILE + ".gif"); ! String logPath = Util.getJRobinDemoPath(FILE + ".log"); ! PrintWriter log = new PrintWriter( ! new BufferedOutputStream(new FileOutputStream(logPath, false)) ! ); ! ! // creation ! println("== Creating RRD file " + rrdPath); ! RrdDef rrdDef = new RrdDef(rrdPath, start - 1, 300); ! rrdDef.addDatasource("sun", "GAUGE", 600, 0, Double.NaN); ! rrdDef.addDatasource("shade", "GAUGE", 600, 0, Double.NaN); ! 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()); ! log.println(rrdDef.dump()); ! println("Estimated file size: " + rrdDef.getEstimatedSize()); ! RrdDb rrdDb = new RrdDb(rrdDef); ! println("== RRD file created."); ! if(rrdDb.getRrdDef().equals(rrdDef)) { ! println("Checking RRD file structure... OK"); ! } ! else { ! println("Invalid RRD file created. This is a serious bug, bailing out"); ! return; ! } ! rrdDb.close(); ! println("== RRD file closed."); ! ! // 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; ! rrdDb = new RrdDb(rrdPath); ! Sample sample = rrdDb.createSample(); ! while(t <= end + 86400L) { ! //rrdDb = new RrdDb(rrdPath); ! //Sample sample = rrdDb.createSample(); ! sample.setTime(t); ! sample.setValue("sun", sunSource.getValue()); ! sample.setValue("shade", shadeSource.getValue()); ! log.println(sample.dump()); ! sample.update(); ! t += RANDOM.nextDouble() * MAX_STEP + 1; ! if(((++n) % 1000) == 0) { ! System.out.print("*"); ! }; ! //rrdDb.close(); ! } ! println(""); ! println("== Finished. RRD file updated " + n + " times"); ! println("== Last update time was: " + rrdDb.getLastUpdateTime()); ! rrdDb.close(); ! ! // test read-only access! ! rrdDb = new RrdDb(rrdPath, true); ! println("File reopen in read-only mode"); ! ! // fetch data ! println("== Fetching data for the whole month"); ! FetchRequest request = rrdDb.createFetchRequest("AVERAGE", start, end); ! println(request.dump()); ! log.println(request.dump()); ! FetchData fetchData = request.fetchData(); ! println("== Data fetched. " + fetchData.getRowCount() + " points obtained"); ! println(fetchData.toString()); ! println("== Dumping fetched data to XML format"); ! println(fetchData.exportXml()); ! println("== Fetch completed"); ! ! // dump to XML file ! println("== Dumping RRD file to XML file " + xmlPath + " (can be restored with RRDTool)"); ! rrdDb.exportXml(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(); ! println("== First file closed"); ! rrdRestoredDb.close(); ! println("== Second file closed"); ! ! // create graph ! println("== Creating graph from the second file"); ! RrdGraphDef gDef = new RrdGraphDef(); ! gDef.setTimePeriod(start, end); ! gDef.setTitle("Temperatures in May 2003"); ! gDef.setVerticalLabel("temperature"); ! gDef.datasource("sun", rrdRestoredPath, "sun", "AVERAGE"); ! gDef.datasource("shade", rrdRestoredPath, "shade", "AVERAGE"); ! gDef.datasource("median", "sun,shade,+,2,/"); ! gDef.datasource("diff", "sun,shade,-,ABS,-1,*"); ! gDef.datasource("sine", "TIME," + start + ",-," + (end - start) + ! ",/,2,PI,*,*,SIN,1000,*"); ! gDef.line("sun", Color.GREEN, "sun temp"); ! gDef.line("shade", Color.BLUE, "shade temp"); ! gDef.line("median", Color.MAGENTA, "median value@L"); ! gDef.area("diff", Color.YELLOW, "difference@r"); ! gDef.line("diff", Color.RED, null); ! gDef.line("sine", Color.CYAN, "sine function demo@L"); ! gDef.gprint("sun", "MAX", "maxSun = @3@s"); ! gDef.gprint("sun", "AVERAGE", "avgSun = @3@S@r"); ! gDef.gprint("shade", "MAX", "maxShade = @3@S"); ! gDef.gprint("shade", "AVERAGE", "avgShade = @3@S@r"); ! // create graph finally ! RrdGraph graph = new RrdGraph(gDef); ! println("== Graph created"); ! graph.saveAsPNG(pngPath, 400, 250); ! println("== Graph saved as a PNG file " + pngPath); ! graph.saveAsJPEG(jpegPath, 400, 250, 0.5F); ! println("== Graph saved as a JPEG file " + jpegPath); ! graph.saveAsGIF(gifPath, 400, 250); ! println("== Graph saved as a GIF file " + gifPath); ! ! // demo ends ! log.close(); ! println("== Demo completed in " + ! ((System.currentTimeMillis() - startMillis) / 1000.0) + " sec"); ! } ! ! static void println(String msg) { ! //System.out.println(msg + " " + Util.getLapTime()); ! System.out.println(msg); ! } ! ! static void print(String msg) { ! System.out.print(msg); ! } ! ! static class GaugeSource { ! private double value; ! private double step; ! ! GaugeSource(double value, double step) { ! this.value = value; ! this.step = step; ! } ! ! long getValue() { ! double oldValue = value; ! double increment = RANDOM.nextDouble() * step; ! if(RANDOM.nextDouble() > 0.5) { ! increment *= -1; ! } ! value += increment; ! if(value <= 0) { ! value = 0; ! } ! return Math.round(oldValue); ! } ! } ! } ! ! ! ! --- 1,251 ---- ! /* ============================================================ ! * JRobin : Pure java implementation of RRDTool's functionality ! * ============================================================ ! * ! * Project Info: http://www.jrobin.org ! * Project Lead: Sasa Markovic (sa...@jr...); ! * ! * (C) Copyright 2003-2005, by Sasa Markovic. ! * ! * This library is free software; you can redistribute it and/or modify it under the terms ! * of the GNU Lesser General Public License as published by the Free Software Foundation; ! * either version 2.1 of the License, or (at your option) any later version. ! * ! * Developers: Sasa Markovic (sa...@jr...) ! * ! * ! * 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.demo; ! ! import org.jrobin.core.*; ! import org.jrobin.graph.RrdGraph; ! import org.jrobin.graph.RrdGraphDef; ! ! import java.awt.*; ! import java.io.BufferedOutputStream; ! import java.io.FileOutputStream; ! import java.io.IOException; ! import java.io.PrintWriter; ! import java.util.Random; ! ! /** ! * Simple demo just to check that everything is OK with this library. Creates two files in your ! * $HOME/jrobin-demo directory: demo.rrd and demo.png. ! */ ! public class Demo { ! static final long SEED = 1909752002L; ! static final Random RANDOM = new Random(SEED); ! 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; ! ! static final int IMG_WIDTH = 500; ! static final int IMG_HEIGHT = 300; ! ! /** ! * <p>To start the demo, use the following command:</p> ! * <pre> ! * java -cp jrobin-{version}.jar org.jrobin.demo.Demo ! * </pre> ! * ! * @param args the name of the backend factory to use (optional) ! * @throws RrdException Thrown in case of JRobin specific error ! * @throws IOException Thrown ! */ ! public static void main(String[] args) throws RrdException, IOException { ! println("== Starting demo"); ! long startMillis = System.currentTimeMillis(); ! if (args.length > 0) { ! println("Setting default backend factory to " + args[0]); ! RrdDb.setDefaultFactory(args[0]); ! } ! long start = START; ! long end = END; ! String rrdPath = Util.getJRobinDemoPath(FILE + ".rrd"); ! String xmlPath = Util.getJRobinDemoPath(FILE + ".xml"); ! String rrdRestoredPath = Util.getJRobinDemoPath(FILE + "_restored.rrd"); ! String imgPath = Util.getJRobinDemoPath(FILE + ".png"); ! String logPath = Util.getJRobinDemoPath(FILE + ".log"); ! PrintWriter log = new PrintWriter(new BufferedOutputStream(new FileOutputStream(logPath, false))); ! // creation ! println("== Creating RRD file " + rrdPath); ! RrdDef rrdDef = new RrdDef(rrdPath, start - 1, 300); ! rrdDef.addDatasource("sun", "GAUGE", 600, 0, Double.NaN); ! rrdDef.addDatasource("shade", "GAUGE", 600, 0, Double.NaN); ! 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()); ! log.println(rrdDef.dump()); ! println("Estimated file size: " + rrdDef.getEstimatedSize()); ! RrdDb rrdDb = new RrdDb(rrdDef); ! println("== RRD file created."); ! if (rrdDb.getRrdDef().equals(rrdDef)) { ! println("Checking RRD file structure... OK"); ! } ! else { ! println("Invalid RRD file created. This is a serious bug, bailing out"); ! return; ! } ! rrdDb.close(); ! println("== RRD file closed."); ! ! // 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; ! //rrdDb = new RrdDb(rrdPath); ! //Sample sample = rrdDb.createSample(); ! while (t <= end + 86400L) { ! rrdDb = new RrdDb(rrdPath); ! rrdDb.setInfo("T=" + t); ! Sample sample = rrdDb.createSample(); ! sample.setTime(t); ! sample.setValue("sun", sunSource.getValue()); ! sample.setValue("shade", shadeSource.getValue()); ! log.println(sample.dump()); ! sample.update(); ! t += RANDOM.nextDouble() * MAX_STEP + 1; ! if (((++n) % 1000) == 0) { ! System.out.print("*"); ! } ! rrdDb.close(); ! } ! println(""); ! println("== Finished. RRD file updated " + n + " times"); ! //rrdDb.close(); ! ! // test read-only access! ! rrdDb = new RrdDb(rrdPath, true); ! println("File reopen in read-only mode"); ! println("== Last update time was: " + rrdDb.getLastUpdateTime()); ! println("== Last info was: " + rrdDb.getInfo()); ! ! // fetch data ! println("== Fetching data for the whole month"); ! FetchRequest request = rrdDb.createFetchRequest("AVERAGE", start, end); ! println(request.dump()); ! log.println(request.dump()); ! FetchData fetchData = request.fetchData(); ! println("== Data fetched. " + fetchData.getRowCount() + " points obtained"); ! println(fetchData.toString()); ! println("== Dumping fetched data to XML format"); ! println(fetchData.exportXml()); ! println("== Fetch completed"); ! ! // dump to XML file ! println("== Dumping RRD file to XML file " + xmlPath + " (can be restored with RRDTool)"); ! rrdDb.exportXml(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(); ! println("== First file closed"); ! rrdRestoredDb.close(); ! println("== Second file closed"); ! ! // create graph ! println("Creating graph " + Util.getLapTime()); ! println("== Creating graph from the second file"); ! RrdGraphDef gDef = new RrdGraphDef(); ! gDef.setWidth(IMG_WIDTH); ! gDef.setHeight(IMG_HEIGHT); ! gDef.setFilename(imgPath); ! gDef.setStartTime(start); ! gDef.setEndTime(end); ! gDef.setTitle("Temperatures in May 2003"); ! gDef.setVerticalLabel("temperature"); ! gDef.datasource("sun", rrdRestoredPath, "sun", "AVERAGE"); ! gDef.datasource("shade", rrdRestoredPath, "shade", "AVERAGE"); ! gDef.datasource("median", "sun,shade,+,2,/"); ! gDef.datasource("diff", "sun,shade,-,ABS,-1,*"); ! gDef.datasource("sine", "TIME," + start + ",-," + (end - start) + ! ",/,2,PI,*,*,SIN,1000,*"); ! gDef.line("sun", Color.GREEN, "sun temp"); ! gDef.line("shade", Color.BLUE, "shade temp"); ! gDef.line("median", Color.MAGENTA, "median value"); ! gDef.area("diff", Color.YELLOW, "difference\\r"); ! gDef.line("diff", Color.RED, null); ! gDef.line("sine", Color.CYAN, "sine function demo\\r"); ! gDef.hrule(2568, Color.GREEN, "hrule"); ! gDef.vrule((start + 2 * end) / 3, Color.MAGENTA, "vrule\\r"); ! gDef.gprint("sun", "MAX", "maxSun = %.3f%s"); ! gDef.gprint("sun", "AVERAGE", "avgSun = %.3f%S\\r"); ! gDef.gprint("shade", "MAX", "maxShade = %.3f%S"); ! gDef.gprint("shade", "AVERAGE", "avgShade = %.3f%S\\r"); ! gDef.print("sun", "MAX", "maxSun = %.3f%s"); ! gDef.print("sun", "AVERAGE", "avgSun = %.3f%S\\r"); ! gDef.print("shade", "MAX", "maxShade = %.3f%S"); ! gDef.print("shade", "AVERAGE", "avgShade = %.3f%S\\r"); ! gDef.setImageInfo("<img src='%s' width='%d' height = '%d'>"); ! gDef.setPoolUsed(false); ! gDef.setImageFormat("png"); ! // create graph finally ! RrdGraph graph = new RrdGraph(gDef); ! println(graph.getRrdGraphInfo().dump()); ! println("== Graph created " + Util.getLapTime()); ! // locks info ! println("== Locks info =="); ! println(RrdSafeFileBackend.getLockInfo()); ! // demo ends ! log.close(); ! println("== Demo completed in " + ! ((System.currentTimeMillis() - startMillis) / 1000.0) + " sec"); ! } ! ! static void println(String msg) { ! //System.out.println(msg + " " + Util.getLapTime()); ! System.out.println(msg); ! } ! ! static void print(String msg) { ! System.out.print(msg); ! } ! ! static class GaugeSource { ! private double value; ! private double step; ! ! GaugeSource(double value, double step) { ! this.value = value; ! this.step = step; ! } ! ! long getValue() { ! double oldValue = value; ! double increment = RANDOM.nextDouble() * step; ! if (RANDOM.nextDouble() > 0.5) { ! increment *= -1; ! } ! value += increment; ! if (value <= 0) { ! value = 0; ! } ! return Math.round(oldValue); ! } ! } ! } ! ! ! ! Index: Test.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/demo/Test.java,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** Test.java 6 Sep 2005 20:40:55 -0000 1.1.1.1 --- Test.java 21 Dec 2006 18:02:43 -0000 1.2 *************** *** 1,15 **** package org.jrobin.demo; ! import org.jrobin.core.RrdToolkit; ! import org.jrobin.core.RrdException; ! import java.io.IOException; class Test { ! public static void main(String[] args) throws IOException, RrdException { ! String dir = "."; ! String[] list = RrdToolkit.getCanonicalPaths(dir, ".rrd", false); ! for (String path : list) { ! System.out.println(path); } } --- 1,28 ---- package org.jrobin.demo; ! import java.io.FileReader; ! import java.io.BufferedReader; import java.io.IOException; + class Test { ! public static final String LOADAVG_FILE = "/proc/loadavg"; ! ! public static void main(String[] args) throws IOException { ! BufferedReader r = new BufferedReader(new FileReader(LOADAVG_FILE)); ! try { ! String line = r.readLine(); ! if (line != null) { ! String[] loads = line.split("\\s+"); ! if (loads.length >= 3) { ! String load = loads[0] + " " + loads[1] + " " + loads[2]; ! System.out.println("LOAD = " + load); ! return; ! } ! System.out.println("Unexpected error while parsing file " + LOADAVG_FILE); ! } ! } ! finally { ! r.close(); } } --- NEW FILE: HeartbeatFix.java --- package org.jrobin.demo; import org.jrobin.core.RrdToolkit; import org.jrobin.core.RrdException; import org.jrobin.core.RrdDb; import java.io.FileFilter; import java.io.File; import java.io.IOException; public class HeartbeatFix { public static void main(String[] args) throws IOException, RrdException { if (args.length != 2) { System.err.println("SYNTAX: HeartbeatFix <rrd directory> <heartbeat>"); System.exit(-1); } File directory = new File(args[0]); long heartbeat = Long.parseLong(args[1]); File[] files = directory.listFiles(new FileFilter() { public boolean accept(File pathname) { return pathname.isFile() && pathname.getName().endsWith(".rrd.jrb"); } }); System.out.println(files.length + " files found"); for (int i = 0; i < files.length; i++) { String path = files[i].getAbsolutePath(); System.out.print((i + 1) + ": " + path + ": "); // fix heartbeat RrdToolkit.setDsHeartbeat(files[i].getAbsolutePath(), 0, heartbeat); RrdToolkit.setDsHeartbeat(files[i].getAbsolutePath(), 1, heartbeat); System.out.print("fixed"); // check consistency of the file RrdDb rrd = new RrdDb(path); if (rrd.getRrdDef().getEstimatedSize() == files[i].length() && rrd.getDatasource(0).getHeartbeat() == heartbeat && rrd.getDatasource(1).getHeartbeat() == heartbeat) { System.out.println(", verified"); } else { System.out.println(", ********** ERROR **********"); } rrd.close(); } System.out.println("FINISHED!"); } } Index: MinMax.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/demo/MinMax.java,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** MinMax.java 6 Sep 2005 20:40:55 -0000 1.1.1.1 --- MinMax.java 21 Dec 2006 18:02:43 -0000 1.2 *************** *** 3,42 **** import org.jrobin.core.*; import org.jrobin.graph.*; import java.io.*; import java.awt.*; class MinMax { ! public static void main(String[] args) throws RrdException, IOException { ! long start = Util.getTime(), end = start + 300 * 300; ! String rrdFile = Util.getJRobinDemoPath("minmax.rrd"); String pngFile = Util.getJRobinDemoPath("minmax.png"); ! // create ! RrdDef rrdDef = new RrdDef(rrdFile, start - 1, 300); ! rrdDef.addDatasource("a", "GAUGE", 600, Double.NaN, Double.NaN); ! rrdDef.addArchive("AVERAGE", 0.5, 1, 300); ! rrdDef.addArchive("MIN", 0.5, 12, 300); ! rrdDef.addArchive("MAX", 0.5, 12, 300); ! RrdDb rrdDb = new RrdDb(rrdDef); ! // update ! for(long t = start; t < end; t += 300) { ! Sample sample = rrdDb.createSample(t); ! sample.setValue("a", Math.sin(t / 3000.0) * 50 + 50); ! sample.update(); ! } ! // graph ! RrdGraphDef gDef = new RrdGraphDef(); gDef.setFilename(pngFile); gDef.setWidth(450); gDef.setHeight(250); gDef.setImageFormat("png"); ! gDef.setTimeSpan(start, start + 86400); ! gDef.setTitle("RRDTool's MINMAX.pl demo"); ! gDef.datasource("a", rrdFile, "a", "AVERAGE"); ! gDef.datasource("b", rrdFile, "a", "MIN"); ! gDef.datasource("c", rrdFile, "a", "MAX"); ! gDef.area("a", Color.decode("0xb6e4"), "real"); ! gDef.line("b", Color.decode("0x22e9"), "min"); ! gDef.line("c", Color.decode("0xee22"), "max"); ! new RrdGraph(gDef); ! } } \ No newline at end of file --- 3,43 ---- import org.jrobin.core.*; import org.jrobin.graph.*; + import java.io.*; import java.awt.*; class MinMax { ! public static void main(String[] args) throws RrdException, IOException { ! long start = Util.getTime(), end = start + 300 * 300; ! String rrdFile = Util.getJRobinDemoPath("minmax.rrd"); String pngFile = Util.getJRobinDemoPath("minmax.png"); ! // create ! RrdDef rrdDef = new RrdDef(rrdFile, start - 1, 300); ! rrdDef.addDatasource("a", "GAUGE", 600, Double.NaN, Double.NaN); ! rrdDef.addArchive("AVERAGE", 0.5, 1, 300); ! rrdDef.addArchive("MIN", 0.5, 12, 300); ! rrdDef.addArchive("MAX", 0.5, 12, 300); ! RrdDb rrdDb = new RrdDb(rrdDef); ! // update ! for (long t = start; t < end; t += 300) { ! Sample sample = rrdDb.createSample(t); ! sample.setValue("a", Math.sin(t / 3000.0) * 50 + 50); ! sample.update(); ! } ! // graph ! RrdGraphDef gDef = new RrdGraphDef(); gDef.setFilename(pngFile); gDef.setWidth(450); gDef.setHeight(250); gDef.setImageFormat("png"); ! gDef.setTimeSpan(start, start + 86400); ! gDef.setTitle("RRDTool's MINMAX.pl demo"); ! gDef.datasource("a", rrdFile, "a", "AVERAGE"); ! gDef.datasource("b", rrdFile, "a", "MIN"); ! gDef.datasource("c", rrdFile, "a", "MAX"); ! gDef.area("a", Color.decode("0xb6e4"), "real"); ! gDef.line("b", Color.decode("0x22e9"), "min"); ! gDef.line("c", Color.decode("0xee22"), "max"); ! new RrdGraph(gDef); ! } } \ No newline at end of file |