1 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 ; 32 import java.io.IOException ; 33 import java.util.GregorianCalendar ; 34 35 40 public class ExportImportDemo 41 { 42 private static String exportRrd1 = ExportExportDemo.exportRrd1; 43 private static String exportRrd2 = ExportExportDemo.exportRrd2; 44 private static String exportCombined = Util.getJRobinDemoPath( "export-combined.xml" ); 45 private static String graphFile = Util.getJRobinDemoPath( "export-graph.png" ); 46 private static String demoResources = ""; 47 48 private static void println( String str ) { 49 System.out.println( str ); 50 } 51 52 private static void prepare( String [] args ) 53 { 54 demoResources = Util.getJRobinHomeDirectory() + "/res/demo/"; 55 } 56 57 public static void main( String [] args ) throws RrdException, IOException 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 RrdGraphDefTemplate xmlTemplate = new RrdGraphDefTemplate( new File (demoResources + "export-graphdef.xml") ); 76 77 GregorianCalendar start = new GregorianCalendar ( 2004, GregorianCalendar.JULY, 3 ); 79 GregorianCalendar end = new GregorianCalendar ( 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 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 println( ">>> Dumping combined export xml" ); 98 ExportData combinedData = graph.getExportData(); 99 combinedData.exportXml( exportCombined ); 100 println( ">>> File saved: " + exportCombined + " " + Util.getLapTime() + "\n" ); 101 102 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 |