<%@ page import="java.io.*, java.util.*, java.text.*"%>
<%@ include file="/sys/include/doctype.jsp" %>
<%@ page contentType="text/html; charset=euc-kr"%>
<html>
<head>
<title>▶System◀</title>
<%!
  private int period = -1; // 현재부터 한달전 로그만 보여주기
  private int getCalcWidth(String width) {
    int cWidth = Integer.parseInt(width);
    cWidth = period==-1?cWidth*4:cWidth;
    cWidth = period==-2?cWidth*2:cWidth;
    return cWidth;
  }
  private int getCalcImgWidth() {
    int cWidth = 1;
    if (period==-1) {
      cWidth = 4;
    } else if (period==-2) {
      cWidth = 2;
    }
    return cWidth;
  }
%>
<!-----------------------------------------------------------------------------
  J A V A   S C R I P T   D E C L A R A T I O N
------------------------------------------------------------------------------>
<script language="javascript">
  function f_OnLoad() {
    obj = document.getElementsByName("cb");
    obj[0].checked = <%=(request.getParameter("cb0")==null ? "true"  : request.getParameter("cb0"))%>;
    obj[1].checked = <%=(request.getParameter("cb1")==null ? "true"  : request.getParameter("cb1"))%>;
    obj[2].checked = <%=(request.getParameter("cb2")==null ? "false" : request.getParameter("cb2"))%>;
    obj[3].checked = <%=(request.getParameter("cb3")==null ? "false" : request.getParameter("cb3"))%>;
    obj[4].checked = <%=(request.getParameter("cb4")==null ? "false" : request.getParameter("cb4"))%>;
    obj[5].checked = <%=(request.getParameter("cb5")==null ? "false" : request.getParameter("cb5"))%>;
    ed_stDate.Text='<%=(request.getParameter("stDate")==null ? ssy.framework.support.util.DateUtil.addMonths(ssy.framework.support.util.DateUtil.getSysdate(),period) :request.getParameter("stDate"))%>';
    ed_edDate.Text='<%=(request.getParameter("edDate")==null ? ssy.framework.support.util.DateUtil.getSysdate() :request.getParameter("edDate"))%>';
   
    var obj = document.getElementsByName("cb")
    for (var i=0 ; i<obj.length ; i++) {
      if (i==0) {
        cb0 = obj[i].checked;
      } else if (i==1) {
        cb1 = obj[i].checked;
      } else if (i==2) {
        cb2 = obj[i].checked;
      } else if (i==3) {
        cb3 = obj[i].checked;
      } else if (i==4) {
        cb4 = obj[i].checked;
      } else if (i==5) {
        cb5 = obj[i].checked;
      }
    }
  }
  //-------------------------------------------------------------------------
  // 검색
  //-------------------------------------------------------------------------
  function f_Retrieve() {
    if (Number(ed_edDate.Text) - Number(ed_stDate.Text) > 300) {
      alert("설정하신 기간은 서버에 무리를 가하므로 실행을 할 수 없습니다.\r\n\r\n기간은 최장 3개월 이내로 설정해 주세요.\r\n\r\n최적기간은 1개월 입니다.");
      return;
    }
    var obj = document.getElementsByName("cb")
    for (var i=0 ; i<obj.length ; i++) {
      if (i==0) {
        cb0 = obj[i].checked;
      } else if (i==1) {
        cb1 = obj[i].checked;
      } else if (i==2) {
        cb2 = obj[i].checked;
      } else if (i==3) {
        cb3 = obj[i].checked;
      } else if (i==4) {
        cb4 = obj[i].checked;
      } else if (i==5) {
        cb5 = obj[i].checked;
      }
    }
    var condition = "?";
    condition += "cb0="+cb0;
    condition += "&cb1="+cb1;
    condition += "&cb2="+cb2;
    condition += "&cb3="+cb3;
    condition += "&cb4="+cb4;
    condition += "&cb5="+cb5;
    condition += "&stDate="+ed_stDate.Text;
    condition += "&edDate="+ed_edDate.Text;
    location.href = "/jsp/***/diskSpace.jsp"+condition;
  }
</script>
</head>
<!-----------------------------------------------------------------------------
    화면영역 시작
