用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  

 

 

 

计算机电子书下载

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值