I’ve spent the past couple of hours completing a first revision for a Java API that makes use of the excellent HtmlUnit libraries to enable monitoring of a web servers response time.
Here’s a simple example of how I’d implement the API:
String[] siteUrls = {"http://www.bingo.com",
"http://www.microsoft.com",
"http://www.google.com"};
for (String url : siteUrls)
{
Website test = new Website(url);
System.out.print("Site: ");
System.out.println(test.getSiteUrl());
System.out.println("\tTest 1:");
System.out.println("\t\tCreated: " + test.getCreateDate());
System.out.println("\t\tResponse time: " + test.getResponseTime() + "ms");
System.out.println("\t\tTime of last refresh: " + test.getLastRefreshed());
System.out.println("\tTest 2:");
System.out.println("\t\tCreated: " + test.getCreateDate());
System.out.println("\t\tResponse time: " + test.getResponseTime() + "ms");
System.out.println("\t\tTime of last refresh: " + test.getLastRefreshed());
System.out.println();
System.out.println("");
}
Which gives:
Site: http://www.bingo.com
Test 1:
Created: Tue Mar 02 20:29:29 GMT 2010
Response time: 149ms
Time of last refresh: Tue Mar 02 20:29:30 GMT 2010
Test 2:
Created: Tue Mar 02 20:29:29 GMT 2010
Response time: 100ms
Time of last refresh: Tue Mar 02 20:29:31 GMT 2010
Site: http://www.microsoft.com
Test 1:
Created: Tue Mar 02 20:29:31 GMT 2010
Response time: 507ms
Time of last refresh: Tue Mar 02 20:29:33 GMT 2010
Test 2:
Created: Tue Mar 02 20:29:31 GMT 2010
Response time: 361ms
Time of last refresh: Tue Mar 02 20:29:34 GMT 2010
Site: http://www.google.com
Test 1:
Created: Tue Mar 02 20:29:34 GMT 2010
Response time: 86ms
Time of last refresh: Tue Mar 02 20:29:35 GMT 2010
Test 2:
Created: Tue Mar 02 20:29:34 GMT 2010
Response time: 85ms
Time of last refresh: Tue Mar 02 20:29:35 GMT 2010
The idea is that I’ll use this API in a bigger project I’m working on, a simple OpenSource website monitoring/reporting suite.
Still a lot of work to do, leave a comment if you’d like to take a closer look at the API. I do intend to make a public SVN server at some point and start porting over some of these little projects.