apc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
# | |
# Magic markers: | |
#%# family=auto | |
#%# capabilities=autoconf | |
my $ret = undef; | |
if (! eval "require LWP::UserAgent;") | |
{ | |
$ret = "LWP::UserAgent not found"; | |
} | |
my $URL = exists $ENV{'url'} ? $ENV{'url'} : "http://127.0.0.1:%d/apcinfo.php?auto"; | |
my @PORTS = exists $ENV{'ports'} ? split(' ', $ENV{'ports'}) : (80); | |
if ( defined $ARGV[0] and $ARGV[0] eq "autoconf" ) | |
{ | |
if ($ret) | |
{ | |
print "no ($ret)\n"; | |
exit 1; | |
} | |
my $ua = LWP::UserAgent->new(timeout => 30); | |
my @badports; | |
foreach my $port (@PORTS) { | |
my $url = sprintf $URL, $port; | |
my $response = $ua->request(HTTP::Request->new('GET',$url)); | |
push @badports, $port unless $response->is_success and $response->content =~ /^size:/im; | |
} | |
if (@badports) { | |
print "no (apc-status)\n"; | |
exit 1; | |
} else { | |
print "yes\n"; | |
exit 0; | |
} | |
} | |
if ( defined $ARGV[0] and $ARGV[0] eq "config" ) | |
{ | |
print('graph_title PHP APC Cache Size | |
graph_args --base 1024 -l 0 | |
graph_vlabel bytes | |
graph_category APC | |
graph_order used free | |
graph_total Total | |
graph_info Plugin created by AA | |
used.label Used | |
used.draw AREA | |
free.label Free | |
free.draw STACK | |
'); | |
exit 0; | |
} | |
foreach my $port (@PORTS) | |
{ | |
my $ua = LWP::UserAgent->new(timeout => 30); | |
my $url = sprintf $URL, $port; | |
my $response = $ua->request(HTTP::Request->new('GET',$url)); | |
if ($response->content =~ /used:\s+([0-9\.]+)/im) { | |
print "used.value $1\n"; | |
} else { | |
print "used.value U\n"; | |
} | |
if ($response->content =~ /free:\s+([0-9\.]+)/im) { | |
print "free.value $1\n"; | |
} else { | |
print "free.value U\n"; | |
} | |
} | |
# vim:syntax=perl |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment