|
Nginx自带监控模块ngx_http_stub_status_module提供Nginx的基本信息
在编译安装Nginx时加参数 --with-http_stub_status_module
安装好以后可以通过nginx -V|grep http_stub_status_module 查看状态模块是否已安装
PHP-FPM也自带监控,通过在php-fpm.conf中设置
pm.status_path = /php-fpm_status
就可以获取URL的方式获取PHP-FPM的状态
参考文章
https://rtcamp.com/tutorials/php/fpm-status-page/
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
| server {
listen 88 ;
location /nginx_status {
stub_status on;
access_log off;
allow 127.0.0.1;
# allow 10.4.1.125;
deny all;
}
location /php-fpm_status {
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
|
1
2
3
4
5
| $ curl 127.0.0.1:88/nginx_status
Active connections: 1
server accepts handled requests
788163 788163 788163
Reading: 0 Writing: 1 Waiting: 0
|
Active connections
The current number of active client connections including Waiting connections.
活跃客户端连接数,包括处于等待状态的连接数
accepts
The total number of accepted client connections.
接收到的客户端连接总数
handled
The total number of handled connections. Generally, the parameter value is the same as accepts unless some resource limits have been reached
处理请求的总数。通常情况下,这个值和accepts的值相同。除非达到了一些资源限制。例如设置worker_connections 1024; 设置一个worker进程能够打开的最大并发连接数。
requests
The total number of client requests.
客户端请求总数
Reading
The current number of connections where nginx is reading the request header.
当前Nginx正在读取请求头的连接数量
Writing
The current number of connections where nginx is writing the response back to the client.
当前Nginx正在将响应写回到客户端的连接数量
Waiting
The current number of idle client connections waiting for a request.
当前正在等待请求的闲置客户端连接数量
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
| $ curl 127.0.0.1:88/php-fpm_status
pool: www
process manager: dynamic
start time: 16/Nov/2014:13:29:11 +0800
start since: 77844
accepted conn: 202788
listen queue: 0
max listen queue: 1
listen queue len: 128
idle processes: 6
active processes: 1
total processes: 7
max active processes: 4
max children reached: 0
slow requests: 0
|
pool pool名称
process manager static or dynamic
start time 启动时间
start since 启动了多长时间,以秒为单位
accepted conn pool接收到的请求数量
listen queue the number of request in the queue of pending connections.这个值如果不为0,最好增加PHP-FPM的进程数量
max listen queue the maximum number of requests in the queue of pending connections since FPM has started
listen queue len the size of the socket queue of pending connections
idle processes the number of idle processes
active processes the number of active processes
total processes the number of idle + active processes
max active processes the maximum number of active processes since FPM has started
max children reached number of times, the process limit has been reached, when pm tries to start more children. If that value is not zero, then you may need to increase max process limit for your PHP-FPM pool. Like this, you can find other useful information to tweak your pool better way.如果这个值不为0,最好增大最大进程的限制。
slow requests 如果这个值不为0,表示有处理慢的程序
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
| $ curl 127.0.0.1:88/php-fpm_status?full
pool: www
process manager: dynamic
start time: 17/Nov/2014:16:09:17 +0800
start since: 1139
accepted conn: 3354
listen queue: 0
max listen queue: 0
listen queue len: 128
idle processes: 5
active processes: 1
total processes: 6
max active processes: 2
max children reached: 0
slow requests: 0
************************
pid: 19921
state: Idle
start time: 17/Nov/2014:16:09:17 +0800
start since: 1139
requests: 563
request duration: 223
request method: GET
request URI: /php-fpm_status
content length: 0
user: -
script: -
last request cpu: 0.00
last request memory: 262144
|
curl 127.0.0.1:88/php-fpm_status?json
curl 127.0.0.1:88/php-fpm_status?html
curl 127.0.0.1:88/php-fpm_status?xml
2.编写Nginx和PHP-FPM状态信息获取脚本
nginx_status.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
| #!/bin/bash
#check nginx status
#ip=$(ifconfig eth0|grep "inet addr"|sed 's/^.*addr://'|awk '{print $1}')
#echo $ip
ip=127.0.0.1
port=88
#echo $ip:$port
function active() {
/usr/bin/curl http://$ip:$port/nginx_status 2>/dev/null|grep "Active"|awk '{print $NF}'
}
function reading() {
/usr/bin/curl http://$ip:$port/nginx_status 2>/dev/null|grep "Reading"|awk '{print $2}'
}
function writing() {
/usr/bin/curl http://$ip:$port/nginx_status 2>/dev/null|grep "Writing"|awk '{print $4}'
}
function waiting() {
/usr/bin/curl http://$ip:$port/nginx_status 2>/dev/null|grep "Waiting"|awk '{print $6}'
}
function accepts() {
/usr/bin/curl http://$ip:$port/nginx_status 2>/dev/null|awk 'NR==3{print $1}'
}
function handled() {
/usr/bin/curl http://$ip:$port/nginx_status 2>/dev/null|awk 'NR==3{print $2}'
}
function requests(){
/usr/bin/curl http://$ip:$port/nginx_status 2>/dev/null|awk 'NR==3{print $3}'
}
case $1 in
active)
active
;;
reading)
reading
;;
writing)
writing
;;
waiting)
waiting
;;
accepts)
accepts
;;
handled)
handled
;;
requests)
requests
;;
*)
exit 1
;;
esac
|
php-fpm_status.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
| #!/bin/bash
#check php-fpm status
ip=127.0.0.1
port=88
function idle() {
/usr/bin/curl http://$ip:$port/php-fpm_status 2>/dev/null|grep "idle processes"|awk '{print $3}'
}
function active() {
/usr/bin/curl http://$ip:$port/php-fpm_status 2>/dev/null|grep "active processes"|awk '{print $3}'|grep -v "processes"
}
function total() {
/usr/bin/curl http://$ip:$port/php-fpm_status 2>/dev/null|grep "total processes"|awk '{print $3}'|grep -v "processes"
}
function mactive() {
/usr/bin/curl http://$ip:$port/php-fpm_status 2>/dev/null|grep "max active processes"|awk '{print $4}'
}
function conn() {
/usr/bin/curl http://$ip:$port/php-fpm_status 2>/dev/null|grep "accepted conn"|awk '{print $3}'
}
function since() {
/usr/bin/curl http://$ip:$port/php-fpm_status 2>/dev/null|grep "start since"|awk '{print $3}'
}
function slow() {
/usr/bin/curl http://$ip:$port/php-fpm_status 2>/dev/null|grep "slow requests"|awk '{print $3}'
}
function listenqueue() {
/usr/bin/curl http://$ip:$port/php-fpm_status 2>/dev/null|grep "listen queue:"|grep -v "max"|awk '{print $3}'
}
function maxlistenqueue() {
/usr/bin/curl http://$ip:$port/php-fpm_status 2>/dev/null|grep "max listen queue:"|awk '{print $4}'
}
function listenqueuelen() {
/usr/bin/curl http://$ip:$port/php-fpm_status 2>/dev/null|grep "listen queue len:"|awk '{print $4}'
}
function maxchildren() {
/usr/bin/curl http://$ip:$port/php-fpm_status 2>/dev/null|grep "max children reached:"|awk '{print $4}'
}
$1
|
3.添加zabbix的子配置文件
nginx_status_zabbix.conf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
| ### Option: UserParameter
# User-defined parameter to monitor. There can be several user-defined parameters.
# Format: UserParameter=<key>,<shell command>
# See 'zabbix_agentd' directory for examples.
#
# Mandatory: no
# Default:
# UserParameter=
# /usr/local/zabbix/bin/nginx_status.sh
UserParameter=nginx.accepts,/usr/local/zabbix/bin/nginx_status.sh accepts
UserParameter=nginx.handled,/usr/local/zabbix/bin/nginx_status.sh handled
UserParameter=nginx.requests,/usr/local/zabbix/bin/nginx_status.sh requests
UserParameter=nginx.connections.active,/usr/local/zabbix/bin/nginx_status.sh active
UserParameter=nginx.connections.reading,/usr/local/zabbix/bin/nginx_status.sh reading
UserParameter=nginx.connections.writing,/usr/local/zabbix/bin/nginx_status.sh writing
UserParameter=nginx.connections.waiting,/usr/local/zabbix/bin/nginx_status.sh waiting
|
php-fpm_status.conf
1
2
3
4
5
6
7
8
9
10
11
| UserParameter=php-fpm.idle.processes,/usr/local/zabbix/bin/php-fpm_status.sh idle
UserParameter=php-fpm.total.processes,/usr/local/zabbix/bin/php-fpm_status.sh total
UserParameter=php-fpm.active.processes,/usr/local/zabbix/bin/php-fpm_status.sh active
UserParameter=php-fpm.max.active.processes,/usr/local/zabbix/bin/php-fpm_status.sh mactive
UserParameter=php-fpm.listen.queue.len,/usr/local/zabbix/bin/php-fpm_status.sh listenqueuelen
UserParameter=php-fpm.listen.queue,/usr/local/zabbix/bin/php-fpm_status.sh listenqueue
UserParameter=php-fpm.start.since,/usr/local/zabbix/bin/php-fpm_status.sh since
UserParameter=php-fpm.accepted.conn,/usr/local/zabbix/bin/php-fpm_status.sh conn
UserParameter=php-fpm.slow.requests,/usr/local/zabbix/bin/php-fpm_status.sh slow
UserParameter=php-fpm.max.listen.queue,/usr/local/zabbix/bin/php-fpm_status.sh maxlistenqueue
UserParameter=php-fpm.max.children,/usr/local/zabbix/bin/php-fpm_status.sh maxchildren
|
4.添加zabbix监控模板
Template Nginx .xml
(21 KB, 下载次数: 5)
Template PHP-FPM.xml
(47.75 KB, 下载次数: 16)
|
|