监控 monitor java 代码
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package monitor; import alilibs.AliFile; import alilibs.AliHTTP; import alilibs.AliMail; import java.io.IOException; import java.text.SimpleDateFormat; import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatterBuilder; import java.util.Date; import java.util.logging.Level; import java.util.logging.Logger; /** * * @author Ali */ public class Monitor { /** * @param args the command line arguments */ public static void main(String[] args) { run(args); } public static void run(String[] args) { String linuxUrl = "http://www.9hlh.com/index.php?m=kv&c=if&a=monitorx"; SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss|"); while (true) { String result = AliHTTP.getString(linuxUrl); try { AliFile.appendString("monitor.txt", sdf.format(new Date()) + result + "\n"); } catch (IOException ex) { // Logger.getLogger(Monitor.class.getName()).log(Level.SEVERE, null, ex); } int x = Integer.parseInt(result); if (x > 300) { System.err.println("out->" + AliHTTP.getString("http://www.9hlh.com/tools/mail/sendmail.php?email=xienaizhong@qq.com&subject=error_win&body=error_win")); } else { System.err.println("in -> " + result); } try { Thread.sleep(1000 * 60 * 5); } catch (InterruptedException ex) { } } } }