One problem with network monitoring is that latency and router performance do not tell the whole story. What you really want to know is if you can transfer data at the application level across the WAN/VPN. This is particularly useful if you are skimping on your connection to your remote offices by using DSL or cable modems. The service levels vary significantly, and it is difficult to track down sporadic slowdowns/lockups without some good data. One way to do this is to simply transfer a file via HTTP every 15 seconds and measure the time it takes. We created a simple perl script that outputs a web page that shows how much time it took for a transfer of a 1000 byte file. Colors vary based on the time, and red XXXs are printed if the time is more than a second. First, we need to create a 1000 byte file and put it on the server we want to test the transfer. We just went in to vi, inserted a character, hit escape and then entered “1000.”. Well, 1002 bytes including EOF, but close enough:
[root@srv-2 html]# ls -l /var/www/html/test.html -rw-r--r-- 1 root root 1002 May 27 00:57 test.html [root@srv-2 html]# |
To monitor the server, we just run the script:
[root@srv-1 httptest]# ./ht.pl |
The output of the web page looks like this:
In this case the server was rebooted, and you can see the error. Note that you could easily test for lack of a timestamp if you wanted, and this would show that the web server was down, but that isn’t really the purpose of the script. Normally the web server stays up, or at least, there are better tools to monitor the server that you are probably already using. Here is the script:
#!/usr/bin/perl open (HTTPTESTOUT, "> /var/www/html/ht.html"); print HTTPTESTOUT "<html><head><title>HTTP Tester</title></head><body>\n"; close HTTPTESTOUT; ($sec,$min,$hour,$mday,$mon,$year,$wday, $yday,$isdst)=localtime(time); $currday=$mday; while (6 ne 9){ #i don't mind ($sec,$min,$hour,$mday,$mon,$year,$wday, $yday,$isdst)=localtime(time); if ($currday ne $mday){ $currday=$mday; open (HTTPTESTOUT, "> /var/www/html/ht.html"); print HTTPTESTOUT "<html><head><title>HTTP Tester</title> </head><body>\n"; close HTTPTESTOUT; } open (HTTPTESTOUT, ">> /var/www/html/ht.html"); $starttime=time; system("/usr/bin/wget -nv -o /root/httptest/ht.txt -O \\ /root/httptest/htp.html http://10.50.100.52/test.html "); ($sec,$min,$hour,$mday,$mon,$year,$wday, $yday,$isdst)=localtime(time); printf HTTPTESTOUT "%4d-%02d-%02d ", $year+1900,$mon+1,$mday; open (HTTPTEST, "< /root/httptest/ht.txt"); while (<HTTPTEST>) { s/(\d\d:\d\d:\d\d)//g; print HTTPTESTOUT $1; } close HTTPTEST; $endtime=time; $difftime=$endtime-$starttime; if ($difftime > 1){ print HTTPTESTOUT "<font color=red>XXXXXXXXX "; } elsif ($difftime > 0){ print HTTPTESTOUT "<font color=blue>"; } else { print HTTPTESTOUT "<font color=black>"; } print HTTPTESTOUT " - ".$difftime."</font><br />"; close HTTPTESTOUT; sleep 15; } |
The HTML really isn’t proper, because we never close the tags. It works fine, though. The idea is that we create the HTML header and then tack on the results to the end of the file. We also truncate the file by seeing if mday changes. The app runs in a loop forever, well, until 6 equals 9. We use the -o option on wget to send the results to a file:
[root@srv-1 httptest]# cat ht.txt 05:01:47 URL:http://10.50.100.52/test.html [1,002/1,002] -> "/root/httptest/htp.html" [1] |