Zabbix Monitor Nginx and FPM (website concurrency) custom key

Source: Internet
Author: User
Tags fpm pkill

Monitor Nginx, mainly to monitor the concurrency number:
1:nginx Compile Parameters:
--prefix=/usr/local/nginx--with-http_stub_status_module

Zabbix Compile parameter view:
/usr/local/nginx/sbin/nginx-v
Nginx version:nginx/1.8.1
Built by GCC 4.4.7 20120313 (Red Hat 4.4.7-18) (GCC)
Built with OpenSSL 1.0.1e-fips 2013
TLS SNI Support Enabled
Configure arguments:--prefix=/usr/local/nginx--with-http_ssl_module--with-http_stub_status_module

2:nginx Configuration New

Location/status {
Allow 127.0.0.1;
Deny all;
Stub_status on;
Access_log off;
}
Restart Nginx:
/usr/local/nginx/sbin/nginx-t
/usr/local/nginx/sbin/nginx-s Reload

3: Test to see if you can get Nginx status
Curl 127.0.0.1/status

4: Write script to get Nginx status
Monitoring Scripts (/usr/local/zabbix/check_nginx.sh):

#!/bin/sh
#20170603 nginx Status
#Active connections:1
#server accepts handled requests
#1035268066 1035268066 1035136592
#Reading: 0 writing:1 waiting:0
While Getopts "O:" opt
Do
Case $opt in
o) option= $OPTARG;;
? )
echo ' parameter is wrong! '
Exit 1;;
Esac
Done
if [! "${option}"];then
echo "parameter is null"
Exit 1
Fi

if [[${option} = = "Active"]];then
Curl-s 127.0.0.1/status |grep ' ^active connections ' |awk ' {print $NF} '
elif [[${option} = = "Accepts"]];then
Curl-s 127.0.0.1/status |awk ' nr==3 ' |awk ' {print $} '
Fi

5:zabbix configuration (/usr/local/zabbix/etc/zabbix_agentd.conf.d/nginx.conf):
Userparameter=nginx.status[*],sh/usr/local/zabbix/check_nginx.sh-o $
Restart Zabbix agentd (Pkill zabbix_agentd; sleep 3;/usr/local/zabbix/sbin/zabbix_agentd)

6:zabbix Web page configuration:
Nginx.status[accepts]xxx (difference per second)

Monitoring fpm, mainly on monitoring the number of dynamic concurrency:
1:/usr/local/php/etc/php-fpm.conf fpm Configuration added:
Pm.status_path =/php_fpm_status
FPM needs to be restarted.

2:nginx Configuration added:

Location/php_fpm_status
{
Allow 127.0.0.1;
Deny all;
Fastcgi_pass 127.0.0.1:9000;
Fastcgi_param script_filename $document _root$fastcgi_script_name;
Include Fastcgi_params;
}
Nginx needs reload

3: Test to see if you can get the status of FPM
Curl 127.0.0.1/php_fpm_status
Pool:www
Process Manager:static
Start time:02/jun/2017:17:45:05 +0800
Start since:58677
Accepted conn:10753843
Listen queue:0
Max Listen queue:0
Listen Queue len:0
Idle processes:249
Active processes:1
Total processes:250
Max Active processes:251
Max Children reached:0
Slow requests:426

4: Write a script to get the status of FPM
Monitoring Scripts (/usr/local/zabbix/check_fpm.sh):

#!/bin/sh
#20170603 fpm status
#curl 127.0.0.1/php_fpm_status
#pool: www
#process manager:static
#start time:02/jun/2017:17:45:05 +0800
#start since:59022
#accepted conn:10768453
#listen queue:0
#max Listen queue:0
#listen queue len:0
#idle processes:249
#active processes:1
#total processes:250
#max A ctive processes:251
#max children reached:0
#slow requests:426
while getopts "O:" opt
does
case $opt IN
o) option= $OPTARG;;
?)
Echo ' parameter is wrong! '
exit 1;;
Esac
Done
If [! "${option}"];then
echo "parameter is null"
Exit 1
Fi

if [[${option} = = "Conn"]];then
Curl-s 127.0.0.1/php_fpm_status |grep ' ^accepted conn ' |awk ' {print $NF} '
elif [[${option} = = "Idle"]];then
Curl-s 127.0.0.1/php_fpm_status |grep ' ^idle processes ' |awk ' {print $NF} '
elif [[${option} = = "Active"]];then
Curl-s 127.0.0.1/php_fpm_status |grep ' ^active processes ' |awk ' {print $NF} '
Fi

5:zabbix configuration (vim/usr/local/zabbix/etc/zabbix_agentd.conf.d/fpm.conf):

Userparameter=fpm.status[*],sh/usr/local/zabbix/check_fpm.sh-o $
Restart the Zabbix agent. Pkill Zabbix_agentd; Sleep 3; /usr/local/zabbix/sbin/zabbix_agentd

6:zabbix Web page configuration:
Fpm.status[conn]

Zabbix Monitor Nginx and FPM (website concurrency) custom key

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.