root / plugins / php / php_fpm_process @ 4528900a
Historique | Voir | Annoter | Télécharger (2,64 ko)
| 1 |
#!/usr/bin/perl |
|---|---|
| 2 |
# -*- cperl -*- |
| 3 |
|
| 4 |
=head1 NAME |
| 5 |
|
| 6 |
php_fpm_process - Munin plugin to show number of number of use processes on php-fpm. |
| 7 |
|
| 8 |
|
| 9 |
Inspirated by php5-fpm_status plugin by Daniel Caillibaud |
| 10 |
|
| 11 |
=head1 APPLICABLE SYSTEMS |
| 12 |
|
| 13 |
Any php-fpm host |
| 14 |
You will need the perl fastcgi::client on your host |
| 15 |
|
| 16 |
=head1 CONFIGURATION |
| 17 |
|
| 18 |
You have to put this in your plugin.conf.d folder |
| 19 |
|
| 20 |
[php_fpm_process] |
| 21 |
env.serveraddr 127.0.0.1 |
| 22 |
env.port 9000 |
| 23 |
env.path /status |
| 24 |
|
| 25 |
=head1 MAGIC MARKERS |
| 26 |
|
| 27 |
#%# family=auto |
| 28 |
#%# capabilities=autoconf |
| 29 |
|
| 30 |
=head1 VERSION |
| 31 |
|
| 32 |
v1.0 |
| 33 |
|
| 34 |
=head1 AUTHOR |
| 35 |
|
| 36 |
Minitux |
| 37 |
|
| 38 |
=head1 LICENSE |
| 39 |
|
| 40 |
GNU General Public License, version 3 |
| 41 |
|
| 42 |
=cut |
| 43 |
|
| 44 |
|
| 45 |
use IO::Socket::INET; |
| 46 |
use FCGI::Client; |
| 47 |
|
| 48 |
my $ish = 1; |
| 49 |
my $header = ""; |
| 50 |
my $body = ""; |
| 51 |
my $IDLE = 0; |
| 52 |
my $ACTIVE = 0; |
| 53 |
my $TOTAL = 0; |
| 54 |
|
| 55 |
my $SERVERADDR = $ENV{'serveraddr'} || "127.0.0.1";
|
| 56 |
my $PORT = $ENV{'port'} || "9000";
|
| 57 |
my $PATH = $ENV{'path'} || "/status";
|
| 58 |
|
| 59 |
my $sock = IO::Socket::INET->new( |
| 60 |
PeerAddr => $SERVERADDR, |
| 61 |
PeerPort => $PORT, |
| 62 |
); |
| 63 |
|
| 64 |
if (!$sock) {
|
| 65 |
print "Server maybe down, unabled to connect to $SERVERADDR:$PORT"; |
| 66 |
exit 2; |
| 67 |
} |
| 68 |
|
| 69 |
my $client = FCGI::Client::Connection->new( sock => $sock ); |
| 70 |
my ( $stdout, $stderr, $appstatus ) = $client->request( |
| 71 |
+{
|
| 72 |
REQUEST_METHOD => 'GET', |
| 73 |
SCRIPT_FILENAME => '', |
| 74 |
QUERY_STRING => '', |
| 75 |
SCRIPT_NAME => $PATH, |
| 76 |
}, |
| 77 |
'' |
| 78 |
); |
| 79 |
|
| 80 |
$stdout =~ s/\r//g; |
| 81 |
|
| 82 |
while($stdout =~ /([^\n]*)\n?/g) {
|
| 83 |
if(!$1) {
|
| 84 |
$ish = 0; |
| 85 |
next; |
| 86 |
} |
| 87 |
if($ish == 1) {
|
| 88 |
$header .= $1."\n"; |
| 89 |
} else {
|
| 90 |
$body .= $1."\n"; |
| 91 |
} |
| 92 |
} |
| 93 |
|
| 94 |
if ( defined $ARGV[0] and $ARGV[0] eq "config" ) |
| 95 |
{
|
| 96 |
|
| 97 |
if($body =~ m/pool:\s+(.*?)\n/) {
|
| 98 |
$pool = $1; |
| 99 |
} |
| 100 |
|
| 101 |
print "graph_title php5-fpm status $pool\n"; |
| 102 |
print "graph_args --base 1000 -l 0\n"; |
| 103 |
print "graph_vlabel Processes\n"; |
| 104 |
print "graph_scale yes\n"; |
| 105 |
print "graph_category php\n"; |
| 106 |
print "graph_info This graph shows the php5-fpm process manager status from pool: $pool\n"; |
| 107 |
print "active.label Active processes\n"; |
| 108 |
print "active.type GAUGE\n"; |
| 109 |
print "active.draw AREA\n"; |
| 110 |
print "active.info The number of active processes\n"; |
| 111 |
print "idle.label Idle processes\n"; |
| 112 |
print "idle.type GAUGE\n"; |
| 113 |
print "idle.draw STACK\n"; |
| 114 |
print "idle.info The number of idle processes\n"; |
| 115 |
print "total.label Total processes\n"; |
| 116 |
print "total.type GAUGE\n"; |
| 117 |
print "total.draw LINE2\n"; |
| 118 |
print "total.info The number of idle + active processes\n"; |
| 119 |
exit 0 |
| 120 |
} |
| 121 |
|
| 122 |
if($body =~ m/idle processes: (.*?)\n/) {
|
| 123 |
$IDLE = $1; |
| 124 |
print "idle.value ".$IDLE."\n"; |
| 125 |
} |
| 126 |
if($body =~ m/active processes: (.*?)\n/) {
|
| 127 |
$ACTIVE = $1; |
| 128 |
print "active.value ".$ACTIVE."\n"; |
| 129 |
} |
| 130 |
if($body =~ m/total processes: (.*?)\n/) {
|
| 131 |
$TOTAL = $1; |
| 132 |
print "total.value ".$TOTAL."\n"; |
| 133 |
} |
