KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jrobin > demo > graph > ExportExportDemo


1 /* ============================================================
2  * JRobin : Pure java implementation of RRDTool's functionality
3  * ============================================================
4  *
5  * Project Info: http://www.jrobin.org
6  * Project Lead: Sasa Markovic (saxon@jrobin.org);
7  *
8  * (C) Copyright 2003, by Sasa Markovic.
9  *
10  * Developers: Sasa Markovic (saxon@jrobin.org)
11  * Arne Vandamme (cobralord@jrobin.org)
12  *
13  * This library is free software; you can redistribute it and/or modify it under the terms
14  * of the GNU Lesser General Public License as published by the Free Software Foundation;
15  * either version 2.1 of the License, or (at your option) any later version.
16  *
17  * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
18  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
19  * See the GNU Lesser General Public License for more details.
20  *
21  * You should have received a copy of the GNU Lesser General Public License along with this
22  * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
23  * Boston, MA 02111-1307, USA.
24  */

25 package org.jrobin.demo.graph;
26
27 import org.jrobin.graph.RrdExportDef;
28 import org.jrobin.graph.RrdExportDefTemplate;
29 import org.jrobin.graph.RrdExport;
30 import org.jrobin.graph.ExportData;
31 import org.jrobin.core.RrdException;
32 import org.jrobin.core.Util;
33
34 import java.io.IOException JavaDoc;
35 import java.io.File JavaDoc;
36 import java.util.GregorianCalendar JavaDoc;
37
38 /**
39  * <p>This is a small demo that illustrates JRobin export functionality.</p>
40  *
41  * @author Arne Vandamme (cobralord@jrobin.org)
42  */

43 public class ExportExportDemo
44 {
45     public static String JavaDoc exportRrd1 = Util.getJRobinDemoPath( "export-eth0.xml" );
46     public static String JavaDoc exportRrd2 = Util.getJRobinDemoPath( "export-eth1.xml" );
47     private static String JavaDoc demoResources = "";
48
49     private static void println( String JavaDoc str ) {
50         System.out.println( str );
51     }
52
53     private static void prepare( String JavaDoc[] args )
54     {
55         demoResources = Util.getJRobinHomeDirectory() + "/res/demo/";
56     }
57
58     public static void main( String JavaDoc[] args ) throws RrdException, IOException JavaDoc
59     {
60         prepare( args );
61
62         println( "+----------------------------------------------------------------------------------+" );
63         println( "| JRobin ExportExportDemo |" );
64         println( "| |" );
65         println( "| This demo will perform the same export on two different rrd files. In fact the |" );
66         println( "| two RRD files contain the same data, they are data from a network interface and |" );
67         println( "| contain a full days worth of samples on July 3rd 2004. For this example the RRD |" );
68         println( "| are treated as if from two different interfaces: eth0 and eth1. |" );
69         println( "| |" );
70         println( "+----------------------------------------------------------------------------------+" );
71
72         long execStart = System.currentTimeMillis();
73
74         // -- Read in the export def xml
75
println( ">>> Reading export def template\n" );
76         RrdExportDefTemplate xmlTemplate = new RrdExportDefTemplate( new File JavaDoc(demoResources + "exportdef.xml") );
77
78         // -- The data we're interested in is from the 3rd of july 2004, to the 4th
79
GregorianCalendar JavaDoc start = new GregorianCalendar JavaDoc( 2004, GregorianCalendar.JULY, 3 );
80         GregorianCalendar JavaDoc end = new GregorianCalendar JavaDoc( 2004, GregorianCalendar.JULY, 4 );
81
82         xmlTemplate.setVariable( "start", start );
83         xmlTemplate.setVariable( "end", end );
84
85         Util.getLapTime();
86
87         // -- Exporting the first rrd
88
println( ">>> Exporting data from eth0 for July 3rd, 2004" );
89         println( ">>> Number of rows for the export is limited to 400." );
90         xmlTemplate.setVariable( "rrd", demoResources + "eth0.rrd" );
91         RrdExportDef exportDef = xmlTemplate.getRrdExportDef();
92         RrdExport export = new RrdExport( exportDef );
93
94         // We don't limit the number of rows returned, this will try to auto limit on 400 max
95
ExportData dataFromRrd1 = export.fetch();
96
97         // Save the exported data to export xml
98
dataFromRrd1.exportXml( exportRrd1 );
99         println( ">>> File saved: " + exportRrd1 + " " + Util.getLapTime() + "\n" );
100
101         // -- Exporting the second rrd
102
println( ">>> Exporting data from eth1 for July 3rd, 2004" );
103         println( ">>> Number of rows for the export is limited to 20." );
104         println( " This means the same data as in the previous export (since in fact" );
105         println( " both RRD files are the same) will be aggregated to around 20 rows." );
106         xmlTemplate.setVariable( "rrd", demoResources + "eth1.rrd" );
107         exportDef = xmlTemplate.getRrdExportDef();
108         export.setExportDef( exportDef );
109
110         // Now we limit the number of rows retrieved to 20
111
ExportData dataFromRrd2 = export.fetch( 20 );
112
113         // Save the exported data to export xml
114
dataFromRrd2.exportXml( exportRrd2 );
115         println( ">>> File saved: " + exportRrd2 + " " + Util.getLapTime() + "\n" );
116
117         long execStop = System.currentTimeMillis();
118
119         println( ">>> Demo finished in " + (execStop - execStart) + " milliseconds" );
120     }
121 }
122
Popular Tags