KickJava   Java API By Example, From Geeks To Geeks.

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


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.core.Util;
28 import org.jrobin.core.RrdException;
29 import org.jrobin.graph.*;
30
31 import java.io.File JavaDoc;
32 import java.io.IOException JavaDoc;
33 import java.util.GregorianCalendar JavaDoc;
34
35 /**
36  * <p>This is a small demo that creates a graph based on the export XML from the ExportExportDemo.</p>
37  *
38  * @author Arne Vandamme (cobralord@jrobin.org)
39  */

40 public class ExportImportDemo
41 {
42     private static String JavaDoc exportRrd1 = ExportExportDemo.exportRrd1;
43     private static String JavaDoc exportRrd2 = ExportExportDemo.exportRrd2;
44     private static String JavaDoc exportCombined = Util.getJRobinDemoPath( "export-combined.xml" );
45     private static String JavaDoc graphFile = Util.getJRobinDemoPath( "export-graph.png" );
46     private static String JavaDoc demoResources = "";
47
48     private static void println( String JavaDoc str ) {
49         System.out.println( str );
50     }
51
52     private static void prepare( String JavaDoc[] args )
53     {
54         demoResources = Util.getJRobinHomeDirectory() + "/res/demo/";
55     }
56
57     public static void main( String JavaDoc[] args ) throws RrdException, IOException JavaDoc
58     {
59         prepare( args );
60
61         println( "+-----------------------------------------------------------------------------------+" );
62         println( "| JRobin ExportImportDemo |" );
63         println( "| |" );
64         println( "| This demo supposes the ExportExportDemo has been run and the necessary data has |" );
65         println( "| been exported to the jrobin-demo directory. The ExportImportDemo creates a graph |" );
66         println( "| containing the data from the separate export XML files, the configuration of the |" );
67         println( "| graph is in the RrdGraphDef xml file in the directory passed as argument on the |" );
68         println( "| command line. |" );
69         println( "| |" );
70         println( "+-----------------------------------------------------------------------------------+" );
71
72         long execStart = System.currentTimeMillis();
73
74         // -- Read in the graph def xml
75
RrdGraphDefTemplate xmlTemplate = new RrdGraphDefTemplate( new File JavaDoc(demoResources + "export-graphdef.xml") );
76
77         // -- The data we're interested in is from the 3rd of july 2004, to the 4th
78
GregorianCalendar JavaDoc start = new GregorianCalendar JavaDoc( 2004, GregorianCalendar.JULY, 3 );
79         GregorianCalendar JavaDoc end = new GregorianCalendar JavaDoc( 2004, GregorianCalendar.JULY, 4 );
80
81         xmlTemplate.setVariable( "start", start );
82         xmlTemplate.setVariable( "end", end );
83         xmlTemplate.setVariable( "export1", exportRrd1 );
84         xmlTemplate.setVariable( "export2", exportRrd2 );
85
86         Util.getLapTime();
87
88         // -- Create the graph
89
println( ">>> Creating graph image from XML graph def" );
90         RrdGraphDef graphDef = xmlTemplate.getRrdGraphDef();
91
92         RrdGraph graph = new RrdGraph( graphDef );
93         graph.saveAsPNG( graphFile );
94         println( ">>> File saved: " + graphFile + " " + Util.getLapTime() + "\n" );
95
96         // -- Dump the combined export
97
println( ">>> Dumping combined export xml" );
98         ExportData combinedData = graph.getExportData();
99         combinedData.exportXml( exportCombined );
100         println( ">>> File saved: " + exportCombined + " " + Util.getLapTime() + "\n" );
101
102         // -- Print out information
103
println( ">>> Retrieving AVERAGE outoing traffic from combined export" );
104         println( combinedData.print( "eth0-2", "AVERAGE", " From eth0 data: @5.2 @sbit/s" ) );
105         println( combinedData.print( "eth1-2", "AVERAGE", " From eth1 data: @5.2 @sbit/s" ) );
106
107         long execStop = System.currentTimeMillis();
108
109         println( "\n>>> Demo finished in " + (execStop - execStart) + " milliseconds" );
110     }
111 }
112
Popular Tags