3
0
mirror of https://github.com/rvalitov/zabbix-php-fpm.git synced 2023-11-05 03:30:27 +01:00

[add] files for Zabbix

This commit is contained in:
Ramil Valitov 2019-08-13 11:32:59 +03:00
parent 16526b37e8
commit ce5b04f74c
No known key found for this signature in database
GPG Key ID: 645768E8FD0E18C7
4 changed files with 1880 additions and 3 deletions

View File

@ -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

View File

@ -8,6 +8,7 @@ S_AWK=`which awk`
S_SORT=`which sort` S_SORT=`which sort`
S_HEAD=`which head` S_HEAD=`which head`
S_LSOF=`which lsof` S_LSOF=`which lsof`
S_JQ=`which jq`
if [[ ! -f $S_PS ]]; then if [[ ! -f $S_PS ]]; then
echo "Utility 'ps' not found. Please, install it first." echo "Utility 'ps' not found. Please, install it first."
@ -33,6 +34,10 @@ if [[ ! -f $S_LSOF ]]; then
echo "Utility 'lsof' not found. Please, install it first." echo "Utility 'lsof' not found. Please, install it first."
exit 1 exit 1
fi 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 ) 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` POOL_LIST=`printf '%s\n' "${PS_LIST[@]}" | $S_AWK '{print $NF}' | $S_SORT -u`
@ -43,12 +48,16 @@ do
if [[ $POOL_FIRST == 1 ]]; then if [[ $POOL_FIRST == 1 ]]; then
echo -n "," echo -n ","
fi fi
POOL_FIRST=1
POOL_PID=`printf '%s\n' "${PS_LIST[@]}" | $S_GREP "php-fpm: pool $line" | $S_HEAD -1 | $S_AWK '{print $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 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 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
fi fi
done <<< "$POOL_LIST" done <<< "$POOL_LIST"

View File

@ -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 "{"

File diff suppressed because it is too large Load Diff