[nginx] cacti percona plugins

FreeBSD cacati percona nginx 템플릿 이용시 반드시 input method 스크립트의 변경이 필요 합니다. 

해당내용의 변경 없이 템플릿을 사용하면 정상적인 모니터링이 불가능 합니다.

 

기존 APM 환경에서 Nginx 로 web server 만 변경 하였기 때문에 cacti.conf 를 추가 하는 방법으로 테스트를 진행하였습니다.

 

 

cacti.conf 파일 생성 

root@bsd11:/usr/local/etc/nginx/conf.d #
root@bsd11:/usr/local/etc/nginx/conf.d # vi cacti.conf
server {
    listen       80;
    server_name  cacti.crois.net;
    index        index.php index.html index.htm;
    root         /usr/local/share;

    location /cacti {
        try_files   $uri $uri/ /index.php?$query_string;
        autoindex on;
    }

    location ~ \.php$ {
        try_files $uri /index.php =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_index index.php;
        fastcgi_param GEOIP_COUNTRY_CODE $geoip_country_code;
        fastcgi_param GEOIP_COUNTRY_NAME $geoip_country_name;
        fastcgi_param SCRIPT_FILENAME $request_filename;
        include fastcgi_params;
    }
        location ~* \.(jpg|jpeg|png|gif|ico|css|js)$ {
        expires 7d;
        add_header Pragma public;
        add_header Cache-Control "public, must-revalidate, proxy-revalidate";
    }
}
root@bsd11:/usr/local/etc/nginx/conf.d #

 

default.conf 파일 수정

root@bsd11:/usr/local/etc/nginx/conf.d # 
root@bsd11:/usr/local/etc/nginx/conf.d # vi default.conf
server {
    listen       80 default_server;
    server_name  localhost _;
    index        index.php index.html index.htm;
    root         /var/www/test.crois.net;

    location / {
        try_files   $uri $uri/ /index.php?$query_string;
        autoindex on;
    }

    location /server-status {
        stub_status on;
        allow 127.0.0.1;
        #deny all;
    }

    location ~ \.php$ {
        try_files $uri /index.php =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_index index.php;
        fastcgi_param GEOIP_COUNTRY_CODE $geoip_country_code;
        fastcgi_param GEOIP_COUNTRY_NAME $geoip_country_name;
        fastcgi_param SCRIPT_FILENAME $request_filename;
        include fastcgi_params;
    }
}

localtion 항목 추가

 

root@bsd11:~ # 
root@bsd11:~ # service nginx restart
Performing sanity check on nginx configuration:
nginx: the configuration file /usr/local/etc/nginx/nginx.conf syntax is ok
nginx: configuration file /usr/local/etc/nginx/nginx.conf test is successful
Stopping nginx.
Waiting for PIDS: 4123.
Performing sanity check on nginx configuration:
nginx: the configuration file /usr/local/etc/nginx/nginx.conf syntax is ok
nginx: configuration file /usr/local/etc/nginx/nginx.conf test is successful
Starting nginx.
root@bsd11:~ #

root@bsd11:~ # curl http://localhost/server-status
Active connections: 1
server accepts handled requests
 1 1 1
Reading: 0 Writing: 1 Waiting: 0
root@bsd11:~ #

 

Nginx 템플릿 추가

root@bsd11:~ #
root@bsd11:~ #
root@bsd11:~ # php /usr/local/share/cacti/cli/import_template.php --filename=/usr/local/share/percona-monitoring-plugins/cacti/templates/cacti_host_template_percona_nginx_server_ht_0.8.6i-sver1.1.3.xml
Read 42601 bytes of XML data
Import ResultsCacti has imported the following items for the Template:
CDEF
[success] Percona Turn Into Bits CDEF [unchanged]
[success] Percona Negate CDEF [unchanged]
GPRINT Preset
[success] Percona Nginx Server Checksum 9d9b37b126648a09bb56030a539e8b2e [new]
[success] Percona Nginx Server Version t1.1.3:s1.1.3 [new]
[success] Percona Normal [unchanged]
Data Input Method
[success] Percona Get Nginx Stats/Nginx Requests IM [new]
[success] Percona Get Nginx Stats/Nginx Accepts/Handled IM [new]
[success] Percona Get Nginx Stats/Nginx Scoreboard IM [new]
Data Template
[success] Percona Nginx Requests DT [new]
[success] Percona Nginx Accepts/Handled DT [new]
[success] Percona Nginx Scoreboard DT [new]
Graph Template
[success] Percona Nginx Requests GT [new]
[success] Percona Nginx Accepts/Handled GT [new]
[success] Percona Nginx Scoreboard GT [new]
Device Template
[success] Percona Nginx Server HT [new]
root@bsd11:~ #

 

Data Collection -> Data Input Methods 

