Configure Nginx Template on ZABBIX 4

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

ZABBIX 4 에서 Nginx 를 모니터링 하기 위한 템플릿을 설정하는 방법입니다. Nginx 의 stub_status 모듈을 이용하는 방법이기 때문에 반드시 stub_status 모듈이 활성화 되어 있어야 합니다.

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

server {
    listen 10061;

    location /nginx_status {
        stub_status on;
        access_log  off;

        allow 127.0.0.1;
        deny  all;
    }
}

nginx 재시작

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

nginx check file 추가
: vi /etc/zabbix/bin/nginx_status.bash

#!/bin/bash

##################################################
# AUTHOR: coulson <fallboyz@umount.net>
# WEBSITE: https://umount.net
# Description:nginx monitoring on zabbix
# Note:Zabbix 2.2 or higher
# DateTime: 2014-11-22
##################################################

# Zabbix requested parameter
KEYNAME="$1"

# Nginx defaults
STATUS_URL="http://localhost:10061/nginx_status"
WGET="/usr/bin/wget"
CURL="/usr/bin/curl"

if [ ! -f $WGET ];
then
    USE_CURL=true
fi

ERROR_WRONG_PARAM="0.0009"
ERROR_DATA="0.0008"

if [ ! $USE_CURL = true ]; then
    STATS=$($WGET_BIN -q $STATUS_URL -O - 2> /dev/null)
else
    STATS=$($CURL -S -s $STATUS_URL)
fi

if [ $? -ne 0 -o -z "$STATS" ]; then
    echo $ERROR_DATA
    exit 1
fi

case $KEYNAME in
    active_connections)
        echo "$STATS" | head -1             | awk '{print $3}'
        ;;
    accepted_connections)
        echo "$STATS" | grep -Ev '[a-zA-Z]' | awk '{print $1}'
        ;;
    handled_connections)
        echo "$STATS" | grep -Ev '[a-zA-Z]' | awk '{print $2}'
        ;;
    handled_requests)
        echo "$STATS" | grep -Ev '[a-zA-Z]' | awk '{print $3}'
        ;;
    reading)
        echo "$STATS" | tail -1             | awk '{print $2}'
        ;;
    writing)
        echo "$STATS" | tail -1             | awk '{print $4}'
        ;;
    waiting)
        echo "$STATS" | tail -1             | awk '{print $6}'
        ;;
    *)
        echo $ERROR_WRONG_PARAM
        exit 1
        ;;
esac

exit 0

UserParameter 파일 추가
: vi /etc/zabbix/zabbix_agentd.d/nginx_status.conf

UserParameter=nginx[*], bash /etc/zabbix/bin/nginx_status.bash "$1" "$2"

자빅스 재시작

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

템플릿 파일 임포트 (nginx_template.xml)

zabbix-nginx-template1

host에 template 적용

zabbix-nginx-template2

적용 후 그래프 확인

zabbix-nginx-template3

You may also like...

Subscribe
Notify of
guest

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

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