示例#1
0
 private static Calendar getToday() {
   int year, month, day;
   Calendar c = new GregorianCalendar();
   year = c.get(Calendar.YEAR);
   month = c.get(Calendar.MONTH);
   day = c.get(Calendar.DAY_OF_MONTH);
   c = new GregorianCalendar(year, month, day, 5, 0, 0);
   return c;
 }
示例#2
0
 private static void monitor() {
   long nowInMillis;
   long dailyTimeStampInMillis;
   init();
   String subject = "HTTP Uptime monitor started: " + remoteHost + ".";
   String message = "Monitoring from " + Server.getHostName() + Names.NEW_LINE;
   message += "URL: " + url + Names.NEW_LINE;
   message += "remote host: " + remoteHost + Names.NEW_LINE;
   message += "local down command:" + downCommand + " " + remoteHost + Names.NEW_LINE;
   message += "local up command:" + upCommand + " " + remoteHost + Names.NEW_LINE;
   try {
     EMail.send(FROM, mailTo, subject, message, smtpHost);
   } catch (Exception e) {
     e.printStackTrace();
   }
   dailyTimeStamp = getToday();
   dailyTimeStampInMillis = dailyTimeStamp.getTimeInMillis();
   int year, month, day;
   year = dailyTimeStamp.get(Calendar.YEAR);
   month = dailyTimeStamp.get(Calendar.MONTH);
   day = dailyTimeStamp.get(Calendar.DAY_OF_MONTH);
   dailyTimeStamp = new GregorianCalendar(year, month, day, 5, 0, 0);
   Calendar currentTimeStamp;
   int i = 0;
   while (true) {
     i++;
     try {
       int code = getResponseCode();
       for (int x = 0; x < (i % 8); x++) System.out.print(".");
       {
       } // System.out.println("Http Response=" + HTTPCodes[code] + "[" +code + "] for " + url);
       if (code < 200 || code > 204) restartServer(code);
     } catch (Exception e) {
       e.printStackTrace();
       restartServer(601);
     }
     Sleep.sleep(POLLING_INTERVAL * 1000);
     currentTimeStamp = new GregorianCalendar();
     nowInMillis = currentTimeStamp.getTimeInMillis();
     if (nowInMillis > (dailyTimeStampInMillis + (1000 * 60 * 60 * 24))) {
       dailyTimeStamp = getToday();
       dailyTimeStampInMillis = dailyTimeStamp.getTimeInMillis();
       subject = "HTTP Uptime monitor running: " + remoteHost + ".";
       message = "Monitoring from " + Server.getHostName() + Names.NEW_LINE;
       message += "URL: " + url + Names.NEW_LINE;
       message += "remote host: " + remoteHost + Names.NEW_LINE;
       message += "local down command:" + downCommand + " " + remoteHost + Names.NEW_LINE;
       message += "local up command:" + upCommand + " " + remoteHost + Names.NEW_LINE;
       try {
         EMail.send(FROM, mailTo, subject, message, smtpHost);
       } catch (Exception e) {
         e.printStackTrace();
       }
     }
   }
 }