root / plugins / php / php_fpm_process @ c3660c2a
Historique | Voir | Annoter | Télécharger (3,59 ko)
| 1 | c0e3ed7f | minitux | #!/usr/bin/perl |
|---|---|---|---|
| 2 | # -*- cperl -*- |
||
| 3 | |||
| 4 | =head1 NAME |
||
| 5 | |||
| 6 | 4528900a | Calle Kabo | php_fpm_process - Munin plugin to show number of number of use processes on php-fpm. |
| 7 | c0e3ed7f | minitux | |
| 8 | |||
| 9 | Inspirated by php5-fpm_status plugin by Daniel Caillibaud |
||
| 10 | |||
| 11 | =head1 APPLICABLE SYSTEMS |
||
| 12 | |||
| 13 | f8bf3961 | Raphaël Droz | Any php-fpm host |
| 14 | You will need the perl fastcgi::client on your host |
||
| 15 | c0e3ed7f | minitux | |
| 16 | =head1 CONFIGURATION |
||
| 17 | |||
| 18 | f8bf3961 | Raphaël Droz | You have to put this in your plugin.conf.d folder |
| 19 | c0e3ed7f | minitux | |
| 20 | f8bf3961 | Raphaël Droz | # If your php process is listening on TCP |
| 21 | c0e3ed7f | minitux | [php_fpm_process] |
| 22 | env.serveraddr 127.0.0.1 |
||
| 23 | env.port 9000 |
||
| 24 | f8bf3961 | Raphaël Droz | env.path /status |
| 25 | c0e3ed7f | minitux | |
| 26 | 926c0ee4 | Vincent Viallet | # If your php process is listening on Unix Socket |
| 27 | [php_fpm_process] |
||
| 28 | env.sock /var/run/php5-fpm.sock |
||
| 29 | f8bf3961 | Raphaël Droz | env.path /status |
| 30 | 926c0ee4 | Vincent Viallet | |
| 31 | c0e3ed7f | minitux | =head1 MAGIC MARKERS |
| 32 | |||
| 33 | #%# family=auto |
||
| 34 | #%# capabilities=autoconf |
||
| 35 | |||
| 36 | =head1 VERSION |
||
| 37 | |||
| 38 | f8bf3961 | Raphaël Droz | v1.0 |
| 39 | c0e3ed7f | minitux | |
| 40 | =head1 AUTHOR |
||
| 41 | |||
| 42 | f8bf3961 | Raphaël Droz | Minitux |
| 43 | c0e3ed7f | minitux | |
| 44 | =head1 LICENSE |
||
| 45 | |||
| 46 | GNU General Public License, version 3 |
||
| 47 | |||
| 48 | =cut |
||
| 49 | |||
| 50 | f8bf3961 | Raphaël Droz | use File::Basename; |
| 51 | c0e3ed7f | minitux | 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 | f8bf3961 | Raphaël Droz | my $SLOW_REQUESTS = 0; |
| 60 | my $PLUGIN_NAME = basename($0); |
||
| 61 | c0e3ed7f | minitux | |
| 62 | my $SERVERADDR = $ENV{'serveraddr'} || "127.0.0.1";
|
||
| 63 | my $PORT = $ENV{'port'} || "9000";
|
||
| 64 | my $PATH = $ENV{'path'} || "/status";
|
||
| 65 | 926c0ee4 | Vincent Viallet | 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 | f8bf3961 | Raphaël Droz | if (!$sock) {
|
| 75 | 926c0ee4 | Vincent Viallet | 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 | f8bf3961 | Raphaël Droz | if (!$sock) {
|
| 85 | 926c0ee4 | Vincent Viallet | print "Server maybe down, unabled to connect to $SERVERADDR:$PORT"; |
| 86 | exit 2; |
||
| 87 | } |
||
| 88 | c0e3ed7f | minitux | } |
| 89 | |||
| 90 | 926c0ee4 | Vincent Viallet | my $client = FCGI::Client::Connection->new( sock => $sock ); |
| 91 | |||
| 92 | f8bf3961 | Raphaël Droz | my ( $stdout, $stderr, $appstatus ) = $client->request( |
| 93 | 926c0ee4 | Vincent Viallet | +{
|
| 94 | REQUEST_METHOD => 'GET', |
||
| 95 | SCRIPT_FILENAME => '', |
||
| 96 | QUERY_STRING => '', |
||
| 97 | SCRIPT_NAME => $PATH, |
||
| 98 | }, |
||
| 99 | '' |
||
| 100 | ); |
||
| 101 | c0e3ed7f | minitux | |
| 102 | $stdout =~ s/\r//g; |
||
| 103 | |||
| 104 | while($stdout =~ /([^\n]*)\n?/g) {
|
||
| 105 | 926c0ee4 | Vincent Viallet | if(!$1) {
|
| 106 | $ish = 0; |
||
| 107 | next; |
||
| 108 | } |
||
| 109 | if($ish == 1) {
|
||
| 110 | $header .= $1."\n"; |
||
| 111 | } else {
|
||
| 112 | $body .= $1."\n"; |
||
| 113 | } |
||
| 114 | 4528900a | Calle Kabo | } |
| 115 | |||
| 116 | if ( defined $ARGV[0] and $ARGV[0] eq "config" ) |
||
| 117 | {
|
||
| 118 | f8bf3961 | Raphaël Droz | |
| 119 | 4528900a | Calle Kabo | if($body =~ m/pool:\s+(.*?)\n/) {
|
| 120 | $pool = $1; |
||
| 121 | } |
||
| 122 | |||
| 123 | f8bf3961 | Raphaël Droz | 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 php-fpm |
||
| 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 php-fpm |
||
| 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 | 4528900a | Calle Kabo | exit 0 |
| 160 | f8bf3961 | Raphaël Droz | } |
| 161 | 926c0ee4 | Vincent Viallet | |
| 162 | f8bf3961 | Raphaël Droz | # print $body; |
| 163 | |||
| 164 | print "multigraph ${PLUGIN_NAME}_process\n";
|
||
| 165 | c0e3ed7f | minitux | |
| 166 | if($body =~ m/idle processes: (.*?)\n/) {
|
||
| 167 | $IDLE = $1; |
||
| 168 | 926c0ee4 | Vincent Viallet | print "idle.value ".$IDLE."\n"; |
| 169 | c0e3ed7f | minitux | } |
| 170 | if($body =~ m/active processes: (.*?)\n/) {
|
||
| 171 | $ACTIVE = $1; |
||
| 172 | 926c0ee4 | Vincent Viallet | print "active.value ".$ACTIVE."\n"; |
| 173 | c0e3ed7f | minitux | } |
| 174 | if($body =~ m/total processes: (.*?)\n/) {
|
||
| 175 | $TOTAL = $1; |
||
| 176 | 926c0ee4 | Vincent Viallet | print "total.value ".$TOTAL."\n"; |
| 177 | c0e3ed7f | minitux | } |
| 178 | f8bf3961 | Raphaël Droz | |
| 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 | } |