Percona Get Nginx Stats/Nginx Accepts/Handled IM 

Percona Get Nginx Stats/Nginx Requests IM

Percona Get Nginx Stats/Nginx Scoreboard IM 

을 편집 합니다. 

 

Percona Get Nginx Stats/Nginx Accepts/Handled IM 수정

Input Sting 수정

수정전 

<path_php_binary> -q <path_cacti>/scripts/ss_get_by_ssh.php --host <hostname> --type nginx --items hx,hy 
--server <server> --url <url> --http-user <http-user> --http-password <password>

 

수정후 

<path_php_binary> -q <path_cacti>/scripts/ss_get_by_ssh.php --host <hostname> --type nginx --items hx,hy

 

Save 를 클릭 하여 저장을 합니다.

동일하게 설정 합니다.

 

Management -> Devices 로 이동하여 Nginx-Server Device 를 생성 합니다.

 

Create Graphs for this Device 를 클릭하여 그래프를 생성 합니다.

 

Graphs 로 이동하여 모니터링 결과를 확인 합니다. (약 5 ~ 10분 정도 시간이 걸립니다.)

 

cacti 유저 변경후 ss_get_by_ssh.php 스크립트 확인

root@bsd11:~ # 
root@bsd11:~ # su - cacti
% php /usr/local/share/cacti/scripts/ss_get_by_ssh.php --type nginx --host 127.0.0.1 --items hw,hx
hw:1 hx:56%

 

cacti log (/var/log/cacti/log file) 정상적인 경우

2017-11-22 21:32:00 - SPINE: Poller[1] DEBUG: In Poller, About to Start Polling of Device for Device ID 6
2017-11-22 21:32:00 - SPINE: Poller[1] Device[6] DEBUG: Entering SNMP Ping
2017-11-22 21:32:00 - SPINE: Poller[1] Updating Full System Information Table
2017-11-22 21:32:00 - SPINE: Poller[1] Device[6] TH[1] Device has no information for recache.
2017-11-22 21:32:00 - SPINE: Poller[1] Device[6] TH[1] NOTE: There are '1' Polling Items for this Device
2017-11-22 21:32:00 - SPINE: Poller[1] Device[6] DEBUG: The NIFTY POPEN returned the following File Descriptor 7

2017-11-22 21:32:00 - SPINE: Poller[1] Device[6] TH[1] DS[34] SCRIPT: /usr/local/bin/php -q /usr/local/share/cacti/scripts/ss_get_by_ssh.php --host '127.0.0.1' --type nginx --items hx,hy , output: hx:46196 hy:46196


2017-11-22 21:32:00 - SPINE: Poller[1] Device[6] TH[1] Total Time:  0.42 Seconds
2017-11-22 21:32:00 - SPINE: Poller[1] Device[6] TH[1] DEBUG: HOST COMPLETE: About to Exit Device Polling Thread Function
2017-11-22 21:32:00 - SPINE: Poller[1] DEBUG: The Value of Active Threads is 0 for Device ID 6
2017/11/22 21:32:02 - SYSTEM STATS: Time:2.3135 Method:spine Processes:2 Threads:16 Hosts:2 HostsPerProcess:1 DataSources:2 RRDsProcessed:4
2017-11-22 21:33:00 - SPINE: Poller[1] DEBUG: In Poller, About to Start Polling of Device for Device ID 6
2017-11-22 21:33:00 - SPINE: Poller[1] Device[6] DEBUG: Entering SNMP Ping
2017-11-22 21:33:00 - SPINE: Poller[1] Updating Full System Information Table
2017-11-22 21:33:00 - SPINE: Poller[1] Device[6] TH[1] Device has no information for recache.
2017-11-22 21:33:00 - SPINE: Poller[1] Device[6] TH[1] NOTE: There are '1' Polling Items for this Device
2017-11-22 21:33:00 - SPINE: Poller[1] Device[6] DEBUG: The NIFTY POPEN returned the following File Descriptor 7

2017-11-22 21:33:00 - SPINE: Poller[1] Device[6] TH[1] DS[35] SCRIPT: /usr/local/bin/php -q /usr/local/share/cacti/scripts/ss_get_by_ssh.php --host '127.0.0.1' --type nginx --items hz , output: hz:191937