------------------------------------------------------------------------------>
<body onload="f_OnLoad()">
<div id="layout_page" class="layout_page">
  <div class="breadcrumb"><sf:breadcrumb menu="<%=curMenuId%>"/></div>
  <div class="page_title"><sf:pagetitle menu="<%=curMenuId%>"/></div>
  <div class="search">
    <table>
      <tr>
        <td style="font: normal 9px verdana, arial, helvetica, sans-serif;">
          <input id=cb type=checkbox name=cb value="/a">/a</checkbox>&nbsp;
          <input id=cb type=checkbox name=cb value="/e">/e</checkbox>&nbsp;
          <input id=cb type=checkbox name=cb value="/o">/o</checkbox>&nbsp;
          <input id=cb type=checkbox name=cb value="/d">/d</checkbox>&nbsp;
          <input id=cb type=checkbox name=cb value="/">/</checkbox>&nbsp;
          <input id=cb type=checkbox name=cb value="/s">/s</checkbox>
          &nbsp; &nbsp;
        </td>
        <td>
          <table>
            <tr>
              <td style="font: normal 9px verdana, arial, helvetica, sans-serif;">시작일 : </td>
              <td valign=bottom>
                <comment id="__NOSCRIPT_ID__"><object id="ed_stDate" class="comnDate" classid="<%=LGauceId.EMEDIT%>" objType="data">
                </object></comment><SCRIPT>__ShowEmbedObject(__NOSCRIPT_ID__);</SCRIPT>
              </td>
              <td><img src='<%= imagePath %>/calendar.gif' width='20' height='16' border='0' onClick='cfShowCalendar(ed_stDate)' onmouseOver=this.style.cursor='hand'></td>
              <td style="font: normal 9px verdana, arial, helvetica, sans-serif;"> ~ &nbsp;&nbsp;종료일 : </td>
              <td>
                <comment id="__NOSCRIPT_ID__"><object id="ed_edDate" class="comnDate" classid="<%=LGauceId.EMEDIT%>" objType="data">
                </object></comment><SCRIPT>__ShowEmbedObject(__NOSCRIPT_ID__);</SCRIPT>
              </td>
              <td><img src='<%= imagePath %>/calendar.gif' width='20' height='16' border='0' onClick='cfShowCalendar(ed_edDate)' onmouseOver=this.style.cursor='hand'></td>
              <td><input name="reset32" type="button" class="button_search" onClick="f_Retrieve()" value="검색"></td>
            </tr>
          </table>
        </td>
      </tr>
    </table>
  </div>
 
  <script language="javascript">
    obj = document.getElementsByName("cb");
    document.write("<%=request.getParameter("cb0")==null ? "<br><br><center><h1>검색할 기간을 선택하여 주세요</h1></center>":""%> ");
  </script>
<!-----------------------------------------------------------------------------
    화면영역 종료
------------------------------------------------------------------------------>
  <div id="diskSpace">
