The same here,
a crude attempt the get rust out of my brain
use strict;
use warnings;
use LWP::UserAgent;
use Time::HiRes qw(gettimeofday tv_interval);
use Getopt::Long;
my @pm_ips = qw(66.39.54.27 216.92.34.251 209.197.123.153);
my $sep = ('-' x 68)."\n";
# defaults
my $url = 'perlmonks.org';
my $count = 1;
my $sleep = 10;
my $timeout = 15;
my $nodeid = '';
# command line options
&helpme()if( (! GetOptions(
'url=s' => \$url,
'count=n' => \$count,
+
'sleep=n' => \$sleep,
'timeout=n' => \$timeout,
'node=n' => \$nodeid,
+
)) );
######################################################################
+##########
my $ua = LWP::UserAgent->new(
protocols_allowed => ['http', 'https']
+,
timeout => $timeout,);
$ua->agent("libwww-perl/5.36");
$ua->ssl_opts( verify_hostname => 0);
######################################################################
+##########
foreach my $iter ( 1..$count ){
print scalar localtime(time)," checking $url at ",(join ' ', @pm_i
+ps),"\n$sep";
foreach my $ip ( @pm_ips ){
my $t0 = [gettimeofday];
my $forced_ip = 'https://'.$ip.'/index.pl?'.($nodeid ? 'node_i
+d='.$nodeid : '');
my $resp = $ua->get( $forced_ip, Host => $url );
my $time_taken = tv_interval ($t0, [gettimeofday]);
my $got_size = length ($resp->content)|| 0;
if ($resp->is_error){
print "$url @ $forced_ip\t\t",
$resp->code," ",$resp->message,
" took $time_taken seconds (timeout $timeout secon
+ds)\n";
}
else{
print "$url @ $forced_ip\t\t",
$resp->code," ",$resp->message," ",
round_human($got_size),
" ($got_size bytes) in $time_taken seconds ",
round_human( $got_size / $time_taken),"/s\n";
}
}
if ( $count > 1 and $iter < $count ){
print $sep;
sleep $sleep;
}
}
######################################################################
+##########
sub round_human{
my( $size, $n ) =( shift, 0 );
return "0 bytes" unless defined $size;
return "0 bytes" unless $size > 0;
++$n and $size /= 1024 until $size < 1024;
return sprintf "%.4f %s",
$size, ( qw[ bytes Kb Mb Gb ] )[ $n ];
}
######################################################################
+##########
sub helpme {
print <<EOH;
USAGE of $0:
$0 [ -c n ] [ -s n ] [ -t n ] [ -n n ] [ -u s ]
-c --count how many times repeat the check. Default is 1
-s --sleep seconds between checks. Default is 10.
-t --timeout the timeout for the connection. Defaults to 15 secon
+ds
-n --nodeid the node to get. defaults to empty string (the index
+)
-u --url the base URL to ask for. Defaults to 'perlmonks.org'
+.
The request is always made using the https protocol
+and
'/index.pl?' will be appended to the URL followed by
+ an eventual nodeid
EOH
exit;
}
that gives for this thread:
perl pm-mon01.pl -t 3 -n 11157192 -c 2 -s 1
Wed Jan 24 14:29:24 2024 checking perlmonks.org at 66.39.54.27 216.92.
+34.251 209.197.123.153
--------------------------------------------------------------------
perlmonks.org @ https://66.39.54.27/index.pl?node_id=11157192
+ 200 OK 22.5518 Kb (23093 bytes) in 2.349543 seconds 9.5984 Kb/s
perlmonks.org @ https://216.92.34.251/index.pl?node_id=11157192
+ 200 OK 22.5518 Kb (23093 bytes) in 2.314545 seconds 9.7435 Kb/s
perlmonks.org @ https://209.197.123.153/index.pl?node_id=11157192
+ 500 Can't connect to 209.197.123.153:443 took 3.025284 seconds (tim
+eout 3 seconds)
--------------------------------------------------------------------
Wed Jan 24 14:29:31 2024 checking perlmonks.org at 66.39.54.27 216.92.
+34.251 209.197.123.153
--------------------------------------------------------------------
perlmonks.org @ https://66.39.54.27/index.pl?node_id=11157192
+ 200 OK 22.1104 Kb (22641 bytes) in 2.834606 seconds 7.8001 Kb/s
perlmonks.org @ https://216.92.34.251/index.pl?node_id=11157192
+ 200 OK 22.0928 Kb (22623 bytes) in 2.9505 seconds 7.4878 Kb/s
perlmonks.org @ https://209.197.123.153/index.pl?node_id=11157192
+ 500 Can't connect to 209.197.123.153:443 took 3.027898 seconds (tim
+eout 3 seconds)
L*
There are no rules, there are no thumbs..
Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.