1 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 ; 35 import java.io.File ; 36 import java.util.GregorianCalendar ; 37 38 43 public class ExportExportDemo 44 { 45 public static String exportRrd1 = Util.getJRobinDemoPath( "export-eth0.xml" ); 46 public static String exportRrd2 = Util.getJRobinDemoPath( "export-eth1.xml" ); 47 private static String demoResources = ""; 48 49 private static void println( String str ) { 50 System.out.println( str ); 51 } 52 53 private static void prepare( String [] args ) 54 { 55 demoResources = Util.getJRobinHomeDirectory() + "/res/demo/"; 56 } 57 58 public static void main( String [] args ) throws RrdException, IOException 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 println( ">>> Reading export def template\n" ); 76 RrdExportDefTemplate xmlTemplate = new RrdExportDefTemplate( new File (demoResources + "exportdef.xml") ); 77 78 GregorianCalendar start = new GregorianCalendar ( 2004, GregorianCalendar.JULY, 3 ); 80 GregorianCalendar end = new GregorianCalendar ( 2004, GregorianCalendar.JULY, 4 ); 81 82 xmlTemplate.setVariable( "start", start ); 83 xmlTemplate.setVariable( "end", end ); 84 85 Util.getLapTime(); 86 87 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 ExportData dataFromRrd1 = export.fetch(); 96 97 dataFromRrd1.exportXml( exportRrd1 ); 99 println( ">>> File saved: " + exportRrd1 + " " + Util.getLapTime() + "\n" ); 100 101 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 ExportData dataFromRrd2 = export.fetch( 20 ); 112 113 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 |