<%!
  //DecimalFormat df = new DecimalFormat("#,##0.0");
  DecimalFormat df = new DecimalFormat("###.0");
  DecimalFormat df1 = new DecimalFormat("###0");
  StringBuffer sb   = new StringBuffer();
  private String cb0;
  private String cb1;
  private String cb2;
  private String cb3;
  private String cb4;
  private String cb5;
  private int stDate;
  private int edDate;
 
  private void writeGraph(String pServerNo, List list_2, float setVal, String subject) {
    String ymd        = "";
    String serverNo  = "";
    String filesystem = "";
    String kbytes     = "";
    String used       = "";
    String avail      = "";
    float  f_kbytes   = 0.0f;
    float  f_used     = 0.0f;
    float  f_avail    = 0.0f;
    String pused      = "";
    String mounted    = "";
    HashMap hm_2;
    Iterator i_2 = list_2.iterator();
    List list_3 = new ArrayList();
    float diskSize = 0;
    if("/a".equals(subject)) {
        diskSize = 20971520;
    } else if("/e".equals(subject)) {
        diskSize = 209682432;
    } else if("/o".equals(subject)) {
        diskSize = 104841216;
    } else if("/a/d".equals(subject)) {
        diskSize = 10485760;
    } else if("/".equals(subject)) {
        diskSize = 41943040;
    } else if("/s".equals(subject)) {
        diskSize = 314736;
    }
    diskSize   = diskSize/1024f/1024f;
   
    sb.append ("<style type='text/css'>");
    sb.append ("  .tb1 {border-collapse: collapse;border-bottom: 0px solid #000000;}");
    sb.append ("  .tb2 {border-collapse: collapse;border-bottom: 1px solid #000000;border-top: 1px solid #000000;}");
    sb.append ("  td, th {border: 0px dashed #ffffff;padding:.0em; font: normal 9px verdana, arial, helvetica, sans-serif; text-align:left}");
    sb.append ("</style>");
    sb.append ("<br>");
    sb.append ("<table class=tb1>");
    sb.append ("  <tr>");
    sb.append ("    <td style='font:12px'>" + subject + " 총:" + df1.format(diskSize) + "G</td>");
    sb.append ("  </tr>");
    sb.append ("  <tr>");
    sb.append ("    <td>");
    sb.append ("      <table class=tb1>");
    String firstMD = null;
    String beforeM = null;
    String afterM = null;
    boolean firstFlag = true;
   
    List list_4 = new ArrayList();
    int cnt = 0;
    while (i_2.hasNext()) {
      list_3 = (List)i_2.next();
      Iterator i_3 = list_3.iterator();
      while (i_3.hasNext()) {
        hm_2       = (HashMap)i_3.next();
        ymd        = (String)hm_2.get("ymd");
        serverNo   = (String)hm_2.get("serverNo");
        filesystem = (String)hm_2.get("Filesystem");
        kbytes     = (String)hm_2.get("kbytes");
        used       = (String)hm_2.get("used");
        avail      = (String)hm_2.get("avail");
        f_kbytes   = Float.parseFloat((String)hm_2.get("kbytes"));
        f_used     = Float.parseFloat((String)hm_2.get("used"));
        f_avail    = Float.parseFloat((String)hm_2.get("avail"));
        used       = String.valueOf(df.format(f_kbytes - f_avail));
        f_kbytes   = f_kbytes*setVal;
        f_used     = f_used*setVal;
        f_avail    = f_avail*setVal;
        f_used     = f_kbytes - f_avail; // 로그 출력상 계산 보이지 않는 used 영역 재계산
        pused      = (String)hm_2.get("pused");
        mounted    = (String)hm_2.get("Mounted");
        if (pServerNo.equals(serverNo) && subject.equals(mounted)) {
          //out.print(ymd + " " + mounted + " : " + kbytes + " / " + used + " / " + avail);
          sb.append ("  <td valign=bottom>");
          sb.append ("    <table class=tb2>");
          sb.append ("      <tr>");
          sb.append ("        <td width=100% height='" + df1.format(f_avail) + "' style='background-color:#00ff00'");
          sb.append ("         id='sel0_'" + pServerNo + " name='90@30@yellow@" + ymd.substring(0,2)+"월"+ymd.substring(2,4)+"일 "+ymd.substring(4,6)+"시<br>남은용량:" + avail+ "G" + "'><img src='/images/al/1px.gif' width='" + getCalcImgWidth() + "'></td>");
          sb.append ("      </tr>");
          sb.append ("      <tr>");
          sb.append ("        <td height='" + df1.format(f_used) + "' style='background-color:red'");
          sb.append ("         id='sel1_'" + pServerNo + " name='90@30@orange@" + ymd.substring(0,2)+"월"+ymd.substring(2,4)+"일 "+ymd.substring(4,6)+"시<br>사용량:" + used + "G" + "'></td>");
          sb.append ("      </tr>");
          sb.append ("    </table>");
          sb.append ("  </td>");
         
          cnt++;
          if (cnt == 1) beforeM = ymd.substring(0,2);
          afterM = ymd.substring(0,2);
          if (firstFlag) {
              firstMD = ymd.substring(0,2)+"월"+ymd.substring(2,4)+"일";
              firstFlag = false;
          }
          if (!beforeM.equals(afterM)) {
            List list_5 = new ArrayList();
            list_5.add(new Integer(cnt));
            list_5.add((firstMD!=null)?firstMD:beforeM+"월");
            list_4.add(list_5);
            firstMD = null;
            cnt = 0;
            beforeM = afterM;
          }
          if ("0100".equals(ymd.substring(2,6))) {
            sb.append ("<td style='border-left: 1px dashed #000000;'></td>");
            cnt++;
          }
        }
      }
    } 
    List list_5 = new ArrayList();
    list_5.add(new Integer(cnt));
    list_5.add(afterM+"월");
    list_4.add(list_5);
    sb.append ("      </table>");
    sb.append ("    </td>");
    sb.append ("  </tr>");
    sb.append ("  <tr>");
    sb.append ("    <td>");
    sb.append ("      <table class=tb1>");
    sb.append ("        <tr>");
    int width = 0;
    for(int i=0 ; i<list_4.size() ; i++) {
      List list_6 = (List)list_4.get(i);
      width = getCalcWidth(String.valueOf(list_6.get(0)));
      sb.append ("          <td width='" + width + "'>" + list_6.get(1) + "</td>");
    }
    sb.append ("          <td>" + ymd.substring(0,2)+"월"+ymd.substring(2,4)+"일</td>");
    sb.append ("        </tr>");
    sb.append ("      </table>");
    sb.append ("    </td>");
    sb.append ("  </tr>");
    sb.append ("</table>");
  }
  private void calcGraph(String report_root, int stDate, int edDate) {
   
    String cServerNo = report_root.substring(report_root.length()-3, report_root.length());
    try {
      String strDate = "";
      int intDate = 0;
      int ttt = 0;
      int tmpCnt = 0;
      List list_2 = new ArrayList();
      File file = new File(report_root);
      File [] listFileArray = file.listFiles();
      File listFile;
      //out.println(listFileArray.length + "건<br>"); 
     for (int i=0 ; i<listFileArray.length ; i++) {
      listFile = listFileArray[i];
        List list = new ArrayList();
       
        strDate = listFile.getName();
        strDate = strDate.replaceAll("15_","");
        strDate = strDate.replaceAll("16_","");
        strDate = strDate.replaceAll(".log","");
        strDate = strDate.substring(0, 8);
        intDate = Integer.parseInt(strDate);
        if (stDate <= intDate && intDate <= edDate) {
          list.add(listFile.getName());
 
          StringTokenizer tokenizer;
          BufferedReader br = null;
          int cnt = 0;
          try {
            br = new BufferedReader( new FileReader( listFile ));
            String s = null;
            while((s=br.readLine()) != null ) {
              if (cnt == 0) {
                  cnt++;
                  continue;
              }
              tokenizer = new StringTokenizer(s.toString(), " ");
              while(tokenizer.hasMoreTokens()){
                list.add(tokenizer.nextToken());
              }
            }
            br.close();
          }finally{
            try {
              br.close();
              br = null;
            } catch (Exception e) {
              e.printStackTrace();
            }
          }
         
          String strTmp;
          String strYmd = "";
          HashMap hm_1 = new HashMap();
          List list_1 = new ArrayList();
          for (int j=0 ; j<list.size() ; j++) {
            float  f_kbytes   = 0.0f;
            float  f_used     = 0.0f;
            float  f_avail    = 0.0f;
            String s_kbytes   ="";
            String s_used     ="";
            String s_avail    ="";
            strTmp = (String)list.get(j);
//System.out.println((ttt++) + " , " + j + " , " + ((j-tmpCnt)%7) + "=" + Math.abs(tmpCnt) + ") &nbsp; " + strTmp + "<br>");
            if (j%43 == 0) strYmd = strTmp;
            if ((j-tmpCnt)%7 == 1) hm_1.put("ymd",        strYmd.substring(8, 14));
            if ((j-tmpCnt)%7 == 1) hm_1.put("serverNo",   strYmd.substring(0, 3));
            if ((j-tmpCnt)%7 == 1) hm_1.put("Filesystem", strTmp);
            if ((j-tmpCnt)%7 == 2) {
              f_kbytes   = Float.parseFloat(strTmp)/1024f/1024f;
              if (df.format(f_kbytes).equals("0.0")) {
                s_kbytes = "0.1";
              } else {
                s_kbytes = df.format(f_kbytes);
              }
              hm_1.put("kbytes"    , s_kbytes);
            }
            if ((j-tmpCnt)%7 == 3) {
              f_used     = Float.parseFloat(strTmp)/1024f/1024f;
              if (df.format(f_used).equals("0.0")) {
                s_used = "0.1";
              } else {
                s_used = df.format(f_used);
              }
              hm_1.put("used"      , s_used);
            }
            if ((j-tmpCnt)%7 == 4) {
              f_avail    = Float.parseFloat(strTmp)/1024f/1024f;
              if (df.format(f_avail).equals("0.0")) {
                s_avail = "0.1";
              } else {
                s_avail = df.format(f_avail);
              }
              hm_1.put("avail"     , s_avail);
            }
            if ((j-tmpCnt)%7 == 5) hm_1.put("pused"     , strTmp);
            if ((j-tmpCnt)%7 == 6) hm_1.put("Mounted"   , strTmp);
            if ((j-tmpCnt)%7 == 6) {
              list_1.add(hm_1);
  //out.println(hm_1 + "<hr>");       
              hm_1 = new HashMap();
              tmpCnt--;
            }
          }
          list_2.add(list_1);
          tmpCnt = 0;
        }
     }
     
      if (list_2.size() > 0) {
 
        sb.append("<br><div class=search style='text-align:left'><table><tr><td style='font: bold 15px verdana, arial, helvetica, sans-serif;'>운영 " + cServerNo + "</td></tr></table></div>");
        if ("true".equals(cb0)) writeGraph(cServerNo, list_2, 5.0f,   "/a");
        if ("true".equals(cb1)) writeGraph(cServerNo, list_2, 0.8f,   "/e");
        if ("true".equals(cb2)) writeGraph(cServerNo, list_2, 1.2f,   "/o");
        if ("true".equals(cb3)) writeGraph(cServerNo, list_2, 5.0f,   "/d");
        if ("true".equals(cb4)) writeGraph(cServerNo, list_2, 2.4f,   "/");
        if ("true".equals(cb5)) writeGraph(cServerNo, list_2, 50.0f, "/s");   
      }
    } catch (Exception e) {
        e.printStackTrace();
    }
  }
