Tomcat 등 servler을 구동하는 VM의 메모리 사이즈 측정

  • authorbibaram
  • 09 October 2006, 13:59:00

<%@ page contentType="text/html; charset=euc-kr" %>
<%@ page import="java.net.InetAddress" %>
<%@ page import="java.text.*" %>
<%@ page import="java.util.*" %>


<%
 Runtime rt = Runtime.getRuntime();
 long free = rt.freeMemory();
 long total = rt.totalMemory();
 long used = total-free;
 long usedRatio = used * 100 / total;
 long unusedRatio = free * 100 / total;
 
 /*
 if (usedRatio >= 55) {
  System.gc();
  System.runFinalization();
 }
 */
 
 Calendar c = null;
 c = Calendar.getInstance();
%>
<html>
<title>Memory Check</title><head>
</head>
<script language="JavaScript">
<!--
function rld()
{
 location.reload();
}
// -->
</SCRIPT>
</HEAD>
<body>
<table width="320" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td height="30" colspan="2"><% out.println(c.getTime()); %></td>
  </tr>
  <tr>
    <td height="5" colspan="2"><hr></td>
  </tr>
  <tr>
    <td width="157" height="30"><strong>Total Memory </strong></td>
    <td width="163" height="30"><%=total%></td>
  </tr>
  <tr>
    <td width="157" height="30"><strong>Used Memory </strong></td>
    <td width="163" height="30"><% if(usedRatio < 60) { %><font color="#336600"><% } else { %><font color="#FF0000"><% } %><%=used%> (<%=usedRatio%>)</font></td>
  </tr>
  <tr>
    <td height="30"><font color="#0000FF"><strong>Free Memory </strong></font></td>
    <td height="30"><% if(unusedRatio >= 40) { %><font color="#336600"><% } else { %><font color="#FF0000"><% } %><%=free%> (<%=unusedRatio%>)</font></td>
  </tr>
</table>
<SCRIPT Language="JavaScript">
<!--
 setTimeout("rld()",5000);
// -->
</SCRIPT>
</body>
</html>

 

Press ESC to close