root / plugins / php / php_fpm_process @ 17f78427
Historique | Voir | Annoter | Télécharger (3,6 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 |
# If your php process is listening on TCP |
| 21 |
[php_fpm_process] |
| 22 |
env.serveraddr 127.0.0.1 |
| 23 |
env.port 9000 |
| 24 |
env.path /status |
| 25 |
|
| 26 |
# If your php process is listening on Unix Socket |
| 27 |
[php_fpm_process] |
| 28 |
env.sock /var/run/php5-fpm.sock |
| 29 |
env.path /status |
| 30 |
|
| 31 |
=head1 MAGIC MARKERS |
| 32 |
|
| 33 |
#%# family=auto |
| 34 |
#%# capabilities=autoconf |
| 35 |
|
| 36 |
=head1 VERSION |
| 37 |
|
| 38 |
v1.0 |
| 39 |
|
| 40 |
=head1 AUTHOR |
| 41 |
|
| 42 |
Minitux |
| 43 |
|
| 44 |
=head1 LICENSE |
| 45 |
|
| 46 |
GNU General Public License, version 3 |
| 47 |
|
| 48 |
=cut |
| 49 |
|
| 50 |
use File::Basename; |
| 51 |
use FCGI::Client; |
| 52 |
|
| 53 |
my $ish = 1; |
| 54 |
my $header = ""; |
| 55 |
my $body = ""; |
| 56 |
my $IDLE = 0; |
| 57 |
my $ACTIVE = 0; |
| 58 |
my $TOTAL = 0; |
| 59 |
my $SLOW_REQUESTS = 0; |
| 60 |
my $PLUGIN_NAME = basename($0); |
| 61 |
|
| 62 |
my $SERVERADDR = $ENV{'serveraddr'} || "127.0.0.1";
|
| 63 |
my $PORT = $ENV{'port'} || "9000";
|
| 64 |
my $PATH = $ENV{'path'} || "/status";
|
| 65 |
my $UNIX_SOCK = $ENV{'sock'};
|
| 66 |
|
| 67 |
my $sock; |
| 68 |
|
| 69 |
if ($UNIX_SOCK) {
|
| 70 |
use IO::Socket::UNIX; |
| 71 |
$sock = IO::Socket::UNIX->new( |
| 72 |
Peer => $UNIX_SOCK, |
| 73 |
); |
| 74 |
if (!$sock) {
|
| 75 |
print "Server maybe down, unabled to connect to $UNIX_SOCK"; |
| 76 |
exit 2; |
| 77 |
} |
| 78 |
} else {
|
| 79 |
use IO::Socket::INET; |
| 80 |
$sock = IO::Socket::INET->new( |
| 81 |
PeerAddr => $SERVERADDR, |
| 82 |
PeerPort => $PORT, |
| 83 |
); |
| 84 |
if (!$sock) {
|
| 85 |
print "Server maybe down, unabled to connect to $SERVERADDR:$PORT"; |
| 86 |
exit 2; |
| 87 |
} |
| 88 |
} |
| 89 |
|
| 90 |
my $client = FCGI::Client::Connection->new( sock => $sock ); |
| 91 |
|
| 92 |
my ( $stdout, $stderr, $appstatus ) = $client->request( |
| 93 |
+{
|
| 94 |
REQUEST_METHOD => 'GET', |
| 95 |
SCRIPT_FILENAME => '', |
| 96 |
QUERY_STRING => '', |
| 97 |
SCRIPT_NAME => $PATH, |
| 98 |
}, |
| 99 |
'' |
| 100 |
); |
| 101 |
|
| 102 |
$stdout =~ s/\r//g; |
| 103 |
|
| 104 |
while($stdout =~ /([^\n]*)\n?/g) {
|
| 105 |
if(!$1) {
|
| 106 |
$ish = 0; |
| 107 |
next; |
| 108 |
} |
| 109 |
if($ish == 1) {
|
| 110 |
$header .= $1."\n"; |
| 111 |
} else {
|
| 112 |
$body .= $1."\n"; |
| 113 |
} |
| 114 |
} |
| 115 |
|
| 116 |
if ( defined $ARGV[0] and $ARGV[0] eq "config" ) |
| 117 |
{
|
| 118 |
|
| 119 |
if($body =~ m/pool:\s+(.*?)\n/) {
|
| 120 |
$pool = $1; |
| 121 |
} |
| 122 |
|
| 123 |
print <<"EOF"; |
| 124 |
multigraph ${PLUGIN_NAME}_process
|
| 125 |
graph_title php5-fpm processes for $pool |
| 126 |
graph_args --base 1000 -l 0 |
| 127 |
graph_vlabel Processes |
| 128 |
graph_scale yes |
| 129 |
graph_category processes |
| 130 |
graph_info This graph shows the php5-fpm process manager status from pool: $pool |
| 131 |
active.label Active processes |
| 132 |
active.type GAUGE |
| 133 |
active.draw AREA |
| 134 |
active.info The number of active processes |
| 135 |
idle.label Idle processes |
| 136 |
idle.type GAUGE |
| 137 |
idle.draw STACK |
| 138 |
idle.info The number of idle processes |
| 139 |
total.label Total processes |
| 140 |
total.type GAUGE |
| 141 |
total.draw LINE2 |
| 142 |
total.info The number of idle + active processes |
| 143 |
|
| 144 |
multigraph ${PLUGIN_NAME}_slowrequests
|
| 145 |
graph_title php5-fpm slow requests $pool |
| 146 |
graph_args --base 1000 -l 0 |
| 147 |
graph_vlabel Slow requests |
| 148 |
graph_scale yes |
| 149 |
graph_category processes |
| 150 |
graph_info This graph shows the php5-fpm slow request from pool: $pool |
| 151 |
slow_requests.label Slow requests |
| 152 |
slow_requests.type DERIVE |
| 153 |
slow_requests.draw LINE2 |
| 154 |
slow_requests.min 0 |
| 155 |
slow_requests.info evolution of slow requests |
| 156 |
|
| 157 |
EOF |
| 158 |
|
| 159 |
exit 0 |
| 160 |
} |
| 161 |
|
| 162 |
# print $body; |
| 163 |
|
| 164 |
print "multigraph ${PLUGIN_NAME}_process\n";
|
| 165 |
|
| 166 |
if($body =~ m/idle processes: (.*?)\n/) {
|
| 167 |
$IDLE = $1; |
| 168 |
print "idle.value ".$IDLE."\n"; |
| 169 |
} |
| 170 |
if($body =~ m/active processes: (.*?)\n/) {
|
| 171 |
$ACTIVE = $1; |
| 172 |
print "active.value ".$ACTIVE."\n"; |
| 173 |
} |
| 174 |
if($body =~ m/total processes: (.*?)\n/) {
|
| 175 |
$TOTAL = $1; |
| 176 |
print "total.value ".$TOTAL."\n"; |
| 177 |
} |
| 178 |
|
| 179 |
if($body =~ m/slow requests: (.*?)\n/) {
|
| 180 |
$SLOW_REQUESTS = $1; |
| 181 |
print "\n"; |
| 182 |
print "multigraph ${PLUGIN_NAME}_slowrequests\n";
|
| 183 |
print "slow_requests.value ".$SLOW_REQUESTS."\n"; |
| 184 |
} |
