1.写一个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