用Javascript查看Tomcat运行情况

代码如下,
<%@page import="java.text.NumberFormat"%>
<%@page import="java.util.Properties"%>
<%@page import="java.math.BigDecimal"%>
<%@page import="java.net.InetAddress"%>
<%@page import="java.util.Enumeration;" %>

<style type="text/css">
image {
    border: 0px;
    margin: 0px;
    padding: 0px;
    clear: both;
}

.img2 {
    margin-left: -3px;
}
</style>
<table style="width: 700; text-align: left; font-size: 9pt;">
    <tr>
        <td>
        <%
        if(request.getParameter("GC") != null){
          System.gc();
        }
Runtime lRuntime = Runtime.getRuntime();
long memTotal = lRuntime.totalMemory();
long memLeft = lRuntime.freeMemory();
long memMax = lRuntime.maxMemory();
long unasigned = memMax - memTotal;
double usePercentage = (memTotal - memLeft) * 1.0/ memMax; 
double usablePercentage = memLeft * 1.0 / memMax;
double unasignedunasignedPercentage = unasigned * 1.0 / memMax;
out.println("<div style='width: 750;'><nobr>");
out.println("<image alt='Memory Used' src='images/memUsed.gif' width='" + usePercentage * 700 + "' height='10px'/>");
out.println("<image alt='Memory Left' class='img2' src='images/memLeft.gif' width='" + usablePercentage * 700 + "' height='10px' />");
out.println("<image alt='Memory Unsigned' class='img2' src='images/memUnsinged.gif' width='" + unasignedPercentage * 700 + "' height='10px' />");
out.println("<form>");
out.println("<input type='submit' value='Run GC' width='50' id='GC' name='GC' />");
out.println("</form>");
out.println("</nobr></div><br>");
%> <image src="images/memUsed.gif"
            style="width: 30px; height : 15px;" /> Memory
        Used            <font
            color="red"><%=round((memTotal - memLeft) * 1.0/1024/1024, 2) %></font>
        MB<br>
&nbsp
<image src="images/memLeft.gif"

            style="width: 30px; height : 15px;" /> Memory
        Left              
        <font color="red"><%=round(memLeft * 1.0/1024/1024, 2) %></font> MB<br>
        <image src="images/memUnsinged.gif"
            style="width: 30px; height : 15px;" /> Memory
        Unsigned    <font color="red"><%=round(unasigned * 1.0/1024/1024, 2) %></font>
        MB<br>
        <br>
        <br>
        <br>
        <br>


   <%
Properties pros = System.getProperties();
InetAddress addr = InetAddress.getLocalHost();
out.println(formatTo("Host Name:", 37) + addr.getHostName().toString() + "<br>");
out.println(formatTo("Host IP:", 42) + addr.getHostAddress().toString() + "<br>");
out.println(formatTo("Server OS:", 40) + pros.getProperty("os.name") + "<br>");
out.println(formatTo("Server OS Version:", 33) + pros.getProperty("os.version") + "<br>");
out.println(formatTo("Server Patch:", 38) + pros.getProperty("sun.os.patch.level") + "<br>");
out.println(formatTo("Current User: ", 38) + pros.getProperty("user.name") + "<br>");
out.println(formatTo("Java Runtim: ", 38) + pros.getProperty("java.runtime.name") + "<br>");
out.println(formatTo("Java Version: ", 38) + pros.getProperty("java.runtime.version") + "<br>");
out.println(formatTo("Java Vendor: ", 38) + pros.getProperty("java.vm.specification.vendor") + "<br>");
out.println(formatTo("Server Encoding: ", 35) + pros.getProperty("sun.jnu.encoding") + "<br>");
%>
<form method="POST">
    <input type="submit" id="showSessions" name="showSessions" value="Print Sessions">
</form>
<table>
<%
        if(request.getParameter("showSessions") != null){
          Enumeration<String> en = session.getAttributeNames();
          while(en.hasMoreElements()){
            String key = en.nextElement();
            out.println("<tr><td>");
            out.println(key);
            out.println("</td><td>");
            out.println(session.getAttribute(key));
            out.println("</tr>");
          }
        }
%>
</table>
<%!
String formatTo(String value, int length){
String result
= value;
    int vL = value.length();
    if(length < vL){
    }else{
        for(int i = 0; i < length - vL; i++){
            result += " ";
        }
    }
    return result;
}
double round(double v,int scale){
    if(scale<0){
        throw new IllegalArgumentException(
            "The scale must be a positive integer or zero");
    }
    BigDecimal b = new BigDecimal(Double.toString(v));
    BigDecimal one = new BigDecimal("1");
    return b.divide(one,scale,BigDecimal.ROUND_HALF_UP).doubleValue();
}
%></td>
    </tr>
</table>

 

 

 

 

转载:http://www.8211.cn/repository/list_2307.html  

 

 

 

计算机电子书下载

 

你可能感兴趣的:(JavaScript,tomcat,css,OS,sun)