1.tomcat内存使用监控页面
<%@ page contentType="text/html;charset=GBK" %>
<%@ page import="java.util.*" %>
<%
out.println("<br>");
out.println("<center><h1>");
out.println(" Server Tomcat works!<br><br>");
out.println("</h1></center>");
long totalMemory=java.lang.Runtime.getRuntime().totalMemory();
long freeMemory=java.lang.Runtime.getRuntime().freeMemory();
long usedMemory=totalMemory-freeMemory;
out.println("<br><br>Total Memory is: " +totalMemory/1024/1024+"M");
out.println("<br>Used Memory is: " +usedMemory/1024/1024+"M");
out.println("<br>Free Memory is: " +freeMemory/1024/1024+"M");
if( (freeMemory/1024/1024) > 60 ) out.println("<br><br>LessOfMemory!");
if( (usedMemory/1024/1024) > 500 ) out.println("<br><br>OutOfMemory!");
%>
2.监测sh程序
#!/bin/sh
#Program
test -e "status.jsp" && rm -rf status.jsp;
rm -rf wget-log*;
wget -b "http://127.0.0.1:8080/website/status.jsp"
sleep 3
tom=`cat status.jsp |grep LessOfMemory`
if
[ "$tom" == "" ] ;then
#这里偷懒,调用以前写的定时任务脚本任务
su - root /home/tomcatrestart.sh
date >>/home/logs/time.txt
elif
[ "$tom" != "" ] ;then
exit 0
fi
总结:这里写的有点简单,判断有点问题,不怎么全面.但功能基本上能满足,就是监控服务有没有死掉,如果停止了就重起服务.本来该加了个发送邮件的功能.最好的做法用c语言编写.