From ce5b04f74c1d4c65eb1d6a8392dd897ddda31b74 Mon Sep 17 00:00:00 2001 From: Ramil Valitov Date: Tue, 13 Aug 2019 11:32:59 +0300 Subject: [PATCH] [add] files for Zabbix --- zabbix/userparameter_php_fpm.conf | 2 + zabbix/zabbix_php_fpm_discovery.sh | 15 +- zabbix/zabbix_php_fpm_status.sh | 37 + zabbix/zabbix_php_fpm_template.xml | 1829 ++++++++++++++++++++++++++++ 4 files changed, 1880 insertions(+), 3 deletions(-) create mode 100644 zabbix/userparameter_php_fpm.conf create mode 100644 zabbix/zabbix_php_fpm_status.sh create mode 100644 zabbix/zabbix_php_fpm_template.xml diff --git a/zabbix/userparameter_php_fpm.conf b/zabbix/userparameter_php_fpm.conf new file mode 100644 index 0000000..7e3db66 --- /dev/null +++ b/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 \ No newline at end of file diff --git a/zabbix/zabbix_php_fpm_discovery.sh b/zabbix/zabbix_php_fpm_discovery.sh index c21f8c5..6e1caad 100644 --- a/zabbix/zabbix_php_fpm_discovery.sh +++ b/zabbix/zabbix_php_fpm_discovery.sh @@ -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." @@ -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` @@ -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" diff --git a/zabbix/zabbix_php_fpm_status.sh b/zabbix/zabbix_php_fpm_status.sh new file mode 100644 index 0000000..590f0aa --- /dev/null +++ b/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 "{" \ No newline at end of file diff --git a/zabbix/zabbix_php_fpm_template.xml b/zabbix/zabbix_php_fpm_template.xml new file mode 100644 index 0000000..16b1f55 --- /dev/null +++ b/zabbix/zabbix_php_fpm_template.xml @@ -0,0 +1,1829 @@ + + + 4.2 + 2019-08-13T08:28:09Z + + + Templates/Applications + + + + + +