rthtge 发表于 2014-12-30 08:09:41

zabbix 监控php

本帖最后由 rthtge 于 2014-12-30 08:10 编辑

zabbix安装好了之后,由于公司目前都是php环境,需要监控下,网上查了些资料把过程记录了下

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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
vim /usr/local/php/etc/php-fpm.conf
添加
pm.status_path = /phpfpmstatus

vim /usr/local/nginx/conf/nginx.conf
添加
server {
      listen       80;
      server_namelocalhost;
      location ~ ^/(phpfpmstatus)$ {
             include fastcgi_params;
             fastcgi_pass 127.0.0.1:9000;
             fastcgi_param SCRIPT_FILENAME $fastcgi_script_name;
      }
}

vim /usr/local/zabbix/etc/zabbix_agentd.conf
UnsafeUserParameters=1
UserParameter=phpfpm.status.pool,/usr/local/zabbix/etc/scripts/monitor_phpfpm_status pool
UserParameter=phpfpm.status.process.manager,/usr/local/zabbix/etc/scripts/monitor_phpfpm_status process_manager
UserParameter=phpfpm.status.start.since,/usr/local/zabbix/etc/scripts/monitor_phpfpm_status start_since
UserParameter=phpfpm.status.accepted.conn,/usr/local/zabbix/etc/scripts/monitor_phpfpm_status accepted_conn
UserParameter=phpfpm.status.listen.queue,/usr/local/zabbix/etc/scripts/monitor_phpfpm_status listen_queue
UserParameter=phpfpm.status.max.listen.queue,/usr/local/zabbix/etc/scripts/monitor_phpfpm_status max_listen_queue
UserParameter=phpfpm.status.listen.queue.len,/usr/local/zabbix/etc/scripts/monitor_phpfpm_status listen_queue_len
UserParameter=phpfpm.status.idle.processes,/usr/local/zabbix/etc/scripts/monitor_phpfpm_status idle_processes
UserParameter=phpfpm.status.active.processes,/usr/local/zabbix/etc/scripts/monitor_phpfpm_status active_processes
UserParameter=phpfpm.status.total.processes,/usr/local/zabbix/etc/scripts/monitor_phpfpm_status total_processes
UserParameter=phpfpm.status.max.active.processes,/usr/local/zabbix/etc/scripts/monitor_phpfpm_status max_active_processes
UserParameter=phpfpm.status.max.children.reached,/usr/local/zabbix/etc/scripts/monitor_phpfpm_status max_children_reached

vim/usr/local/zabbix/etc/scripts/monitor_phpfpm_status

#!/bin/bash
source /etc/bashrc >/dev/null 2>&1
source /etc/profile>/dev/null 2>&1

LOG_FILE=/tmp/phpfpmstatus.log
curl http://127.0.0.1/phpfpmstatus >${LOG_FILE}

pool(){
      awk '/pool/ {print $NF}' ${LOG_FILE}
}      
process_manager() {      
      awk '/process manager/ {print $NF}' ${LOG_FILE}
}

start_since(){
    awk '/start since:/ {print $NF}' ${LOG_FILE}
}
accepted_conn(){
    awk '/accepted conn:/ {print $NF}' ${LOG_FILE}
}
listen_queue(){   
    awk '/listen queue:/ {print $NF}' ${LOG_FILE}
}
max_listen_queue(){
    awk '/max listen queue:/ {print $NF}' ${LOG_FILE}
}
listen_queue_len(){
    awk '/listen queue len:/ {print $NF}' ${LOG_FILE}
}
idle_processes(){
    awk '/idle processes:/ {print $NF}' ${LOG_FILE}
}
active_processes(){
    awk '/active processes:/ {print $NF}' ${LOG_FILE}
}
total_processes(){
    awk '/total processes:/ {print $NF}' ${LOG_FILE}
}
max_active_processes(){
    awk '/max active processes:/ {print $NF}' ${LOG_FILE}
}
max_children_reached(){
    awk '/max children reached:/ {print $NF}' ${LOG_FILE}
}


case "$1" in
pool)
pool
;;
process_manager)
process_manager
;;
start_since)
start_since
;;
accepted_conn)
accepted_conn
;;
listen_queue)
listen_queue
;;
max_listen_queue)
max_listen_queue
;;
listen_queue_len)
listen_queue_len
;;
idle_processes)
idle_processes
;;
active_processes)
active_processes
;;
total_processes)
total_processes
;;
max_active_processes)
max_active_processes
;;
max_children_reached)
max_children_reached
;;
*)
echo "Usage: $0 {pool|process_manager|start_since|accepted_conn|listen_queue|max_listen_queue|listen_queue_len|idle_processes|active
_processes|total_processes|max_active_processes|max_children_reached}"
esac

chmod 755 /usr/local/zabbix/etc/scripts/monitor_phpfpm_status
最后重启nginx php-fpm
然后导入php-fpm模块,关联到相应主机








1
参考地址https://github.com/pengyao/zabbix/tree/master/PHP-FPM



页: [1]
查看完整版本: zabbix 监控php