Configure PHP-FPM Template on ZABBIX 4

ZABBIX 4 에서 PHP-FPM 모니터링 템플릿 설정 가이드

ZABBIX 4 에서 PHP-FPM 을 모니터링 하기 위한 템플릿을 설정하는 방법입니다. PHP-FPM 설정에서 pm.status_path 설정을 반드시 해 주시고 Nginx 에서 해당 경로를 읽을 수 있도록 추가 해 주셔야 합니다.

이 템플릿은 GitHub – jizhang/zabbix-templates: Zabbix templates for various services and applications. 을 참조하여 작성하였습니다.

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

템플릿 파일 임포트

zabbix-nginx-template1

host에 template 적용

zabbix-php-template1

적용 후 그래프 확인

zabbix-php-template2

You may also like...

Subscribe
Notify of
guest

이 사이트는 스팸을 줄이는 아키스밋을 사용합니다. 댓글이 어떻게 처리되는지 알아보십시오.

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x