Java Story

[ JAVA ] [ Spring ] rrd4j 그래프 그리기

WhiteDuck 2016. 4. 1. 10:58

rrdDb의 간단한 설명

http://blog.daum.net/_blog/BlogTypeView.do?blogid=0niJy&articleno=24

자세한 설명

http://www.joinc.co.kr/w/Site/RRD


1) rrd4j 라이브러리 추가 




2) 데이터 저장 

String rrdFile = "/data/" + "1_1.rrd";

File file = new File(rrdFile);


START = Util.getTimestamp( c1.getTime())-1;

final int step = 60;

final int sampling = 5;

final int row = 8640;

        

RrdDef rrdDef = new RrdDef(rrdFile, step);

rrdDef.setStartTime(START);


rrdDef.addDatasource("response_time", DsType.GAUGE, step * 7, 0, Double.NaN);  

rrdDef.addDatasource("speed", DsType.GAUGE, step * 7, 0, Double.NaN);  

rrdDef.addArchive(ConsolFun.MAX, 0.5, sampling, row); // 1 step(sampling), 



     RrdDb rrdDb = null;

          Sample sample = null;

     try {

  rrdDb = new RrdDb(rrdDef);

  sample = rrdDb.createSample();

  } catch (IOException e1) {

  System.out.println("HomeController - IOException - create");

  e1.printStackTrace();

  }

          for( info_DTO mi : list) 

          {

          long ts = Util.getTimestamp(mi.test_time);

       

          sample.setTime(ts);

          sample.setValue("response_time", mi.response_time/1024*1024); 

          sample.setValue("speed", mi.speed); 


          try

          {

          sample.update();

          }

          catch (IOException e) {

  System.out.println("HomeController - IOException - update");

  e.printStackTrace();

  }

          }

        

          try {

rrdDb.close();

   } catch (IOException e) {

 System.out.println("HomeController - IOException - close");

  e.printStackTrace();

   }




반응형