Skip to content

Commit

Permalink
[add] files for Zabbix
Browse files Browse the repository at this point in the history
  • Loading branch information
rvalitov committed Aug 13, 2019
1 parent 16526b3 commit ce5b04f
Show file tree
Hide file tree
Showing 4 changed files with 1,880 additions and 3 deletions.
2 changes: 2 additions & 0 deletions zabbix/userparameter_php_fpm.conf
@@ -0,0 +1,2 @@
UserParameter=php-fpm.discover,/etc/zabbix/zabbix_php_fpm_discovery.sh
UserParameter=php-fpm.status[*],/etc/zabbix/zabbix_php_fpm_status.sh $1 $2
15 changes: 12 additions & 3 deletions zabbix/zabbix_php_fpm_discovery.sh
Expand Up @@ -8,6 +8,7 @@ S_AWK=`which awk`
S_SORT=`which sort`
S_HEAD=`which head`
S_LSOF=`which lsof`
S_JQ=`which jq`

if [[ ! -f $S_PS ]]; then
echo "Utility 'ps' not found. Please, install it first."
Expand All @@ -33,6 +34,10 @@ if [[ ! -f $S_LSOF ]]; then
echo "Utility 'lsof' not found. Please, install it first."
exit 1
fi
if [[ ! -f $S_JQ ]]; then
echo "Utility 'jq' not found. Please, install it first."
exit 1
fi

mapfile -t PS_LIST < <( $S_PS ax | $S_GREP "php-fpm: pool " | $S_GREP -v grep )
POOL_LIST=`printf '%s\n' "${PS_LIST[@]}" | $S_AWK '{print $NF}' | $S_SORT -u`
Expand All @@ -43,12 +48,16 @@ do
if [[ $POOL_FIRST == 1 ]]; then
echo -n ","
fi
POOL_FIRST=1
POOL_PID=`printf '%s\n' "${PS_LIST[@]}" | $S_GREP "php-fpm: pool $line" | $S_HEAD -1 | $S_AWK '{print $1}'`
if [[ ! -z $POOL_PID ]]; then
POOL_SOCKET=`$S_LSOF -p $POOL_PID | $S_GREP unix | $S_HEAD -1 | $S_AWK '{ print $(NF-1)}'`
POOL_SOCKET=`$S_LSOF -p $POOL_PID 2>/dev/null | $S_GREP unix | $S_HEAD -1 | $S_AWK '{ print $(NF-1)}'`
if [[ ! -z $POOL_SOCKET ]]; then
echo -n "{\"{#POOLNAME}\":\"$line\",\"{#POOLSOCKET}\":\"$POOL_SOCKET\"}"
echo -n "{\"{#POOLNAME}\":"
echo -n "$line" | $S_JQ -aR .
echo -n ",\"{#POOLSOCKET}\":"
echo -n "$POOL_SOCKET" | $S_JQ -aR .
echo -n "}"
POOL_FIRST=1
fi
fi
done <<< "$POOL_LIST"
Expand Down
37 changes: 37 additions & 0 deletions zabbix/zabbix_php_fpm_status.sh
@@ -0,0 +1,37 @@
#!/bin/bash
#Ramil Valitov ramilvalitov@gmail.com
#https://github.com/rvalitov/zabbix-php-fpm

S_FCGI=`which cgi-fcgi`
S_GREP=`which grep`

if [[ ! -f $S_FCGI ]]; then
echo "Utility 'cgi-fcgi' not found. Please, install it first."
echo "In Debian you should install a package libfcgi0ldbl"
exit 1
fi

if [[ ! -f $S_GREP ]]; then
echo "Utility 'grep' not found. Please, install it first."
exit 1
fi

if [[ -z $1 ]] || [[ -z $2 ]]; then
echo "No input data specified"
echo "Usage: $0 socket status"
echo "where:"
echo "socket - path to socket file, for example, /var/lib/php7.3-fpm/web1.sock"
echo "status - path configured in pm.status of PHP-FPM"
exit 1
fi

POOL_URL=$1
POOL_PATH=$2
echo "$POOL_URL $POOL_PATH" > /tmp/test.txt
#connecting to socket or address, https://easyengine.io/tutorials/php/directly-connect-php-fpm/
PHP_STATUS=`SCRIPT_NAME=$POOL_PATH \
SCRIPT_FILENAME=$POOL_PATH \
QUERY_STRING=json \
REQUEST_METHOD=GET \
$S_FCGI -bind -connect $POOL_URL 2>/dev/null`
echo "$PHP_STATUS" | $S_GREP "{"

0 comments on commit ce5b04f

Please sign in to comment.