root / plugins / php / eaccelerator-usage @ b0b39b01
Historique | Voir | Annoter | Télécharger (2,18 ko)
| 1 |
#!/usr/bin/perl -w |
|---|---|
| 2 |
# -*- perl -*- |
| 3 |
|
| 4 |
=head1 NAME |
| 5 |
|
| 6 |
eacc - Plugin to monitor eAccelerator |
| 7 |
|
| 8 |
=head1 CONFIGURATION EXAMPLE |
| 9 |
|
| 10 |
/etc/munin/plugin-conf.d/eacc or other file in that dir must contain: |
| 11 |
|
| 12 |
[eacc] |
| 13 |
env.user admin |
| 14 |
env.pass eAccelerator |
| 15 |
env.host 127.0.0.1 |
| 16 |
env.port 80 |
| 17 |
env.page control.php |
| 18 |
|
| 19 |
|
| 20 |
=head1 AUTHOR |
| 21 |
|
| 22 |
falselike at gmail dot com |
| 23 |
|
| 24 |
=head1 LICENSE |
| 25 |
|
| 26 |
No license |
| 27 |
|
| 28 |
=head1 MAGIC MARKERS |
| 29 |
|
| 30 |
#%# family=auto |
| 31 |
#%# capabilities=autoconf |
| 32 |
|
| 33 |
=cut |
| 34 |
|
| 35 |
use LWP; |
| 36 |
|
| 37 |
my $host = $ENV{'host'} || '127.0.0.1';
|
| 38 |
my $port = $ENV{'port'} || 80;
|
| 39 |
my $page = $ENV{'page'} || 'control.php';
|
| 40 |
|
| 41 |
my $user = $ENV{'user'} || 'admin';
|
| 42 |
my $pass = $ENV{'pass'} || 'eAccelerator';
|
| 43 |
my $realm = $ENV{'realm'} || 'eAccelerator control panel';
|
| 44 |
|
| 45 |
if ($#ARGV eq 0) {
|
| 46 |
if ($ARGV[0] eq 'autoconf') {
|
| 47 |
print "yes\n"; |
| 48 |
exit(0); |
| 49 |
} |
| 50 |
|
| 51 |
if ($ARGV[0] eq 'config') {
|
| 52 |
print "eAccelerator\n"; |
| 53 |
print "graph_title eAccelerator\n"; |
| 54 |
print "graph_category webserver\n"; |
| 55 |
print "memusage.label Memory Usage %\n"; |
| 56 |
print "memusage.warning 95\n"; |
| 57 |
print "memusage.critical 95\n"; |
| 58 |
print "memusage.label Memory Usage MB\n"; |
| 59 |
print "memmax.label Cache Size MB\n"; |
| 60 |
print "memused.label Used Memory MB\n"; |
| 61 |
print "memfree.label Free Memory MB\n"; |
| 62 |
print "cached.label Scripts Cached\n"; |
| 63 |
print "removed.label Scripts Removed\n"; |
| 64 |
print "keys.label Keys Cached\n"; |
| 65 |
exit(); |
| 66 |
} |
| 67 |
} |
| 68 |
|
| 69 |
my $ua = LWP::UserAgent->new(); |
| 70 |
$ua->credentials($host . ':' . $port, $realm, $user, $pass); |
| 71 |
my $url = 'http://'. $host .':'. $port .'/'. $page; |
| 72 |
my $resp = $ua->get($url); |
| 73 |
|
| 74 |
if ($resp->is_success) {
|
| 75 |
$b = ''; |
| 76 |
foreach (split '\n', $resp->content) {
|
| 77 |
if (/([\d\.]+)/) {
|
| 78 |
$v = $1; |
| 79 |
# debug |
| 80 |
#print "$b\n$_\n"; |
| 81 |
print "memmax.value $v\n" if $b =~ /total/i; |
| 82 |
if ($b =~ /in use/i) {
|
| 83 |
print "memused.value $v\n"; |
| 84 |
if (/([\d+\.]+)\s*%/) {
|
| 85 |
print "memusage.value $1\n"; |
| 86 |
} |
| 87 |
} |
| 88 |
print "memfree.value $v\n" if $b =~ /free/i; |
| 89 |
print "cached.value $v\n" if $b =~ /cached/i; |
| 90 |
print "removed.value $v\n" if $b =~ /removed/i; |
| 91 |
print "keys.value $v\n" if $b =~ /keys/i; |
| 92 |
|
| 93 |
} |
| 94 |
$b = $_; |
| 95 |
} |
| 96 |
} else {
|
| 97 |
my $ret = $resp->status_line; |
| 98 |
die "Authorization failed!\nPlease recheck your credentials:\n\tenv.user $user\n\tenv.pass $pass\n\n" if $ret =~ /401/; |
| 99 |
die "Can't get $url -- ", $ret; |
| 100 |
} |
