Menu Close

Configure php-fpm template on Zabbix

Configure php-fpm template on Zabbix

 

참고 URL
https://github.com/jizhang/zabbix-templates

 

php-fpm.conf 파일 수정
: vi /data/apps/ln/php/etc/php-fpm.conf (아래 라인 추가)

pm.status_path = /fpm_status

 

nginx site config 파일 생성
: vi /data/apps/ln/nginx/conf/sites-enabled/php_status.conf

server {
    listen 10061;

    location /fpm_status {
        fastcgi_pass  unix:/data/apps/ln/php/php-fpm.sock;
        include       fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        access_log off;
        allow 127.0.0.1;
        deny  all;
    }
}

 

nginx 재시작

[root@10-19-10-10 /]# systemctl restart nginx

 

php-fpm check file 추가
: vi /etc/zabbix/bin/php-fpm_status.bash

#!/bin/bash
##################################
# Zabbix monitoring script
#
# php-fpm:
#  - anything available via FPM status page
#
##################################
# Contact:
#  vincent.viallet@gmail.com
##################################
# ChangeLog:
#  20100922	VV	initial creation
##################################

# Zabbix requested parameter
ZBX_REQ_DATA="$1"
ZBX_REQ_DATA_URL="$2"

# Nginx defaults
NGINX_STATUS_DEFAULT_URL="http://localhost:10061/fpm_status"
WGET_BIN="/usr/bin/wget"

#
# Error handling:
#  - need to be displayable in Zabbix (avoid NOT_SUPPORTED)
#  - items need to be of type "float" (allow negative + float)
#
ERROR_NO_ACCESS_FILE="-0.9900"
ERROR_NO_ACCESS="-0.9901"
ERROR_WRONG_PARAM="-0.9902"
ERROR_DATA="-0.9903" # either can not connect /	bad host / bad port

# Handle host and port if non-default
if [ ! -z "$ZBX_REQ_DATA_URL" ]; then
  URL="$ZBX_REQ_DATA_URL"
else
  URL="$NGINX_STATUS_DEFAULT_URL"
fi

# save the nginx stats in a variable for future parsing
NGINX_STATS=$($WGET_BIN -q $URL -O - 2> /dev/null)

# error during retrieve
if [ $? -ne 0 -o -z "$NGINX_STATS" ]; then
  echo $ERROR_DATA
  exit 1
fi

# 
# Extract data from nginx stats
#
RESULT=$(echo "$NGINX_STATS" | awk 'match($0, "^'"$ZBX_REQ_DATA"':[[:space:]]+(.*)", a) { print a[1] }')
if [ $? -ne 0 -o -z "$RESULT" ]; then
    echo $ERROR_WRONG_PARAM
    exit 1
fi

echo $RESULT

exit 0

 

UserParameter 파일 추가
: vi /etc/zabbix/zabbix_agentd/php-fpm_status.conf

UserParameter=php-fpm[*], bash /etc/zabbix/bin/php-fpm_status.bash "$1" "$2"

 

자빅스 재시작

[root@10-19-10-10 /]# systemctl restart zabbix_agentd

 

템플릿 파일 임포트
Tempalate URL

zabbix-nginx-template1

 

host에 template 적용

zabbix-php-template1

 

적용 후 그래프 확인

zabbix-php-template2

 

댓글 남기기

이메일은 공개되지 않습니다. 필수 입력창은 * 로 표시되어 있습니다

This site uses Akismet to reduce spam. Learn how your comment data is processed.