1.寫一個java類/jspjava
Runtime run = Runtime.getRuntime(); linux
long max = run.maxMemory()/1024/1024; //最大內存curl
long total = run.totalMemory()/1024/1024; //已分配內存long free = run.freeMemory()/1024/1024; //剩餘空間jsp
if((run.freeMemory()/1024/1024)<150){url
JavaMailSenderImpl sender = new JavaMailSenderImpl();spa
sender.setHost("192.168.1.1");rest
MimeMessage message = sender.createMimeMessage();crontab
MimeMessageHelper helper = new MimeMessageHelper(message, true,內存
"UTF-8");get
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