2017-11-22 21:33:00 - SPINE: Poller[1] Device[6] TH[1] Total Time: 0.086 Seconds
2017-11-22 21:33:00 - SPINE: Poller[1] Device[6] TH[1] DEBUG: HOST COMPLETE: About to Exit Device Polling Thread Function
2017-11-22 21:33:00 - SPINE: Poller[1] DEBUG: The Value of Active Threads is 0 for Device ID 6
2017/11/22 21:33:02 - SYSTEM STATS: Time:2.2942 Method:spine Processes:2 Threads:16 Hosts:2 HostsPerProcess:1 DataSources:2 RRDsProcessed:4
2017-11-22 21:34:00 - SPINE: Poller[1] DEBUG: In Poller, About to Start Polling of Device for Device ID 6
2017-11-22 21:34:00 - SPINE: Poller[1] Device[6] DEBUG: Entering SNMP Ping
2017-11-22 21:34:00 - SPINE: Poller[1] Updating Full System Information Table
2017-11-22 21:34:00 - SPINE: Poller[1] Device[6] TH[1] Device has no information for recache.
2017-11-22 21:34:00 - SPINE: Poller[1] Device[6] TH[1] NOTE: There are '1' Polling Items for this Device
2017-11-22 21:34:00 - SPINE: Poller[1] Device[6] DEBUG: The NIFTY POPEN returned the following File Descriptor 7

2017-11-22 21:34:00 - SPINE: Poller[1] Device[6] TH[1] DS[36] SCRIPT: /usr/local/bin/php -q /usr/local/share/cacti/scripts/ss_get_by_ssh.php --host '127.0.0.1' --type nginx --items hw,ig,ih,ii , output: hw:101 ig:0 ih:98 ii:3


2017-11-22 21:34:00 - SPINE: Poller[1] Device[6] TH[1] Total Time:  0.11 Seconds
2017-11-22 21:34:00 - SPINE: Poller[1] Device[6] TH[1] DEBUG: HOST COMPLETE: About to Exit Device Polling Thread Function
2017-11-22 21:34:00 - SPINE: Poller[1] DEBUG: The Value of Active Threads is 0 for Device ID 6
2017/11/22 21:34:02 - SYSTEM STATS: Time:2.2448 Method:spine Processes:2 Threads:16 Hosts:2 HostsPerProcess:1 DataSources:2 RRDsProcessed:4

output: 메세지에 -1 이 아닌 정상적인 값이 출력 됩니다.

 

Data Input Methods 수정을 안할경우 아래와 같은 메시지가 출력 됩니다. 

output: 메시지에 -1 이 출력 됩니다.

 

정상적으로 모니터링이 되지 않아 Debug 모드 enable 후 /var/log/cacti/log 확인 하였지만 정상적으로 그래프 생성이 안되는 것을 확인 하였습니다.

단, log 확인시 –server , –url , –http-user , –http-password 필드 사용시 문제가 되는것을 확인 하였습니다.

 

cacti log (/var/log/cacti/log file) 비정상인 경우 

2017-11-22 03:36:00 - SPINE: Poller[1] Device[5] TH[1] DS[31] SCRIPT: /usr/local/bin/php -q /usr/local/share/cacti/scripts/ss_get_by_ssh.php 
--host '127.0.0.1' --type nginx --items hx,hy --server '' --url '' --http-user '' --http-password , 
output: hx:-1 hy:-1


2017-11-22 03:36:00 - SPINE: Poller[1] Device[5] DEBUG: The NIFTY POPEN returned the following File Descriptor 7
2017-11-22 03:36:00 - SPINE: Poller[1] Device[5] TH[1] DS[32] SCRIPT: /usr/local/bin/php -q /usr/local/share/cacti/scripts/ss_get_by_ssh.php 
--host '127.0.0.1' --type nginx --items hz --server '' --url '' --http-user '' --http-password , 
output: hz:-1


2017-11-22 03:36:00 - SPINE: Poller[1] Device[5] DEBUG: The NIFTY POPEN returned the following File Descriptor 7
2017-11-22 03:36:01 - SPINE: Poller[1] Device[5] TH[1] DS[33] SCRIPT: /usr/local/bin/php -q /usr/local/share/cacti/scripts/ss_get_by_ssh.php 
--host '127.0.0.1' --type nginx --items hw,ig,ih,ii --server '' --url '' --http-user '' --http-password , 
output: hw:-1 ig:-1 ih:-1 ii:-1

output: -1 로 나오는것을 확인 할수 있습니다.

 

cacti User 테스트 

root@bsd11:~/.ssh # su - cacti
% /usr/local/bin/php -q /usr/local/share/cacti/scripts/ss_get_by_ssh.php --host '127.0.0.1' --type nginx 
--items hw,ig,ih,ii --server '' --url '' --http-user '' --http-password ''
hw:-1 ig:-1 ih:-1 ii:-1%

모든 값이 -1 값으로 나옵니다.

 

필드 제거후 테스트

% /usr/local/bin/php -q /usr/local/share/cacti/scripts/ss_get_by_ssh.php --host '127.0.0.1' --type nginx --items hw,ig,ih,ii
hw:51 ig:0 ih:50 ii:1%

정상값을 확인 할수 있습니다.

 

 

댓글 남기기