当前位置: > Linux服务器 > Tomcat >

简单的tomcat内存监控报警

时间:2015-08-04 17:35来源:linux.it.net.cn 作者:IT
.写一个java类/jsp

 Runtime run = Runtime.getRuntime(); 

 long max = run.maxMemory()/1024/1024; //最大内存

long total = run.totalMemory()/1024/1024; //已分配内存

long free = run.freeMemory()/1024/1024; //剩余空间

 

if((run.freeMemory()/1024/1024)<150){

JavaMailSenderImpl sender = new JavaMailSenderImpl();

sender.setHost("192.168.1.1");

MimeMessage message = sender.createMimeMessage();

MimeMessageHelper helper = new MimeMessageHelper(message, true,

"UTF-8");

helper.setFrom("miotourerror@mic.com.tw");

helper.setTo(new String[] {"itxinmeng@gmail.com"});

helper.setSubject("miotour 异常");

String content = "mio tour 已处于宕机边缘,内存只剩下:"+free+"M";

content =content + "<br>";

helper.setText(content, true);

sender.send(message);

}

 

 

 

    2.linux下添加定时(fedora 11下):

 

 

            /etc/crontab -e 添加如下内容(每15分钟查一次)

 

 

            */15 * * * * curl http://www.aaa.com/memory-detail.jsp

 

 

            /sbin/service crond restart

 

(责任编辑:IT)
------分隔线----------------------------
栏目列表
推荐内容