zabbix自帶了一些模版,可根據須要修改對應監控項的閾值;但是像nginx/ph-fpm/redis/mysql等一些應用還須要咱們自定義監控項、用腳本在客戶端取值。下面簡單監控nginx和php-fpm的狀態:兩者自己自帶status參數,只需開啓便可。php
1,開啓statushtml
vi /etc/php-fpm.conf 尾部添加一行
pm.status_path = /php-fpm_statusmysql
cd /etc/nginc/conf.d/
vi nginxphp_status.conf
server {nginx
listen 40080;
allow 127.0.0.1;
deny all;
access_log off;
location /php-fpm_status {
fastcgi_pass 127.0.0.1:9000;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $fastcgi_script_name;
}git
location /nginx_status {
stub_status on;
}
}github
service php-fpm restart
service nginx restartweb
curl -s http://127.0.0.1:40080/nginx_status
Active connections: 1
server accepts handled requests
6 6 6
Reading: 0 Writing: 1 Waiting: 0redis
nginx status詳解
active connections – 活躍的鏈接數
server accepts handled requests — 總共處理了6個鏈接 , 成功建立6次握手, 總共處理了6個請求
reading — 讀取客戶端的鏈接數
writing — 響應數據到客戶端的數量
waiting — 開啓 keep-alive 的狀況下,這個值等於 active – (reading+writing), 意思就是 Nginx 已經處理完正在等候下一次請求指令的駐留鏈接。因此,在訪問效率高,請求很快被處理完畢的狀況下,Waiting數比較可能是正常的.若是reading +writing數較多,則說明併發訪問量很是大,正在處理過程當中。sql
curl -s http://127.0.0.1:40080/php-fpm_status
pool: www
process manager: dynamic
start time: 17/Aug/2017:17:09:32 +0800
start since: 64
accepted conn: 2
listen queue: 0
max listen queue: 0
listen queue len: 128
idle processes: 4
active processes: 1
total processes: 5
max active processes: 1
max children reached: 0
slow requests: 0shell
php-fpm status詳解
pool – fpm池子名稱,大多數爲www
process manager – 進程管理方式,值:static, dynamic or ondemand. dynamic
start time – 啓動日期,若是reload了php-fpm,時間會更新
start since – 運行時長
accepted conn – 當前池子接受的請求數
listen queue – 請求等待隊列,若是這個值不爲0,那麼要增長FPM的進程數量
max listen queue – 請求等待隊列最高的數量
listen queue len – socket等待隊列長度
idle processes – 空閒進程數量
active processes – 活躍進程數量
total processes – 總進程數量
max active processes – 最大的活躍進程數量(FPM啓動開始算)
max children reached - 大道進程最大數量限制的次數,若是這個數量不爲0,那說明你的最大進程數量大小了,需改大一點。
php-fpm狀態頁能夠經過帶參數實現個性化,能夠帶參數json、xml、html而且前面三個參數能夠分別和full作一個組合。
json格式:http://127.0.0.1:40080/php-status?json
xml格式: http://127.0.0.1:40080/php-status?xml
html 格式: http://127.0.0.1:40080/php-status?html
full格式: http://127.0.0.1:40080/php-status?ful
2,在zabbix agent端新建shell腳原本取值
cd /etc/zabbix/zabbix_agentd.d
vi php-fpm_status.sh
#!/bin/bash
idle(){
wget --quiet -O - http://127.0.0.1:40080/php-fpm_status?auto |grep "idle processes" |awk '{print$3}'
}
total(){
wget --quiet -O - http://127.0.0.1:40080/php-fpm_status?auto |grep "total processes" |awk '{print$3}'
}
active(){
wget --quiet -O - http://127.0.0.1:40080/php-fpm_status?auto |grep "active" |awk '{print$3}'|grep -v "process"
}
mactive(){
wget --quiet -O - http://127.0.0.1:40080/php-fpm_status?auto |grep "max active processes:" |awk '{print$4}'
}
listenqueuelen(){
wget --quiet -O - http://127.0.0.1:40080/php-fpm_status?auto |grep "listen queue len" |awk '{print$4}'
}
listenqueue(){
wget --quiet -O - http://127.0.0.1:40080/php-fpm_status?auto |grep "listen queue:"|grep -vE "len|max"|awk '{print$3}'
}
since(){
wget --quiet -O - http://127.0.0.1:40080/php-fpm_status?auto |grep "start since: " |awk '{print$3}'
}
conn(){
wget --quiet -O - http://127.0.0.1:40080/php-fpm_status?auto |grep "accepted conn" |awk '{print$3}'
}
$1
vi nginx_status.sh
#!/bin/bash
Active(){
wget --quiet -O - http://localhost:40080/nginx_status?auto |awk 'NR==1 {print$3}'
}
Reading(){
wget --quiet -O - http://localhost:40080/nginx_status?auto |awk 'NR==4 {print$2}'
}
Writing(){
wget --quiet -O - http://localhost:40080/nginx_status?auto |awk 'NR==4 {print$4}'
}
Waiting(){
wget --quiet -O - http://localhost:40080/nginx_status?auto |awk 'NR==4 {print$6}'
}
$1
3,修改/etc/zabbix/zabbix_agentd.conf添加一下內容
UnsafeUserParameters=1
UserParameter=idle.processe,/etc/zabbix/zabbix_agentd.d/php-fpm_status.sh idle
UserParameter=total.processes,/etc/zabbix/zabbix_agentd.d/php-fpm_status.sh total
UserParameter=active.processes,/etc/zabbix/zabbix_agentd.d/php-fpm_status.sh active
UserParameter=max.active.processes,/etc/zabbix/zabbix_agentd.d/php-fpm_status.sh mactive
UserParameter=listen.queue.len,/etc/zabbix/zabbix_agentd.d/php-fpm_status.sh listenqueuelen
UserParameter=listen.queue,/etc/zabbix/zabbix_agentd.d/php-fpm_status.sh listenqueue
UserParameter=start.since,/etc/zabbix/zabbix_agentd.d/php-fpm_status.sh since
UserParameter=accepted.conn,/etc/zabbix/zabbix_agentd.d/php-fpm_status.sh conn
UserParameter=Active,/etc/zabbix/zabbix_agentd.d/nginx_status.sh Active
UserParameter=Reading,/etc/zabbix/zabbix_agentd.d/nginx_status.sh Reading
UserParameter=Writing,/etc/zabbix/zabbix_agentd.d/nginx_status.sh Writing
UserParameter=Waiting,/etc/zabbix/zabbix_agentd.d/nginx_status.sh Waiting
service zabbix-agent restart
4,在zabbix web端導入如下模版
http://pan.baidu.com/s/1bp3wJYf
將主機關聯以上模版,隨後在最新數據裏查看是否收集到監控值
github上搜索zabbix會看到不少開源的監控模版,挑你須要的試試吧