现在的位置: 首页 > 综合 > 正文

JRobin中rrd——xml和xml——rrd

2013年10月06日 ⁄ 综合 ⁄ 共 1181字 ⁄ 字号 评论关闭

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();
}  
       
}

}

抱歉!评论已关闭.