%>
<%
  stDate = Integer.parseInt(request.getParameter("stDate")==null ? "0" :request.getParameter("stDate"));
  edDate = Integer.parseInt(request.getParameter("edDate")==null ? "0" :request.getParameter("edDate"));
  if (edDate - stDate >= 300) {
    period = -3;
  } else if (edDate - stDate >= 200) {
    period = -2;
  } else if (edDate - stDate >= 100) {
    period = -1;
  }
  cb0 = request.getParameter("cb0")==null ? "true"  : request.getParameter("cb0");
  cb1 = request.getParameter("cb1")==null ? "true"  : request.getParameter("cb1");
  cb2 = request.getParameter("cb2")==null ? "true"  : request.getParameter("cb2");
  cb3 = request.getParameter("cb3")==null ? "true"  : request.getParameter("cb3");
  cb4 = request.getParameter("cb4")==null ? "true"  : request.getParameter("cb4");
  cb5 = request.getParameter("cb5")==null ? "true"  : request.getParameter("cb5");
  
  String report_root15 = "/***/15";
  String report_root16 = "/***/16";
  calcGraph(report_root15, stDate, edDate);
  calcGraph(report_root16, stDate, edDate);
 
  out.print(sb.toString());
  sb.setLength(0);
%>
<div id=h style="position:absolute;left:0;top:0;width:100;height:50;background:black;filter:alpha(opacity=100);border:1 solid 1px;display:none"></div>
<script language="JavaScript" type="text/JavaScript">
<!--
  // 풍선위치 = 마우스 좌표 + 스크롤된 y 좌표
  document.onmousemove=function () {
    oElement = document.elementFromPoint(event.x, event.y);
    if(oElement.id.indexOf('sel')>-1){
      var tmp=oElement.name.split("@");
      h.style.width=tmp[0];
      h.style.height=tmp[1];
      h.style.background=tmp[2];
      h.innerHTML=tmp[3];
      h.style.pixelLeft=event.x+13;
      h.style.pixelTop=event.y+10+getNowScroll().Y;
      h.style.display="";
    } else {
      h.style.display="none";
    }
  }
  </div>
</div>
</html>

+ Recent posts