tan.darell has asked for the wisdom of the Perl Monks concerning the following question:
OS: CentOS 4.3
Apache version: 2.0
Monitoring tool: SolarWinds APM 4.0.1
Here's the sample script:
command line: perl ${SCRIPT}
Script:
#!/usr/bin/perl
#
#
# Copyright ?? 1999-2008 SolarWinds, Inc. All Rights Reserved.
#
#
use LWP::UserAgent;
if (@ARGV[0] =~ /\bhelp\b/)
{
print "ServerKBytesPerRequest.pl StatusURL\n";
print "StatusURL - url to apache server status (ex. www.mysite.com/server-status ) \n";
exit 1;
}
# Get hostname and trim newline
$localhost = `hostname`;
$localhost =~ s/\s*$//g;
$hostname = shift || "localhost"; # $localhost
$url = "$hostname/server-status?auto&match=www&errors=0";
# Create a user agent object
$ua = new LWP::UserAgent;
$ua->agent("AgentName/0.1 " . $ua->agent);
# Create a request
my $req = new HTTP::Request GET => "http://$url";
#print "http://$url\n";
$req->content_type("application/x-www-form-urlencoded");
$req->content("match=www&errors=0");
# Pass request to the user agent and get a response back
my $res = $ua->request($req);
my $val ="";
# Check the outcome of the response
if ($res->is_success) {
#print $res->content;
$content = $res->content;
while ( $content =~ /BytesPerReq:\s(\d*)/g ){
$val = sprintf("%.2f",$1 / 1024);
print "Message: Traffic at host \"$hostname\": $val\n";
print "Statistic: $val\n";
exit 0;
}
} else {
print "Message: unable access to $hostname\n";
print "Statistic: 0\n";
exit 1;
}
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Testing on node localhost.localdomain: failed with "Undefined" status, Invalid script return code: 9
by Mr. Muskrat (Canon) on May 09, 2011 at 19:39 UTC | |
|
Re: Testing on node localhost.localdomain: failed with "Undefined" status, Invalid script return code: 9
by Anonymous Monk on May 07, 2011 at 02:51 UTC | |
by tan.darell (Initiate) on May 07, 2011 at 03:21 UTC | |
by Corion (Patriarch) on May 07, 2011 at 05:58 UTC |