Last active
August 29, 2015 14:07
-
-
Save tierra/4e34f3f36c8985a54288 to your computer and use it in GitHub Desktop.
Munin plugins for PHP-FPM
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
#%# family=manual | |
#%# capabilities=autoconf | |
if [ "$1" = "autoconf" ]; then | |
echo yes | |
exit 0 | |
fi | |
if [ "$1" = "config" ]; then | |
echo 'graph_title php-fpm average process size' | |
echo 'graph_args --base 1024 -l 0 ' | |
echo 'graph_vlabel average process size' | |
echo 'graph_category php-fpm' | |
echo 'graph_info This graph shows the average process size for all php-fpm pools.' | |
for sock in /var/run/php5-fpm*.sock | |
do | |
POOL=$(echo $sock | sed 's|/var/run/php5-fpm-||' | sed 's|\.sock||') | |
MUNIN_VAR=$(echo "$POOL" | sed 's|-|_|') | |
echo "$MUNIN_VAR.label $POOL" | |
echo "$MUNIN_VAR.info The average process size for pool: $POOL" | |
done; | |
exit 0 | |
fi | |
for sock in /var/run/php5-fpm*.sock | |
do | |
POOL=$(echo $sock | sed 's|/var/run/php5-fpm-||' | sed 's|\.sock||') | |
MUNIN_VAR=$(echo "$POOL" | sed 's|-|_|') | |
PS_POOLS=$(ps ho rss,command --ppid $(cat /var/run/php5-fpm.pid)) | |
if ! $(echo "$PS_POOLS" | grep -q $POOL); then | |
echo "$MUNIN_VAR.value 0" | |
continue | |
fi | |
AVG_SIZE=$(echo "$PS_POOLS" | grep $POOL | awk '{total_mem = $1 * 1024 + total_mem; total_proc++} END{printf("%d\n", total_mem / total_proc)}') | |
echo "$MUNIN_VAR.value $AVG_SIZE" | |
done; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
#%# family=manual | |
#%# capabilities=autoconf | |
if [ "$1" = "autoconf" ]; then | |
echo yes | |
exit 0 | |
fi | |
if [ "$1" = "config" ]; then | |
echo 'graph_title php-fpm listen queue' | |
echo 'graph_args --base 1024 -l 0 ' | |
echo 'graph_vlabel queued connections' | |
echo 'graph_category php-fpm' | |
echo 'graph_info The number of queued connections for all php-fpm pools.' | |
for sock in /var/run/php5-fpm*.sock | |
do | |
POOL=$(echo $sock | sed 's|/var/run/php5-fpm-||' | sed 's|\.sock||') | |
MUNIN_VAR=$(echo "$POOL" | sed 's|-|_|') | |
echo "$MUNIN_VAR.label $POOL" | |
echo "$MUNIN_VAR.info The queued connections for pool: $POOL" | |
done; | |
exit 0 | |
fi | |
for sock in /var/run/php5-fpm*.sock | |
do | |
POOL=$(echo $sock | sed 's|/var/run/php5-fpm-||' | sed 's|\.sock||') | |
MUNIN_VAR=$(echo "$POOL" | sed 's|-|_|') | |
CONNECTIONS=$(curl -s http://127.0.0.1/fpm_status_$POOL | grep -m 1 'listen queue' | egrep -o '([0-9]+)') | |
echo "$MUNIN_VAR.value $CONNECTIONS" | |
done; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
#%# family=manual | |
#%# capabilities=autoconf | |
if [ "$1" = "autoconf" ]; then | |
echo yes | |
exit 0 | |
fi | |
if [ "$1" = "config" ]; then | |
echo 'graph_title php-fpm memory usage' | |
echo 'graph_args --base 1024 -l 0 ' | |
echo 'graph_vlabel RAM' | |
echo 'graph_category php-fpm' | |
echo 'graph_info This graph shows the total memory usage for all php-fpm pools.' | |
for sock in /var/run/php5-fpm*.sock | |
do | |
POOL=$(echo $sock | sed 's|/var/run/php5-fpm-||' | sed 's|\.sock||'); | |
MUNIN_VAR=$(echo "$POOL" | sed 's|-|_|') | |
echo "$MUNIN_VAR.label $POOL" | |
echo "$MUNIN_VAR.draw AREASTACK" | |
echo "$MUNIN_VAR.info The memory usage for pool: $POOL" | |
done; | |
exit 0 | |
fi | |
for sock in /var/run/php5-fpm*.sock | |
do | |
POOL=$(echo $sock | sed 's|/var/run/php5-fpm-||' | sed 's|\.sock||'); | |
MUNIN_VAR=$(echo "$POOL" | sed 's|-|_|') | |
PS_POOLS=$(ps ho rss,command --ppid $(cat /var/run/php5-fpm.pid)); | |
if ! $(echo "$PS_POOLS" | grep -q $POOL); then | |
echo "$MUNIN_VAR.value 0" | |
continue | |
fi | |
MEMORY_USAGE=$(echo "$PS_POOLS" | grep $POOL | awk '{total_mem = $1 * 1024 + total_mem} END{printf("%d\n", total_mem)}') | |
echo "$MUNIN_VAR.value $MEMORY_USAGE" | |
done; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment