Here you go, my first shot, should get you started for your measurements. Pay attention to the following points:
The code:
#!/usr/bin/perl use strict; use warnings; use vars qw[ $cf $lf $opt_h $VERSION ]; ($VERSION) = ' $Revision: 1.1 $ ' =~ /\$Revision:\s+([^\s]+)/; use Time::HiRes qw( time sleep ); use Config::Auto; $Config::Auto::DisablePerl = 1; use Getopt::Long; use Pod::Usage; use LWP::UserAgent; use IO::File; GetOptions ( "h" => \$opt_h, "help" => \$opt_h, "c=s" => \$cf, "config=s" => \$cf, "l=s" => \$lf, "log=s" => \$lf, ); pod2usage(0) if ($opt_h); unless ($cf && $lf) { pod2usage({-msg => "You have to specify both config- and log-file! +", -exitval => 1}); } my $conf = Config::Auto::parse($cf); my $prog_start = time; my $prog_end = $prog_start + $conf->{general}->{runtime}; my $finished = ($prog_start >= $prog_end) ? 1 : 0; unless ($finished) { my $log = IO::File->new($lf,'a+') or die ("Couldn't open log-file! +"); select $log; $|++; my $recurrence = $conf->{general}->{recurrence}; $recurrence ||= 30; print $log "Starting timecms $VERSION with configuration from $cf\ +n"; my ($cms_host, $cms_url) = ($conf->{cms}->{host}, $conf->{cms}->{u +rl}); my ($cmp_host, $cmp_url) = ($conf->{comparator}->{host}, $conf->{c +omparator}->{url}); my ($start, $response, $end, $response_time, $size_time_ratio, $sl +eep); until ($finished) { ($start, $response, $end) = (time, fetch($cms_host, $cms_url, +0), time); $response_time = $end - $start; $size_time_ratio = (length($response) / 1024) / $response_time + ; $sleep = $recurrence - $response_time; print $log "CMS \t [" . time . "] \t " . $response_time . " s +\t " . $size_time_ratio . " KB/s" . "\t " . (length($response) / 10 +24) . " KB" . "\n"; ($start, $response, $end) = (time, fetch($cmp_host, $cmp_url, +0), time); $response_time = $end - $start; $size_time_ratio = (length($response) / 1024) / $response_time + ; $sleep -= $response_time; print $log "CMP \t [" . time . "] \t " . $response_time . " s +\t " . $size_time_ratio . " KB/s" . "\t " . (length($response) / 102 +4) . " KB" ."\n"; sleep($sleep); $finished = (time >= $prog_end) ? 1 : 0; } print $log "Ending this run...\n"; $log->close(); } sub fetch { my ($server, $path, $dopost) = @_; $dopost ||= 0; my $ua = LWP::UserAgent->new( env_proxy=>1, keep_alive=>0, timeout +=>15,); my $response; $response = $ua->get('http://' . $server . $path) unless $dopost; $response = $ua->post('http://' . $server . $path) if $dopost; my $result = $response->content(); return 'error' if (!defined($result) || length($result)<=1); return $result; } __END__ =head1 NAME timecms - a simple programm to mesure deviation in response-times of t +wo web-servers =head1 SYNOPSIS timecms {-c|--config} configfile {-l|--log} logfile =head1 OPTIONS =over 4 =item B<--help> Print a brief help message and exit =item B<--config filename> Specify the config-file to use =item B<--log filename> Specify the lofile to write to =back =head1 DESCRIPTION B<This program> will read the configuration file given with C<--config +> and test the therein specified URLs every I<configurable-amount-of> seconds comparing the response-time an +d KB/sec ratio. Results of each run are logged to the file specified with the C<--log> argument. The default-recurrence is 30 seconds Events are logged in the following form C<<< CMS [logtime] response-time s KB/s KB >>> C<<< CMP [logtime] response-time s KB/s KB >>> =head1 CONFIGURATION [general] # recurrence of comparison in seconds recurrence=30 # time to live in sec runtime=172800 [cms] host=your weblogic server url=/url/to/test [comparator] host=another-host url=/url/with/nearly/same/size/content/as/cms/page =cut
regards,
tomte
Hlade's Law:
If you have a difficult task, give it to a lazy person --
they will find an easier way to do it.
In reply to Re: how to use perl to send a request to weblogic server and determine the time to response
by Tomte
in thread how to use perl to send a request to weblogic server and determine the time to response
by sasikumar
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |