2013-04-24 4 views
0

정기적으로 실행중인 서버 (tomcat)를 모니터링하고 싶습니다. 독립 실행 형 응용 프로그램으로 이것을 수행하고 있습니다. 정기적으로 (30 분마다) 서버 모니터 프로그램을 호출하고 싶습니다. 괜찮나 당신은 ExecutorService를하고 작업을 사용해야합니다 자바자바 스레드를 사용하여 모니터링

+2

사용'Executors.newSingleThreadedScheduledExecutor'하고'그 위에 작업을 schedule'. –

+0

그런 다음 Apache HTTP 클라이언트 라이브러리를 사용하여 Tomcat 서버를 호출하고 응답을 수신하고 서버가 실행 중인지 확인합니다. –

답변

1

를 사용하여이 작업을 수행합니다 :

class MyTask implements Runnable { 
    @Override 
     public void run() { 
      //do your work here 
     } 
} 


ScheduledExecutorService service = Executors.newScheduledThreadPool(NUMBER_OF_THREADS); 
service.scheduleAtFixedRate(new MyTask(), 0, 30, TimeUnit.MINUTES); 

ExecutorService

0

체크 아웃의 Nagios를. 그것의 오픈 소스 모니터링 서비스는 또한 자바 API를 제공합니다. 이것은 서버를 모니터하는 가장 좋은 방법입니다.

하지만 Nagios는 구현 측면에서 약간의 노력이 필요합니다. 그것이 당신의 선택이 아니라면 예 ScheduledExecutorservice로 가십시오.

0

당신이 할 수있는 많은 방법이 있지만, 나는 이런 종류의 일을 위해 셀레늄을 권하고 싶습니다. http://docs.seleniumhq.org/projects/webdriver/

그러면 서버가 응답하는지 확인할 수있을뿐만 아니라 올바른 내용이 표시되는지 확인할 수 있습니다.

http://docs.seleniumhq.org/docs/03_webdriver.jsp#introducing-the-selenium-webdriver-api-by-example

package org.openqa.selenium.example; 

import org.openqa.selenium.By; 
import org.openqa.selenium.WebDriver; 
import org.openqa.selenium.WebElement; 
import org.openqa.selenium.firefox.FirefoxDriver; 
import org.openqa.selenium.support.ui.ExpectedCondition; 
import org.openqa.selenium.support.ui.WebDriverWait; 

public class Selenium2Example { 
    public static void main(String[] args) { 
     while (1){ 
      test(); 
      Thread.sleep(30L*60L*1000L); //sleep for 30 mins 
     } 
    } 

    public static void test(){ 


     // Create a new instance of the Firefox driver 
     // Notice that the remainder of the code relies on the interface, 
     // not the implementation. 
     WebDriver driver = new FirefoxDriver(); 

     // And now use this to visit Google 
     driver.get("http://www.google.com"); 
     // Alternatively the same thing can be done like this 
     // driver.navigate().to("http://www.google.com"); 

     // Find the text input element by its name 
     WebElement element = driver.findElement(By.name("q")); 

     // Enter something to search for 
     element.sendKeys("Cheese!"); 

     // Now submit the form. WebDriver will find the form for us from the element 
     element.submit(); 

     // Check the title of the page 
     System.out.println("Page title is: " + driver.getTitle()); 

     // Google's search is rendered dynamically with JavaScript. 
     // Wait for the page to load, timeout after 10 seconds 
     (new WebDriverWait(driver, 10)).until(new ExpectedCondition<Boolean>() { 
      public Boolean apply(WebDriver d) { 
       return d.getTitle().toLowerCase().startsWith("cheese!"); 
      } 
     }); 

     // Should see: "cheese! - Google Search" 
     System.out.println("Page title is: " + driver.getTitle()); 

     //Close the browser 
     driver.quit(); 
    } 
} 
+0

Selenium을 실행하기 위해 브라우저를 설치하지 않으려면'WebDriver driver = new HtmlUnitDriver();'를 사용하십시오 –

관련 문제