정기적으로 실행중인 서버 (tomcat)를 모니터링하고 싶습니다. 독립 실행 형 응용 프로그램으로 이것을 수행하고 있습니다. 정기적으로 (30 분마다) 서버 모니터 프로그램을 호출하고 싶습니다. 괜찮나 당신은 ExecutorService를하고 작업을 사용해야합니다 자바자바 스레드를 사용하여 모니터링
0
A
답변
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);
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();'를 사용하십시오 –
관련 문제
- 1. 자바 스레드에서 스레드를 사용하여
- 2. 자바 스레드 모니터링. 데몬 라이브가 아닌 스레드를 찾는 방법은?
- 3. 스레드를 모니터링 Visual Studio의 Windows Phone 에뮬레이터
- 4. 자바 모니터링 도구
- 5. 모니터링 자바 직렬화
- 6. join()과 wait() 스레드를 사용하여 자바
- 7. 자바 스레드를 사용하여 데이터베이스에 병렬 삽입
- 8. 자바 스레드 : 스레드를 사용하여 amethod에 액세스하는 방법
- 9. 자바 모니터링 : jconsole의 오버 헤드?
- 10. 특정 자바 스레드를 중지
- 11. SNMP를 사용하여 JVM 모니터링
- 12. 자바 스레드를 정상적으로 인터럽트
- 13. 구조/스레드를 사용하여 응용 프로그램
- 14. 자바 스크립트 속도 모니터링 도구?
- 15. 자바 웹 애플리케이션 트래픽 모니터링
- 16. 자바 기반의 모니터링 응용 프로그램
- 17. 자바 7 디렉토리 모니터링 질문
- 18. 계속 자바 자바 스레드를 실행하고 싶습니다.
- 19. ASM을 사용하여 java.lang.ProcessBuilder 모니터링
- 20. EJB3를 사용하여 모니터링 빈
- 21. FileSystemWatcher를 사용하여 디렉토리 모니터링
- 22. FileSystemWatcher를 사용하여 디렉터리 모니터링
- 23. PThread 모니터링
- 24. 영사를 사용하여 타사 서비스 모니터링
- 25. 자바 스크립트를 사용하여 디렉토리 수정을 모니터링 할 수 있습니까?
- 26. C에서 평생 스레드를 사용하여 병렬 스레드를 시작하십시오.
- 27. TaskCompleteSource.Wait을 사용하여 스레드를 만드는 스레드를 차단합니까?
- 28. 내가이 같은 스레드를 사용하여 스레드를 시작하고 스레드
- 29. 자바 스크립트에서 스레드를 사용하는 방법
- 30. 자바 시계 서비스로 하위 폴더 모니터링
사용'Executors.newSingleThreadedScheduledExecutor'하고'그 위에 작업을 schedule'. –
그런 다음 Apache HTTP 클라이언트 라이브러리를 사용하여 Tomcat 서버를 호출하고 응답을 수신하고 서버가 실행 중인지 확인합니다. –