├── LICENSE ├── phpfpm_processes ├── phpfpm_memory ├── phpfpm_average ├── README.md ├── phpfpm_connections └── phpfpm_status /LICENSE: -------------------------------------------------------------------------------- 1 | (The MIT License) 2 | 3 | Copyright (c) 2011 TJ Stein 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the 'Software'), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /phpfpm_processes: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # -*- sh -*- 3 | 4 | : <<=cut 5 | 6 | =head1 NAME 7 | 8 | phpfpm_average - Munin plugin to monitor the number of PHP5-FPM processes on the machine. 9 | 10 | =head1 CONFIGURATION 11 | 12 | You might need to specify connection parameters in the plugin 13 | configuration to override the defaults. These are the defaults: 14 | 15 | [phpfpm_*] 16 | env.phpbin php-fpm 17 | env.phppool www 18 | 19 | =head1 PARAMETERS: 20 | 21 | config (required) 22 | autoconf (optional - used by munin-config) 23 | 24 | =over 25 | 26 | =head1 LICENSE 27 | 28 | Copyright TJ Stein 2010 http://constantshift.com 29 | 30 | =head1 MAGICK MARKERS 31 | 32 | #%# family=manual 33 | #%# capabilities=autoconf 34 | 35 | =cut 36 | 37 | PHP_BIN=${phpbin-"php-fpm"} 38 | PHP_POOL=${phppool-"www"} 39 | 40 | if [ "$1" = "autoconf" ]; then 41 | echo yes 42 | exit 0 43 | fi 44 | 45 | if [ "$1" = "config" ]; then 46 | echo 'graph_title PHP-FPM Processes' 47 | echo 'graph_args --base 1000 -l 0 ' 48 | echo 'graph_vlabel PHP-FPM Processes' 49 | echo 'graph_category PHP' 50 | echo 'graph_info This graph shows the number of PHP-FPM processes in the system.' 51 | echo 'php_processes.label PHP-FPM Processes' 52 | echo 'php_processes.draw LINE2' 53 | echo 'php_processes.info The current number of PHP-FPM processes.' 54 | exit 0 55 | fi 56 | 57 | echo -n "php_processes.value " 58 | ps awwwux | grep "$PHP_BIN: pool $PHP_POOL" | grep -v grep | wc -l 59 | -------------------------------------------------------------------------------- /phpfpm_memory: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl 2 | # -*- perl -*- 3 | 4 | =encoding utf8 5 | 6 | =head1 NAME 7 | 8 | phpfpm_connections - Munin plugin for monitoring PHP-FPM memory usage. 9 | 10 | =head1 CONFIGURATION 11 | 12 | You might need to specify connection parameters in the plugin 13 | configuration to override the defaults. These are the defaults: 14 | 15 | [phpfpm_*] 16 | env.phpbin php-fpm 17 | env.phppool www 18 | 19 | =head1 PARAMETERS: 20 | 21 | config (required) 22 | autoconf (optional - used by munin-config) 23 | 24 | =over 25 | 26 | =head1 LICENSE 27 | 28 | Copyright TJ Stein 2010 http://constantshift.com 29 | 30 | =head1 MAGICK MARKERS 31 | 32 | #%# family=auto 33 | #%# capabilities=autoconf 34 | 35 | =cut 36 | 37 | 38 | my $PHP_BIN = exists $ENV{'phpbin'} ? $ENV{'phpbin'} : "php-fpm"; 39 | my $PHP_POOL = exists $ENV{'phppool'} ? $ENV{'phppool'} : "www"; 40 | 41 | if ( defined $ARGV[0] and $ARGV[0] eq "autoconf" ) 42 | { 43 | print "yes\n"; 44 | exit 0; 45 | } 46 | 47 | if ( exists $ARGV[0] and $ARGV[0] eq "config" ) { 48 | print "graph_title PHP-FPM Memory Usage\n"; 49 | print "graph_vlabel RAM\n"; 50 | print "graph_category PHP\n"; 51 | print "ram.label ram\n"; 52 | print "graph_args --base 1024\n"; 53 | } else { 54 | my $i = Integer; 55 | @cmd = `ps auwx | grep "$PHP_BIN: pool $PHP_POOL" | grep -v grep | grep -v phpfpm_memory`; 56 | foreach (@cmd) { 57 | @return = split(/ +/, $_); 58 | $i += @return[5]*1024; 59 | } 60 | print "ram.value ".$i."\n"; 61 | } 62 | -------------------------------------------------------------------------------- /phpfpm_average: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # -*- sh -*- 3 | 4 | : <<=cut 5 | 6 | =head1 NAME 7 | 8 | phpfpm_average - Munin plugin to monitor the average process size of PHP-FPM on the machine. 9 | 10 | =head1 CONFIGURATION 11 | 12 | You might need to specify connection parameters in the plugin 13 | configuration to override the defaults. These are the defaults: 14 | 15 | [phpfpm_*] 16 | env.phpbin php-fpm 17 | env.phppool www 18 | 19 | =head1 PARAMETERS: 20 | 21 | config (required) 22 | autoconf (optional - used by munin-config) 23 | 24 | =over 25 | 26 | =head1 LICENSE 27 | 28 | Copyright TJ Stein 2010 http://constantshift.com 29 | 30 | =head1 MAGICK MARKERS 31 | 32 | #%# family=manual 33 | #%# capabilities=autoconf 34 | 35 | =cut 36 | 37 | 38 | PHP_BIN=${phpbin-"php-fpm"} 39 | PHP_POOL=${phppool-"www"} 40 | 41 | if [ "$1" = "autoconf" ]; then 42 | echo yes 43 | exit 0 44 | fi 45 | 46 | if [ "$1" = "config" ]; then 47 | echo 'graph_title PHP-FPM Average Process Size' 48 | echo 'graph_args --base 1024 -l 0 ' 49 | echo 'graph_vlabel PHP-FPM Average Process Size' 50 | echo 'graph_category PHP' 51 | echo 'graph_info This graph shows the average process size for PHP-FPM' 52 | echo 'php_average.label PHP-FPM Average Proccess Size' 53 | echo 'php_average.draw LINE2' 54 | echo 'php_average.info The average process size for PHP-FPM' 55 | exit 0 56 | fi 57 | 58 | echo -n "php_average.value " 59 | tmpfile=/dev/shm/$$ 60 | ps awwwux | grep "${PHP_BIN}: pool $PHP_POOL" | grep -v grep | grep -v master > $tmpfile 61 | test -s $tmpfile && awk '{total_mem = $6 * 1024 + total_mem; total_proc++} END{printf("%d\n", total_mem / total_proc)}' $tmpfile || echo N 62 | rm -f $tmpfile 63 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ### To install on Ubuntu: 2 | 3 | ``` 4 | cd /usr/share/munin/plugins 5 | git clone git://github.com/tjstein/php5-fpm-munin-plugins.git 6 | chmod +x php5-fpm-munin-plugins/phpfpm_* 7 | ln -s /usr/share/munin/plugins/php5-fpm-munin-plugins/phpfpm_average /etc/munin/plugins/phpfpm_average 8 | ln -s /usr/share/munin/plugins/php5-fpm-munin-plugins/phpfpm_connections /etc/munin/plugins/phpfpm_connections 9 | ln -s /usr/share/munin/plugins/php5-fpm-munin-plugins/phpfpm_memory /etc/munin/plugins/phpfpm_memory 10 | ln -s /usr/share/munin/plugins/php5-fpm-munin-plugins/phpfpm_status /etc/munin/plugins/phpfpm_status 11 | ln -s /usr/share/munin/plugins/php5-fpm-munin-plugins/phpfpm_processes /etc/munin/plugins/phpfpm_processes 12 | service munin-node restart 13 | ``` 14 | 15 | For the phpfpm_status and phpfpm_connections plugins, you'll need to enable the _status_ feature included in versions 5.3.2+ of PHP-FPM. The directive can be found in the php5-fpm.conf file: 16 | ``` 17 | pm.status_path = /status 18 | ``` 19 | 20 | Jérôme Loyet from the Nginx forums provided some useful insight on how to get this working with Nginx. You'll essentially set up the status location directive like this: 21 | 22 | ``` 23 | location ~ ^/(status|ping)$ { 24 | include fastcgi_params; 25 | fastcgi_pass backend; 26 | fastcgi_param SCRIPT_FILENAME $fastcgi_script_name; 27 | allow 127.0.0.1:9000; 28 | allow stats_collector.localdomain; 29 | allow watchdog.localdomain; 30 | deny all; 31 | } 32 | ``` 33 | 34 | You'll need to make sure that from within your box, you can curl /status with `# curl http://localhost/status`. You should get a response similar to this: 35 | 36 | ``` 37 | accepted conn: 40163 38 | pool: www 39 | process manager: dynamic 40 | idle processes: 6 41 | active processes: 0 42 | total processes: 6 43 | ``` 44 | 45 | #### Note: 46 | 47 | The phpfpm_status plugin is particularly useful if you're using dynamic or on-demand process management. You can choose static, dynamic or on-demand in the php5-fpm.conf. 48 | 49 | ### Environment variables 50 | 51 | * env.url: Set a custom url, defaults to _http://127.0.0.1/status_ 52 | * env.ports: Set a custom port, defaults to _80_ 53 | * env.phpbin: Set a custom php binary name, defaults to _php5-fpm_ 54 | * env.phppool: Set a custom php pool, defaults to www 55 | * env.warning: Set the warning alarm, triggered when % of active/total connections higher than the defined value. Defaults to 0.6 (60%). 56 | * env.critical: Set the critical alarm, triggered when % of active/total connections higher than the defined value. Defaults to 0.8 (80%). 57 | 58 | #### Requirements: 59 | 60 | libwww-perl -------------------------------------------------------------------------------- /phpfpm_connections: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl 2 | # -*- perl -*- 3 | 4 | =encoding utf8 5 | 6 | =head1 NAME 7 | 8 | phpfpm_connections - Munin plugin to monitor the number of accepted connections to PHP-FPM. 9 | 10 | =head1 CONFIGURATION 11 | 12 | For this plugin, you will need to enable the status feature 13 | included in versions 5.3.2+ of PHP-FPM. The directive can be 14 | found in the php-fpm.conf file: 15 | 16 | pm.status_path = /status 17 | 18 | You might need to specify connection parameters in the plugin 19 | configuration to override the defaults. These are the defaults: 20 | 21 | [phpfpm_*] 22 | env.url http://127.0.0.1/status 23 | env.ports 80 24 | 25 | =head1 PARAMETERS: 26 | 27 | config (required) 28 | autoconf (optional - used by munin-config) 29 | 30 | =over 31 | 32 | =head1 LICENSE 33 | 34 | Copyright TJ Stein 2010 http://constantshift.com 35 | 36 | =head1 MAGICK MARKERS 37 | 38 | #%# family=auto 39 | #%# capabilities=autoconf 40 | 41 | =cut 42 | 43 | 44 | my $ret = undef; 45 | 46 | if (! eval "require LWP::UserAgent;") 47 | { 48 | $ret = "LWP::UserAgent not found"; 49 | } 50 | 51 | my $URL = exists $ENV{'url'} ? $ENV{'url'} : "http://127.0.0.1:%d/status"; 52 | my @PORTS = exists $ENV{'ports'} ? split(' ', $ENV{'ports'}) : (80); 53 | 54 | if ( defined $ARGV[0] and $ARGV[0] eq "autoconf" ) 55 | { 56 | if ($ret) 57 | { 58 | print "no ($ret)\n"; 59 | exit 1; 60 | } 61 | 62 | my $ua = LWP::UserAgent->new(timeout => 30); 63 | 64 | my @badports; 65 | foreach my $port (@PORTS) { 66 | my $url = sprintf $URL, $port; 67 | my $response = $ua->request(HTTP::Request->new('GET',$url)); 68 | push @badports, $port unless $response->is_success and $response->content =~ /^accepted conn:/im; 69 | } 70 | if (@badports) { 71 | print "no (phpfpm-status)\n"; 72 | exit 1; 73 | } else { 74 | print "yes\n"; 75 | exit 0; 76 | } 77 | } 78 | 79 | if ( defined $ARGV[0] and $ARGV[0] eq "config" ) 80 | { 81 | print('graph_title PHP-FPM Accepted Connections 82 | graph_args --base 1024 -l 0 83 | graph_vlabel Connections 84 | graph_category PHP 85 | graph_info Plugin created by TJ Stein 86 | accepted.label Accepted 87 | accepted.draw AREA 88 | accepted.type DERIVE 89 | accepted.min 0 90 | '); 91 | 92 | exit 0; 93 | } 94 | 95 | foreach my $port (@PORTS) 96 | { 97 | my $ua = LWP::UserAgent->new(timeout => 30); 98 | my $url = sprintf $URL, $port; 99 | my $response = $ua->request(HTTP::Request->new('GET',$url)); 100 | if ($response->content =~ /accepted conn:\s+([0-9\.]+)/im) { 101 | print "accepted.value $1\n"; 102 | } else { 103 | print "accepted.value U\n"; 104 | } 105 | } 106 | 107 | # vim:syntax=perl 108 | -------------------------------------------------------------------------------- /phpfpm_status: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl 2 | # -*- perl -*- 3 | 4 | =encoding utf8 5 | 6 | =head1 NAME 7 | 8 | phpfpm_status - Munin plugin to monitor the staus of PHP-FPM. 9 | 10 | =head1 CONFIGURATION 11 | 12 | For this plugin, you will need to enable the status feature 13 | included in versions 5.3.2+ of PHP-FPM. The directive can be 14 | found in the php5-fpm.conf file: 15 | 16 | pm.status_path = /status 17 | 18 | You might need to specify connection parameters in the plugin 19 | configuration to override the defaults. These are the defaults: 20 | 21 | [phpfpm_*] 22 | env.url http://127.0.0.1/status 23 | env.ports 80 24 | env.warning 0.6 25 | env.critical 0.8 26 | 27 | Critical and warning are optional settings and are by default 28 | triggered at 60% and 80% respectively of the total capacity. 29 | 30 | =head1 PARAMETERS: 31 | 32 | config (required) 33 | autoconf (optional - used by munin-config) 34 | 35 | =over 36 | 37 | =head1 LICENSE 38 | 39 | Copyright TJ Stein 2010 http://constantshift.com 40 | 41 | =head1 MAGICK MARKERS 42 | 43 | #%# family=auto 44 | #%# capabilities=autoconf 45 | 46 | =cut 47 | 48 | 49 | my $ret = undef; 50 | 51 | if (! eval "require LWP::UserAgent;") 52 | { 53 | $ret = "LWP::UserAgent not found"; 54 | } 55 | 56 | my $URL = exists $ENV{'url'} ? $ENV{'url'} : "http://127.0.0.1:%d/status"; 57 | my @PORTS = exists $ENV{'ports'} ? split(' ', $ENV{'ports'}) : (80); 58 | 59 | if ( defined $ARGV[0] and $ARGV[0] eq "autoconf" ) 60 | { 61 | if ($ret) 62 | { 63 | print "no ($ret)\n"; 64 | exit 1; 65 | } 66 | 67 | my $ua = LWP::UserAgent->new(timeout => 30); 68 | 69 | my @badports; 70 | foreach my $port (@PORTS) { 71 | my $url = sprintf $URL, $port; 72 | my $response = $ua->request(HTTP::Request->new('GET',$url)); 73 | push @badports, $port unless $response->is_success and $response->content =~ /^accepted conn:/im; 74 | } 75 | if (@badports) { 76 | print "no (phpfpm-status)\n"; 77 | exit 1; 78 | } else { 79 | print "yes\n"; 80 | exit 0; 81 | } 82 | } 83 | 84 | if ( defined $ARGV[0] and $ARGV[0] eq "config" ) 85 | { 86 | print('graph_title PHP-FPM Status 87 | graph_args --base 1024 -l 0 88 | graph_vlabel Connections 89 | graph_category PHP 90 | graph_order active idle total 91 | graph_info Plugin created by TJ Stein 92 | active.label Active 93 | active.draw AREA 94 | idle.label Idle 95 | idle.draw STACK 96 | total.label Total 97 | total.draw LINE1 98 | '); 99 | 100 | exit 0; 101 | } 102 | 103 | foreach my $port (@PORTS) 104 | { 105 | my $ua = LWP::UserAgent->new(timeout => 30); 106 | my $url = sprintf $URL, $port; 107 | my $response = $ua->request(HTTP::Request->new('GET',$url)); 108 | if ($response->content =~ /idle processes:\s+([0-9\.]+)/im) { 109 | print "idle.value $1\n"; 110 | } else { 111 | print "idle.value U\n"; 112 | } 113 | if ($response->content =~ /active processes:\s+([0-9\.]+)/im) { 114 | print "active.value $1\n"; 115 | } else { 116 | print "active.value U\n"; 117 | } 118 | if ($response->content =~ /total processes:\s+([0-9\.]+)/im) { 119 | print "total.value $1\n"; 120 | } else { 121 | print "total.value U\n"; 122 | } 123 | 124 | my $total = $1; 125 | my $warning_threshold = exists $ENV{warning} ? $ENV{warning} : '0.60'; 126 | my $critical_threshold = exists $ENV{critical} ? $ENV{critical} : '0.80'; 127 | 128 | my $warning_level = int($total*$warning_threshold); 129 | my $critical_level = int($total*$critical_threshold); 130 | 131 | print ("active.warning $warning_level\n"); 132 | print ("active.critical $critical_level\n"); 133 | 134 | 135 | } 136 | 137 | # vim:syntax=perl 138 | --------------------------------------------------------------------------------