当前位置: 首页 > 工具软件 > JRobin > 使用案例 >

JRobin中rrd——xml和xml——rrd

黎同
2023-12-01
import java.io.IOException;
import org.jrobin.core.RrdDb;
import org.jrobin.core.RrdDef;
import org.jrobin.core.RrdException;




public class testXML {


/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
testXML test = new testXML();
test.transXML("D://");
//test.fromRrd("D://");
}

// 根据XML文件获取RrdDb  RrdDb rrdDb = new RrdDb("new.rrd" "old.xml"); 对应:rrdtool restore new.rrd old.xml
public void transXML(String rootPath){

        RrdDb rrdDb;
        
try {
//创建rrd

try {
rrdDb = new RrdDb(rootPath + "disk.rrd",rootPath  
       + "disk.xml");
System.out.println("[info:]" + rrdDb.getInfo() + "[path:]"  
               + rrdDb.getPath());  
       rrdDb.close();  
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
 
} catch (RrdException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}  
       
}

//根据rrd获得xml 对应:rrdtool dump test.rrd > test.xml
public void fromRrd(String rootPath){
RrdDb rrdDb;
        
try {
rrdDb = new RrdDb(rootPath + "disk.rrd");
System.out.println("[info:]" + rrdDb.getInfo() + "[path:]"  
               + rrdDb.getPath());  
rrdDb.dumpXml(rootPath+"disk.xml");
       rrdDb.close();  
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (RrdException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}  
       
}


}
 类似资料: